Commit df3ce24f authored by François Agneray's avatar François Agneray
Browse files

Optimisation des search type criterion

parent b634210b
......@@ -59,7 +59,7 @@
</app-time>
</div>
<div *ngSwitchCase="'ts'">
<app-datetime class="criteria" [id]="attribute.id" [label]="attribute.form_label"
<app-datetime class="criteria" [id]="attribute.id" [label]="attribute.form_label" [operator]="attribute.operator"
[criterion]="getCriterion(attribute.id)" (add)="add($event)" (delete)="delete($event)">
</app-datetime>
</div>
......
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Criterion, BetweenDateCriterion } from '../../../store/model';
import { Criterion, BetweenCriterion } from '../../../store/model';
@Component({
selector: 'app-between-date',
......@@ -16,7 +16,7 @@ export class BetweenDateComponent {
set criterion(criterion: Criterion) {
this.getDefault(criterion);
}
@Output() add: EventEmitter<BetweenDateCriterion> = new EventEmitter();
@Output() add: EventEmitter<BetweenCriterion> = new EventEmitter();
@Output() delete: EventEmitter<number> = new EventEmitter();
field = new FormControl('');
......@@ -24,7 +24,7 @@ export class BetweenDateComponent {
addCriterion(): void {
const dateMin = this.getDateString(this.field.value[0]);
const dateMax = this.getDateString(this.field.value[1]);
const fd = new BetweenDateCriterion(this.id, dateMin, dateMax);
const fd = new BetweenCriterion(this.id, dateMin, dateMax);
this.add.emit(fd);
}
......@@ -37,7 +37,7 @@ export class BetweenDateComponent {
this.field.setValue('');
this.field.enable();
} else {
const c = criterion as BetweenDateCriterion;
const c = criterion as BetweenCriterion;
this.field.setValue([new Date(c.min), new Date(c.max)]);
this.field.disable();
}
......
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Criterion, DatetimeCriterion } from '../../../store/model';
import { Criterion, FieldCriterion } from '../../../store/model';
@Component({
selector: 'app-datetime',
......@@ -11,13 +11,14 @@ import { Criterion, DatetimeCriterion } from '../../../store/model';
})
export class DatetimeComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() placeholder: string;
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
}
@Output() add: EventEmitter<DatetimeCriterion> = new EventEmitter();
@Output() add: EventEmitter<FieldCriterion> = new EventEmitter();
@Output() delete: EventEmitter<number> = new EventEmitter();
hours: string[] = [];
......@@ -35,7 +36,11 @@ export class DatetimeComponent {
}
addCriterion() {
const fd = new DatetimeCriterion(this.id, this.datetime);
const month = ('0' + (this.datetime.getMonth() + 1)).slice(-2);
const day = ('0' + (this.datetime.getDate())).slice(-2);
const date = this.datetime.getFullYear() + '-' + month + '-' + day;
const time = this.hh.value + ':' + this.mm.value;
const fd = new FieldCriterion(this.id, this.operator, date + ' ' + time);
this.add.emit(fd);
}
......@@ -53,14 +58,14 @@ export class DatetimeComponent {
this.mm.enable();
this.isValidFields = false;
} else {
const c = criterion as DatetimeCriterion;
const hour = ('0' + (c.value.getHours())).slice(-2);
const minute = ('0' + (c.value.getMinutes())).slice(-2);
this.date.setValue(c.value);
const c = criterion as FieldCriterion;
const [d, t] = c.value.split(' ');
const [h, m] = t.split(':');
this.date.setValue(new Date(d));
this.date.disable();
this.hh.setValue(hour);
this.hh.setValue(h);
this.hh.disable();
this.mm.setValue(minute);
this.mm.setValue(m);
this.mm.disable();
this.isValidFields = true;
}
......
import { Criterion } from './criterion.model';
export class BetweenDateCriterion extends Criterion {
min: string;
max: string;
constructor(id: number, min: string, max: string) {
super(id);
this.min = min;
this.max = max;
}
printCriterion(): string {
return '∈ [' + this.min + ';' + this.max + ']';
}
getCriterionStr() {
return this.id + '::bd::' + this.min + '|' + this.max;
}
}
import { Criterion } from './criterion.model';
import { Option } from '../../../metamodel/model/option.model';
export class CheckboxCriterion extends Criterion {
values: Option[];
operator: string;
constructor(id: number, operator: string, values: Option[]) {
super(id);
this.operator = operator;
this.values = values;
}
printCriterion(): string {
return '[' + this.values.map(option => option.label).join(',') + ']';
}
getCriterionStr(): string {
if (this.operator === 'eq') {
return this.id + '::in::' + this.values.map(option => option.value).join('|');
} else {
return this.values.map(option => this.id + '::' + this.operator + '::' + option.value).join(';');
}
}
}
import { Criterion } from './criterion.model';
export class DatetimeCriterion extends Criterion {
value: Date;
constructor(id: number, value: Date) {
super(id);
this.value = value;
}
printCriterion(): string {
const month = ('0' + (this.value.getMonth() + 1)).slice(-2);
const day = ('0' + (this.value.getDate())).slice(-2);
const hour = ('0' + (this.value.getHours())).slice(-2);
const minute = ('0' + (this.value.getMinutes())).slice(-2);
const date = this.value.getFullYear() + '-' + month + '-' + day;
const time = hour + ':' + minute;
return date + ' ' + time;
}
getCriterionStr(): string {
const month = ('0' + (this.value.getMonth() + 1)).slice(-2);
const day = ('0' + (this.value.getDate())).slice(-2);
const hour = ('0' + (this.value.getHours())).slice(-2);
const minute = ('0' + (this.value.getMinutes())).slice(-2);
const date = this.value.getFullYear() + '-' + month + '-' + day;
const time = hour + ':' + minute;
return this.id + '::eq::' + date + '.' + time;
}
}
export * from './criterion.model';
export * from './between-criterion.model';
export * from './between-date-criterion.model';
export * from './field-criterion.model';
export * from './checkbox-criterion.model';
export * from './select-multiple-criterion.model';
export * from './search-meta.model';
export * from './datetime-criterion.model';
export * from './search-query-params.model';
export * from './json-criterion.model';
......@@ -12,7 +12,7 @@ import * as fromRouter from '@ngrx/router-store';
import * as fromSearch from './search.reducer';
import * as utils from '../../shared/utils';
import { SearchService } from './search.service';
import { BetweenCriterion, BetweenDateCriterion, SearchMeta, FieldCriterion, SelectMultipleCriterion, JsonCriterion } from './model';
import { BetweenCriterion, SearchMeta, FieldCriterion, SelectMultipleCriterion, JsonCriterion } from './model';
@Injectable()
export class SearchEffects {
......@@ -89,13 +89,13 @@ export class SearchEffects {
case 'dl':
case 'rd':
case 'dt':
case 'ts':
case 'tm':
return new FieldCriterion(parseInt(params[0], 10), params[1], params[2]);
case 'bw':
case 'bd':
const bwValues = params[2].split('|');
return new BetweenCriterion(parseInt(params[0], 10), bwValues[0], bwValues[1]);
case 'bd':
const bwdValues = params[2].split('|');
return new BetweenDateCriterion(parseInt(params[0], 10), bwdValues[0], bwdValues[1]);
case 'ms':
case 'cb':
const msValues = params[2].split('|');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment