Skip to content

Commit 62240bb

Browse files
committed
Loader: Load legacy progress from browser storage
1 parent f9d4e4f commit 62240bb

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/app/model/progress-store.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,46 @@ export class ProgressStore {
416416
return this.yamlService.parse(yamlStr);
417417
}
418418

419+
public retrieveLegacyStoredTeamProgress(): TeamProgressFile | null {
420+
let progress: Progress = {};
421+
let progressFile: TeamProgressFile = { progress: progress };
422+
let stored = localStorage.getItem('dataset');
423+
let completeTitle: ProgressTitle = this.getCompletedProgressTitle();
424+
if (stored) {
425+
try {
426+
const legacyDataset = JSON.parse(stored);
427+
428+
legacyDataset.forEach((entry: any) => {
429+
const legacyActivities = entry.Activity;
430+
431+
if (Array.isArray(legacyActivities)) {
432+
legacyActivities.forEach((legacyActivity: any) => {
433+
const activityUuid = legacyActivity.uuid;
434+
const teamsImplemented = legacyActivity.teamsImplemented;
435+
if (teamsImplemented) {
436+
Object.keys(teamsImplemented).forEach((team: string) => {
437+
if (legacyActivity.teamsImplemented[team]) {
438+
if (!progress![activityUuid]) {
439+
progress![activityUuid] = {};
440+
}
441+
if (!progress![activityUuid][team]) {
442+
progress![activityUuid][team] = {};
443+
}
444+
console.log(`Legacy import: Setting '${completeTitle}' on ${activityUuid} for ${team}`);
445+
progress![activityUuid][team][completeTitle] = new Date();
446+
}
447+
});
448+
}
449+
});
450+
}
451+
});
452+
} catch (error) {
453+
console.error("Failed to parse legacy dataset", error);
454+
}
455+
}
456+
return progressFile;
457+
}
458+
419459
/**
420460
* Clear progress for a team's activity, from startIndex to endIndex.
421461
* It will store a backup of the progress in _tempProgress, in case

src/app/service/loader/data-loader.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ export class LoaderService {
6060
this.dataStore.addProgressData(teamProgress.progress);
6161
let browserProgress: TeamProgressFile | null =
6262
this.dataStore.progressStore?.retrieveStoredTeamProgress() || null;
63+
if (browserProgress == null) {
64+
browserProgress = this.dataStore.progressStore?.retrieveLegacyStoredTeamProgress() || null;
65+
}
6366
if (browserProgress != null) {
6467
this.dataStore.addProgressData(browserProgress?.progress);
6568
}
6669

67-
// TODO: Load old yaml format (generated.yaml)
68-
// TODO: Load old yaml format (localStorage)
6970
console.log(`${perfNow()}: YAML: All YAML files loaded`);
7071

7172
return this.dataStore;

0 commit comments

Comments
 (0)