@@ -17,9 +17,10 @@ import {
1717 ModalMessageComponent ,
1818 DialogInfo ,
1919} from '../modal-message/modal-message.component' ;
20- import { ActivityStore } from 'src/app/model/activity-store' ;
21- import { MetaFile , ProgressDefinition } from 'src/app/model/meta' ;
20+ import { Activity , ActivityStore } from 'src/app/model/activity-store' ;
21+ import { Uuid , ProgressDefinition , TeamName , ProgressTitle } from 'src/app/model/meta' ;
2222import { SectorViewController } from './sector-viewcontroller' ;
23+ import { DataStore } from 'src/app/model/data-store' ;
2324
2425
2526export interface old_activitySchema {
@@ -72,8 +73,8 @@ export class CircularHeatmapComponent implements OnInit {
7273 old_activityDetails : any ;
7374 @ViewChildren ( MatChip ) chips ! : QueryList < MatChip > ;
7475 matChipsArray : MatChip [ ] = [ ] ;
75- meta : MetaFile | null = null ;
76- activityStore : ActivityStore | null = null ;
76+ // meta: MetaFile | null = null;
77+ dataStore : DataStore | null = null ;
7778
7879 // New properties for refactored data
7980 dimLabels : string [ ] = [ ] ;
@@ -99,19 +100,26 @@ export class CircularHeatmapComponent implements OnInit {
99100 // Ensure that Levels and Teams load before MaturityData
100101 // using promises, since ngOnInit does not support async/await
101102 this . loader . load ( )
102- . then ( ( activityStore : ActivityStore ) => {
103+ . then ( ( dataStore : DataStore ) => {
103104 console . log ( `${ this . perfNow ( ) } s: set filters: ${ this . chips ?. length } ` ) ;
104105 this . matChipsArray = this . chips . toArray ( ) ;
105- this . meta = this . loader . meta ;
106- this . filtersTeams = this . buildFilters ( this . meta ?. teams as string [ ] ) ;
107- this . filtersTeamGroups = this . buildFilters ( Object . keys ( this . meta ?. teamGroups || { } ) ) ;
106+ // this.meta = this.loader.meta;
107+ if ( ! dataStore . activityStore ) {
108+ throw Error ( "TODO: Ooops! Dette må håndteres" ) ;
109+ }
110+ if ( ! dataStore . progressStore ) {
111+ throw Error ( "TODO: Ooops! Dette må håndteres" ) ;
112+ }
113+
114+ this . filtersTeams = this . buildFilters ( dataStore . meta ?. teams as string [ ] ) ;
115+ this . filtersTeamGroups = this . buildFilters ( Object . keys ( dataStore . meta ?. teamGroups || { } ) ) ;
108116 this . filtersTeamGroups [ 'All' ] = true ;
109117
110- let progressDefinition : ProgressDefinition = this . meta ?. progressDefinition || { } ;
111- SectorViewController . init ( this . meta ?. teams || [ ] , activityStore . getProgress ( ) , progressDefinition ) ;
118+ let progressDefinition : ProgressDefinition = dataStore . meta ?. progressDefinition || { } ;
119+ SectorViewController . init ( dataStore . progressStore , dataStore . meta ?. teams || [ ] , dataStore ?. progressStore ?. getProgressData ( ) || { } , progressDefinition ) ;
112120 this . progressStates = SectorViewController . getProgressStates ( ) ;
113121
114- this . setYamlData ( activityStore ) ;
122+ this . setYamlData ( dataStore ) ;
115123
116124 // For now, just draw the sectors (no activities yet)
117125 this . loadCircularHeatMap (
@@ -138,16 +146,16 @@ export class CircularHeatmapComponent implements OnInit {
138146 console . log ( message ) ;
139147 }
140148
141- setYamlData ( activityStore : ActivityStore ) {
142- this . activityStore = activityStore ;
143- this . maxLevel = this . loader . getMaxLevel ( ) ;
144- this . dimensionLabels = activityStore . getAllDimensionNames ( ) ;
149+ setYamlData ( dataStore : DataStore ) {
150+ this . dataStore = dataStore ;
151+ this . maxLevel = dataStore . getMaxLevel ( ) ;
152+ this . dimensionLabels = dataStore ?. activityStore ? .getAllDimensionNames ( ) || [ ] ;
145153
146154 // Prepare all sectors: one for each (dimension, level) pair
147155 this . allSectors = [ ] ;
148156 for ( let lvl = 1 ; lvl <= this . maxLevel ; lvl ++ ) {
149157 for ( let dimName of this . dimensionLabels ) {
150- const activities = activityStore . getActivities ( dimName , lvl ) ;
158+ const activities : Activity [ ] = dataStore ?. activityStore ? .getActivities ( dimName , lvl ) || [ ] ;
151159 this . allSectors . push ( new SectorViewController (
152160 dimName ,
153161 'Level ' + lvl ,
@@ -174,7 +182,7 @@ export class CircularHeatmapComponent implements OnInit {
174182 this . old_yaml . setURI ( './assets/YAML/generated/generated.yaml' ) ;
175183 this . old_yaml . getJson ( ) . subscribe ( async data => {
176184 console . log ( `${ this . perfNow ( ) } s: LoadMaturityData Downloaded` ) ;
177- const activityStore : ActivityStore = await this . loader . load ( ) ;
185+ const activityStore : ActivityStore = new ActivityStore ( ) ; // await this.loader.load();
178186 this . old_YamlObject = activityStore . data ;
179187 this . OBSOLETE_AddSegmentLabels ( this . old_YamlObject ) ;
180188 const localStorageData = this . getDatasetFromBrowserStorage ( ) ;
@@ -361,16 +369,15 @@ export class CircularHeatmapComponent implements OnInit {
361369 chip . toggleSelected ( ) ;
362370
363371 Object . keys ( this . filtersTeams ) . forEach ( key => {
364- this . filtersTeams [ key ] = this . meta ?. teamGroups [ teamGroup ] ?. includes ( key ) || false ;
372+ this . filtersTeams [ key ] = this . dataStore ?. meta ?. teamGroups [ teamGroup ] ?. includes ( key ) || false ;
365373 } ) ;
366374 this . hasTeamsFilter = Object . values ( this . filtersTeams ) . some ( v => v === true ) ;
367375 }
368376 }
369377
370378 getTeamProgressState ( activityUuid : string , teamName : string ) : string {
371- return this . activityStore ?. getTeamProgressState ( activityUuid , teamName ) || '' ;
372- return this . selectedSector ?. activities ?. find ( a => a . uuid === activityUuid ) ?. teamsImplemented [ teamName ] || '' ;
373-
379+ return this . dataStore ?. progressStore ?. getTeamActivityTitle ( activityUuid , teamName ) || '' ;
380+ // return this.selectedSector?.activities?.find(a => a.uuid === activityUuid)?.teamsImplemented[teamName] || '';
374381 }
375382
376383 toggleTeamFilter ( chip : MatChip ) {
@@ -381,8 +388,8 @@ export class CircularHeatmapComponent implements OnInit {
381388
382389 let selectedTeams : string [ ] = Object . keys ( this . filtersTeams ) . filter ( key => this . filtersTeams [ key ] ) ;
383390
384- Object . keys ( this . meta ?. teamGroups || { } ) . forEach ( group => {
385- let match : boolean = equalArray ( selectedTeams , this . meta ?. teamGroups [ group ] ) ;
391+ Object . keys ( this . dataStore ?. meta ?. teamGroups || { } ) . forEach ( group => {
392+ let match : boolean = equalArray ( selectedTeams , this . dataStore ?. meta ?. teamGroups [ group ] ) ;
386393 this . filtersTeamGroups [ group ] = match ;
387394 } ) ;
388395 }
@@ -480,6 +487,28 @@ export class CircularHeatmapComponent implements OnInit {
480487 this . reColorHeatmap ( ) ;
481488 }
482489
490+ onProgressChange (
491+ activityUuid : Uuid ,
492+ teamName : TeamName ,
493+ newProgress : ProgressTitle )
494+ {
495+ if ( ! this . dataStore || ! this . dataStore . progressStore || ! this . dataStore . activityStore ) {
496+ throw Error ( 'Data store or progress store is not initialized.' ) ;
497+ }
498+
499+ this . dataStore . progressStore . setTeamActivityProgressState (
500+ activityUuid ,
501+ teamName ,
502+ newProgress ) ;
503+ // this.reColorHeatmap();
504+ let activity : Activity = this . dataStore . activityStore . getActivityByUuid ( activityUuid ) ;
505+ let index = this . dimensionLabels . indexOf ( activity . dimension )
506+ + this . dimensionLabels . length * ( activity . level - 1 ) ;
507+
508+ this . recolorSector ( index ) ;
509+ // this.recolorSector(activityUuid, teamName);
510+ }
511+
483512 loadCircularHeatMap (
484513 dom_element_to_append_to : string ,
485514 dataset : any ,
@@ -513,6 +542,8 @@ export class CircularHeatmapComponent implements OnInit {
513542 . segmentLabelHeight ( segmentLabelHeight ) ;
514543
515544 chart . accessor ( function ( d : any ) {
545+ if ( d . getSectorProgress ( ) > 0 )
546+ console . log ( 'Color' , d . level , d . dimension , d . value , d . getSectorProgress ( ) ) ;
516547 return d . getSectorProgress ( ) ;
517548 } ) ;
518549
@@ -885,6 +916,21 @@ export class CircularHeatmapComponent implements OnInit {
885916 }
886917 }
887918
919+ recolorSector ( index : number ) {
920+ // console.log('recolorSector', index);
921+ var colorSector = d3
922+ . scaleLinear < string , string > ( )
923+ . domain ( [ 0 , 1 ] )
924+ . range ( [ 'white' , 'green' ] ) ;
925+
926+ let progressValue : number = this . allSectors [ index ] . getSectorProgress ( ) ;
927+ d3 . select ( '#index-' + index ) . attr (
928+ 'fill' ,
929+ colorSector ( progressValue )
930+ ) ;
931+ console . log ( `Recolor sector ${ index } with progress ${ ( progressValue * 100 ) . toFixed ( 1 ) } %` ) ;
932+ }
933+
888934 reColorHeatmap ( ) {
889935 console . log ( 'recolor' ) ;
890936 var teamsCount = this . old_teamVisible . length ;
0 commit comments