Commit 69da0f9c authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Merge branch '39-search_type-between_date' into 'develop'

Resolve "Ajouter search_type between_date"

Closes #39

See merge request !43
parents 2f9eb554 e6f0fccc
Pipeline #1361 passed with stages
in 6 minutes and 6 seconds
......@@ -48,9 +48,14 @@
[criterion]="getCriterion(attribute.id)" (add)="add($event)">
</app-date>
</div>
<div *ngSwitchCase="'bd'">
<app-between-date class="criteria" [id]="attribute.id" [operator]="attribute.operator"
[label]="attribute.form_label" [criterion]="getCriterion(attribute.id)" (add)="add($event)">
</app-between-date>
</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 { Criterion } from '../../store/model';
import { Family, Attribute } from '../../../metamodel/model';
import { Family, Attribute, Option } from '../../../metamodel/model';
@Component({
selector: 'app-criteria-by-family',
......@@ -16,13 +16,13 @@ export class CriteriaByFamilyComponent {
@Output() addCriterion: EventEmitter<Criterion> = new EventEmitter();
@Output() deleteCriterion: EventEmitter<number> = new EventEmitter();
getAttributeByFamily(idFamily) {
getAttributeByFamily(idFamily: number): Attribute[] {
return this.datasetAttributeList
.filter(attribute => attribute.id_criteria_family === idFamily)
.sort((a, b) => a.criteria_display - b.criteria_display);
}
getOptions(idAttribute) {
getOptions(idAttribute: number): Option[] {
return this.datasetAttributeList.find(attribute => attribute.id === idAttribute).options;
}
......
<div class="form-group row">
<label class="col-3 col-form-label">{{ label }}</label>
<div class="col">
<input type="text" placeholder="Pick a date range..." class="form-control" [formControl]="field"
[bsValue]="field.value" [bsConfig]="{ rangeInputFormat: 'YYYY-MM-DD' }" autocomplete="off"
bsDaterangepicker>
</div>
<div class="col-2 text-center">
<button class="btn btn-outline-success" *ngIf="!field.disabled" [hidden]="!field.value"
(click)="addCriterion()"><i class="fas fa-plus-circle"></i></button>
</div>
</div>
\ No newline at end of file
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Criterion, BetweenDateCriterion } from '../../../store/model';
@Component({
selector: 'app-between-date',
templateUrl: 'between-date.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class BetweenDateComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input()
set criterion(criterion: Criterion) {
this.getDefault(criterion);
}
@Output() add: EventEmitter<BetweenDateCriterion> = new EventEmitter();
field = new FormControl('');
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);
this.add.emit(fd);
}
getDefault(criterion: Criterion): void {
if (!criterion) {
this.field.setValue('');
this.field.enable();
} else {
const c = criterion as BetweenDateCriterion;
this.field.setValue([new Date(c.min), new Date(c.max)]);
this.field.disable();
}
}
getDateString(date: Date): string {
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + (date.getDate())).slice(-2);
return date.getFullYear() + '-' + month + '-' + day;
}
}
<div class="form-group row">
<label class="col-3 col-form-label">{{label}}</label>
<label class="col-3 col-form-label">{{ label }}</label>
<div class="col">
<input type="text" class="form-control" [placeholder]="getPlaceholderMin()" [formControl]="fieldMin"
autocomplete="off" />
......
......@@ -6,6 +6,7 @@ import { DatalistComponent } from './datalist.component';
import { RadioComponent } from './radio.component';
import { CheckboxComponent } from './checkbox.component';
import { DateComponent } from './date.component';
import { BetweenDateComponent } from './between-date.component';
import { TimeComponent } from './time.component';
import { DatetimeComponent } from './datetime.component';
import { JsonComponent } from './json.component';
......@@ -19,6 +20,7 @@ export const criteriaComponents = [
RadioComponent,
CheckboxComponent,
DateComponent,
BetweenDateComponent,
TimeComponent,
DatetimeComponent,
JsonComponent
......
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));
......
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;
}
}
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 './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;
}
}
......@@ -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, SearchMeta, FieldCriterion, SelectMultipleCriterion } from './model';
import { BetweenCriterion, BetweenDateCriterion, SearchMeta, FieldCriterion, SelectMultipleCriterion } from './model';
@Injectable()
export class SearchEffects {
......@@ -30,7 +30,7 @@ export class SearchEffects {
switchMap(([action, state]) => {
if (state.search.pristine) {
const datasetName = state.router.state.params.dname;
let actions: Action[] = [
const actions: Action[] = [
new attributeActions.LoadAttributeSearchMetaAction(datasetName),
new searchActions.SelectDatasetAction(datasetName)
];
......@@ -68,7 +68,7 @@ export class SearchEffects {
.map(attribute => attribute.id);
if (state.router.state.queryParams.a) {
defaultOutputList = state.router.state.queryParams.a.split(';').map((o: string) => parseInt(o));
defaultOutputList = state.router.state.queryParams.a.split(';').map((o: string) => parseInt(o, 10));
}
let defaultCriteriaList = loadAttributeSearchMetaSuccessAction.payload
......@@ -82,22 +82,25 @@ export class SearchEffects {
if (state.router.state.queryParams.c) {
defaultCriteriaList = state.router.state.queryParams.c.split(';').map((c: string) => {
const params = c.split(':');
const attribute = loadAttributeSearchMetaSuccessAction.payload.find(a => a.id === parseInt(params[0]));
const attribute = loadAttributeSearchMetaSuccessAction.payload.find(a => a.id === parseInt(params[0], 10));
switch (attribute.search_type) {
case 'fd':
case 'se':
case 'dl':
case 'rd':
case 'dt':
return new FieldCriterion(parseInt(params[0]), params[1], params[2]);
return new FieldCriterion(parseInt(params[0], 10), params[1], params[2]);
case 'bw':
const bwValues = params[2].split('|');
return new BetweenCriterion(parseInt(params[0]), bwValues[0], bwValues[1]);
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('|');
const options = attribute.options.filter(option => msValues.includes(option.value));
return new SelectMultipleCriterion(parseInt(params[0]), params[1], options);
return new SelectMultipleCriterion(parseInt(params[0], 10), params[1], options);
default:
return null;
}
......
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