-
-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathmeta-store.ts
More file actions
150 lines (131 loc) · 5.48 KB
/
meta-store.ts
File metadata and controls
150 lines (131 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { YamlService } from '../service/yaml-loader/yaml-loader.service';
import { ActivityFileMeta } from './activity-store';
import { ProgressDefinitions, TeamNames, TeamGroups } from './types';
import { perfNow } from 'src/app/util/util';
export interface MetaStrings {
team: string;
group: string;
allTeamsGroupName: string;
labels: string[];
maturityLevels: string[];
knowledgeLabels: string[];
}
const fallbackMetaStrings: MetaStrings = {
team: 'Team',
group: 'Group',
allTeamsGroupName: 'All',
maturityLevels: ['Level 1', 'Level 2'],
labels: ['Easy', 'Medium', 'Hard'],
knowledgeLabels: ['Low', 'Medium', 'High'],
};
const STORAGE_TEAMS_KEY: string = 'meta.teams';
const STORAGE_GROUPS_KEY: string = 'meta.teamGroups';
const STORAGE_PROGRESS_DEFINITIONS_KEY: string = 'meta.progressDefinitions';
export class MetaStore {
private yamlService: YamlService = new YamlService();
public hasLocalStorage: boolean = false;
private defaultProgressDefinition: ProgressDefinitions = {};
public activityMeta: ActivityFileMeta | null = null;
checkForDsommUpdates: boolean = false;
lang: string = 'en';
strings: Record<string, MetaStrings> = { en: fallbackMetaStrings };
progressDefinition: ProgressDefinitions = {};
teamGroups: TeamGroups = {};
teams: TeamNames = [];
activityFiles: string[] = [];
teamProgressFile: string = '';
allowChangeTeamNameInBrowser: boolean = true;
dimensionIcons: Record<string, string> = {
'Build and Deployment': 'front_loader',
'Culture and Organization': 'diversity_3',
Implementation: 'design_services',
'Information Gathering': 'insights',
'Test and Verification': 'checklist',
default: 'check_box_outline_blank',
};
public init(metaData: any): void {
this.addMeta(metaData);
}
public addMeta(metaData: any): void {
if (metaData) {
// Only overwrite existing values if new values are provided
this.checkForDsommUpdates =
metaData.checkForDsommUpdates || this.checkForDsommUpdates || false;
this.lang = metaData.lang || this.lang || 'en';
this.strings = metaData.strings || this.strings || fallbackMetaStrings;
// Store default progress definition
if (metaData.progressDefinition) {
this.defaultProgressDefinition = { ...metaData.progressDefinition };
}
// Load custom progress definition if exists, otherwise use default
this.loadStoredProgressDefinition();
this.teamGroups = metaData.teamGroups || this.teamGroups || {};
this.teams = metaData.teams || this.teams || [];
this.activityFiles = metaData.activityFiles || this.activityFiles || [];
this.teamProgressFile = metaData.teamProgressFile || this.teamProgressFile || '';
if (metaData.allowChangeTeamNameInBrowser !== undefined)
this.allowChangeTeamNameInBrowser = metaData.allowChangeTeamNameInBrowser;
}
}
public saveProgressDefinition(definitions: ProgressDefinitions): void {
this.progressDefinition = definitions;
localStorage.setItem(STORAGE_PROGRESS_DEFINITIONS_KEY, JSON.stringify(definitions));
}
public resetProgressDefinition(): void {
this.progressDefinition = { ...this.defaultProgressDefinition };
localStorage.removeItem(STORAGE_PROGRESS_DEFINITIONS_KEY);
}
private loadStoredProgressDefinition(): void {
const stored = localStorage.getItem(STORAGE_PROGRESS_DEFINITIONS_KEY);
if (stored) {
try {
this.progressDefinition = JSON.parse(stored);
} catch (error) {
console.error('Failed to load stored progress definitions:', error);
this.progressDefinition = { ...this.defaultProgressDefinition };
}
} else {
this.progressDefinition = { ...this.defaultProgressDefinition };
}
}
public updateTeamsAndGroups(teams: TeamNames, teamGroups: TeamGroups): void {
this.teams = teams;
this.teamGroups = teamGroups;
this.saveTeamsAndGroups();
}
public asStorableYamlString(): string {
return this.yamlService.stringify({ teams: this.teams, teamGroups: this.teamGroups });
}
public saveTeamsAndGroups() {
let yamlStr: string = this.yamlService.stringify({ teams: this.teams });
localStorage.setItem(STORAGE_TEAMS_KEY, yamlStr);
console.log('Saved teams to localStorage: ' + yamlStr);
yamlStr = this.yamlService.stringify({ teamGroups: this.teamGroups });
localStorage.setItem(STORAGE_GROUPS_KEY, yamlStr);
console.log('Saved team groups to localStorage: ' + yamlStr);
this.hasLocalStorage = true;
}
public deleteTeamsAndGroups() {
localStorage.removeItem(STORAGE_TEAMS_KEY);
localStorage.removeItem(STORAGE_GROUPS_KEY);
this.hasLocalStorage = false;
}
public loadTeamsAndGroups(): void {
let storedTeams: string | null = localStorage.getItem(STORAGE_TEAMS_KEY);
let storedGroups: string | null = localStorage.getItem(STORAGE_GROUPS_KEY);
try {
let metaTeams: { teams: TeamNames } | null = null;
let metaGroups: { teamGroups: TeamGroups } | null = null;
if (storedTeams) metaTeams = this.yamlService.parse(storedTeams);
if (storedGroups) metaGroups = this.yamlService.parse(storedGroups);
this.addMeta({ teams: metaTeams?.teams, teamGroups: metaGroups?.teamGroups });
this.hasLocalStorage = true;
console.log('Loaded stored meta from localStorage');
} catch (error) {
console.error('Failed to load stored meta from localStorage:', error);
}
}
getIcon(dimension: string): string {
return this.dimensionIcons[dimension] || this.dimensionIcons['default'];
}
}