From 4e3f4389106c681330df6c69b7fba1d2f34f5f2e Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Wed, 21 Oct 2020 11:43:09 +0200 Subject: [PATCH] FEAT #15011 TIME 1:40 load custom diffusion list --- .../diffusions/diffusions-list.component.ts | 53 ++++-- .../indexing-form.component.html | 157 +++++++++++------- .../indexing-form/indexing-form.component.ts | 21 ++- 3 files changed, 150 insertions(+), 81 deletions(-) diff --git a/src/frontend/app/diffusions/diffusions-list.component.ts b/src/frontend/app/diffusions/diffusions-list.component.ts index efb29a21188..0a549428daa 100644 --- a/src/frontend/app/diffusions/diffusions-list.component.ts +++ b/src/frontend/app/diffusions/diffusions-list.component.ts @@ -4,7 +4,7 @@ import { TranslateService } from '@ngx-translate/core'; import { NotificationService } from '@service/notification/notification.service'; import { CdkDragDrop, transferArrayItem } from '@angular/cdk/drag-drop'; import { FormControl } from '@angular/forms'; -import { catchError, map, tap, elementAt } from 'rxjs/operators'; +import { catchError, map, tap } from 'rxjs/operators'; import { of } from 'rxjs'; import { AlertComponent } from '../../plugins/modal/alert.component'; import { MatDialog } from '@angular/material/dialog'; @@ -36,17 +36,17 @@ export class DiffusionsListComponent implements OnInit { /** * Ressource identifier to load listinstance (Incompatible with templateId) */ - @Input('resId') resId: number = null; + @Input() resId: number = null; /** * Add previous dest in copy (Only compatible with resId) */ - @Input('keepDestForRedirection') keepDestForRedirection: boolean = false; + @Input() keepDestForRedirection: boolean = false; /** * Entity identifier to load listModel of entity (Incompatible with resId) */ - @Input('entityId') entityId: any = null; + @Input() entityId: any = null; /** * To specify the context to load listModel @@ -61,17 +61,22 @@ export class DiffusionsListComponent implements OnInit { /** * For manage current loaded list */ - @Input('adminMode') adminMode: boolean = false; + @Input() adminMode: boolean = false; /** * Ids of related allowed entities perimeters */ - @Input('allowedEntities') allowedEntities: number[] = []; + @Input() allowedEntities: number[] = []; /** * Expand all roles */ - @Input('expanded') expanded: boolean = false; + @Input() expanded: boolean = false; + + /** + * Custom diffusion to display + */ + @Input() customDiffusion: any[] = [false]; /** * To load privilege of current list management @@ -80,17 +85,17 @@ export class DiffusionsListComponent implements OnInit { * @param process * @param redirect */ - @Input('target') target: string = ''; + @Input() target: string = ''; /** * FormControl to use this component in form */ - @Input('diffFormControl') diffFormControl: FormControl; + @Input() diffFormControl: FormControl; /** * Catch external event after select an element in autocomplete */ - @Output('triggerEvent') triggerEvent = new EventEmitter(); + @Output() triggerEvent = new EventEmitter(); constructor( public translate: TranslateService, @@ -106,8 +111,10 @@ export class DiffusionsListComponent implements OnInit { await this.initRoles(); if (this.resId !== null && this.resId != 0 && this.target !== 'redirect') { this.loadListinstance(this.resId); - } else if ((this.resId === null || this.resId == 0) && !this.functions.empty(this.entityId)) { + } else if (((this.resId === null || this.resId == 0) && !this.functions.empty(this.entityId)) && this.customDiffusion.length === 0) { this.loadListModel(this.entityId, false, this.selfDest); + } else if (this.customDiffusion.length > 0) { + this.loadCustomDiffusion(); } this.loading = false; } @@ -131,6 +138,30 @@ export class DiffusionsListComponent implements OnInit { return true; } + loadCustomDiffusion() { + const roles = [...new Set(this.customDiffusion.map(item => item.mode))]; + + roles.forEach(role => { + this.diffList[role].items = this.customDiffusion.filter((item: any) => item.mode === role).map((item: any) => { + return { + item_mode: role, + item_type: item.type, + itemSerialId: item.type, + itemId: '', + itemLabel: item.labelToDisplay, + itemSubLabel: item.descriptionToDisplay, + difflist_type: 'entity_id', + process_date: null, + process_comment: null, + }; + }); + }); + + if (this.diffFormControl !== undefined) { + this.setFormValues(); + } + } + async loadListModel(entityId: number, destResource: boolean = false, destCurrentUser: boolean = false) { this.loading = true; this.currentEntityId = entityId; diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.html b/src/frontend/app/indexation/indexing-form/indexing-form.component.html index 28eaa7412ce..1674465bf61 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.html +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.html @@ -29,15 +29,16 @@ <div class="fieldRow" *ngIf="field.unit === category" cdkDrag cdkDragLockAxis="y" [cdkDragData]="field"> <div class="fieldLabel" *ngIf="(!adminMode && !appService.getViewMode()) || adminMode"> - <i *ngIf="adminMode" [title]="this.translate.instant('lang.move')" class="fas fa-bars fa-2x" color="primary" - style="cursor: move" cdkDragHandle></i> + <i *ngIf="adminMode" [title]="this.translate.instant('lang.move')" + class="fas fa-bars fa-2x" color="primary" style="cursor: move" + cdkDragHandle></i> {{field.label}} - <button *ngIf="adminMode" mat-icon-button - [matMenuTriggerFor]="fieldActions"> + <button *ngIf="adminMode" mat-icon-button [matMenuTriggerFor]="fieldActions"> <mat-icon class="fa fa-ellipsis-v" color="secondary"></mat-icon> </button> <mat-menu #fieldActions="matMenu" [class]="'parametersFieldsMenu'"> - <button mat-menu-item (click)="field.mandatory = !field.mandatory" *ngIf="!field.system"> + <button mat-menu-item (click)="field.mandatory = !field.mandatory" + *ngIf="!field.system"> <span *ngIf="!field.mandatory">{{'lang.mandatoryField' | translate}}</span> <span *ngIf="field.mandatory">{{'lang.optionalField' | translate}}</span> </button> @@ -49,7 +50,7 @@ <span>{{'lang.disableField' | translate}}</span> </button> <mat-divider *ngIf="!field.system"></mat-divider> - <button mat-menu-item (click)="removeItem('indexingModels_'+category,field,i)" + <button mat-menu-item (click)="removeItem('indexingModels_'+category,field,i)" *ngIf="!field.system && field.identifier.indexOf('registeredMail_') === -1 && ((currentCategory == 'registeredMail' && field.identifier != 'departureDate') || currentCategory != 'registeredMail')"> <mat-icon class="fa fa-trash" color="warn"></mat-icon> @@ -57,61 +58,65 @@ </button> </mat-menu> </div> - <div class="fieldInput" [class.textareaInput]="field.type === 'string'" [class.checkboxInput]="field.type === 'checkbox'"> + <div class="fieldInput" [class.textareaInput]="field.type === 'string'" + [class.checkboxInput]="field.type === 'checkbox'"> <ng-container *ngIf="field.type === 'string'"> - <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix mat-icon-button - disabled style="position: absolute;left: -40px;" [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> - <mat-icon color="primary" - class="fas fa-database"> + <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix + mat-icon-button disabled style="position: absolute;left: -40px;" + [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> + <mat-icon color="primary" class="fas fa-database"> </mat-icon> </button> <mat-form-field class="input-form" [floatLabel]="appService.getViewMode() ? '' : 'never'"> <mat-label *ngIf="appService.getViewMode()">{{field.label}}</mat-label> <textarea [id]="field.identifier" matInput matTextareaAutosize - [formControl]="arrFormControl[field.identifier]" + [formControl]="arrFormControl[field.identifier]" [placeholder]="!adminMode ? this.translate.instant('lang.typeValue') : this.translate.instant('lang.defaultValue')" - class="subject"></textarea> + class="subject"></textarea> </mat-form-field> </ng-container> <ng-container *ngIf="field.type === 'integer'"> - <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix mat-icon-button - disabled style="position: absolute;left: -40px;" [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> - <mat-icon color="primary" - class="fas fa-database"> + <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix + mat-icon-button disabled style="position: absolute;left: -40px;" + [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> + <mat-icon color="primary" class="fas fa-database"> </mat-icon> </button> <mat-form-field class="input-form" [floatLabel]="appService.getViewMode() ? '' : 'never'"> <mat-label *ngIf="appService.getViewMode()">{{field.label}}</mat-label> - <input [id]="field.identifier" type="number" matInput [formControl]="arrFormControl[field.identifier]" - [placeholder]="!adminMode ? this.translate.instant('lang.typeValue') : this.translate.instant('lang.defaultValue')" min="0" - step="0.1"> + <input [id]="field.identifier" type="number" matInput + [formControl]="arrFormControl[field.identifier]" + [placeholder]="!adminMode ? this.translate.instant('lang.typeValue') : this.translate.instant('lang.defaultValue')" + min="0" step="0.1"> </mat-form-field> </ng-container> <ng-container *ngIf="field.type === 'select'"> - <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix mat-icon-button - disabled style="position: absolute;left: -40px;" [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> - <mat-icon color="primary" - class="fas fa-database"> + <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix + mat-icon-button disabled style="position: absolute;left: -40px;" + [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> + <mat-icon color="primary" class="fas fa-database"> </mat-icon> </button> - <plugin-select-search [id]="field.identifier" [showResetOption]="adminMode || !field.mandatory" [label]="field.label" + <plugin-select-search [id]="field.identifier" + [showResetOption]="adminMode || !field.mandatory" [label]="field.label" [placeholderLabel]="!adminMode ? this.translate.instant('lang.chooseValue') : this.translate.instant('lang.defaultValue')" [formControlSelect]="arrFormControl[field.identifier]" [datas]="field.values" (afterSelected)="launchEvent($event, field)" style="width:100%;"> </plugin-select-search> </ng-container> <ng-container *ngIf="field.type === 'date'"> - <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix mat-icon-button - disabled style="position: absolute;left: -40px;" [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> - <mat-icon color="primary" - class="fas fa-database"> + <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix + mat-icon-button disabled style="position: absolute;left: -40px;" + [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> + <mat-icon color="primary" class="fas fa-database"> </mat-icon> </button> - <button mat-button color="primary" *ngIf="adminMode && !field.SQLMode" matPrefix mat-icon-button - (click)="$event.stopPropagation();toggleTodayDate(field);" - [matTooltip]="this.translate.instant('lang.todayDate')" style="position: absolute;left: -40px;"> + <button mat-button color="primary" *ngIf="adminMode && !field.SQLMode" matPrefix + mat-icon-button (click)="$event.stopPropagation();toggleTodayDate(field);" + [matTooltip]="this.translate.instant('lang.todayDate')" + style="position: absolute;left: -40px;"> <mat-icon color="primary" class="{{field.today ? 'far fa-bell-slash' : 'far fa-bell'}}"> </mat-icon> @@ -120,8 +125,8 @@ [floatLabel]="appService.getViewMode() ? '' : 'never'" (click)="picker.open()" style="cursor:pointer;"> <mat-label *ngIf="appService.getViewMode()">{{field.label}}</mat-label> - <input [id]="field.identifier" [formControl]="arrFormControl[field.identifier]" matInput - [matDatepicker]="picker" + <input [id]="field.identifier" [formControl]="arrFormControl[field.identifier]" + matInput [matDatepicker]="picker" [placeholder]="!adminMode ? this.translate.instant('lang.chooseDate') : this.translate.instant('lang.defaultValue')" [min]="getMinDate(field.startDate)" [max]="getMaxDate(field.endDate)" readonly style="cursor:pointer;" (dateChange)="launchEvent($event, field)"> @@ -139,10 +144,10 @@ </mat-form-field> </ng-container> <ng-container *ngIf="field.type === 'radio'"> - <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix mat-icon-button - disabled style="position: absolute;left: -40px;" [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> - <mat-icon color="primary" - class="fas fa-database"> + <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix + mat-icon-button disabled style="position: absolute;left: -40px;" + [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> + <mat-icon color="primary" class="fas fa-database"> </mat-icon> </button> <mat-form-field class="input-form input-radio" @@ -151,24 +156,25 @@ <input matInput style="display: none;"> <mat-radio-group class="radio-form" color="primary" [formControl]="arrFormControl[field.identifier]"> - <mat-radio-button *ngFor="let value of field.values" [value]="value.id" [disabled]="value.disabled"> + <mat-radio-button *ngFor="let value of field.values" [value]="value.id" + [disabled]="value.disabled"> {{value.label}} </mat-radio-button> </mat-radio-group> </mat-form-field> </ng-container> <ng-container *ngIf="field.type === 'checkbox'"> - <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix mat-icon-button - disabled style="position: absolute;left: -40px;" [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> - <mat-icon color="primary" - class="fas fa-database"> + <button mat-button color="primary" *ngIf="field.SQLMode && adminMode" matPrefix + mat-icon-button disabled style="position: absolute;left: -40px;" + [title]="this.translate.instant('lang.bddModeCustomFieldMsg')"> + <mat-icon color="primary" class="fas fa-database"> </mat-icon> </button> <div class="input-form checkbox-form"> <mat-selection-list #shoes class="div-list" [formControl]="arrFormControl[field.identifier]"> - <mat-list-option color="primary" *ngFor="let value of field.values" [value]="value.id" - checkboxPosition="before"> + <mat-list-option color="primary" *ngFor="let value of field.values" + [value]="value.id" checkboxPosition="before"> {{value.label}} </mat-list-option> </mat-selection-list> @@ -188,7 +194,9 @@ </plugin-autocomplete> </ng-container>--> <ng-container *ngIf="['senders','recipients'].indexOf(field.identifier) > -1"> - <app-contact-autocomplete [id]="field.identifier" [control]="arrFormControl[field.identifier]" style="width:100%;" (retrieveDocumentEvent)="retrieveDocumentEvent.emit()"> + <app-contact-autocomplete [id]="field.identifier" + [control]="arrFormControl[field.identifier]" style="width:100%;" + (retrieveDocumentEvent)="retrieveDocumentEvent.emit()"> </app-contact-autocomplete> </ng-container> <ng-container *ngIf="field.identifier === 'folders'"> @@ -200,22 +208,36 @@ </app-tag-input> </ng-container> <ng-container *ngIf="field.type === 'banAutocomplete'"> - <app-address-ban-input [control]="arrFormControl[field.identifier]" [admin]="adminMode" style="width:100%;"> + <app-address-ban-input [control]="arrFormControl[field.identifier]" + [admin]="adminMode" style="width:100%;"> </app-address-ban-input> </ng-container> <ng-container *ngIf="field.type === 'contact'"> - <app-contact-autocomplete [id]="field.identifier" [control]="arrFormControl[field.identifier]" style="width:100%;" (retrieveDocumentEvent)="retrieveDocumentEvent.emit()"> + <app-contact-autocomplete [id]="field.identifier" + [control]="arrFormControl[field.identifier]" style="width:100%;" + (retrieveDocumentEvent)="retrieveDocumentEvent.emit()"> </app-contact-autocomplete> </ng-container> <ng-container *ngIf="field.identifier === 'registeredMail_issuingSite'"> - <app-issuing-site-input #appIssuingSiteInput [registedMailType]="arrFormControl['registeredMail_type'].value" [control]="arrFormControl[field.identifier]" [showResetOption]="adminMode || !field.mandatory" (afterSelected)="launchEvent($event, field)" style="width:100%;"> + <app-issuing-site-input #appIssuingSiteInput + [registedMailType]="arrFormControl['registeredMail_type'].value" + [control]="arrFormControl[field.identifier]" + [showResetOption]="adminMode || !field.mandatory" + (afterSelected)="launchEvent($event, field)" style="width:100%;"> </app-issuing-site-input> </ng-container> <ng-container *ngIf="field.identifier === 'registeredMail_recipient'"> - <app-contact-autocomplete *ngIf="mode === 'indexation'" [exclusion]="'?noUsers=true&noEntities=true&noContactsGroups=true'" [id]="field.identifier" [singleMode]="true" [control]="arrFormControl[field.identifier]" style="width:100%;" (retrieveDocumentEvent)="retrieveDocumentEvent.emit()"> + <app-contact-autocomplete *ngIf="mode === 'indexation'" + [exclusion]="'?noUsers=true&noEntities=true&noContactsGroups=true'" + [id]="field.identifier" [singleMode]="true" + [control]="arrFormControl[field.identifier]" style="width:100%;" + (retrieveDocumentEvent)="retrieveDocumentEvent.emit()"> </app-contact-autocomplete> - - <app-registered-mail-recipient-input *ngIf="mode !== 'indexation'" #appRegisteredMailRecipientInput [control]="arrFormControl[field.identifier]" [registeredMailType]="arrFormControl['registeredMail_type'].value" style="width:100%;"> + + <app-registered-mail-recipient-input *ngIf="mode !== 'indexation'" + #appRegisteredMailRecipientInput [control]="arrFormControl[field.identifier]" + [registeredMailType]="arrFormControl['registeredMail_type'].value" + style="width:100%;"> </app-registered-mail-recipient-input> </ng-container> </div> @@ -225,28 +247,39 @@ [class.noMandatory]="!field.mandatory"></i> <i class="fas fa-exclamation-triangle fieldError" *ngIf="!adminMode && arrFormControl[field.identifier].touched && arrFormControl[field.identifier].hasError('required')"></i> - <i class="fas fa-check fieldFull" *ngIf="!adminMode && arrFormControl[field.identifier].valid && !isEmptyField(field)"></i> + <i class="fas fa-check fieldFull" + *ngIf="!adminMode && arrFormControl[field.identifier].valid && !isEmptyField(field)"></i> </div> </div> - <div *ngIf="field.identifier === 'destination' && !adminMode && arrFormControl['destination'].value > 0 && !hideDiffusionList"> + <div + *ngIf="field.identifier === 'destination' && !adminMode && arrFormControl['destination'].value > 0 && !hideDiffusionList"> <mat-divider></mat-divider> <div style="padding: 10px;font-size: 16px;color: #135F7F;letter-spacing: 2px;font-weight: bold;display: flex; align-items: center;"> <div style="display: flex;flex: 1;align-items: center;"> - {{'lang.diffusionList' | translate}} <button mat-icon-button *ngIf="appDiffusionsList.canUpdateRoles() && canEdit && mode !== 'process' && field.enabled" color="primary" - (click)="appDiffusionsList.switchMode()" [title]="this.translate.instant('lang.modifyDiffusionList')"> - <mat-icon class="fa fa-edit"></mat-icon> - </button> + {{'lang.diffusionList' | translate}} <button mat-icon-button + *ngIf="appDiffusionsList.canUpdateRoles() && canEdit && mode !== 'process' && field.enabled" + color="primary" (click)="appDiffusionsList.switchMode()" + [title]="this.translate.instant('lang.modifyDiffusionList')"> + <mat-icon class="fa fa-edit"></mat-icon> + </button> </div> <div class="fieldState" style="width: 20px;padding: 0px;"> <i class="fas fa-asterisk fieldRequired" *ngIf="adminMode || (arrFormControl['diffusionList'].hasError('required') && arrFormControl['diffusionList'].untouched)" [class.noMandatory]="!field.mandatory"></i> - <i class="fas fa-exclamation-triangle fieldError" *ngIf="!adminMode && arrFormControl['diffusionList'].touched && arrFormControl['diffusionList'].hasError('required')"></i> - <i class="fas fa-check fieldFull" *ngIf="!adminMode && arrFormControl['diffusionList'].valid && !isEmptyField(field)"></i> + <i class="fas fa-exclamation-triangle fieldError" + *ngIf="!adminMode && arrFormControl['diffusionList'].touched && arrFormControl['diffusionList'].hasError('required')"></i> + <i class="fas fa-check fieldFull" + *ngIf="!adminMode && arrFormControl['diffusionList'].valid && !isEmptyField(field)"></i> </div> </div> - <app-diffusions-list #appDiffusionsList [resId]="resId" [entityId]="arrFormControl[field.identifier].value" [diffFormControl]="arrFormControl['diffusionList']" [allowedEntities]="field.allowedEntities" [category]="currentCategory" [target]="'indexation'" [selfDest]="selfDest" (triggerEvent)="changeDestination($event,field.allowedEntities)"> + <app-diffusions-list #appDiffusionsList [resId]="resId" + [entityId]="arrFormControl[field.identifier].value" + [diffFormControl]="arrFormControl['diffusionList']" + [allowedEntities]="field.allowedEntities" [category]="currentCategory" + [target]="'indexation'" [selfDest]="selfDest" [customDiffusion]="customDiffusion" + (triggerEvent)="changeDestination($event,field.allowedEntities)"> </app-diffusions-list> <mat-divider></mat-divider> </div> @@ -255,4 +288,4 @@ </div> </div> </ng-container> -</ng-container> +</ng-container> \ No newline at end of file diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts index 0f2109b59a0..dc3b2fc1ee0 100755 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -27,14 +27,14 @@ export class IndexingFormComponent implements OnInit { loading: boolean = true; - @Input('indexingFormId') indexingFormId: number; - @Input('resId') resId: number = null; - @Input('groupId') groupId: number; + @Input() indexingFormId: number; + @Input() resId: number = null; + @Input() groupId: number; @Input('admin') adminMode: boolean; - @Input('canEdit') canEdit: boolean = true; - @Input('mode') mode: string = 'indexation'; + @Input() canEdit: boolean = true; + @Input() mode: string = 'indexation'; - @Input('hideDiffusionList') hideDiffusionList: boolean = false; + @Input() hideDiffusionList: boolean = false; @Output() retrieveDocumentEvent = new EventEmitter<string>(); @Output() loadingFormEndEvent = new EventEmitter<string>(); @@ -254,6 +254,7 @@ export class IndexingFormComponent implements OnInit { currentResourceValues: any = null; selfDest: boolean = false; + customDiffusion: any = []; dialogRef: MatDialogRef<any>; @@ -625,7 +626,7 @@ export class IndexingFormComponent implements OnInit { title: title, label: entity.entity_label, disabled: !entity.enabled - } + }; }); elem.event = 'loadDiffusionList'; elem.allowedEntities = elem.values.filter((val: any) => val.disabled === false).map((entities: any) => entities.id); @@ -951,10 +952,14 @@ export class IndexingFormComponent implements OnInit { } } + if (field.identifier === 'diffusionList') { + this.customDiffusion = field.default_value; + } + if (fieldExist) { this['indexingModels_' + field.unit].push(field); this.initValidator(field); - } else { + } else if (field.identifier !== 'diffusionList') { this.notify.error(this.translate.instant('lang.fieldNotExist') + ': ' + field.identifier); } -- GitLab