Skip to content

Commit 359212b

Browse files
authored
Fixed bugs related to range DateTimePicker (#88)
* gestion datetime url * clean console
1 parent a4588dd commit 359212b

File tree

8 files changed

+325
-151
lines changed

8 files changed

+325
-151
lines changed

src/app/model/conf.model.ts

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ interface Session {
1010
}
1111

1212
interface Main {
13-
default_period: Partial<DefaultPeriod>;
13+
default_period: Period;
1414
}
1515

1616
interface Dashboard {
17-
default_period: Partial<DefaultPeriod>;
17+
default_period: Partial<Period>;
1818
home: Partial<Home>;
1919
api: Partial<Api>;
2020
app: Partial<App>;
@@ -23,26 +23,131 @@ interface Dashboard {
2323
}
2424

2525
interface Api {
26-
default_period: Partial<DefaultPeriod>;
26+
default_period: Period;
2727
}
2828

2929
interface App {
30-
default_period: Partial<DefaultPeriod>;
30+
default_period: Partial<Period>;
3131
}
3232

3333
interface Database {
34-
default_period: Partial<DefaultPeriod>;
34+
default_period: Partial<Period>;
3535
}
3636

3737
interface User {
38-
default_period: Partial<DefaultPeriod>;
38+
default_period: Partial<Period>;
3939
}
4040

4141
interface Home{
42-
default_period: Partial<DefaultPeriod>;
42+
default_period: Partial<Period>;
4343
}
4444

45-
interface DefaultPeriod {
46-
start: Date;
47-
end: Date;
45+
export class QueryParams {
46+
constructor(public _period: Period, public _env: string, public _servers: string[]) {
47+
}
48+
49+
set period(period: Period) {
50+
this._period = period;
51+
}
52+
53+
get period(): Period {
54+
return this._period;
55+
}
56+
57+
get env(): string {
58+
return this._env;
59+
}
60+
61+
set servers(servers: string[]) {
62+
this._servers = servers;
63+
}
64+
65+
get servers(): string[] {
66+
return this._servers;
67+
}
68+
69+
buildParams(): { [key: string]: any } {
70+
let params = { ...this.period.buildParams() };
71+
if(this.servers && this.servers.length > 0){
72+
params = { ...params, server: this.servers.length == 1 ? this.servers[0] : this.servers};
73+
}
74+
if(this.env) {
75+
params = { ...params, env: this.env };
76+
}
77+
return params;
78+
}
79+
80+
buildPath(): string {
81+
return Object.entries(this.buildParams()).map(v => {
82+
if(Array.isArray(v[1])) {
83+
if(v[1].length) return v[1].map(a => `${v[0]}=${a}`).join('&');
84+
else return null;
85+
}
86+
return `${v[0]}=${v[1]}`;
87+
}).filter(s => s != null).join('&');
88+
}
89+
}
90+
91+
export class IPeriod implements Period {
92+
constructor(public _start: Date, public _end: Date) {
93+
}
94+
95+
set start(start: Date) {
96+
this._start = start;
97+
}
98+
99+
get start(): Date {
100+
return this._start;
101+
}
102+
103+
set end(end: Date) {
104+
this._end = end;
105+
}
106+
107+
get end(): Date {
108+
return this._end;
109+
}
110+
111+
buildParams(): { start: string, end: string } {
112+
return { start: this.start.toISOString(), end: this.end.toISOString() };
113+
}
114+
}
115+
116+
export class IStep implements Period {
117+
118+
constructor(public _step: number) {
119+
}
120+
121+
set start(start: Date) {
122+
console.warn("not implemented");
123+
}
124+
125+
get start(): Date {
126+
let now = new Date();
127+
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes() - this._step);
128+
}
129+
130+
set end(end: Date) {
131+
console.warn("not implemented");
132+
}
133+
134+
get end(): Date {
135+
let now = new Date();
136+
now.setSeconds(0, 0);
137+
return now;
138+
}
139+
140+
buildParams(): { step: number } {
141+
return { step: this._step };
142+
}
143+
}
144+
145+
export interface Period {
146+
set start(value: Date);
147+
get start(): Date;
148+
149+
set end(value: Date);
150+
get end(): Date;
151+
152+
buildParams(): {[key: string]: any};
48153
}

src/app/shared/material/custom-date-adapter.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ export class CustomDateAdapter extends NativeDateAdapter {
66
parse(value: any, parseFormat?: any): Date | null {
77
if (typeof value === 'string') {
88
// Custom parsing logic to handle both date and time.
9-
const dateTimeRegex = /^([0-9][1-9])\/(0[1-9]|1[0-2])\/(\d{4}) ([0-1][0-9]|2[0-3]):([0-5]\d)$/;
9+
const dateTimeRegex = /^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/(\d{4}) ([0-1][0-9]|2[0-3]):([0-5]\d)$/;
1010
const match = value.match(dateTimeRegex);
1111
if (match) {
12-
return new Date(
13-
parseInt(match[3], 10),
14-
parseInt(match[2], 10) - 1, // Month is 0-based
15-
parseInt(match[1], 10),
16-
parseInt(match[4], 10),
17-
parseInt(match[5], 10)
18-
);
12+
let dayNumberOfMonth = new Date(parseInt(match[3], 10), parseInt(match[2], 10), 0).getDate();
13+
if(dayNumberOfMonth >= parseInt(match[1], 10)) {
14+
return new Date(
15+
parseInt(match[3], 10),
16+
parseInt(match[2], 10) - 1, // Month is 0-based
17+
parseInt(match[1], 10),
18+
parseInt(match[4], 10),
19+
parseInt(match[5], 10)
20+
);
21+
}
1922
}
2023
}
2124
return null;

src/app/views/search/main/search-main.view.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<header-page [titleIcon]="MAPPING_TYPE[params.type]?.icon" [ui-title]="MAPPING_TYPE[params.type]?.title">
1+
<header-page [titleIcon]="MAPPING_TYPE[type]?.icon" [ui-title]="MAPPING_TYPE[type]?.title">
22
<form [formGroup]="serverFilterForm" class="header-filter md-2">
33
<advanced-filter-recap [filters]="advancedParams" (filterRemoved)="handleRemovedFilter($event)"
44
(focusField)="focusField($event)"></advanced-filter-recap>
@@ -13,17 +13,17 @@
1313
</mat-form-field>
1414
<mat-form-field class="no-subscript" [class.loading]="serverNameIsLoading" appearance="outline">
1515
<mat-label>Serveur</mat-label>
16-
<mat-select [formControl]="serverFilterForm.controls.appname" multiple>
16+
<mat-select [formControl]="serverFilterForm.controls.appname" multiple (selectionChange)="onChangeServer($event)">
1717

18-
<span *ngIf="serverNameIsLoading && params.serveurs[0]!=''"><mat-option *ngFor="let s of params.serveurs" [value]="s">{{s}}</mat-option></span>
18+
<span *ngIf="serverNameIsLoading && queryParams.servers[0]!=''"><mat-option *ngFor="let s of queryParams.servers" [value]="s">{{s}}</mat-option></span>
1919
<mat-option *ngFor="let d of nameDataList" [value]="d">{{d}}</mat-option>
2020
</mat-select>
2121
<mat-spinner *ngIf="serverNameIsLoading" [diameter]="18"></mat-spinner>
2222
</mat-form-field>
2323
<button mat-mini-fab color="primary" (click)="search()">
2424
<mat-icon matSuffix>search</mat-icon>
2525
</button>
26-
<advanced-filter-trigger [pageName]="'session-main'" [filterConfig]="filterConstants.SEARCH[params.type]"
26+
<advanced-filter-trigger [pageName]="'session-main'" [filterConfig]="filterConstants.SEARCH[type]"
2727
[focusField]="focusFieldName" (handleDialogclose)="handledialogclose($event)"
2828
(handlePresetSelection)="handlePresetSelection($event)"
2929
(handlePresetSelectionReset)="handlePresetSelectionReset()"
@@ -37,7 +37,7 @@
3737
<mat-icon matSuffix>search</mat-icon>
3838
</mat-form-field>
3939

40-
<mat-button-toggle-group *ngIf="params.type != 'view'" #group="matButtonToggleGroup" multiple
40+
<mat-button-toggle-group *ngIf="type != 'view'" #group="matButtonToggleGroup" multiple
4141
[disabled]="isLoading" (change)="toggleFilter($event.value)">
4242
<mat-button-toggle value="OK">
4343
<span class="material-symbols-outlined" style="color: #22bb33;">

0 commit comments

Comments
 (0)