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

Refactoring time criteria

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