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 a5b7bd67ef96e1080df87b81c197107efe62c3d4..f9249c619b86339377989b806c7bef02cf295fea 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 d153d073060d97940b8a3ce6a579b18eb292ffd6..245f6fba7466aaba222547c067c764facfa8ad8c 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 384fec9fedf22ed74f2127a6d7272fbee81c43df..6a2833b207e45204194a5599100d0acc92eccf39 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 4c4aa4f85e16c0aae55b8c0ad992deaf6491781f..0d8b4b7b6b6d4f9f272dcd9cf9b99669d30abda5 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 7b8dc70369502a202ceee754b392185ec92747fb..8704391594cb241bf3f714629a75a74a594d0108 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 a8f0eb5cb4a60725ccf87eb2bc5dd8bbaaf0f458..2706a27eef6f55c9dff0053da83dc3bdaee10f29 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 6e74e24441f9ba3b58340807806a2bc5bca87d98..945264f656788b31084fda5129b4b4e88328b1c3 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 d3939a8215729c8919accb5d1ebb8aa114908e7d..0aeeb599b2f5c71978cc70aceb221fe837fccd58 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 e524f73683f6a36783fa76ff683572817b629037..5ebc32918f042ee6ecd11d2f4ea1f55ece22aba6 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 2457ca1d7d95d3628c16a79d16dab74b29b91220..9fe0de55dbb9ff23c08073c4c204cb71b3bda6e7 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 08ae2334cfd8d226fcd495d6f4ff07d88057c8ad..0ff56c56a87051757e80a54a475647cad8eab706 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 09d01f5f954b50d551e1117ada0b40be5edadd41..9a5ea5681bc81efd3466bfbec95989ada1ad5a1f 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 77216290a73a140d68412d97f13dc932853899e4..653f8363e3f7258b6a3df928991452d88a601341 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 56722f491ddd95cbf59960890c0ea9ef93824227..4a83e051bb1aebce5bcf99c37784d95eb07fc60e 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 d977f5c3dc9c89996ac490d980addbcb6e5123e0..81477fd60035ca0a052cbef6e8c1446427f40a46 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 a0293a591ec15b88f53ddf85a143b7025a00cb72..1399230f55a9e7be55ae4c6646103dd52c04641b 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 07043464e5f2ceae7290cc8acebb6166bd453177..ec7caa9db52a737b0e319014ca81a08b0ba82bdc 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 71009323a1dbe851085e9dd32fc89152ab6d01c0..4383525e3153cc0f1b8132c701f19ee28d526f82 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 57d0b881778289a7dc6f47de85bae733db17d2e1..b372f83f4da954adf2370e3cb2c3ecbe503d89b5 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 74d000d5b23e6d838401e8873b41cc2b13183372..6ea1df79bfb08dbdd86e41748919a5d4a0d4a727 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 80044cfc6850e2497f298259bbc3d855f6a3a77b..3ee473e18f6fa6c6fb8e8ae4575e2db00daa7efd 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 a0ff610672c2d2d780b1406fec5e2c2c6e50fc4d..e514d0866d819176ccddf2177b8f31a93dfb2e93 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 53955b852f4156cb2dd502c1db321f87e614b9f7..28b826350c29372bab5382873104ce2577c2d380 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 a0601d6fdf42a4c9333d4076be096f79fff92d3f..1f9e9be41381561eeebe46cc747f79c9a5d016c7 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 f97db9b311d3eee49fe94127eaff3270e2912672..399e1ef28792dee37467b247f434c18b51b12fef 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 d7857d7ca8a2783253503114c043d7b7b02c37e7..eddc3134205470b81e86cdaa5bcc7f06b7044209 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();