Skip to content
Snippets Groups Projects
Commit e7480bee authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #11954 TIME 0:30 add ext + size control upload file

parent 00b77ab8
No related branches found
No related tags found
No related merge requests found
...@@ -86,3 +86,8 @@ ...@@ -86,3 +86,8 @@
border-radius: 10px; border-radius: 10px;
background: #ffffff47; background: #ffffff47;
} }
.extensionsList {
height: 200px;
overflow: auto;
}
\ No newline at end of file
...@@ -8,6 +8,8 @@ import { tap, catchError, finalize, filter } from 'rxjs/operators'; ...@@ -8,6 +8,8 @@ import { tap, catchError, finalize, filter } from 'rxjs/operators';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ConfirmComponent } from '../../plugins/modal/confirm.component'; import { ConfirmComponent } from '../../plugins/modal/confirm.component';
import { MatDialogRef, MatDialog } from '@angular/material'; import { MatDialogRef, MatDialog } from '@angular/material';
import { AlertComponent } from '../../plugins/modal/alert.component';
import { SortPipe } from '../../plugins/sorting.pipe';
@Component({ @Component({
...@@ -16,7 +18,7 @@ import { MatDialogRef, MatDialog } from '@angular/material'; ...@@ -16,7 +18,7 @@ import { MatDialogRef, MatDialog } from '@angular/material';
styleUrls: [ styleUrls: [
'document-viewer.component.scss', 'document-viewer.component.scss',
], ],
providers: [NotificationService, AppService] providers: [NotificationService, AppService, SortPipe]
}) })
export class DocumentViewerComponent implements OnInit { export class DocumentViewerComponent implements OnInit {
...@@ -33,6 +35,9 @@ export class DocumentViewerComponent implements OnInit { ...@@ -33,6 +35,9 @@ export class DocumentViewerComponent implements OnInit {
src: null src: null
}; };
allowedExtensions: any[] = [];
maxFileSize: number = 0;
dialogRef: MatDialogRef<any>; dialogRef: MatDialogRef<any>;
constructor( constructor(
...@@ -41,12 +46,29 @@ export class DocumentViewerComponent implements OnInit { ...@@ -41,12 +46,29 @@ export class DocumentViewerComponent implements OnInit {
private headerService: HeaderService, private headerService: HeaderService,
public appService: AppService, public appService: AppService,
private dialog: MatDialog, private dialog: MatDialog,
private sortPipe: SortPipe
) { ) {
(<any>window).pdfWorkerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js'; (<any>window).pdfWorkerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js';
} }
ngOnInit() { ngOnInit() {
this.http.get('../../rest/indexing/fileInformations').pipe(
tap((data: any) => {
this.allowedExtensions = data.informations.allowedFiles.map((ext: any) => {
return {
extension: '.' + ext.extension.toLowerCase(),
mimeType: ext.mimeType,
}
});
this.allowedExtensions = this.sortPipe.transform(this.allowedExtensions, 'extension');
this.maxFileSize = data.informations.maximumSize;
}),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
} }
uploadTrigger(fileInput: any) { uploadTrigger(fileInput: any) {
...@@ -58,7 +80,8 @@ export class DocumentViewerComponent implements OnInit { ...@@ -58,7 +80,8 @@ export class DocumentViewerComponent implements OnInit {
}; };
this.noConvertedFound = false; this.noConvertedFound = false;
this.loading = true; this.loading = true;
if (fileInput.target.files && fileInput.target.files[0]) {
if (fileInput.target.files && fileInput.target.files[0] && this.checkFile(fileInput.target.files[0])) {
var reader = new FileReader(); var reader = new FileReader();
this.file.name = fileInput.target.files[0].name; this.file.name = fileInput.target.files[0].name;
...@@ -76,6 +99,8 @@ export class DocumentViewerComponent implements OnInit { ...@@ -76,6 +99,8 @@ export class DocumentViewerComponent implements OnInit {
this.loading = false; this.loading = false;
} }
}; };
} else {
this.loading = false;
} }
} }
...@@ -152,4 +177,17 @@ export class DocumentViewerComponent implements OnInit { ...@@ -152,4 +177,17 @@ export class DocumentViewerComponent implements OnInit {
this.uploadTrigger(fileInput); this.uploadTrigger(fileInput);
} }
checkFile(file: any) {
if (this.allowedExtensions.map(ext => ext.mimeType).indexOf(file.type) === -1) {
this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { title: 'Extension non autorisé !', msg: '<u>Extension autorisée</u> : <br/>' + this.allowedExtensions.map(ext => ext.extension).filter((elem: any, index: any, self: any) => index === self.indexOf(elem)).join(', ') } });
return false;
} else if (file.size > this.maxFileSize) {
this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { title: 'Taille maximale dépassée ! ', msg: 'Taille maximale : ' + this.maxFileSize } });
return false;
} else {
return true;
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment