mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-29 02:30:03 +00:00
feat: prepare project delete cleanup
This commit is contained in:
parent
8b3721ed8a
commit
e749b91d6a
3 changed files with 34 additions and 7 deletions
|
|
@ -43,6 +43,7 @@ import {WorkContextType} from '../../work-context/work-context.model';
|
|||
import {setActiveWorkContext} from '../../work-context/store/work-context.actions';
|
||||
import {WorkContextService} from '../../work-context/work-context.service';
|
||||
import {Project} from '../project.model';
|
||||
import {TaskService} from '../../tasks/task.service';
|
||||
|
||||
@Injectable()
|
||||
export class ProjectEffects {
|
||||
|
|
@ -168,6 +169,7 @@ export class ProjectEffects {
|
|||
tap(async (action: DeleteProject) => {
|
||||
await this._persistenceService.removeCompleteRelatedDataForProject(action.payload.id);
|
||||
this._reminderService.removeReminderByWorkContextId(action.payload.id);
|
||||
this._taskService.removeOrphanTasksForProject(action.payload.id);
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
@ -283,6 +285,7 @@ export class ProjectEffects {
|
|||
private _obstructionService: ObstructionService,
|
||||
private _improvementService: ImprovementService,
|
||||
private _workContextService: WorkContextService,
|
||||
private _taskService: TaskService,
|
||||
private _router: Router,
|
||||
) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,6 +170,9 @@ export class TaskService {
|
|||
private readonly _actions$: Actions,
|
||||
private readonly _router: Router,
|
||||
) {
|
||||
// TODO remove
|
||||
this.removeOrphanTasksForProject('DEFAULT');
|
||||
|
||||
this.currentTaskId$.subscribe((val) => this.currentTaskId = val);
|
||||
|
||||
// time tracking
|
||||
|
|
@ -589,6 +592,27 @@ export class TaskService {
|
|||
}
|
||||
|
||||
|
||||
async removeOrphanTasksForProject(projectIdToDelete: string): Promise<{ today: string[] }> {
|
||||
const taskState: TaskState = await this.taskFeatureState$.pipe(
|
||||
filter(s => s.isDataLoaded),
|
||||
first(),
|
||||
).toPromise();
|
||||
const nonArchiveTaskIdsToDelete = taskState.ids.filter((id) => {
|
||||
const t = taskState.entities[id];
|
||||
return t.projectId === projectIdToDelete;
|
||||
});
|
||||
const taskArchiveState: TaskArchive = await this._persistenceService.taskArchive.loadState();
|
||||
const archiveTaskIdsToDelete = (taskArchiveState.ids as string[]).filter((id) => {
|
||||
const t = taskArchiveState.entities[id];
|
||||
return t.projectId === projectIdToDelete;
|
||||
});
|
||||
// TODO just filter all tags for those ids
|
||||
console.log('TaskIds to remove', nonArchiveTaskIdsToDelete, archiveTaskIdsToDelete);
|
||||
return {
|
||||
today: nonArchiveTaskIdsToDelete,
|
||||
};
|
||||
}
|
||||
|
||||
createNewTaskWithDefaults(
|
||||
title: string,
|
||||
additional: Partial<Task> = {},
|
||||
|
|
|
|||
|
|
@ -52,13 +52,13 @@
|
|||
<!-- mat-icon-button>-->
|
||||
<!-- <mat-icon>flight</mat-icon>-->
|
||||
<!-- </button>-->
|
||||
<!-- <button (click)="remove(project.id)"-->
|
||||
<!-- [disabled]="project.id === (workContextService.activeWorkContextId$|async)"-->
|
||||
<!-- [title]="T.PP.DELETE_PROJECT|translate"-->
|
||||
<!-- color="warn"-->
|
||||
<!-- mat-icon-button>-->
|
||||
<!-- <mat-icon>delete</mat-icon>-->
|
||||
<!-- </button>-->
|
||||
<button (click)="remove(project.id)"
|
||||
[disabled]="project.id === (workContextService.activeWorkContextId$|async)"
|
||||
[title]="T.PP.DELETE_PROJECT|translate"
|
||||
color="warn"
|
||||
mat-icon-button>
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</mat-card>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue