11import { YamlService } from '../service/yaml-loader/yaml-loader.service' ;
2- import { ProgressDefinition , TeamNames , TeamGroups } from './types' ;
2+ import { ProgressDefinitions , TeamNames , TeamGroups } from './types' ;
33import { perfNow } from 'src/app/util/util' ;
44
55export interface MetaStrings {
@@ -16,16 +16,18 @@ const fallbackMetaStrings: MetaStrings = {
1616} ;
1717
1818const LOCALSTORAGE_KEY : string = 'meta' ;
19+ const PROGRESS_DEFINITIONS_KEY : string = 'progressDefinitions' ;
1920
2021export class MetaStore {
2122 private yamlService : YamlService = new YamlService ( ) ;
2223
2324 public hasLocalStorage : boolean = false ;
25+ private defaultProgressDefinition : ProgressDefinitions = { } ;
2426
2527 checkForDsommUpdates : boolean = false ;
2628 lang : string = 'en' ;
2729 strings : Record < string , MetaStrings > = { en : fallbackMetaStrings } ;
28- progressDefinition : ProgressDefinition = { } ;
30+ progressDefinition : ProgressDefinitions = { } ;
2931 teamGroups : TeamGroups = { } ;
3032 teams : TeamNames = [ ] ;
3133 activityFiles : string [ ] = [ ] ;
@@ -52,7 +54,12 @@ export class MetaStore {
5254 metaData . checkForDsommUpdates || this . checkForDsommUpdates || false ;
5355 this . lang = metaData . lang || this . lang || 'en' ;
5456 this . strings = metaData . strings || this . strings || fallbackMetaStrings ;
55- this . progressDefinition = metaData . progressDefinition || this . progressDefinition || { } ;
57+ // Store default progress definition
58+ if ( metaData . progressDefinition ) {
59+ this . defaultProgressDefinition = { ...metaData . progressDefinition } ;
60+ }
61+ // Load custom progress definition if exists, otherwise use default
62+ this . loadStoredProgressDefinition ( ) ;
5663 this . teamGroups = metaData . teamGroups || this . teamGroups || { } ;
5764 this . teams = metaData . teams || this . teams || [ ] ;
5865 this . activityFiles = metaData . activityFiles || this . activityFiles || [ ] ;
@@ -62,6 +69,30 @@ export class MetaStore {
6269 }
6370 }
6471
72+ public saveProgressDefinition ( definitions : ProgressDefinitions ) : void {
73+ this . progressDefinition = definitions ;
74+ localStorage . setItem ( PROGRESS_DEFINITIONS_KEY , JSON . stringify ( definitions ) ) ;
75+ }
76+
77+ public resetProgressDefinition ( ) : void {
78+ this . progressDefinition = { ...this . defaultProgressDefinition } ;
79+ localStorage . removeItem ( PROGRESS_DEFINITIONS_KEY ) ;
80+ }
81+
82+ private loadStoredProgressDefinition ( ) : void {
83+ const stored = localStorage . getItem ( PROGRESS_DEFINITIONS_KEY ) ;
84+ if ( stored ) {
85+ try {
86+ this . progressDefinition = JSON . parse ( stored ) ;
87+ } catch ( error ) {
88+ console . error ( 'Failed to load stored progress definitions:' , error ) ;
89+ this . progressDefinition = { ...this . defaultProgressDefinition } ;
90+ }
91+ } else {
92+ this . progressDefinition = { ...this . defaultProgressDefinition } ;
93+ }
94+ }
95+
6596 public updateTeamsAndGroups ( teams : TeamNames , teamGroups : TeamGroups ) : void {
6697 this . teams = teams ;
6798 this . teamGroups = teamGroups ;
0 commit comments