From 11d59b62ace335faee7203b3316400b4db84d546 Mon Sep 17 00:00:00 2001 From: Angapay Divin <divin.angapay@lam.fr> Date: Wed, 8 Jun 2022 16:40:24 +0200 Subject: [PATCH] make selector desabled in time, svom json, select search type when the user validate a criteria --- .../search-type/checkbox.component.ts | 4 +++- .../criteria/search-type/radio.component.ts | 10 ++++----- .../select-multiple.component.html | 2 +- .../search-type/select-multiple.component.ts | 21 +++++++++++-------- .../search-type/svom-json-kw.component.html | 2 +- .../search-type/svom-json-kw.component.ts | 15 +++++++++---- .../criteria/search-type/time.component.ts | 1 + 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/client/src/app/instance/search/components/criteria/search-type/checkbox.component.ts b/client/src/app/instance/search/components/criteria/search-type/checkbox.component.ts index e5f610ad..9a263ae3 100644 --- a/client/src/app/instance/search/components/criteria/search-type/checkbox.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/checkbox.component.ts @@ -30,13 +30,15 @@ export class CheckboxComponent extends AbstractSearchTypeComponent { setCriterion(criterion: Criterion) { super.setCriterion(criterion); - this.form.controls.label.setValue('In'); + if (criterion) { for (let i = 0; i < this.attribute.options.length; i++) { if ((criterion as SelectMultipleCriterion).options.find(o => o.label === this.attribute.options[i].label)) { this.getCheckboxes().controls[i].setValue(true); } } + }else{ + this.form.controls.label.setValue('In'); } } diff --git a/client/src/app/instance/search/components/criteria/search-type/radio.component.ts b/client/src/app/instance/search/components/criteria/search-type/radio.component.ts index 3dd9bb3a..57d0b881 100644 --- a/client/src/app/instance/search/components/criteria/search-type/radio.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/radio.component.ts @@ -17,23 +17,21 @@ export class RadioComponent extends AbstractSearchTypeComponent { radio: new FormControl('', [Validators.required]) }); } - + setCriterion(criterion: Criterion) { super.setCriterion(criterion); if (criterion) { this.form.controls.radio.setValue((criterion as FieldCriterion).value); } else { + this.form.controls.operator.setValue(this.attribute.operator); if (!this.attribute.dynamic_operator) { this.operators = searchTypeOperators.filter( operator => [this.attribute.operator, 'nl', 'nnl'].includes(operator.value) ); } - } } - - /** * Return new criterion * @@ -41,10 +39,10 @@ export class RadioComponent extends AbstractSearchTypeComponent { */ getCriterion(): Criterion { let value = null; - // if (this.form.controls.operator.value != 'nl' && this.form.controls.operator.value != 'nnl') { + if (this.form.controls.operator.value != 'nl' && this.form.controls.operator.value != 'nnl') { const option = this.attribute.options.find(o => o.value === this.form.value.radio); value = option.value; - // } + } return { id: this.attribute.id, diff --git a/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.html b/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.html index 32219daf..80044cfc 100644 --- a/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.html @@ -1,7 +1,7 @@ <form [formGroup]="form" novalidate> <div class="row form-group"> <div class="col-md-3 col-sm-auto pr-sm-1 mb-1 mb-lg-0"> - <select class="custom-select" (change)="labelOnChange($event.target.value)"> + <select class="custom-select" (change)="labelOnChange()" formControlName="label"> <option [value]="">in</option> <option [value]="'nl'">Null</option> <option [value]="'nnl'">Not Null</option> diff --git a/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.ts b/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.ts index 5675afee..a0ff6106 100644 --- a/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/select-multiple.component.ts @@ -12,7 +12,8 @@ export class SelectMultipleComponent extends AbstractSearchTypeComponent { constructor() { super(); this.form = new FormGroup({ - select: new FormControl('', [Validators.required]) + select: new FormControl('', [Validators.required]), + label: new FormControl('') }); } @@ -23,9 +24,11 @@ export class SelectMultipleComponent extends AbstractSearchTypeComponent { const values = multipleCriterion.options.map(option => option.value); this.form.controls.select.setValue(values); + }else{ + this.form.controls.label.setValue('in'); } } - + /** * Return new criterion * @@ -41,16 +44,16 @@ export class SelectMultipleComponent extends AbstractSearchTypeComponent { options } as SelectMultipleCriterion; } - labelOnChange(value: string) { - if (value === 'nl' || value === 'nnl') { - this.nullOrNotNull = value; + labelOnChange() { + if (this.form.controls.label.value === 'nl' || this.form.controls.label.value === 'nnl') { + this.nullOrNotNull = this.form.controls.label.value; this.form.controls.select.disable(); - + } else { - this.nullOrNotNull = ''; - this.form.controls.select.enable(); - + this.nullOrNotNull = ''; + this.form.controls.select.enable(); + } } } diff --git a/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.html b/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.html index 6cbb2392..a0601d6f 100644 --- a/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.html @@ -1,7 +1,7 @@ <form [formGroup]="form" novalidate> <div class="row form-group"> <div class="col-md-3 col-sm-auto pr-sm-1 mb-1 mb-lg-0"> - <select class="custom-select" (change)="labelOnChange($event.target.value)"> + <select class="custom-select" (change)="labelOnChange()" formControlName="label"> <option [value]="">json</option> <option [value]="'nl'">Null</option> <option [value]="'nnl'">Not Null</option> diff --git a/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.ts b/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.ts index 3592bc25..f97db9b3 100644 --- a/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/svom-json-kw.component.ts @@ -20,13 +20,17 @@ export class SvomJsonKwComponent extends AbstractSearchTypeComponent { this.form = new FormGroup({ path: new FormControl('', [Validators.required]), operator: new FormControl('', [Validators.required]), - value: new FormControl('', [Validators.required]) + value: new FormControl('', [Validators.required]), + label: new FormControl('') }); } setCriteriaList(criteriaList: Criterion[]): void { + super.setCriteriaList(criteriaList); if (this.svomKeywords.length < 1 && criteriaList.find((c: Criterion) => c.id === 3)) { + + const acronym = (criteriaList.find((c: Criterion) => c.id === 3) as FieldCriterion).value; this.http.get<{search_kw: SvomKeyword[]}[]>(`${this.config.apiUrl}/search/sp_cards?a=8&c=1::eq::${acronym}`).pipe( map(data => data[0].search_kw) @@ -39,6 +43,9 @@ export class SvomJsonKwComponent extends AbstractSearchTypeComponent { if (this.svomKeywords.length > 0 && !criteriaList.find((c: Criterion) => c.id === 3)) { this.svomKeywords = []; } + if(! criteriaList.length){ + this.form.controls.label.setValue('json'); + } } /** @@ -63,9 +70,9 @@ export class SvomJsonKwComponent extends AbstractSearchTypeComponent { getKeywordValue(svomKeyword: SvomKeyword): string { return `${svomKeyword.extension},${svomKeyword.name}` } - labelOnChange(value: string) { - if (value === 'nl' || value === 'nnl') { - this.nullOrNotNull = value; + labelOnChange() { + if (this.form.controls.label.value === 'nl' || this.form.controls.label.value === 'nnl') { + this.nullOrNotNull = this.form.controls.label.value; this.form.controls.operator.disable(); this.form.controls.path.disable(); this.form.controls.value.disable(); diff --git a/client/src/app/instance/search/components/criteria/search-type/time.component.ts b/client/src/app/instance/search/components/criteria/search-type/time.component.ts index 7e14e831..d7857d7c 100644 --- a/client/src/app/instance/search/components/criteria/search-type/time.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/time.component.ts @@ -32,6 +32,7 @@ export class TimeComponent extends AbstractSearchTypeComponent { this.form.controls.mm.setValue(fieldCriterion.value.slice(3, 5)); } } else { + this.form.controls.operator.setValue(this.attribute.operator); if (!this.attribute.dynamic_operator) { this.operators = searchTypeOperators.filter( operator => [this.attribute.operator, 'nl', 'nnl'].includes(operator.value) -- GitLab