mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-08-02 20:42:24 +00:00
feat: add projectId to task model
This commit is contained in:
parent
e509c13ffc
commit
e99dad8b4e
4 changed files with 40 additions and 17 deletions
|
|
@ -142,12 +142,16 @@ export class PersistenceService {
|
|||
...acc,
|
||||
[task.id]: {
|
||||
...task,
|
||||
projectId,
|
||||
subTasks: null,
|
||||
},
|
||||
};
|
||||
if (task.subTasks) {
|
||||
task.subTasks.forEach((subTask) => {
|
||||
newAcc[subTask.id] = subTask;
|
||||
newAcc[subTask.id] = {
|
||||
...subTask,
|
||||
projectId,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
28
src/app/features/tasks/migrate-task-state.util.ts
Normal file
28
src/app/features/tasks/migrate-task-state.util.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import {Dictionary} from '@ngrx/entity';
|
||||
import {Task, TaskState} from './task.model';
|
||||
import {GITHUB_TYPE, LEGACY_GITHUB_TYPE} from '../issue/issue.const';
|
||||
|
||||
export const migrateTaskState = (taskState: TaskState, projectId: string): TaskState => {
|
||||
const taskEntities: Dictionary<Task> = {...taskState.entities};
|
||||
Object.keys(taskEntities).forEach((key) => {
|
||||
taskEntities[key] = _addProjectId(taskEntities[key], projectId);
|
||||
taskEntities[key] = _replaceLegacyGitType(taskEntities[key]);
|
||||
});
|
||||
return {...taskState, entities: taskEntities};
|
||||
};
|
||||
|
||||
const _addProjectId = (task: Task, projectId: string): Task => {
|
||||
return (task.hasOwnProperty('projectId') && task.projectId !== null && task.projectId)
|
||||
? task
|
||||
: {
|
||||
...task,
|
||||
projectId,
|
||||
};
|
||||
};
|
||||
|
||||
const _replaceLegacyGitType = (task: Task) => {
|
||||
const issueType = task.issueType as string;
|
||||
return (issueType === LEGACY_GITHUB_TYPE)
|
||||
? {...task, issueType: GITHUB_TYPE}
|
||||
: task;
|
||||
};
|
||||
|
|
@ -20,6 +20,7 @@ export type TimeSpentOnDay = Readonly<TimeSpentOnDayCopy>;
|
|||
|
||||
export interface TaskCopy {
|
||||
id: string;
|
||||
projectId: string;
|
||||
title: string;
|
||||
|
||||
subTaskIds: string[];
|
||||
|
|
@ -62,6 +63,7 @@ export interface TaskWithSubTasks extends TaskWithIssueData {
|
|||
|
||||
export const DEFAULT_TASK: Task = {
|
||||
id: null,
|
||||
projectId: null,
|
||||
subTaskIds: [],
|
||||
attachmentIds: [],
|
||||
timeSpentOnDay: {},
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import {
|
|||
SHORT_SYNTAX_REG_EX,
|
||||
ShowSubTasksMode,
|
||||
Task,
|
||||
TaskState,
|
||||
TaskWithIssueData,
|
||||
TaskWithSubTasks
|
||||
} from './task.model';
|
||||
|
|
@ -94,7 +93,7 @@ import {IssueService} from '../issue/issue.service';
|
|||
import {ProjectService} from '../project/project.service';
|
||||
import {RoundTimeOption} from '../project/project.model';
|
||||
import {Dictionary} from '@ngrx/entity';
|
||||
import {GITHUB_TYPE, LEGACY_GITHUB_TYPE} from '../issue/issue.const';
|
||||
import {migrateTaskState} from './migrate-task-state.util';
|
||||
|
||||
|
||||
@Injectable({
|
||||
|
|
@ -287,9 +286,10 @@ export class TaskService {
|
|||
async loadStateForProject(projectId) {
|
||||
const lsTaskState = await this._persistenceService.task.load(projectId);
|
||||
if (lsTaskState) {
|
||||
this._replaceLegacyGitType(lsTaskState);
|
||||
this.loadState(migrateTaskState(lsTaskState, projectId));
|
||||
} else {
|
||||
this.loadState(initialTaskState);
|
||||
}
|
||||
this.loadState(lsTaskState || initialTaskState);
|
||||
}
|
||||
|
||||
loadState(state) {
|
||||
|
|
@ -656,6 +656,7 @@ export class TaskService {
|
|||
created: Date.now(),
|
||||
title,
|
||||
id: shortid(),
|
||||
projectId: this._projectService.currentId,
|
||||
...additional,
|
||||
}) as Task;
|
||||
}
|
||||
|
|
@ -692,16 +693,4 @@ export class TaskService {
|
|||
return task;
|
||||
}
|
||||
}
|
||||
|
||||
// hacky but it should work
|
||||
private _replaceLegacyGitType(state: TaskState) {
|
||||
const ids = state.ids as string[];
|
||||
ids.forEach(id => {
|
||||
const task = state.entities[id] as any;
|
||||
const issueType = task.issueType as string;
|
||||
if (issueType === LEGACY_GITHUB_TYPE) {
|
||||
task.issueType = GITHUB_TYPE;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue