Commit 25e6a312 authored by Tifenn Guillas's avatar Tifenn Guillas

Add comments for search module => DONE

parent 9f682bb0
......@@ -16,6 +16,10 @@ import { Dataset } from '../../../metamodel/model';
templateUrl: 'cone-search-tab.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Search cone search tab component.
*/
export class ConeSearchTabComponent {
@Input() datasetName: string;
@Input() datasetList: Dataset[];
......@@ -23,6 +27,11 @@ export class ConeSearchTabComponent {
@Input() isValidConeSearch: boolean;
@Output() coneSearchAdded: EventEmitter<boolean> = new EventEmitter();
/**
* Checks if cone search is enabled.
*
* @return boolean
*/
coneSearchEnabled(): boolean {
const config = this.datasetList.find(d => d.name === this.datasetName).config;
if (config !== null && 'cone_search' in config) {
......
......@@ -11,12 +11,17 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from
import { Criterion } from '../../store/model';
import { Attribute, Option } from '../../../metamodel/model';
import { sortByDisplay } from '../../../shared/utils';
@Component({
selector: 'app-criteria-by-family',
templateUrl: 'criteria-by-family.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Search criteria by family component.
*/
export class CriteriaByFamilyComponent {
@Input() attributeList: Attribute[];
@Input() criteriaList: Criterion[];
......@@ -25,26 +30,57 @@ export class CriteriaByFamilyComponent {
advancedForm = false;
/**
* Returns attribute list sorted by criteria display.
*
* @return Attribute[]
*/
getAttributeListSortedByDisplay(): Attribute[] {
return this.attributeList
.sort((a, b) => a.criteria_display - b.criteria_display);
}
/**
* Returns options for the given attribute ID.
*
* @param {number} idAttribute - The attribute ID.
*
* @return Option[]
*/
getOptions(idAttribute: number): Option[] {
return [...this.attributeList
.find(attribute => attribute.id === idAttribute)
.options]
.sort((a, b) => a.display - b.display);
return [...this.attributeList.find(attribute => attribute.id === idAttribute).options]
.sort(sortByDisplay);
}
/**
* Returns criterion for the given criterion ID.
*
* @param {number} id - The criterion ID.
*
* @return Criterion
*/
getCriterion(id: number): Criterion {
return this.criteriaList.find(criterion => criterion.id === id);
}
/**
* Emits event to add the given criterion to the criteria list.
*
* @param {Criterion} criterion - The criterion.
*
* @fires EventEmitter<Criterion>
*/
emitAdd(criterion: Criterion): void {
this.addCriterion.emit(criterion);
}
/**
* Emits event to remove the given criterion ID from the criteria list.
*
* @param {number} id - The criterion ID.
*
* @fires EventEmitter<number>
*/
emitDelete(id: number): void {
this.deleteCriterion.emit(id);
}
......
......@@ -17,6 +17,10 @@ import { Family, Attribute } from '../../../metamodel/model';
templateUrl: 'criteria-tabs.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Search criteria tabs component.
*/
export class CriteriaTabsComponent {
@Input() criteriaFamilyList: Family[];
@Input() attributeList: Attribute[];
......@@ -24,15 +28,36 @@ export class CriteriaTabsComponent {
@Output() addCriterion: EventEmitter<Criterion> = new EventEmitter();
@Output() deleteCriterion: EventEmitter<number> = new EventEmitter();
/**
* Returns attribute list for the given criteria family ID.
*
* @param {number} idFamily - The criteria family ID.
*
* @return Attribute[]
*/
getAttributeByFamily(idFamily: number): Attribute[] {
return this.attributeList
.filter(attribute => attribute.id_criteria_family === idFamily);
}
/**
* Emits event to add the given criterion to the criteria list.
*
* @param {Criterion} criterion - The criterion.
*
* @fires EventEmitter<Criterion>
*/
emitAdd(criterion: Criterion): void {
this.addCriterion.emit(criterion);
}
/**
* Emits event to remove the given criterion ID to the criteria list.
*
* @param {number} id - The criterion ID.
*
* @fires EventEmitter<number>
*/
emitDelete(id: number): void {
this.deleteCriterion.emit(id);
}
......
......@@ -17,10 +17,19 @@ import { Criterion, BetweenCriterion } from '../../../store/model';
templateUrl: 'between-date.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Between date search type component.
*/
export class BetweenDateComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
/**
* Calls getDefault function for the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
......@@ -30,6 +39,11 @@ export class BetweenDateComponent {
field = new FormControl('');
/**
* Emits event to add criterion to the criteria list.
*
* @fires EventEmitter<BetweenCriterion>
*/
emitAdd(): void {
const dateMin = this.getDateString(this.field.value[0]);
const dateMax = this.getDateString(this.field.value[1]);
......@@ -37,10 +51,20 @@ export class BetweenDateComponent {
this.addCriterion.emit(fd);
}
/**
* Emits event to remove criterion ID from the criteria list.
*
* @fires EventEmitter<number>
*/
emitDelete(): void {
this.deleteCriterion.emit(this.id);
}
/**
* Fills form with the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
getDefault(criterion: Criterion): void {
if (!criterion) {
this.field.reset();
......@@ -52,6 +76,13 @@ export class BetweenDateComponent {
}
}
/**
* Stringifies the given date.
*
* @param {Date} date - The date.
*
* @return string
*/
getDateString(date: Date): string {
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + (date.getDate())).slice(-2);
......
......@@ -18,11 +18,20 @@ import { Criterion, BetweenCriterion } from '../../../store/model';
styleUrls: ['operator.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Between search type component.
*/
export class BetweenComponent {
@Input() id: number;
@Input() label: string;
@Input() placeholderMin: string;
@Input() placeholderMax: string;
/**
* Calls getDefault function for the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
......@@ -33,15 +42,30 @@ export class BetweenComponent {
fieldMin = new FormControl('');
fieldMax = new FormControl('');
emitAdd() {
/**
* Emits event to add criterion to the criteria list.
*
* @fires EventEmitter<BetweenCriterion>
*/
emitAdd(): void {
const fd = {id: this.id, type: 'between', min: this.fieldMin.value, max: this.fieldMax.value};
this.addCriterion.emit(fd);
}
emitDelete() {
/**
* Emits event to remove criterion ID from the criteria list.
*
* @fires EventEmitter<number>
*/
emitDelete(): void {
this.deleteCriterion.emit(this.id);
}
/**
* Fills form with the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
getDefault(criterion: Criterion): void {
if (!criterion) {
this.fieldMin.reset();
......@@ -57,7 +81,12 @@ export class BetweenComponent {
}
}
getPlaceholderMin() {
/**
* Returns placeholder for the minimum value.
*
* @return string
*/
getPlaceholderMin(): string {
if (!this.placeholderMin) {
return '';
} else {
......@@ -65,7 +94,12 @@ export class BetweenComponent {
}
}
getPlaceholderMax() {
/**
* Returns placeholder for the maximum value.
*
* @return string
*/
getPlaceholderMax(): string {
if (!this.placeholderMax) {
return '';
} else {
......
......@@ -19,10 +19,19 @@ import { Option } from '../../../../metamodel/model';
styleUrls: ['checkbox.component.css', 'operator.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Checkbox search type component.
*/
export class CheckboxComponent {
@Input() id: number;
@Input() label: string;
@Input() options: Option[];
/**
* Calls getDefault function for the given criterion.
*
* @param {SelectMultipleCriterion} criterion - The criterion.
*/
@Input()
set criterion(criterion: SelectMultipleCriterion) {
this.getDefault(criterion);
......@@ -32,18 +41,33 @@ export class CheckboxComponent {
checkboxes: FormArray;
emitAdd() {
/**
* Emits event to add criterion to the criteria list.
*
* @fires EventEmitter<SelectMultipleCriterion>
*/
emitAdd(): void {
// Filter options to keep only the checked checkboxes and emit the new criterion
const selected = this.checkboxes.value;
const values = [...this.options.filter((option, index) => selected[index])];
this.addCriterion.emit({id: this.id, type: 'multiple', options: values});
}
emitDelete() {
/**
* Emits event to remove criterion ID from the criteria list.
*
* @fires EventEmitter<number>
*/
emitDelete(): void {
// Delete the criterion into the state to reactivate the checkboxes
this.deleteCriterion.emit(this.id);
}
/**
* Fills form with the given criterion.
*
* @param {SelectMultipleCriterion} criterion - The criterion.
*/
getDefault(criterion: SelectMultipleCriterion): void {
// Initialization of checkboxes (1 per option)
const formControls: FormControl[] = [];
......@@ -66,7 +90,12 @@ export class CheckboxComponent {
}
}
isChecked() {
/**
* Checks if one of the checkboxes is checked.
*
* @return boolean
*/
isChecked(): boolean {
// If one of the checkboxes is checked returns true else returns false
return this.checkboxes.controls.filter(formControl => formControl.value).length > 0;
}
......
......@@ -18,12 +18,21 @@ import { Option } from '../../../../metamodel/model';
templateUrl: 'datalist.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Datalist search type component.
*/
export class DatalistComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() placeholder: string;
@Input() options: Option[];
/**
* Calls getDefault function for the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
......@@ -35,19 +44,39 @@ export class DatalistComponent {
field = new FormControl('');
disabledOperator: boolean;
/**
* Modifies operator with the given one.
*
* @param {operator} operator - The operator.
*/
changeOperator(operator: string): void {
this.operator = operator;
}
emitAdd() {
/**
* Emits event to add criterion to the criteria list.
*
* @fires EventEmitter<FieldCriterion>
*/
emitAdd(): void {
const fd = {id: this.id, type: 'field', operator: this.operator, value: this.field.value};
this.addCriterion.emit(fd);
}
emitDelete() {
/**
* Emits event to remove criterion ID from the criteria list.
*
* @fires EventEmitter<number>
*/
emitDelete(): void {
this.deleteCriterion.emit(this.id);
}
/**
* Fills form with the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
getDefault(criterion: Criterion): void {
if (!criterion) {
this.field.reset();
......@@ -61,7 +90,12 @@ export class DatalistComponent {
}
}
getPlaceholder() {
/**
* Returns placeholder.
*
* @return string
*/
getPlaceholder(): string {
if (!this.placeholder) {
return '';
} else {
......@@ -69,7 +103,12 @@ export class DatalistComponent {
}
}
getDatalistId() {
/**
* Returns string datalist ID.
*
* @return string
*/
getDatalistId(): string {
return 'datalist_' + this.id;
}
}
......@@ -17,11 +17,20 @@ import { Criterion, FieldCriterion } from '../../../store/model';
templateUrl: 'date.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Date search type component.
*/
export class DateComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() placeholder: string;
/**
* Calls getDefault function for the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
......@@ -33,19 +42,39 @@ export class DateComponent {
field = new FormControl('');
disabledOperator: boolean;
/**
* Modifies operator with the given one.
*
* @param {operator} operator - The operator.
*/
changeOperator(operator: string): void {
this.operator = operator;
}
emitAdd() {
/**
* Emits event to add criterion to the criteria list.
*
* @fires EventEmitter<FieldCriterion>
*/
emitAdd(): void {
const fd = {id: this.id, type: 'field', operator: this.operator, value: this.getDateString(this.field.value)};
this.addCriterion.emit(fd);
}
emitDelete() {
/**
* Emits event to remove criterion ID from the criteria list.
*
* @fires EventEmitter<number>
*/
emitDelete():void {
this.deleteCriterion.emit(this.id);
}
/**
* Fills form with the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
getDefault(criterion: Criterion): void {
if (!criterion) {
this.field.reset();
......@@ -59,6 +88,11 @@ export class DateComponent {
}
}
/**
* Returns placeholder.
*
* @return string
*/
getPlaceholder(): string {
if (!this.placeholder) {
return '';
......@@ -67,7 +101,14 @@ export class DateComponent {
}
}
getDateString(date: Date) {
/**
* Stringifies the given date.
*
* @param {Date} date - The date.
*
* @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;
......
......@@ -17,10 +17,19 @@ import { Criterion, FieldCriterion } from '../../../store/model';
templateUrl: 'datetime.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Datetime search type component.
*/
export class DatetimeComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
/**
* Calls getDefault function for the given criterion.
*
* @param {Criterion} criterion - The criterion.
*/
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
......@@ -29,9 +38,8 @@ export class DatetimeComponent {
@Output() addCriterion: EventEmitter<FieldCriterion> = new EventEmitter();
@Output() deleteCriterion: EventEmitter<number> = new EventEmitter();
hours: string[] = [];
minutes: string[] = [];
hours: string[] = this.initTime(24);
minutes: string[] = this.initTime(60);
date = new FormControl('');
hh = new FormControl();
mm = new FormControl();
......@@ -40,16 +48,21 @@ export class DatetimeComponent {