From 37362823ca56f535546669f9c8d09c67d58a965d Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Thu, 19 Sep 2019 11:32:16 +0200 Subject: [PATCH] FEAT #11271 TIME 1:30 add data cat + doctypes in indexing form --- .../indexing-form.component.html | 16 ++--- .../indexing-form.component.scss | 3 + .../indexing-form/indexing-form.component.ts | 59 +++++++++++++++++++ 3 files changed, 70 insertions(+), 8 deletions(-) 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 3eab00d1c40..0caf3e88e14 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.html +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.html @@ -46,7 +46,7 @@ <textarea matInput [(ngModel)]="field.default_value" [placeholder]="field.system ? lang[field.type + 'Input'] : lang.defaultValue" matTextareaAutosize matAutosizeMinRows="1" cdkAutosizeMaxRows="6" - [disabled]="field.system"></textarea> + [disabled]="field.system && adminMode"></textarea> </mat-form-field> </ng-container> <ng-container *ngIf="field.type === 'integer'"> @@ -59,9 +59,9 @@ <mat-form-field class="input-form" floatLabel="never"> <mat-select [placeholder]="field.system ? lang[field.type + 'Input'] : lang.defaultValue" - [(ngModel)]="field.default_value" [disabled]="field.system"> - <mat-option *ngFor="let value of field.values" [value]="value"> - {{value}} + [(ngModel)]="field.default_value" [disabled]="field.system && adminMode"> + <mat-option *ngFor="let value of field.values" [value]="value.id" [title]="value.label" [disabled]="value.isTitle" [class.opt-group]="value.isTitle" [style.color]="value.color"> + {{value.label}} </mat-option> </mat-select> </mat-form-field> @@ -70,14 +70,14 @@ <mat-form-field class="input-form" floatLabel="never" (click)="picker.open()"> <input matInput [matDatepicker]="picker" [placeholder]="field.system ? lang[field.type + 'Input'] : lang.defaultValue" - [(ngModel)]="field.default_value" [disabled]="field.system"> + [(ngModel)]="field.default_value" [disabled]="field.system && adminMode"> <mat-datepicker-toggle matSuffix [for]="picker"> </mat-datepicker-toggle> <mat-datepicker #picker></mat-datepicker> </mat-form-field> </ng-container> <ng-container *ngIf="field.type === 'radio'"> - <mat-radio-group class="radio-form" color="primary" [disabled]="field.system" + <mat-radio-group class="radio-form" color="primary" [disabled]="field.system && adminMode" [(ngModel)]="field.default_value"> <mat-radio-button *ngFor="let value of field.values" [value]="value"> {{value}} @@ -86,7 +86,7 @@ </ng-container> <ng-container *ngIf="field.type === 'checkbox'"> <div class="input-form checkbox-form"> - <mat-selection-list #shoes class="div-list" [disabled]="field.system" + <mat-selection-list #shoes class="div-list" [disabled]="field.system && adminMode" [(ngModel)]="field.default_value"> <mat-list-option *ngFor="let value of field.values" [value]="value" checkboxPosition="before"> @@ -94,7 +94,7 @@ </mat-list-option> </mat-selection-list> </div> - <mat-chip-list class="checkbox-selected-list" [disabled]="field.system"> + <mat-chip-list class="checkbox-selected-list" [disabled]="field.system && adminMode"> <mat-chip *ngFor="let chip of shoes.selectedOptions.selected" selected> {{chip.value}} </mat-chip> diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.scss b/src/frontend/app/indexation/indexing-form/indexing-form.component.scss index a7901750cbb..bab99cf6413 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.scss +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.scss @@ -140,6 +140,9 @@ height: auto; } } +.opt-group { + font-weight: bold; +} .button-form-primary { background: $primary; 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 a0603ff1496..276966631cd 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -244,6 +244,8 @@ export class IndexingFormComponent implements OnInit { this.fieldCategories.forEach(element => { this['indexingModels_' + element + 'Clone'] = JSON.parse(JSON.stringify(this['indexingModels_' + element])); }); + + this.initElemForm(); }), finalize(() => this.loading = false), catchError((err: any) => { @@ -330,4 +332,61 @@ export class IndexingFormComponent implements OnInit { this['indexingModels_' + element] = JSON.parse(JSON.stringify(this['indexingModels_' + element + 'Clone'])); }); } + + initElemForm() { + this.fieldCategories.forEach(element => { + this['indexingModels_' + element].forEach((elem: any) => { + if (elem.identifier === 'category_id') { + this.http.get("../../rest/categories").pipe( + tap((data: any) => { + elem.values = data.categories; + }), + finalize(() => this.loading = false), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe(); + } + if (elem.identifier === 'doctype') { + this.http.get("../../rest/doctypes").pipe( + tap((data: any) => { + let arrValues: any[] = []; + data.structure.forEach((doctype: any) => { + if (doctype['doctypes_second_level_id'] === undefined) { + arrValues.push({ + id: doctype.doctypes_first_level_id, + label: doctype.doctypes_first_level_label, + isTitle: true, + color: doctype.css_style + }); + } else if (doctype['description'] === undefined) { + arrValues.push({ + id: doctype.doctypes_second_level_id, + label: doctype.doctypes_second_level_label, + isTitle: true, + color: doctype.css_style + }); + + arrValues = arrValues.concat(data.structure.filter((info: any) => info.doctypes_second_level_id === doctype.doctypes_second_level_id && info.description !== undefined).map((info: any) => { + return { + id: info.type_id, + label: info.description, + isTitle: false + } + })); + } + }); + elem.values = arrValues; + }), + finalize(() => this.loading = false), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe(); + } + }); + }); + } } \ No newline at end of file -- GitLab