Commit e6f0fccc authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Refactoring time criteria

parent 9bc50008
......@@ -55,7 +55,7 @@
</div>
<div *ngSwitchCase="'tm'">
<app-time class="criteria" [id]="attribute.id" [label]="attribute.form_label"
[criterion]="getCriterion(attribute.id)" (add)="add($event)">
[operator]="attribute.operator" [criterion]="getCriterion(attribute.id)" (add)="add($event)">
</app-time>
</div>
<div *ngSwitchCase="'ts'">
......
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Criterion, TimeCriterion } from '../../../store/model';
import { Criterion, FieldCriterion } from '../../../store/model';
@Component({
selector: 'app-time',
......@@ -11,12 +11,13 @@ import { Criterion, TimeCriterion } from '../../../store/model';
})
export class TimeComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
}
@Output() add: EventEmitter<TimeCriterion> = new EventEmitter();
@Output() add: EventEmitter<FieldCriterion> = new EventEmitter();
public hours: string[] = [];
public minutes: string[] = [];
......@@ -30,7 +31,7 @@ export class TimeComponent {
}
addCriterion() {
const time = new TimeCriterion(this.id, this.hh.value + ':' + this.mm.value);
const time = new FieldCriterion(this.id, this.operator, this.hh.value + ':' + this.mm.value);
this.add.emit(time);
}
......@@ -41,7 +42,7 @@ export class TimeComponent {
this.mm.reset();
this.mm.enable();
} else {
const c = criterion as TimeCriterion;
const c = criterion as FieldCriterion;
this.hh.setValue(c.value.slice(0, 2));
this.hh.disable();
this.mm.setValue(c.value.slice(3, 5));
......
......@@ -5,7 +5,6 @@ export * from './field-criterion.model';
export * from './checkbox-criterion.model';
export * from './select-multiple-criterion.model';
export * from './search-meta.model';
export * from './time-criterion.model';
export * from './datetime-criterion.model';
export * from './search-query-params.model';
export * from './json-criterion.model';
import { Criterion } from './criterion.model';
export class TimeCriterion extends Criterion {
value: string;
constructor(id: number, value: string) {
super(id);
this.value = value;
}
printCriterion(): string {
return this.value;
}
getCriterionStr(): string {
return this.id + ':gt:' + this.value;
}
}
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