Skip to content

Commit c45ad7b

Browse files
authored
Merge pull request #21 from netgrif/NAE-1590
[NAE-1590] Taskref with file field must be assigned
2 parents 0141862 + 401be6a commit c45ad7b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

projects/netgrif-components-core/src/lib/data-fields/file-field/abstract-file-field.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {take} from 'rxjs/operators';
1414
import {EventOutcomeMessageResource} from '../../resources/interface/message-resource';
1515
import {EventService} from '../../event/services/event.service';
1616
import {ChangedFieldsMap} from '../../event/services/interfaces/changed-fields-map';
17+
import {FileFieldIdBody} from '../models/file-field-id-body';
1718

1819
export interface FileState {
1920
progress: number;
@@ -197,8 +198,11 @@ export abstract class AbstractFileFieldComponent extends AbstractDataFieldCompon
197198
this.state.uploading = true;
198199
const fileFormData = new FormData();
199200
const fileToUpload = this.fileUploadEl.nativeElement.files.item(0) as File;
201+
const data: FileFieldIdBody = {};
202+
data[this.resolveParentTaskId()] = this.dataField.stringId;
200203
fileFormData.append('file', fileToUpload);
201-
this._taskResourceService.uploadFile(this.resolveParentTaskId(), this.dataField.stringId, fileFormData, false)
204+
fileFormData.append('data', new Blob([JSON.stringify(data)], {type: 'application/json'}));
205+
this._taskResourceService.uploadFile(this.taskId, this.dataField.stringId, fileFormData, false)
202206
.subscribe((response: EventOutcomeMessageResource) => {
203207
if ((response as ProviderProgress).type && (response as ProviderProgress).type === ProgressType.UPLOAD) {
204208
this.state.progress = (response as ProviderProgress).progress;
@@ -307,7 +311,7 @@ export abstract class AbstractFileFieldComponent extends AbstractDataFieldCompon
307311
return;
308312
}
309313

310-
this._taskResourceService.deleteFile(this.resolveParentTaskId(),
314+
this._taskResourceService.deleteFile(this.taskId,
311315
this.dataField.stringId).pipe(take(1)).subscribe(response => {
312316
if (response.success) {
313317
const filename = this.dataField.value.name;

projects/netgrif-components-core/src/lib/data-fields/file-list-field/abstract-file-list-field.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {EventOutcomeMessageResource} from '../../resources/interface/message-res
1313
import {EventService} from '../../event/services/event.service';
1414
import {ChangedFieldsMap} from '../../event/services/interfaces/changed-fields-map';
1515
import {Subscription} from 'rxjs';
16+
import {FileFieldIdBody} from '../models/file-field-id-body';
1617

1718
export interface FilesState {
1819
progress: number;
@@ -158,7 +159,10 @@ export abstract class AbstractFileListFieldComponent extends AbstractDataFieldCo
158159
filesToUpload.forEach(fileToUpload => {
159160
fileFormData.append('files', fileToUpload);
160161
});
161-
this._taskResourceService.uploadFile(this.resolveParentTaskId(),
162+
const data: FileFieldIdBody = {};
163+
data[this.resolveParentTaskId()] = this.dataField.stringId;
164+
fileFormData.append('data', new Blob([JSON.stringify(data)], {type: 'application/json'}));
165+
this._taskResourceService.uploadFile(this.taskId,
162166
this.dataField.stringId, fileFormData, true)
163167
.subscribe((response: EventOutcomeMessageResource) => {
164168
if ((response as ProviderProgress).type && (response as ProviderProgress).type === ProgressType.UPLOAD) {
@@ -253,7 +257,7 @@ export abstract class AbstractFileListFieldComponent extends AbstractDataFieldCo
253257
return;
254258
}
255259

256-
this._taskResourceService.deleteFile(this.resolveParentTaskId(),
260+
this._taskResourceService.deleteFile(this.taskId,
257261
this.dataField.stringId, fileName).pipe(take(1)).subscribe(response => {
258262
if (response.success) {
259263
this.uploadedFiles = this.uploadedFiles.filter(uploadedFile => uploadedFile !== fileName);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface FileFieldIdBody {
2+
[key: string]: string;
3+
}

0 commit comments

Comments
 (0)