From 5f09f89f88918dd42259359c1cd8dab32fd2f876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= <francois.agneray@lam.fr> Date: Tue, 14 Jun 2022 22:13:45 +0200 Subject: [PATCH] Fixed to merge into develop --- .../criteria/criterion.component.html | 2 +- .../criteria/criterion.component.ts | 121 +++++++++--------- .../search/components/criteria/index.ts | 9 ++ .../abstract-search-type.component.ts | 10 ++ .../search-type/between-date.component.html | 8 +- .../search-type/between-date.component.ts | 31 +++-- .../search-type/between.component.html | 6 +- .../criteria/search-type/between.component.ts | 64 ++++----- .../search-type/checkbox.component.html | 6 +- .../search-type/checkbox.component.ts | 32 +++-- .../search-type/datalist.component.ts | 11 +- .../criteria/search-type/date.component.ts | 20 ++- .../search-type/datetime.component.ts | 22 +++- .../criteria/search-type/field.component.ts | 9 ++ .../criteria/search-type/json.component.html | 6 +- .../criteria/search-type/json.component.ts | 36 ++++-- .../criteria/search-type/list.component.html | 6 +- .../criteria/search-type/list.component.ts | 31 +++-- .../criteria/search-type/radio.component.ts | 11 +- .../search-type-loader.directive.ts | 9 ++ .../select-multiple.component.html | 6 +- .../search-type/select-multiple.component.ts | 27 ++-- .../criteria/search-type/select.component.ts | 11 +- .../search-type/svom-json-kw.component.html | 6 +- .../search-type/svom-json-kw.component.ts | 35 +++-- .../criteria/search-type/time.component.ts | 15 ++- 26 files changed, 342 insertions(+), 208 deletions(-) diff --git a/client/src/app/instance/search/components/criteria/criterion.component.html b/client/src/app/instance/search/components/criteria/criterion.component.html index a5b7bd67..f9249c61 100644 --- a/client/src/app/instance/search/components/criteria/criterion.component.html +++ b/client/src/app/instance/search/components/criteria/criterion.component.html @@ -1,7 +1,7 @@ <div class="row"> <div class="col form-group"> <label> - <app-attribute-label [label]="attribute.label" [description]="attribute.description"></app-attribute-label> + <app-attribute-label [label]="attribute.form_label" [description]="attribute.description"></app-attribute-label> </label> <ng-template searchType></ng-template> </div> diff --git a/client/src/app/instance/search/components/criteria/criterion.component.ts b/client/src/app/instance/search/components/criteria/criterion.component.ts index d153d073..245f6fba 100644 --- a/client/src/app/instance/search/components/criteria/criterion.component.ts +++ b/client/src/app/instance/search/components/criteria/criterion.component.ts @@ -7,65 +7,64 @@ * file that was distributed with this source code. */ - import { Component, Input, Output, EventEmitter, ViewChild, SimpleChanges, OnInit, OnChanges } from '@angular/core'; +import { Component, Input, Output, EventEmitter, ViewChild, SimpleChanges, OnInit, OnChanges } from '@angular/core'; - import { Attribute } from 'src/app/metamodel/models'; - import { Criterion, FieldCriterion } from 'src/app/instance/store/models'; - import { SearchTypeLoaderDirective, AbstractSearchTypeComponent, getSearchTypeComponent } from './search-type'; - - @Component({ - selector: 'app-criterion', - templateUrl: 'criterion.component.html' - }) - export class CriterionComponent implements OnInit, OnChanges { - @Input() attribute: Attribute; - @Input() criterion: Criterion; - @Input() criteriaList: Criterion[]; - @Output() addCriterion: EventEmitter<Criterion> = new EventEmitter(); - @Output() deleteCriterion: EventEmitter<number> = new EventEmitter(); - - @ViewChild(SearchTypeLoaderDirective, {static: true}) SearchTypeLoaderDirective!: SearchTypeLoaderDirective; - - public searchTypeComponent: AbstractSearchTypeComponent; - - ngOnInit() { - const viewContainerRef = this.SearchTypeLoaderDirective.viewContainerRef; - const componentRef = viewContainerRef.createComponent<AbstractSearchTypeComponent>( - getSearchTypeComponent(this.attribute.search_type) - ); - componentRef.instance.setAttribute(this.attribute); - componentRef.instance.setCriterion(this.criterion); - componentRef.instance.setCriteriaList(this.criteriaList); - this.searchTypeComponent = componentRef.instance; - } - - ngOnChanges(changes: SimpleChanges): void { - if (changes.criterion && !changes.criterion.firstChange) { - this.searchTypeComponent.setCriterion(changes.criterion.currentValue); - } - - if (changes.criteriaList && !changes.criteriaList.firstChange) { - this.searchTypeComponent.setCriteriaList(changes.criteriaList.currentValue); - } - } - - /** - * Emits event to add criterion to the criteria list. - * - * @fires EventEmitter<Criterion> - */ - emitAdd(): void { - let criterion: Criterion; - if (this.searchTypeComponent.nullOrNotNull) { - criterion = { - id: this.attribute.id, - type: 'field', - operator: this.searchTypeComponent.nullOrNotNull - } as FieldCriterion; - } else { - criterion = this.searchTypeComponent.getCriterion(); - } - this.addCriterion.emit(criterion); - } - } - \ No newline at end of file +import { Attribute } from 'src/app/metamodel/models'; +import { Criterion, FieldCriterion } from 'src/app/instance/store/models'; +import { SearchTypeLoaderDirective, AbstractSearchTypeComponent, getSearchTypeComponent } from './search-type'; + +@Component({ + selector: 'app-criterion', + templateUrl: 'criterion.component.html' +}) +export class CriterionComponent implements OnInit, OnChanges { + @Input() attribute: Attribute; + @Input() criterion: Criterion; + @Input() criteriaList: Criterion[]; + @Output() addCriterion: EventEmitter<Criterion> = new EventEmitter(); + @Output() deleteCriterion: EventEmitter<number> = new EventEmitter(); + + @ViewChild(SearchTypeLoaderDirective, {static: true}) SearchTypeLoaderDirective!: SearchTypeLoaderDirective; + + public searchTypeComponent: AbstractSearchTypeComponent; + + ngOnInit() { + const viewContainerRef = this.SearchTypeLoaderDirective.viewContainerRef; + const componentRef = viewContainerRef.createComponent<AbstractSearchTypeComponent>( + getSearchTypeComponent(this.attribute.search_type) + ); + componentRef.instance.setAttribute(this.attribute); + componentRef.instance.setCriterion(this.criterion); + componentRef.instance.setCriteriaList(this.criteriaList); + this.searchTypeComponent = componentRef.instance; + } + + ngOnChanges(changes: SimpleChanges): void { + if (changes.criterion && !changes.criterion.firstChange) { + this.searchTypeComponent.setCriterion(changes.criterion.currentValue); + } + + if (changes.criteriaList && !changes.criteriaList.firstChange) { + this.searchTypeComponent.setCriteriaList(changes.criteriaList.currentValue); + } + } + + /** + * Emits event to add criterion to the criteria list. + * + * @fires EventEmitter<Criterion> + */ + emitAdd(): void { + let criterion: Criterion; + if (this.searchTypeComponent.nullOrNotNull) { + criterion = { + id: this.attribute.id, + type: 'field', + operator: this.searchTypeComponent.nullOrNotNull + } as FieldCriterion; + } else { + criterion = this.searchTypeComponent.getCriterion(); + } + this.addCriterion.emit(criterion); + } +} diff --git a/client/src/app/instance/search/components/criteria/index.ts b/client/src/app/instance/search/components/criteria/index.ts index 384fec9f..6a2833b2 100644 --- a/client/src/app/instance/search/components/criteria/index.ts +++ b/client/src/app/instance/search/components/criteria/index.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { ConeSearchTabComponent } from './cone-search-tab.component'; import { CriteriaTabsComponent } from './criteria-tabs.component'; import { CriteriaByFamilyComponent } from './criteria-by-family.component'; diff --git a/client/src/app/instance/search/components/criteria/search-type/abstract-search-type.component.ts b/client/src/app/instance/search/components/criteria/search-type/abstract-search-type.component.ts index 4c4aa4f8..0d8b4b7b 100644 --- a/client/src/app/instance/search/components/criteria/search-type/abstract-search-type.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/abstract-search-type.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Directive } from '@angular/core'; import { FormGroup } from '@angular/forms'; @@ -27,6 +36,7 @@ export abstract class AbstractSearchTypeComponent { } else { this.form.enable(); this.form.reset(); + this.nullOrNotNull = ''; } } diff --git a/client/src/app/instance/search/components/criteria/search-type/between-date.component.html b/client/src/app/instance/search/components/criteria/search-type/between-date.component.html index 7b8dc703..87043915 100644 --- a/client/src/app/instance/search/components/criteria/search-type/between-date.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/between-date.component.html @@ -1,11 +1,9 @@ <form [formGroup]="form" novalidate> <div class="row form-group"> <div class="col-md-3 col-sm-auto pr-sm-1 mb-1 mb-sm-0"> - <select class="custom-select" (change)="labelOnChange()" formControlName ="label"> - <option [value]="'Bw'">Bw</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> - </select> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> + </select> </div> <div class="w-100 d-block d-sm-none"></div> <div class="col pl-sm-1"> diff --git a/client/src/app/instance/search/components/criteria/search-type/between-date.component.ts b/client/src/app/instance/search/components/criteria/search-type/between-date.component.ts index a8f0eb5c..2706a27e 100644 --- a/client/src/app/instance/search/components/criteria/search-type/between-date.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/between-date.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -9,25 +18,31 @@ import { Criterion, BetweenCriterion } from 'src/app/instance/store/models'; templateUrl: 'between-date.component.html' }) export class BetweenDateComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'bw', label: 'between' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; + constructor() { super(); this.form = new FormGroup({ - dateRange: new FormControl('', [Validators.required]), - label: new FormControl() + label: new FormControl(), + dateRange: new FormControl('', [Validators.required]) }); } setCriterion(criterion: Criterion) { super.setCriterion(criterion); - this.form.controls.label.setValue('Bw'); if (criterion) { const betweenCriterion = criterion as BetweenCriterion; this.form.controls.dateRange.setValue([ new Date(betweenCriterion.min), new Date(betweenCriterion.max) ]); - + } else { + this.form.controls.label.setValue('bw'); } } @@ -55,24 +70,18 @@ export class BetweenDateComponent extends AbstractSearchTypeComponent { * * @return string */ - getDateString(date: Date): string { const month = ('0' + (date.getMonth() + 1)).slice(-2); const day = ('0' + (date.getDate())).slice(-2); return `${date.getFullYear()}-${month}-${day}`; } - /** - * manage label change - */ + labelOnChange() { if (this.form.controls.label.value === 'nl' || this.form.controls.label.value === 'nnl') { this.nullOrNotNull = this.form.controls.label.value; this.form.controls.dateRange.disable(); } else { - this.nullOrNotNull = ''; this.form.controls.dateRange.enable(); } } - - } diff --git a/client/src/app/instance/search/components/criteria/search-type/between.component.html b/client/src/app/instance/search/components/criteria/search-type/between.component.html index 6e74e244..945264f6 100644 --- a/client/src/app/instance/search/components/criteria/search-type/between.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/between.component.html @@ -1,10 +1,8 @@ <form [formGroup]="form" novalidate> <div class="row form-group"> <div class="col-md-3 col-sm-auto pr-sm-1 mb-1 mb-sm-0"> - <select class="custom-select" (change)="labelOnChange()" formControlName="label"> - <option [value]="'Min/Max'">Min/Max</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> </select> </div> <div class="w-100 d-block d-sm-none"></div> diff --git a/client/src/app/instance/search/components/criteria/search-type/between.component.ts b/client/src/app/instance/search/components/criteria/search-type/between.component.ts index d3939a82..0aeeb599 100644 --- a/client/src/app/instance/search/components/criteria/search-type/between.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/between.component.ts @@ -1,4 +1,13 @@ -import { Component, OnInit } from '@angular/core'; +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { AbstractSearchTypeComponent } from './abstract-search-type.component'; @@ -8,21 +17,27 @@ import { Criterion, BetweenCriterion } from 'src/app/instance/store/models'; selector: 'app-between', templateUrl: 'between.component.html' }) -export class BetweenComponent extends AbstractSearchTypeComponent implements OnInit { - +export class BetweenComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'bw', label: 'min/max' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; constructor() { super(); this.form = new FormGroup({ + label: new FormControl('', [Validators.required]), min: new FormControl('', [Validators.required]), - max: new FormControl('', [Validators.required]), - label: new FormControl('') + max: new FormControl('', [Validators.required]) }); - - } - ngOnInit(): void { - this.form.controls.label.setValue("Min/Max"); + + setCriterion(criterion: Criterion): void { + super.setCriterion(criterion); + if (!criterion) { + this.form.controls.label.setValue('bw'); + } } /** @@ -50,24 +65,6 @@ export class BetweenComponent extends AbstractSearchTypeComponent implements OnI return this.attribute.placeholder_min; } } - /** - * manage label change - */ - labelOnChange() { - if (this.form.controls.label.value === 'nl' || this.form.controls.label.value === 'nnl') { - this.nullOrNotNull = this.form.controls.label.value; - this.form.controls.min.disable(); - this.form.controls.max.disable(); - } else { - - if (!(this.form.controls.min.value || this.form.controls.max.value)) { - - this.nullOrNotNull = ''; - } - this.form.controls.max.enable(); - this.form.controls.min.enable(); - } - } /** * Returns placeholder for the maximum value. @@ -86,11 +83,14 @@ export class BetweenComponent extends AbstractSearchTypeComponent implements OnI return this.form.controls.min.value || this.form.controls.max.value; } - enable() { - super.enable(); - if (this.criteriaList) { - this.form.controls.label.disable(); + labelOnChange() { + if (this.form.controls.label.value === 'nl' || this.form.controls.label.value === 'nnl') { + this.nullOrNotNull = this.form.controls.label.value; + this.form.controls.min.disable(); + this.form.controls.max.disable(); + } else { + this.form.controls.max.enable(); + this.form.controls.min.enable(); } } - } diff --git a/client/src/app/instance/search/components/criteria/search-type/checkbox.component.html b/client/src/app/instance/search/components/criteria/search-type/checkbox.component.html index e524f736..5ebc3291 100644 --- a/client/src/app/instance/search/components/criteria/search-type/checkbox.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/checkbox.component.html @@ -1,10 +1,8 @@ <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()" formControlName="label"> - <option [value]="">In</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> </select> </div> <div class="w-100 d-block d-sm-none"></div> 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 2457ca1d..9fe0de55 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 @@ -1,5 +1,14 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; -import { FormGroup, FormControl, FormArray, Validators } from '@angular/forms'; +import { FormGroup, FormControl, FormArray } from '@angular/forms'; import { AbstractSearchTypeComponent } from './abstract-search-type.component'; import { Criterion, SelectMultipleCriterion } from 'src/app/instance/store/models'; @@ -11,10 +20,16 @@ import { Attribute } from 'src/app/metamodel/models'; styleUrls: ['checkbox.component.scss'], }) export class CheckboxComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'in', label: 'in' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; + constructor() { super(); this.form = new FormGroup({ - label: new FormControl(''), + label: new FormControl('') }); } @@ -37,11 +52,9 @@ export class CheckboxComponent extends AbstractSearchTypeComponent { this.getCheckboxes().controls[i].setValue(true); } } - }else{ - this.form.controls.label.setValue('In'); + } else { + this.form.controls.label.setValue('in'); } - this.labelOnChange(); - } /** @@ -90,14 +103,11 @@ export class CheckboxComponent extends AbstractSearchTypeComponent { this.nullOrNotNull = this.form.controls.label.value; this.getCheckboxes().controls.map((value, index) => { value.disable(); - }) - + }); } else { - this.nullOrNotNull = ''; this.getCheckboxes().controls.map((value, index) => { value.enable(); - }) - + }); } } } diff --git a/client/src/app/instance/search/components/criteria/search-type/datalist.component.ts b/client/src/app/instance/search/components/criteria/search-type/datalist.component.ts index 08ae2334..0ff56c56 100644 --- a/client/src/app/instance/search/components/criteria/search-type/datalist.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/datalist.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -74,6 +83,7 @@ export class DatalistComponent extends AbstractSearchTypeComponent { getDatalistId(): string { return `datalist_${this.attribute.id}`; } + operatorOnChange() { if (this.form.controls.operator.value === 'nl' || this.form.controls.operator.value === 'nnl') { this.form.controls.value.disable(); @@ -81,5 +91,4 @@ export class DatalistComponent extends AbstractSearchTypeComponent { this.form.controls.value.enable(); } } - } diff --git a/client/src/app/instance/search/components/criteria/search-type/date.component.ts b/client/src/app/instance/search/components/criteria/search-type/date.component.ts index 09d01f5f..9a5ea568 100644 --- a/client/src/app/instance/search/components/criteria/search-type/date.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/date.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -24,11 +33,11 @@ export class DateComponent extends AbstractSearchTypeComponent { this.form.controls.date.setValue(new Date((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) - ); - } + if (!this.attribute.dynamic_operator) { + this.operators = searchTypeOperators.filter( + operator => [this.attribute.operator, 'nl', 'nnl'].includes(operator.value) + ); + } } } @@ -95,5 +104,4 @@ export class DateComponent extends AbstractSearchTypeComponent { this.form.controls.date.enable(); } } - } diff --git a/client/src/app/instance/search/components/criteria/search-type/datetime.component.ts b/client/src/app/instance/search/components/criteria/search-type/datetime.component.ts index 77216290..653f8363 100644 --- a/client/src/app/instance/search/components/criteria/search-type/datetime.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/datetime.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -36,14 +45,13 @@ export class DateTimeComponent extends AbstractSearchTypeComponent { } } 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) - ); - } + if (!this.attribute.dynamic_operator) { + this.operators = searchTypeOperators.filter( + operator => [this.attribute.operator, 'nl', 'nnl'].includes(operator.value) + ); + } } } - /** * Return new criterion @@ -105,6 +113,7 @@ export class DateTimeComponent extends AbstractSearchTypeComponent { const day = ('0' + (date.getDate())).slice(-2); return `${date.getFullYear()}-${month}-${day}`; } + operatorOnChange() { if (this.form.controls.operator.value === 'nl' || this.form.controls.operator.value === 'nnl') { this.form.controls.date.disable(); @@ -116,5 +125,4 @@ export class DateTimeComponent extends AbstractSearchTypeComponent { this.form.controls.mm.enable(); } } - } diff --git a/client/src/app/instance/search/components/criteria/search-type/field.component.ts b/client/src/app/instance/search/components/criteria/search-type/field.component.ts index 56722f49..4a83e051 100644 --- a/client/src/app/instance/search/components/criteria/search-type/field.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/field.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; diff --git a/client/src/app/instance/search/components/criteria/search-type/json.component.html b/client/src/app/instance/search/components/criteria/search-type/json.component.html index d977f5c3..81477fd6 100644 --- a/client/src/app/instance/search/components/criteria/search-type/json.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/json.component.html @@ -1,10 +1,8 @@ <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()" formControlName="label"> - <option [value]="">json</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> </select> </div> <div class="w-100 d-block d-sm-none"></div> diff --git a/client/src/app/instance/search/components/criteria/search-type/json.component.ts b/client/src/app/instance/search/components/criteria/search-type/json.component.ts index a0293a59..1399230f 100644 --- a/client/src/app/instance/search/components/criteria/search-type/json.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/json.component.ts @@ -1,4 +1,13 @@ -import { Component, OnInit } from '@angular/core'; +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { AbstractSearchTypeComponent } from './abstract-search-type.component'; @@ -8,19 +17,28 @@ import { Criterion, JsonCriterion } from 'src/app/instance/store/models'; selector: 'app-json', templateUrl: 'json.component.html' }) -export class JsonComponent extends AbstractSearchTypeComponent implements OnInit { +export class JsonComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'js', label: 'json' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; + constructor() { super(); this.form = new FormGroup({ + label: new FormControl(''), path: new FormControl('', [Validators.required]), operator: new FormControl('', [Validators.required]), - value: new FormControl('', [Validators.required]), - label: new FormControl('') + value: new FormControl('', [Validators.required]) }); - } - ngOnInit(): void { - this.form.controls.label.setValue('json') + + setCriterion(criterion: Criterion) { + super.setCriterion(criterion); + if (!criterion) { + this.form.controls.label.setValue('js'); + } } /** @@ -36,20 +54,16 @@ export class JsonComponent extends AbstractSearchTypeComponent implements OnInit } as JsonCriterion; } - 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(); - } else { - this.nullOrNotNull = ''; this.form.controls.operator.enable(); this.form.controls.path.enable(); this.form.controls.value.enable(); - } } } diff --git a/client/src/app/instance/search/components/criteria/search-type/list.component.html b/client/src/app/instance/search/components/criteria/search-type/list.component.html index 07043464..ec7caa9d 100644 --- a/client/src/app/instance/search/components/criteria/search-type/list.component.html +++ b/client/src/app/instance/search/components/criteria/search-type/list.component.html @@ -1,10 +1,8 @@ <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()" formControlName="label"> - <option [value]="'='">=</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> </select> </div> <div class="w-100 d-block d-sm-none"></div> diff --git a/client/src/app/instance/search/components/criteria/search-type/list.component.ts b/client/src/app/instance/search/components/criteria/search-type/list.component.ts index 71009323..4383525e 100644 --- a/client/src/app/instance/search/components/criteria/search-type/list.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/list.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -9,22 +18,27 @@ import { Criterion, ListCriterion } from 'src/app/instance/store/models'; templateUrl: 'list.component.html' }) export class ListComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'in', label: 'in' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; + constructor() { super(); this.form = new FormGroup({ - list: new FormControl('', [Validators.required]), - label: new FormControl('') + label: new FormControl(''), + list: new FormControl('', [Validators.required]) }); } setCriterion(criterion: Criterion) { super.setCriterion(criterion); - if (criterion) { this.form.controls.list.setValue((criterion as ListCriterion).values.join('\n')); this.form.disable(); } else { - this.form.controls.label.setValue('='); + this.form.controls.label.setValue('in'); } } @@ -58,17 +72,8 @@ export class ListComponent extends AbstractSearchTypeComponent { if (this.form.controls.label.value === 'nl' || this.form.controls.label.value === 'nnl') { this.nullOrNotNull = this.form.controls.label.value; this.form.controls.list.disable(); - } else { - this.nullOrNotNull = ''; this.form.controls.list.enable(); - - } - } - enable(): void { - if (this.criteriaList) { - this.form.controls.label.disable(); - } } } 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 57d0b881..b372f83f 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 @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -62,6 +71,7 @@ export class RadioComponent extends AbstractSearchTypeComponent { this.form.controls.operator.disable(); } } + operatorOnChange() { if (this.form.controls.operator.value === 'nl' || this.form.controls.operator.value === 'nnl') { this.form.controls.radio.disable(); @@ -69,5 +79,4 @@ export class RadioComponent extends AbstractSearchTypeComponent { this.form.controls.radio.enable(); } } - } diff --git a/client/src/app/instance/search/components/criteria/search-type/search-type-loader.directive.ts b/client/src/app/instance/search/components/criteria/search-type/search-type-loader.directive.ts index 74d000d5..6ea1df79 100644 --- a/client/src/app/instance/search/components/criteria/search-type/search-type-loader.directive.ts +++ b/client/src/app/instance/search/components/criteria/search-type/search-type-loader.directive.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Directive, ViewContainerRef } from '@angular/core'; @Directive({ 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 80044cfc..3ee473e1 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,10 +1,8 @@ <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()" formControlName="label"> - <option [value]="">in</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> </select> </div> <div class="w-100 d-block d-sm-none"></div> 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 a0ff6106..e514d086 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 @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -9,11 +18,17 @@ import { Criterion, SelectMultipleCriterion } from 'src/app/instance/store/model templateUrl: 'select-multiple.component.html' }) export class SelectMultipleComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'in', label: 'in' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; + constructor() { super(); this.form = new FormGroup({ - select: new FormControl('', [Validators.required]), - label: new FormControl('') + label: new FormControl(''), + select: new FormControl('', [Validators.required]) }); } @@ -21,10 +36,9 @@ export class SelectMultipleComponent extends AbstractSearchTypeComponent { super.setCriterion(criterion); if (criterion) { const multipleCriterion = criterion as SelectMultipleCriterion; - const values = multipleCriterion.options.map(option => option.value); this.form.controls.select.setValue(values); - }else{ + } else { this.form.controls.label.setValue('in'); } } @@ -44,16 +58,13 @@ export class SelectMultipleComponent extends AbstractSearchTypeComponent { options } as SelectMultipleCriterion; } + 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(); - } } } diff --git a/client/src/app/instance/search/components/criteria/search-type/select.component.ts b/client/src/app/instance/search/components/criteria/search-type/select.component.ts index 53955b85..28b82635 100644 --- a/client/src/app/instance/search/components/criteria/search-type/select.component.ts +++ b/client/src/app/instance/search/components/criteria/search-type/select.component.ts @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -17,7 +26,6 @@ export class SelectComponent extends AbstractSearchTypeComponent { select: new FormControl('', [Validators.required]) }); } - setCriterion(criterion: Criterion) { super.setCriterion(criterion); @@ -60,6 +68,7 @@ export class SelectComponent extends AbstractSearchTypeComponent { this.form.controls.operator.disable(); } } + operatorOnChange() { if (this.form.controls.operator.value === 'nl' || this.form.controls.operator.value === 'nnl') { this.form.controls.select.disable(); 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 a0601d6f..1f9e9be4 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,10 +1,8 @@ <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()" formControlName="label"> - <option [value]="">json</option> - <option [value]="'nl'">Null</option> - <option [value]="'nnl'">Not Null</option> + <select class="custom-select" formControlName="label" (change)="labelOnChange()"> + <option *ngFor="let l of labels" [ngValue]="l.value">{{ l.label }}</option> </select> </div> <div class="w-100 d-block d-sm-none"></div> 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 f97db9b3..399e1ef2 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 @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component, ChangeDetectorRef } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { HttpClient } from '@angular/common/http'; @@ -13,24 +22,33 @@ import { Criterion, FieldCriterion, JsonCriterion, SvomKeyword } from 'src/app/i templateUrl: 'svom-json-kw.component.html' }) export class SvomJsonKwComponent extends AbstractSearchTypeComponent { + labels = [ + { value: 'js', label: 'json' }, + { value: 'nl', label: 'null' }, + { value: 'nnl', label: 'not null' } + ]; svomKeywords: SvomKeyword[] = []; constructor(private changeDetectorRef: ChangeDetectorRef, private http: HttpClient, private config: AppConfigService) { super(); this.form = new FormGroup({ + label: new FormControl(''), path: new FormControl('', [Validators.required]), operator: new FormControl('', [Validators.required]), - value: new FormControl('', [Validators.required]), - label: new FormControl('') + value: new FormControl('', [Validators.required]) }); } + + setCriterion(criterion: Criterion) { + super.setCriterion(criterion); + if (!criterion) { + this.form.controls.label.setValue('js'); + } + } 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) @@ -43,9 +61,6 @@ 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'); - } } /** @@ -70,19 +85,17 @@ export class SvomJsonKwComponent extends AbstractSearchTypeComponent { getKeywordValue(svomKeyword: SvomKeyword): string { return `${svomKeyword.extension},${svomKeyword.name}` } + 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(); - } else { - this.nullOrNotNull = ''; this.form.controls.operator.enable(); this.form.controls.path.enable(); this.form.controls.value.enable(); - } } } 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 d7857d7c..eddc3134 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 @@ -1,3 +1,12 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + import { Component } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; @@ -37,12 +46,9 @@ export class TimeComponent extends AbstractSearchTypeComponent { this.operators = searchTypeOperators.filter( operator => [this.attribute.operator, 'nl', 'nnl'].includes(operator.value) ); - - } - + } } } - /** * Return new criterion @@ -89,6 +95,7 @@ export class TimeComponent extends AbstractSearchTypeComponent { } return array; } + operatorOnChange() { if (this.form.controls.operator.value === 'nl' || this.form.controls.operator.value === 'nnl') { this.form.controls.hh.disable(); -- GitLab