mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-25 00:47:39 +00:00
feat: improve data repair handling #552
This commit is contained in:
parent
c9c2e0cad5
commit
1012edbd42
3 changed files with 15 additions and 7 deletions
|
|
@ -3,6 +3,7 @@ import { AppDataComplete } from '../../imex/sync/sync.model';
|
|||
import { T } from '../../t.const';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { dataRepair } from './data-repair.util';
|
||||
import { isDataRepairPossible } from './is-data-repair-possible.util';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
|
@ -19,13 +20,8 @@ export class DataRepairService {
|
|||
}
|
||||
|
||||
isRepairPossibleAndConfirmed(dataIn: AppDataComplete): boolean {
|
||||
const isDataRepairPossible: boolean =
|
||||
typeof dataIn === 'object' && dataIn !== null
|
||||
&& typeof dataIn.task === 'object' && dataIn.task !== null
|
||||
&& typeof dataIn.project === 'object' && dataIn.project !== null
|
||||
|
||||
if (!isDataRepairPossible) {
|
||||
alert('Data damaged, repair not possible.')
|
||||
if (!isDataRepairPossible(dataIn)) {
|
||||
alert('Data damaged, repair not possible.');
|
||||
return false;
|
||||
}
|
||||
return confirm(this._translateService.instant(T.CONFIRM.AUTO_FIX));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
import { AppBaseDataEntityLikeStates, AppDataComplete } from '../../imex/sync/sync.model';
|
||||
import { TagCopy } from '../../features/tag/tag.model';
|
||||
import { ProjectCopy } from '../../features/project/project.model';
|
||||
import { isDataRepairPossible } from './is-data-repair-possible.util';
|
||||
|
||||
const ENTITY_STATE_KEYS: (keyof AppDataComplete)[] = ['task', 'taskArchive', 'taskRepeatCfg', 'tag', 'project', 'simpleCounter'];
|
||||
|
||||
export const dataRepair = (data: AppDataComplete): AppDataComplete => {
|
||||
if (!isDataRepairPossible(data)) {
|
||||
throw new Error('Data repair attempted but not possible');
|
||||
}
|
||||
|
||||
// console.time('dataRepair');
|
||||
let dataOut: AppDataComplete = data;
|
||||
// let dataOut: AppDataComplete = dirtyDeepCopy(data);
|
||||
|
|
|
|||
7
src/app/core/data-repair/is-data-repair-possible.util.ts
Normal file
7
src/app/core/data-repair/is-data-repair-possible.util.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { AppDataComplete } from '../../imex/sync/sync.model';
|
||||
|
||||
export const isDataRepairPossible = (data: AppDataComplete): boolean => {
|
||||
return typeof data === 'object' && data !== null
|
||||
&& typeof data.task === 'object' && data.task !== null
|
||||
&& typeof data.project === 'object' && data.project !== null;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue