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

FEAT #14561 TIME 2:30 WIP front indexation

parent 0fe993c4
No related branches found
No related tags found
No related merge requests found
......@@ -41,8 +41,10 @@
<img [src]="diffusion.userPicture">
</ion-avatar>
<ion-label>{{diffusion.userDisplay}}</ion-label>
<ion-select [(ngModel)]="diffusion.mode" interface="popover">
<ion-select-option [value]="mode" *ngFor="let mode of diffusion.modes">{{'lang.' + mode + 'User' | translate}}</ion-select-option>
<ion-select [(ngModel)]="diffusion.mode" interface="popover" [interfaceOptions]="customPopoverOptions" [style.color]="getRole(diffusion.mode).color">
<ion-select-option [value]="mode" *ngFor="let mode of diffusion.modes">
{{getRole(mode).label}}
</ion-select-option>
</ion-select>
<ion-button fill="clear" slot="end" shape="round" color="danger" (click)="removeUser(i)">
<ion-icon slot="icon-only" name="trash-outline"></ion-icon>
......
......@@ -26,7 +26,7 @@
}
ion-select {
color: var(--ion-color-primary);
// color: var(--ion-color-primary);
font-size: 12px;
}
......
......@@ -20,6 +20,29 @@ export class VisaWorkflowComponent implements OnInit {
visaUsersSearchVal: string = '';
visaUsersList: any = [];
showVisaUsersList: boolean = false;
customPopoverOptions = {
header: 'Roles'
};
roles: any[] = [
{
id: 'rgs',
type: 'sign',
label: 'Signataire (RGS**)',
color: '#cb4335'
},
{
id: 'stamp',
type: 'sign',
label: 'Signataire (Griffe)',
color: '#f39c12'
},
{
id: 'visa',
type: 'visa',
label: 'Viseur',
color: '#27ae60'
},
];
@Input() editMode: boolean = false;
@Input() visaWorkflow: any = [];
......@@ -70,7 +93,7 @@ export class VisaWorkflowComponent implements OnInit {
'current': false,
'modes': [
'visa',
'sign',
'stamp',
'rgs'
]
};
......@@ -85,7 +108,7 @@ export class VisaWorkflowComponent implements OnInit {
}
getAvatarUser(index: number) {
if (this.visaWorkflow[index].userPicture === undefined && this.visaWorkflow[index].userDisplay !== '') {
if (this.visaWorkflow[index].userPicture === undefined && this.visaWorkflow[index].userDisplay !== '') {
this.http.get('../rest/users/' + this.visaWorkflow[index].userId + '/picture').pipe(
tap((data: any) => {
this.visaWorkflow[index].userPicture = data.picture;
......@@ -119,10 +142,14 @@ export class VisaWorkflowComponent implements OnInit {
this.getAvatarUser(index);
});
}
});
});
}
getCurrentWorkflow() {
return this.visaWorkflow;
}
getRole(id: string) {
return this.roles.filter((mode: any) => mode.id === id)[0];
}
}
......@@ -13,7 +13,7 @@
</div>
<ion-list *ngIf="filesToUpload.length > 0">
<ion-list-header>
<ion-label color="primary">Document(s) téléversé(s)</ion-label>
<ion-label color="primary">Document(s) à téléverser</ion-label>
</ion-list-header>
<ion-item *ngFor="let file of filesToUpload;let i=index">
<ion-buttons slot="start">
......
import { HttpClient } from '@angular/common/http';
import { Component, OnInit, TemplateRef, ViewChild, ViewContainerRef } from '@angular/core';
import { Router } from '@angular/router';
import { MenuController } from '@ionic/angular';
import { of } from 'rxjs';
import { catchError, finalize, tap } from 'rxjs/operators';
import { VisaWorkflowComponent } from '../document/visa-workflow/visa-workflow.component';
import { AuthService } from '../service/auth.service';
import { NotificationService } from '../service/notification.service';
import { SignaturesContentService } from '../service/signatures.service';
......@@ -12,14 +17,19 @@ export class IndexationComponent implements OnInit {
loading: boolean = false;
filesToUpload: any[] = [];
errors: any[] = [];
@ViewChild('appVisaWorkflow', { static: false }) appVisaWorkflow: VisaWorkflowComponent;
@ViewChild('rightContent', { static: true }) rightContent: TemplateRef<any>;
constructor(
public http: HttpClient,
public router: Router,
private menu: MenuController,
public signaturesService: SignaturesContentService,
public viewContainerRef: ViewContainerRef,
public notificationService: NotificationService,
public authService: AuthService,
) { }
ngOnInit(): void {
......@@ -37,12 +47,63 @@ export class IndexationComponent implements OnInit {
this.signaturesService.detachTemplate('rightContent');
}
onSubmit() {
async onSubmit() {
if (this.isValid()) {
console.log('ok');
const objTosend = this.formatData();
for (let index = 0; index < objTosend.length; index++) {
console.log('save..');
await this.saveDocument(objTosend[index], index);
}
if (this.errors.length === 0) {
this.notificationService.success('Document(s) importé(s)');
this.router.navigate(['/home']);
}
}
}
saveDocument(data: any, index: number) {
return new Promise((resolve) => {
this.http.post('../rest/documents', data).pipe(
tap(() => {
}),
finalize(() => resolve(true)),
catchError((err: any) => {
this.errors.push(data.title);
this.notificationService.handleErrors(err);
return of(false);
})
).subscribe();
});
}
formatData() {
const formattedObj: any[] = [];
const signedFiles = this.filesToUpload.filter((item: any) => item.mainDocument);
const attachFiles = this.filesToUpload.filter((item: any) => !item.mainDocument);
signedFiles.forEach((file: any) => {
formattedObj.push({
title: file.title,
encodedDocument: file.content,
sender: `${this.authService.user.firstname} ${this.authService.user.lastname}`,
attachments: attachFiles.map((item: any) => {
return {
title: item.title,
encodedDocument: item.content
};
}),
workflow: this.appVisaWorkflow.getCurrentWorkflow().map((item: any) => {
return {
userId: item.userId,
mode: item.mode
};
})
});
});
return formattedObj;
}
dndUploadFile(event: any) {
const fileInput = {
target: {
......@@ -55,7 +116,7 @@ export class IndexationComponent implements OnInit {
}
uploadTrigger(fileInput: any) {
if (fileInput.target.files && fileInput.target.files[0] /*&& this.isExtensionAllowed(fileInput.target.files[0])*/) {
if (fileInput.target.files && fileInput.target.files[0] && this.isExtensionAllowed(fileInput.target.files)) {
for (let index = 0; index < fileInput.target.files.length; index++) {
let file = {
title: fileInput.target.files[index].name,
......@@ -75,6 +136,16 @@ export class IndexationComponent implements OnInit {
}
}
isExtensionAllowed(files: any[]) {
for (let index = 0; index < files.length; index++) {
if (files[index].name.toLowerCase().split('.').pop() !== 'pdf') {
this.notificationService.error('Seul des fichiers pdf sont autorisés');
return false;
}
}
return true;
}
getBase64Document(buffer: ArrayBuffer) {
const TYPED_ARRAY = new Uint8Array(buffer);
const STRING_CHAR = TYPED_ARRAY.reduce((data, byte) => {
......
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