11import { Component , OnInit , HostListener } from '@angular/core' ;
2- import { CouchService } from '../../shared/couchdb.service ' ;
2+ import { UntypedFormBuilder , UntypedFormGroup , Validators } from '@angular/forms ' ;
33import { forkJoin } from 'rxjs' ;
4+ import { CouchService } from '../../shared/couchdb.service' ;
45import { StateService } from '../../shared/state.service' ;
56import { PlanetMessageService } from '../../shared/planet-message.service' ;
67import { ManagerService } from '../manager.service' ;
78import { filterSpecificFields } from '../../shared/table-helpers' ;
89import { attachNamesToPlanets , areNoChildren , filterByDate } from './reports.utils' ;
910import { CsvService } from '../../shared/csv.service' ;
10- import { UntypedFormBuilder , UntypedFormGroup , Validators } from '@angular/forms' ;
1111import { DeviceInfoService , DeviceType } from '../../shared/device-info.service' ;
1212import { ReportsService } from './reports.service' ;
1313
@@ -17,14 +17,12 @@ import { ReportsService } from './reports.service';
1717} )
1818export 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
0 commit comments