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 d63b2850bd5207bfc093d3830ded9d18a6599039..995ef917cae8177f2aff35e614e487dc718a49aa 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.html +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.html @@ -61,7 +61,7 @@ <ng-container *ngIf="field.type === 'select'"> <plugin-select-search [showResetOption]="adminMode" [placeholderLabel]="!adminMode ? lang.chooseValue : lang.defaultValue" - [formControlSelect]="arrFormControl[field.identifier]" [datas]="field.values" + [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'"> 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 bc497c927049ded0c37b90fc1cd51f08f1ef5973..5925cda303329ea7573090841bdf9f99e4735ad5 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -402,6 +402,7 @@ export class IndexingFormComponent implements OnInit { } }); elem.values = arrValues; + elem.event = 'calcLimitDate'; } }); }); @@ -483,7 +484,7 @@ export class IndexingFormComponent implements OnInit { }), exhaustMap((data) => this.http.get("../../rest/indexingModels/" + indexModelId)), tap((data: any) => { - + this.currentCategory = data.indexingModel.category; let fieldExist: boolean; if (data.indexingModel.fields.length === 0) { @@ -601,4 +602,26 @@ export class IndexingFormComponent implements OnInit { this.arrFormControl[field.identifier].enable(); } } + + launchEvent(value: any, field: any) { + this[field.event](field.identifier, value); + } + + calcLimitDate(identifier: string, value: any) { + + // TO DO: REMOVE AFTER BACK + if (this.arrFormControl['processLimitDate'] !== undefined) { + this.arrFormControl['processLimitDate'].setValue(new Date()); + } + + /*this.http.get("../../rest/doctypes/types/" + value + '/getLimitDate').pipe( + tap((data: any) => { + this.arrFormControl['processLimitDate'].setValue(data); + }), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe();*/ + } } \ No newline at end of file diff --git a/src/frontend/plugins/select-search/select-search.component.html b/src/frontend/plugins/select-search/select-search.component.html index 8f5030464c6b6c66a3d7d9a7a1799b2dbfeffdd0..8b9a728c7c746eeabe5b95f6fb9997e73c884c36 100644 --- a/src/frontend/plugins/select-search/select-search.component.html +++ b/src/frontend/plugins/select-search/select-search.component.html @@ -1,5 +1,5 @@ <mat-form-field class="input-form" floatLabel="never"> - <mat-select [formControl]="formControlSelect" [placeholder]="placeholderLabel" #test> + <mat-select [formControl]="formControlSelect" [placeholder]="placeholderLabel" #test (selectionChange)="launchEvent($event)"> <input *ngIf="datas.length > 5" matInput class="mat-select-search-input mat-select-search-hidden" /> <div *ngIf="datas.length > 5" class="mat-select-search-inner" [ngClass]="{'mat-select-search-inner-multiple': matSelect.multiple}"> diff --git a/src/frontend/plugins/select-search/select-search.component.ts b/src/frontend/plugins/select-search/select-search.component.ts index 376e0c801d6d1a06c27f6ae09f355d83241664a5..2fa8e62398304fa583ea521d0b2d01a79cb90d4e 100644 --- a/src/frontend/plugins/select-search/select-search.component.ts +++ b/src/frontend/plugins/select-search/select-search.component.ts @@ -2,7 +2,8 @@ import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, QueryList, ViewChild, - Renderer2 + Renderer2, + Output } from '@angular/core'; import { ControlValueAccessor, FormControl } from '@angular/forms'; import { MatOption, MatSelect } from '@angular/material'; @@ -27,6 +28,11 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView @Input('showResetOption') showResetOption: boolean; + /** + * Catch external event after select an element in autocomplete + */ + @Output('afterSelected') afterSelected = new EventEmitter(); + /** Reference to the search input field */ @ViewChild('searchSelectInput', { read: ElementRef, static: true }) searchSelectInput: ElementRef; @@ -121,10 +127,10 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView }, 800);*/ this.filteredDatas = this.formControlSearch.valueChanges - .pipe( - startWith(''), - map(value => this._filter(value)) - ); + .pipe( + startWith(''), + map(value => this._filter(value)) + ); // this.initMultipleHandling(); @@ -231,8 +237,10 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView .pipe(takeUntil(this._onDestroy)) .subscribe(() => { // note: this is hacky, but currently there is no better way to do this - this.searchSelectInput.nativeElement.parentElement.parentElement - .parentElement.parentElement.parentElement.classList.add(overlayClass); + if (this.searchSelectInput !== undefined) { + this.searchSelectInput.nativeElement.parentElement.parentElement + .parentElement.parentElement.parentElement.classList.add(overlayClass); + } }); this.overlayClassSet = true; @@ -286,4 +294,9 @@ export class PluginSelectSearchComponent implements OnInit, OnDestroy, AfterView } } + launchEvent(ev: any) { + if (this.afterSelected !== undefined) { + this.afterSelected.emit(ev.value); + } + } }