Skip to content

Commit e15d507

Browse files
WIP: established functionality of number range filter
1 parent bbd934d commit e15d507

File tree

6 files changed

+56
-40
lines changed

6 files changed

+56
-40
lines changed
Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from "@angular/core";
1+
import { Component, Input, SimpleChanges } from "@angular/core";
22
import { Entity } from "../../../entity/model/entity";
33
import { MatFormFieldModule } from "@angular/material/form-field";
44
import {
@@ -24,27 +24,40 @@ export class NumberRangeFilterComponent<T extends Entity> {
2424
@Input() filterConfig: NumberFilter<T>;
2525

2626
formControl: FormControl<NumericRange>;
27+
from: number;
28+
to: number;
2729

28-
private validatorFunction: ValidatorFn = (): ValidationErrors | null => {
29-
if (
30-
this.formControl.value.from &&
31-
this.formControl.value.to &&
32-
this.formControl.value.from === this.formControl.value.to
33-
) {
34-
return {
35-
sameValue: "The from value is the same as the to value.",
36-
};
37-
} else {
38-
return null;
39-
}
40-
};
41-
42-
constructor() {
43-
this.formControl = new FormControl<NumericRange>({ from: 0, to: 1 });
44-
this.formControl.addValidators([this.validatorFunction]);
30+
// private validatorFunction: ValidatorFn = (): ValidationErrors | null => {
31+
// if (
32+
// this.formControl.value.from &&
33+
// this.formControl.value.to &&
34+
// this.formControl.value.from === this.formControl.value.to
35+
// ) {
36+
// return {
37+
// sameValue: "The from value is the same as the to value.",
38+
// };
39+
// } else {
40+
// return null;
41+
// }
42+
// };
4543

44+
ngOnInit() {
45+
console.log("filterConfig", this.filterConfig);
46+
this.formControl = new FormControl<NumericRange>({
47+
from: Number(this.filterConfig.selectedOptionValues[0]),
48+
to: Number(this.filterConfig.selectedOptionValues[1]),
49+
});
4650
this.formControl.valueChanges.subscribe((value) => {
4751
console.log(this.formControl.valid, this.formControl.errors);
52+
53+
this.filterConfig.selectedOptionValues = [
54+
this.formControl.value.from?.toString() ?? "",
55+
this.formControl.value.to?.toString() ?? "",
56+
];
57+
58+
this.filterConfig.selectedOptionChange.emit(
59+
this.filterConfig.selectedOptionValues,
60+
);
4861
});
4962
}
5063
}

src/app/core/basic-datatypes/number/number-range-filter/range-input/range-input.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class RangeInputComponent extends CustomFormControlDirective<NumericRange
6969
private validatorFunction: ValidatorFn = (): ValidationErrors | null => {
7070
if (this.value.from && this.value.to && this.value.from > this.value.to) {
7171
return {
72-
fromGreaterThanTo: "The from value is greater than the to value.",
72+
fromGreaterThanTo: "The 'from' value is greater than the 'to' value.",
7373
};
7474
} else {
7575
return null;

src/app/core/config/config-fix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export const defaultJsonConfig = {
478478
"label": $localize`:Label of schools filter:School`
479479
},
480480
{
481-
"id": "numbers",
481+
"id": "schoolClass",
482482
"type": "numbers",
483483
"label": "Classes"
484484
}

src/app/core/entity-list/EntityListConfig.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface GroupConfig {
7272
export type FilterConfig<T = any> =
7373
| BasicFilterConfig
7474
| BooleanFilterConfig
75+
| NumberFilterConfig
7576
| PrebuiltFilterConfig<T>
7677
| ConfigurableEnumFilterConfig<T>;
7778

@@ -86,10 +87,7 @@ export interface BooleanFilterConfig extends BasicFilterConfig {
8687
true: string;
8788
false: string;
8889
}
89-
export interface NumberFilterConfig extends BasicFilterConfig {
90-
true: string;
91-
false: string;
92-
}
90+
export interface NumberFilterConfig extends BasicFilterConfig {}
9391

9492
export interface PrebuiltFilterConfig<T> extends BasicFilterConfig {
9593
options: FilterSelectionOption<T>[];

src/app/core/filter/filters/numberFilter.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Entity } from "../../entity/model/entity";
22
import { DateRangeFilterConfigOption } from "../../entity-list/EntityListConfig";
3-
import { DateRange } from "@angular/material/datepicker";
3+
import { DateRange, NumberRange } from "@angular/material/datepicker";
44
import { calculateDateRange } from "../../basic-datatypes/date/date-range-filter/date-range-filter-panel/date-range-filter-panel.component";
55
import moment from "moment";
66
import { DataFilter, Filter } from "./filters";
@@ -20,34 +20,39 @@ export class NumberFilter<T extends Entity> extends Filter<T> {
2020
// public rangeOptions: DateRangeFilterConfigOption[],
2121
) {
2222
super(name, label);
23-
// this.selectedOptionValues = [];
23+
this.selectedOptionValues = [];
2424
}
2525

2626
/**
2727
* Returns the date range according to the selected option or dates
2828
*/
29-
// getDateRange(): DateRange<Date> {
30-
// const selectedOption = this.getSelectedOption();
31-
// if (selectedOption) {
32-
// return calculateDateRange(selectedOption);
29+
// getNumberRange(): NumberRange<Number> {
30+
// // const selectedOption = this.getSelectedOption();
31+
// // if (selectedOption) {
32+
// // return calculateDateRange(selectedOption);
33+
// // }
34+
// const values = this.selectedOptionValues;
35+
// if (values?.length == 2) {
36+
// return new NumberRange(values[0], values[1]);
3337
// }
34-
// const dates = this.selectedOptionValues;
35-
// if (dates?.length == 2) {
36-
// return this.getDateRangeFromDateStrings(dates[0], dates[1]);
37-
// }
38-
// return new DateRange(undefined, undefined);
38+
// return new NumberRange(undefined, undefined);
3939
// }
4040

4141
getFilter(): DataFilter<T> {
42-
// const range = this.getDateRange();
43-
const filterObject: { $gte?: string; $lte?: string } = {};
42+
console.log("Peter this.selectedOptionValues", this.selectedOptionValues);
43+
44+
// const range = this.getNumberRange();
45+
const filterObject: { $gte?: number; $lte?: number } = {};
4446
if (this.selectedOptionValues[0]) {
45-
filterObject.$gte = this.selectedOptionValues[0];
47+
filterObject.$gte = Number(this.selectedOptionValues[0]);
4648
}
4749
if (this.selectedOptionValues[1]) {
48-
filterObject.$lte = this.selectedOptionValues[1];
50+
filterObject.$lte = Number(this.selectedOptionValues[1]);
4951
}
5052
if (filterObject.$gte || filterObject.$lte) {
53+
console.log("Peter data filter", {
54+
[this.name]: filterObject,
55+
} as DataFilter<T>);
5156
return {
5257
[this.name]: filterObject,
5358
} as DataFilter<T>;

src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const environment = {
3232
remoteLoggingDsn: undefined, // only set for production mode in environment.prod.ts
3333
/** The following settings can be overridden by the `config.json` if present, see {@link AppSettings} */
3434
demo_mode: true,
35-
session_type: SessionType.mock,
35+
session_type: SessionType.local,
3636
account_url: "https://accounts.aam-digital.net",
3737
email: undefined,
3838
};

0 commit comments

Comments
 (0)