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

FEAT #11954 TIME 1:45 add loader http request

parent 9fc3eca2
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
</mat-card>--> </mat-card>-->
<div class="example-loading-shade" *ngIf="loading"> <div class="example-loading-shade" *ngIf="loading">
<mat-spinner></mat-spinner> <mat-progress-spinner [mode]="loadingInfo.mode" [value]="loadingInfo.percent"></mat-progress-spinner>
<div style="padding-top: 10px;">{{loadingInfo.message}}</div>
</div> </div>
<div *ngIf="file.content === null && !loading" class="view-doc-container" appUploadFileDragDrop (onFileDropped)="dndUploadFile($event)"> <div *ngIf="file.content === null && !loading" class="view-doc-container" appUploadFileDragDrop (onFileDropped)="dndUploadFile($event)">
<i class="fa fa-file-upload upload-icon"></i><br /> <i class="fa fa-file-upload upload-icon"></i><br />
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
.example-loading-shade { .example-loading-shade {
background: rgba(255, 255, 255, 0.7); background: rgba(255, 255, 255, 0.7);
display: flex;
flex-direction: column;
} }
.viewer-tools { .viewer-tools {
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient, HttpEventType } from '@angular/common/http';
import { LANG } from '../translate.component'; import { LANG } from '../translate.component';
import { NotificationService } from '../notification.service'; import { NotificationService } from '../notification.service';
import { HeaderService } from '../../service/header.service'; import { HeaderService } from '../../service/header.service';
import { AppService } from '../../service/app.service'; import { AppService } from '../../service/app.service';
import { tap, catchError, finalize, filter } from 'rxjs/operators'; import { tap, catchError, finalize, filter, map } 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';
...@@ -37,6 +37,15 @@ export class DocumentViewerComponent implements OnInit { ...@@ -37,6 +37,15 @@ export class DocumentViewerComponent implements OnInit {
allowedExtensions: any[] = []; allowedExtensions: any[] = [];
maxFileSize: number = 0; maxFileSize: number = 0;
maxFileSizeLabel: string = '';
percentInProgress: number = 0;
loadingInfo: any = {
mode : 'determinate',
percent: 0,
message: '',
};
dialogRef: MatDialogRef<any>; dialogRef: MatDialogRef<any>;
...@@ -64,6 +73,7 @@ export class DocumentViewerComponent implements OnInit { ...@@ -64,6 +73,7 @@ export class DocumentViewerComponent implements OnInit {
this.allowedExtensions = this.sortPipe.transform(this.allowedExtensions, 'extension'); this.allowedExtensions = this.sortPipe.transform(this.allowedExtensions, 'extension');
this.maxFileSize = data.informations.maximumSize; this.maxFileSize = data.informations.maximumSize;
this.maxFileSizeLabel = data.informations.maximumSizeLabel;
}), }),
catchError((err: any) => { catchError((err: any) => {
this.notify.handleErrors(err); this.notify.handleErrors(err);
...@@ -126,24 +136,60 @@ export class DocumentViewerComponent implements OnInit { ...@@ -126,24 +136,60 @@ export class DocumentViewerComponent implements OnInit {
convertDocument(file: any) { convertDocument(file: any) {
if (this.allowedExtensions.filter(ext => ext.canConvert === true && ext.mimeType === file.type).length > 0) { if (this.allowedExtensions.filter(ext => ext.canConvert === true && ext.mimeType === file.type).length > 0) {
this.http.post('../../rest/convertedFile', { name: file.name, base64: file.content }).pipe( const data = { name: file.name, base64: file.content };
tap((data: any) => { this.upload(data).subscribe(
this.file.src = this.base64ToArrayBuffer(data.encodedResource); (res: any) => {
}), if (res.encodedResource) {
finalize(() => this.loading = false), this.file.src = this.base64ToArrayBuffer(res.encodedResource);
catchError((err: any) => { this.loading = false;
}
},
(err: any) => {
this.noConvertedFound = true; this.noConvertedFound = true;
//this.notify.handleErrors(err); console.log(err);
return of(false); return of(false);
}) }
).subscribe(); );
} else { } else {
this.noConvertedFound = true; this.noConvertedFound = true;
this.loading = false this.loading = false
} }
} }
upload(data: any) {
let uploadURL = `../../rest/convertedFile`;
return this.http.post<any>(uploadURL, data, {
reportProgress: true,
observe: 'events'
}).pipe(map((event) => {
switch (event.type) {
case HttpEventType.UploadProgress:
const progress = Math.round(100 * event.loaded / event.total);
this.loadingInfo.percent = progress;
if (progress === 100) {
this.loadingInfo.mode = 'indeterminate';
this.loadingInfo.message = 'Conversion du fichier...';
} else {
this.loadingInfo.mode = 'determinate';
this.loadingInfo.message = 'Chargement du fichier...';
}
return { status: 'progress', message: progress };
case HttpEventType.Response:
return event.body;
default:
return `Unhandled event: ${event.type}`;
}
})
);
}
onError(error: any) { onError(error: any) {
console.log(error); console.log(error);
} }
...@@ -190,7 +236,7 @@ export class DocumentViewerComponent implements OnInit { ...@@ -190,7 +236,7 @@ export class DocumentViewerComponent implements OnInit {
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(', ') } }); 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; return false;
} else if (file.size > this.maxFileSize) { } 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 } }); this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { title: 'Taille maximale dépassée ! ', msg: 'Taille maximale : ' + this.maxFileSizeLabel } });
return false; return false;
} else { } else {
return true; return true;
......
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