11import { AfterViewInit , Component , OnInit , ViewChild } from '@angular/core' ;
22import { MatSort } from '@angular/material/sort' ;
33import { MatTableDataSource } from '@angular/material/table' ;
4+ import { sum } from 'd3' ;
45import {
56 DialogInfo ,
67 ModalMessageComponent ,
@@ -33,7 +34,7 @@ export class TeamsComponent implements OnInit, AfterViewInit {
3334 infoTeams : TeamNames = [ ] ;
3435 info : Record < string , TeamSummary > = { } ;
3536
36- dataSource : MatTableDataSource < TeamActivityProgress > = new MatTableDataSource < TeamActivityProgress > ( [ ] ) ; // eslint-disable-line
37+ dataSource : MatTableDataSource < TeamSummaryActivityProgress > = new MatTableDataSource < TeamSummaryActivityProgress > ( [ ] ) ; // eslint-disable-line
3738 allColumnNames : string [ ] = [ ] ;
3839 progressColumnNames : string [ ] = [ ] ;
3940 @ViewChild ( MatSort , { static : false } ) sort ! : MatSort ;
@@ -60,7 +61,10 @@ export class TeamsComponent implements OnInit, AfterViewInit {
6061 ngAfterViewInit ( ) {
6162 if ( this . sort ) {
6263 this . dataSource . sort = this . sort ;
63- this . dataSource . sortingDataAccessor = ( item : TeamActivityProgress , property : string ) => {
64+ this . dataSource . sortingDataAccessor = (
65+ item : TeamSummaryActivityProgress ,
66+ property : string
67+ ) => {
6468 if ( property === 'Team' ) {
6569 return item . team ;
6670 }
@@ -170,12 +174,13 @@ export class TeamsComponent implements OnInit, AfterViewInit {
170174
171175 makeTeamSummary ( name : string , teams : TeamNames ) : TeamSummary {
172176 /* eslint-disable */
173- let activitiesCompleted : progressStoreMapping [ ] = this . dataStore ?. progressStore ?. getActivitiesCompletedForTeams ( teams ) || [ ] ;
177+ let activitiesStarted : progressStoreMapping [ ] = this . dataStore ?. progressStore ?. getActivitiesStartedForTeams ( teams ) || [ ] ;
174178 let activitiesInProgress : progressStoreMapping [ ] = this . dataStore ?. progressStore ?. getActivitiesInProgressForTeams ( teams ) || [ ] ;
179+ let activitiesCompleted : progressStoreMapping [ ] = this . dataStore ?. progressStore ?. getActivitiesCompletedForTeams ( teams ) || [ ] ;
175180
176181 let summary : TeamSummary = {
177182 teams,
178- lastUpdated : new Date ( ) ,
183+ lastUpdated : null ,
179184 activitiesCompleted : [ ] ,
180185 activitiesInProgress : [ ] ,
181186 uniqueActivitiesCompletedCount : 0 ,
@@ -186,32 +191,43 @@ export class TeamsComponent implements OnInit, AfterViewInit {
186191 summary . activitiesInProgress = activitiesInProgress . map ( activityProgress => _self . mapIncludeActivity ( activityProgress ) ) ;
187192 summary . uniqueActivitiesCompletedCount = uniqueCount ( summary . activitiesCompleted . map ( item => item . activity . uuid ) ) ;
188193 summary . uniqueActivitiesInProgressCount = uniqueCount ( summary . activitiesInProgress . map ( item => item . activity . uuid ) ) ;
194+ if ( activitiesStarted . length == 0 ) {
195+ summary . lastUpdated = null ;
196+ } else {
197+ summary . lastUpdated = activitiesStarted . map ( activityProgress => _self . mapIncludeActivity ( activityProgress ) . lastUpdated )
198+ // .map(activityProgress => activityProgress.lastUpdated)
199+ . reduce ( ( max , current ) => ( current > max ? current : max ) ) ;
200+ }
189201 /* eslint-enable */
190202
191203 return summary ;
192204 }
193205
194- mapIncludeActivity ( input : progressStoreMapping ) : TeamActivityProgress {
206+ mapIncludeActivity ( input : progressStoreMapping ) : TeamSummaryActivityProgress {
195207 return {
196208 team : input . team ,
197209 activity :
198210 this . dataStore ?. activityStore ?. getActivityByUuid ( input . activityUuid ) || ( { } as Activity ) ,
199211 progress : input . progress ,
212+ lastUpdated : Object . values ( input . progress ) . reduce ( ( max , current ) =>
213+ current > max ? current : max
214+ ) ,
200215 } ;
201216 }
202217}
203218
204219export interface TeamSummary {
205220 teams : TeamNames ;
206- lastUpdated : Date ;
207- activitiesCompleted : TeamActivityProgress [ ] ;
208- activitiesInProgress : TeamActivityProgress [ ] ;
221+ lastUpdated : Date | null ;
222+ activitiesCompleted : TeamSummaryActivityProgress [ ] ;
223+ activitiesInProgress : TeamSummaryActivityProgress [ ] ;
209224 uniqueActivitiesCompletedCount : number ;
210225 uniqueActivitiesInProgressCount : number ;
211226}
212227
213- export interface TeamActivityProgress {
228+ export interface TeamSummaryActivityProgress {
214229 team : TeamName ;
215230 activity : Activity ;
216231 progress : TeamProgress ;
232+ lastUpdated : Date ;
217233}
0 commit comments