Skip to content

Commit f622f93

Browse files
Merge pull request #2801 from ReliefApplications/next
Next
2 parents 958dea2 + 510f000 commit f622f93

File tree

2 files changed

+55
-50
lines changed

2 files changed

+55
-50
lines changed

libs/shared/src/lib/components/widgets/editor/editor.component.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
}"
66
(click)="onClick($event)"
77
>
8-
<div
9-
*ngIf="!loading; else loadingTmpl"
10-
class="w-full h-fit"
11-
(click)="onClick($event)"
12-
>
8+
<div *ngIf="!loading; else loadingTmpl" class="w-full h-fit">
139
<shared-html-widget-content
1410
[html]="formattedHtml"
1511
[style]="formattedStyle"

libs/shared/src/lib/services/form-helper/form-helper.service.ts

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class FormHelpersService {
131131
for (const name of questionsToUpload) {
132132
const files = temporaryFilesStorage[name];
133133
if (!isNil(files)) {
134-
for (const [index, file] of files.entries()) {
134+
for (const [, file] of files.entries()) {
135135
// Upload the file using document management system
136136
if (useDocumentManagement) {
137137
// Avoid already uploaded ones checking if contains an itemId
@@ -148,33 +148,37 @@ export class FormHelpersService {
148148
question
149149
);
150150
if (driveId && itemId) {
151-
const fileContent = data[name][index].content;
152-
data[name][index].content = {
153-
driveId,
154-
itemId,
155-
};
156-
157-
// Check if any other question is using the same file
158-
survey.getAllQuestions().forEach((question) => {
159-
const questionType = question.getType();
160-
if (
161-
questionType !== 'file' ||
162-
// Only change files that are not in the temporary storage
163-
// meaning their values came from the default values
164-
!!temporaryFilesStorage[question.name]
165-
) {
166-
return;
167-
}
168-
const files = data[question.name] ?? [];
169-
files.forEach((file: any) => {
170-
if (file && file.content === fileContent) {
171-
file.content = {
172-
driveId,
173-
itemId,
174-
};
151+
const matchingFile = data[name].find(
152+
(x: any) => x.name === file.name
153+
);
154+
if (matchingFile) {
155+
const fileContent = matchingFile.content;
156+
matchingFile.content = {
157+
driveId,
158+
itemId,
159+
};
160+
// Check if any other question is using the same file
161+
survey.getAllQuestions().forEach((question) => {
162+
const questionType = question.getType();
163+
if (
164+
questionType !== 'file' ||
165+
// Only change files that are not in the temporary storage
166+
// meaning their values came from the default values
167+
!!temporaryFilesStorage[question.name]
168+
) {
169+
return;
175170
}
171+
const files = data[question.name] ?? [];
172+
files.forEach((file: any) => {
173+
if (file && file.content === fileContent) {
174+
file.content = {
175+
driveId,
176+
itemId,
177+
};
178+
}
179+
});
176180
});
177-
});
181+
}
178182
}
179183
} catch (error) {
180184
failedFilesToUpload.push({ question: name, file });
@@ -188,28 +192,33 @@ export class FormHelpersService {
188192
formId
189193
)) as string;
190194
if (path) {
191-
const fileContent = data[name][index].content;
192-
data[name][index].content = path;
195+
const matchingFile = data[name].find(
196+
(x: any) => x.name === file.name
197+
);
198+
if (matchingFile) {
199+
const fileContent = matchingFile.content;
200+
matchingFile.content = path;
193201

194-
// Check if any other question is using the same file
195-
survey.getAllQuestions().forEach((question) => {
196-
const questionType = question.getType();
197-
if (
198-
questionType !== 'file' ||
199-
// Only change files that are not in the temporary storage
200-
// meaning their values came from the default values
201-
!!temporaryFilesStorage[question.name]
202-
) {
203-
return;
204-
}
205-
206-
const files = data[question.name] ?? [];
207-
files.forEach((file: any) => {
208-
if (file && file.content === fileContent) {
209-
file.content = path;
202+
// Check if any other question is using the same file
203+
survey.getAllQuestions().forEach((question) => {
204+
const questionType = question.getType();
205+
if (
206+
questionType !== 'file' ||
207+
// Only change files that are not in the temporary storage
208+
// meaning their values came from the default values
209+
!!temporaryFilesStorage[question.name]
210+
) {
211+
return;
210212
}
213+
214+
const files = data[question.name] ?? [];
215+
files.forEach((file: any) => {
216+
if (file && file.content === fileContent) {
217+
file.content = path;
218+
}
219+
});
211220
});
212-
});
221+
}
213222
}
214223
}
215224
}

0 commit comments

Comments
 (0)