Skip to content

Commit

Permalink
Improving the file browser for importing metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Aug 1, 2024
1 parent a6e3bc3 commit ce2abfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<span><i class="fas fa-cloud-upload"
aria-hidden="true"></i> {{ ((fileObject === null || fileObject === undefined) ? dropMessageLabel : dropMessageLabelReplacement) | translate}} {{'uploader.or' | translate}}</span>
<label class="btn btn-link m-0 p-0 ml-1">
<input class="form-control-file d-none" requireFile #file="ngModel" type="file" name="file-upload"
<input class="form-control-file d-none" type="file" name="file-upload"
id="file-upload"
[ngModel]="fileObject" (ngModelChange)="setFile($event)">
(change)="handleFileInput($event)">
{{'uploader.browse' | translate}}
</label>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class FileDropzoneNoUploaderComponent implements OnInit {
/**
* The function to call when file is added
*/
@Output() onFileAdded: EventEmitter<any> = new EventEmitter<any>();
@Output() onFileAdded: EventEmitter<File> = new EventEmitter<File>();

Check warning on line 57 in src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts#L57

Added line #L57 was not covered by tests

/**
* The uploader configuration options
Expand Down Expand Up @@ -83,15 +83,17 @@ export class FileDropzoneNoUploaderComponent implements OnInit {
}

@HostListener('window:drop', ['$event'])
onDrop(event: any) {
onDrop(event: DragEvent) {
event.preventDefault();
event.stopPropagation();

Check warning on line 88 in src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts#L88

Added line #L88 was not covered by tests
}

@HostListener('window:dragover', ['$event'])
onDragOver(event: any) {
onDragOver(event: DragEvent) {
// Show drop area on the page
event.preventDefault();
if ((event.target as any).tagName !== 'HTML') {
event.stopPropagation();

Check warning on line 95 in src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts#L95

Added line #L95 was not covered by tests
if ((event.target as HTMLElement).tagName !== 'HTML') {
this.isOverDocumentDropZone = observableOf(true);
}
}
Expand All @@ -105,11 +107,18 @@ export class FileDropzoneNoUploaderComponent implements OnInit {
}
}

public handleFileInput(event: Event) {
const input = event.target as HTMLInputElement;

Check warning on line 111 in src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts#L111

Added line #L111 was not covered by tests
if (input.files && input.files.length > 0) {
this.setFile(input.files);

Check warning on line 113 in src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/upload/file-dropzone-no-uploader/file-dropzone-no-uploader.component.ts#L113

Added line #L113 was not covered by tests
}
}

/**
* Set file
* @param files
*/
setFile(files) {
public setFile(files: FileList) {
this.fileObject = files.length > 0 ? files[0] : undefined;
this.onFileAdded.emit(this.fileObject);
}
Expand Down

0 comments on commit ce2abfe

Please sign in to comment.