Skip to content

Commit 32a14dd

Browse files
Mutugiiidogi
andauthored
manager: smoother reports navigation filter clearing (fixes #9022) (#9052)
Co-authored-by: dogi <[email protected]>
1 parent fecbae1 commit 32a14dd

File tree

5 files changed

+30
-39
lines changed

5 files changed

+30
-39
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.11",
4+
"version": "0.20.12",
55
"myplanet": {
6-
"latest": "v0.30.1",
7-
"min": "v0.29.1"
6+
"latest": "v0.30.25",
7+
"min": "v0.29.25"
88
},
99
"scripts": {
1010
"ng": "ng",

src/app/manager-dashboard/reports/logs-myplanet.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<mat-option *ngFor="let option of timeFilterOptions" [value]="option.value">{{option.label}}</mat-option>
3636
</mat-select>
3737
</mat-form-field>
38-
<button mat-raised-button (click)="clearFilters()" color="primary" [disabled]="!searchValue && !selectedVersion && !selectedType && disableShowAllTime" class="margin-lr-5">
38+
<button mat-raised-button (click)="clearFilters()" color="primary" [disabled]="!searchValue && !selectedVersion && !selectedType && isDefaultTimeFilter" class="margin-lr-5">
3939
<span i18n>Clear</span>
4040
</button>
4141
<mat-icon>search</mat-icon>
@@ -94,7 +94,7 @@
9494
</form>
9595
</mat-toolbar-row>
9696
<mat-toolbar-row *ngIf="showFiltersRow">
97-
<button mat-raised-button color="primary" (click)="clearFilters()" [disabled]="!searchValue && !selectedVersion && !selectedType && disableShowAllTime" class="margin-lr-5">
97+
<button mat-raised-button color="primary" (click)="clearFilters()" [disabled]="!searchValue && !selectedVersion && !selectedType && isDefaultTimeFilter" class="margin-lr-5">
9898
<span i18n>Clear</span>
9999
</button>
100100
<mat-icon>search</mat-icon>

src/app/manager-dashboard/reports/logs-myplanet.component.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Component, OnInit, HostListener } from '@angular/core';
2-
import { CouchService } from '../../shared/couchdb.service';
2+
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
33
import { forkJoin } from 'rxjs';
4+
import { CouchService } from '../../shared/couchdb.service';
45
import { StateService } from '../../shared/state.service';
56
import { PlanetMessageService } from '../../shared/planet-message.service';
67
import { ManagerService } from '../manager.service';
78
import { filterSpecificFields } from '../../shared/table-helpers';
89
import { attachNamesToPlanets, areNoChildren, filterByDate } from './reports.utils';
910
import { CsvService } from '../../shared/csv.service';
10-
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
1111
import { DeviceInfoService, DeviceType } from '../../shared/device-info.service';
1212
import { ReportsService } from './reports.service';
1313

@@ -17,14 +17,12 @@ import { ReportsService } from './reports.service';
1717
})
1818
export class LogsMyPlanetComponent implements OnInit {
1919

20+
private readonly defaultTimeFilter: string = '24h';
21+
private allPlanets: any[] = [];
2022
apklogs: any[] = [];
2123
isEmpty = false;
22-
private allPlanets: any[] = [];
2324
searchValue = '';
2425
planetType = this.stateService.configuration.planetType;
25-
get childType() {
26-
return this.planetType === 'center' ? $localize`Community` : $localize`Nation`;
27-
}
2826
startDate: Date = new Date(new Date().setFullYear(new Date().getDate() - 1));
2927
endDate: Date = new Date();
3028
selectedChildren: any[] = [];
@@ -35,14 +33,19 @@ export class LogsMyPlanetComponent implements OnInit {
3533
selectedVersion = '';
3634
types: string[] = [];
3735
selectedType = '';
38-
disableShowAllTime = true;
3936
showFiltersRow = false;
4037
deviceType: DeviceType;
4138
deviceTypes: typeof DeviceType = DeviceType;
4239
selectedTimeFilter = '24h';
4340
showCustomDateFields = false;
4441
timeFilterOptions = this.activityService.standardTimeFilters;
4542
isLoading = false;
43+
get childType() {
44+
return this.planetType === 'center' ? $localize`Community` : $localize`Nation`;
45+
}
46+
get isDefaultTimeFilter(): boolean {
47+
return this.selectedTimeFilter === this.defaultTimeFilter;
48+
}
4649

4750
constructor(
4851
private csvService: CsvService,
@@ -76,7 +79,6 @@ export class LogsMyPlanetComponent implements OnInit {
7679
if (!this.logsForm.errors?.invalidDates) {
7780
this.applyFilters();
7881
}
79-
this.updateShowAllTimeButton();
8082
});
8183
}
8284

@@ -85,12 +87,6 @@ export class LogsMyPlanetComponent implements OnInit {
8587
this.deviceType = this.deviceInfoService.getDeviceType({ tablet: 1350 });
8688
}
8789

88-
updateShowAllTimeButton() {
89-
const startIsMin = new Date(this.startDate).setHours(0, 0, 0, 0) === new Date(this.minDate).setHours(0, 0, 0, 0);
90-
const endIsToday = new Date(this.endDate).setHours(0, 0, 0, 0) === new Date(this.today).setHours(0, 0, 0, 0);
91-
this.disableShowAllTime = startIsMin && endIsToday;
92-
}
93-
9490
filterData(filterValue: string) {
9591
this.searchValue = filterValue;
9692
this.apklogs = this.allPlanets.filter(planet => filterSpecificFields([ 'name', 'doc.code' ])(planet, filterValue));
@@ -179,10 +175,12 @@ export class LogsMyPlanetComponent implements OnInit {
179175
}
180176

181177
applyFilters() {
182-
this.apklogs = this.allPlanets.map(planet => ({
183-
...planet,
184-
children: this.filterLogs(planet.children)
185-
}));
178+
this.apklogs = this.allPlanets
179+
.filter(planet => !this.searchValue || filterSpecificFields([ 'name', 'doc.code' ])(planet, this.searchValue))
180+
.map(planet => ({
181+
...planet,
182+
children: this.filterLogs(planet.children)
183+
}));
186184
this.isEmpty = areNoChildren(this.apklogs);
187185
}
188186

src/app/manager-dashboard/reports/reports-myplanet.component.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<mat-option *ngFor="let option of timeFilterOptions" [value]="option.value">{{option.label}}</mat-option>
3030
</mat-select>
3131
</mat-form-field>
32-
<button mat-raised-button (click)="clearFilters()" color="primary" [disabled]="!searchValue && !selectedVersion && disableShowAllTime" class="margin-lr-5">
32+
<button mat-raised-button (click)="clearFilters()" color="primary" [disabled]="!searchValue && !selectedVersion && isDefaultTimeFilter" class="margin-lr-5">
3333
<span i18n>Clear</span>
3434
</button>
3535
<mat-icon>search</mat-icon>
@@ -97,10 +97,7 @@
9797
</form>
9898
</mat-toolbar-row>
9999
<mat-toolbar-row *ngIf="showFiltersRow">
100-
<button mat-raised-button color="primary" (click)="resetDateFilter()" [disabled]="disableShowAllTime" class="margin-lr-5">
101-
<span i18n>Show All Time</span>
102-
</button>
103-
<button mat-raised-button color="primary" (click)="clearFilters()" [disabled]="!searchValue && !selectedVersion && disableShowAllTime" class="margin-lr-5">
100+
<button mat-raised-button color="primary" (click)="clearFilters()" [disabled]="!searchValue && !selectedVersion && isDefaultTimeFilter" class="margin-lr-5">
104101
<span i18n>Clear</span>
105102
</button>
106103
<mat-icon>search</mat-icon>

src/app/manager-dashboard/reports/reports-myplanet.component.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CsvService } from '../../shared/csv.service';
1919
})
2020
export class ReportsMyPlanetComponent implements OnInit {
2121

22+
private readonly defaultTimeFilter: string = 'all';
2223
private allPlanets: any[] = [];
2324
searchValue = '';
2425
planets: any[] = [];
@@ -30,9 +31,6 @@ export class ReportsMyPlanetComponent implements OnInit {
3031
deviceTypes: typeof DeviceType = DeviceType;
3132
planetType = this.stateService.configuration.planetType;
3233
configuration = this.stateService.configuration;
33-
get childType() {
34-
return this.planetType === 'center' ? 'Community' : 'Nation';
35-
}
3634
hubId: string | null = null;
3735
hub = { spokes: [] };
3836
startDate: Date = new Date(new Date().setFullYear(new Date().getFullYear() - 1));
@@ -42,10 +40,15 @@ export class ReportsMyPlanetComponent implements OnInit {
4240
today = new Date();
4341
versions: string[] = [];
4442
selectedVersion = '';
45-
disableShowAllTime = true;
4643
selectedTimeFilter = 'all';
4744
timeFilterOptions = this.activityService.standardTimeFilters;
4845
showCustomDateFields = false;
46+
get childType() {
47+
return this.planetType === 'center' ? 'Community' : 'Nation';
48+
}
49+
get isDefaultTimeFilter(): boolean {
50+
return this.selectedTimeFilter === this.defaultTimeFilter;
51+
}
4952

5053
constructor(
5154
private csvService: CsvService,
@@ -83,7 +86,6 @@ export class ReportsMyPlanetComponent implements OnInit {
8386
if (!this.reportsForm.errors?.invalidDates) {
8487
this.applyFilters();
8588
}
86-
this.updateShowAllTimeButton();
8789
});
8890
}
8991

@@ -146,12 +148,6 @@ export class ReportsMyPlanetComponent implements OnInit {
146148
return new Date(earliest);
147149
}
148150

149-
updateShowAllTimeButton() {
150-
const startIsMin = new Date(this.startDate).setHours(0, 0, 0, 0) === new Date(this.minDate).setHours(0, 0, 0, 0);
151-
const endIsToday = new Date(this.endDate).setHours(0, 0, 0, 0) === new Date(this.today).setHours(0, 0, 0, 0);
152-
this.disableShowAllTime = startIsMin && endIsToday;
153-
}
154-
155151
onVersionChange(version: string) {
156152
this.selectedVersion = version;
157153
this.applyFilters();

0 commit comments

Comments
 (0)