Skip to content

Commit 64ed5fe

Browse files
[DSC-2425] fix file handling for bulk import
1 parent d1c900a commit 64ed5fe

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/app/bulk-import/bulk-import-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h2 class="mb-3">{{ 'bulk-import.title' | translate }}</h2>
77
</div>
88
<div class="form-group">
99
<label for="file">{{ 'bulk-import.file' | translate }}</label>
10-
<input type="file" formControlName="file" id="file" class="form-control-file" requireFile/>
10+
<input type="file" (change)="handleFileInput($event)" formControlName="file" id="file" class="form-control-file" requireFile/>
1111
</div>
1212
<div class="form-check">
1313
<input type="checkbox" formControlName="abortOnError" id="abortOnError" class="form-check-input" />

src/app/bulk-import/bulk-import-page.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe('BulkImportPageComponent', () => {
122122
beforeEach(() => {
123123
component.form.value.abortOnError = true;
124124
component.form.value.file = fileList;
125+
component.setFile(fileList);
125126
component.submit();
126127
});
127128

src/app/bulk-import/bulk-import-page.component.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export class BulkImportPageComponent implements OnInit, OnDestroy {
7676
*/
7777
processingImport$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
7878

79+
private selectedFile: File;
80+
7981
constructor(
8082
private authService: AuthService,
8183
private formBuilder: FormBuilder,
@@ -119,19 +121,16 @@ export class BulkImportPageComponent implements OnInit, OnDestroy {
119121

120122
const values: any = this.form.value;
121123

122-
const files: FileList = values.file;
123-
const file: File = files.item(0);
124-
125124
const stringParameters: ProcessParameter[] = [
126125
{ name: '-c', value: this.collectionId },
127-
{ name: '-f', value: file.name },
126+
{ name: '-f', value: this.selectedFile.name },
128127
];
129128

130129
if (values.abortOnError) {
131130
stringParameters.push( { name: '-er', value: values.abortOnError } );
132131
}
133132

134-
this.scriptService.invoke('bulk-import', stringParameters, [file])
133+
this.scriptService.invoke('bulk-import', stringParameters, [this.selectedFile])
135134
.pipe(getFirstCompletedRemoteData())
136135
.subscribe((rd: RemoteData<Process>) => {
137136
if (rd.isSuccess) {
@@ -165,4 +164,15 @@ export class BulkImportPageComponent implements OnInit, OnDestroy {
165164
this.subs.forEach((sub) => sub.unsubscribe());
166165
}
167166

167+
public handleFileInput(event: Event) {
168+
const input = event.target as HTMLInputElement;
169+
if (input.files && input.files.length > 0) {
170+
this.setFile(input.files);
171+
}
172+
}
173+
174+
public setFile(files: FileList) {
175+
this.selectedFile = files.length > 0 ? files.item(0) : undefined;
176+
}
177+
168178
}

0 commit comments

Comments
 (0)