Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task IDs #236

Merged
merged 5 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/components/ChunkModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import { Component, Vue } from "vue-property-decorator";
import vxm from "@/store/index.vuex";
import Chunk from "@/types/Chunk";
import DateUtils from "@/util/DateUtils";
import TaskUtils from "@/util/TaskUtils";
import UserTask from "@/types/Task";

@Component
Expand Down Expand Up @@ -153,8 +152,8 @@ export default class ChunkModal extends Vue {
vxm.store.completedChunks.push(this.chunk);

if (
vxm.store.chunks.chunks.filter((chunk) =>
TaskUtils.tasksEqual(chunk.task, this.chunk?.task ?? new UserTask({}))
vxm.store.chunks.chunks.filter(
(chunk) => chunk.task.id === this.chunk?.task?.id
).length <= 1
) {
Vue.delete(vxm.store.tasks, vxm.store.tasks.indexOf(this.chunk.task));
Expand Down
22 changes: 11 additions & 11 deletions src/components/Day/DayModal.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<template>
<div class="daymodal-container">
<b-modal
id="day-modal"
:title="`${month + 1}/${day}`"
@hide="vxm.store.chunks.update"
>
<b-modal id="day-modal" :title="`${month + 1}/${day}`" @hide="updateChunks">
<p class="h6" v-show="chunks.length">Chunks ({{ chunks.length }})</p>
<div
v-for="(chunk, i) in chunks"
Expand Down Expand Up @@ -69,7 +65,7 @@
:value="startTimeValue"
@input="startInput"
minutes-step="5"
@blur="vxm.store.chunks.update"
@blur="updateChunks"
/>
<b-input-group-append is-text>
<b-form-checkbox
Expand All @@ -89,7 +85,7 @@
:value="endTimeValue"
@input="endInput"
minutes-step="5"
@blur="vxm.store.chunks.update"
@blur="updateChunks"
/>
<b-input-group-append is-text>
<b-form-checkbox
Expand Down Expand Up @@ -200,25 +196,25 @@ export default class DayModal extends Vue {
lockStart() {
Vue.set(vxm.store.settings.dayStartTimes, this.numKey, this.startTime);
vxm.store.storage.updateSettings();
vxm.store.chunks.update();
this.updateChunks();
}

lockEnd() {
Vue.set(vxm.store.settings.dayEndTimes, this.numKey, this.endTime);
vxm.store.storage.updateSettings();
vxm.store.chunks.update();
this.updateChunks();
}

unlockStart() {
Vue.delete(vxm.store.settings.dayStartTimes, this.numKey);
vxm.store.storage.updateSettings();
vxm.store.chunks.update();
this.updateChunks();
}

unlockEnd() {
Vue.delete(vxm.store.settings.dayEndTimes, this.numKey);
vxm.store.storage.updateSettings();
vxm.store.chunks.update();
this.updateChunks();
}

startInput(event: string) {
Expand Down Expand Up @@ -268,6 +264,10 @@ export default class DayModal extends Vue {
timeToString(baseEndTime)
);
}

updateChunks() {
this.vxm.store.chunks.update();
}
}
</script>
<style lang="scss" scoped>
Expand Down
13 changes: 10 additions & 3 deletions src/components/Task/TaskModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ import UserTask, { TASK_DESCRIPTIONS } from "@/types/Task";
import { Component, Vue } from "vue-property-decorator";
import vxm from "@/store/index.vuex";
import DateUtils from "@/util/DateUtils";
import TaskUtils from "@/util/TaskUtils";

@Component
export default class TaskModal extends Vue {
Expand Down Expand Up @@ -209,8 +208,8 @@ export default class TaskModal extends Vue {
return; // We can't delete a task that hasn't been created
}

for (let chunk of vxm.store.chunks.chunks.filter((chunk) =>
TaskUtils.tasksEqual(chunk.task, this.task)
for (let chunk of vxm.store.chunks.chunks.filter(
(chunk) => chunk.task.id === this.task.id
)) {
chunk.date = DateUtils.currentDate;
vxm.store.completedChunks.push(chunk);
Expand Down Expand Up @@ -238,6 +237,14 @@ export default class TaskModal extends Vue {
: vxm.store.tasks,
this.editedIndex
);

let { completedChunks } = vxm.store;
for (let i = completedChunks.length - 1; i >= 0; i--) {
if (vxm.store.completedChunks[i]?.task.id === this.task?.id) {
Vue.delete(vxm.store.completedChunks, i);
}
}

vxm.store.chunks.update(); // Update chunks
vxm.store.storage.updateTasks();
vxm.store.storage.updateCompleted();
Expand Down
5 changes: 2 additions & 3 deletions src/store/ChunkStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Chunk from "@/types/Chunk";
import Settings from "@/types/Settings";
import UserTask from "@/types/Task";
import DateUtils from "@/util/DateUtils";
import TaskUtils from "@/util/TaskUtils";
import Substore from "./Substore";

export default class ChunkStore extends Substore {
Expand Down Expand Up @@ -98,8 +97,8 @@ export default class ChunkStore extends Substore {
for (const task of this.tasks) {
let { chunks } = task;
chunks -= task.lockedChunks.length;
chunks -= this.store.completedChunks.filter((chunk) =>
TaskUtils.tasksEqual(task, chunk.task)
chunks -= this.store.completedChunks.filter(
(chunk) => task.id === chunk.task.id
).length;
const { due } = task;
let daysUntilDue = DateUtils.daysBetween(DateUtils.currentDate, due);
Expand Down
3 changes: 3 additions & 0 deletions src/store/index.vuex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Chunk from "@/types/Chunk";
import UserEvent from "@/types/Event";
import UserReminder from "@/types/Reminder";
import Settings from "@/types/Settings";
import IDUtils from "@/util/IDUtils";
import Vue from "vue";
import Vuex from "vuex";
import {
Expand Down Expand Up @@ -42,6 +43,8 @@ export class Store extends VuexModule {
constructor() {
super();

IDUtils.store = this;

this.tasks = this.storage.tasks.value;
this.settings = this.storage.settings.value;
this.events = this.storage.events.value;
Expand Down
9 changes: 9 additions & 0 deletions src/store/storage/IDSubstore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Store } from "../index.vuex";
import StorageStore from "./StorageStore";
import StorageSubstore from "./StorageSubstore";

export default class IDSubstore extends StorageSubstore<number, number> {
constructor(store: Store, storage: StorageStore) {
super(store, storage, "id");
}
}
2 changes: 2 additions & 0 deletions src/store/storage/StorageStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Substore from "../Substore";
import CompletedSubstore from "./CompletedSubstore";
import EventsSubstore from "./EventsSubstore";
import IDSubstore from "./IDSubstore";
import RemindersSubstore from "./RemindersSubstore";
import SettingsSubstore from "./SettingsSubstore";
import TasksSubstore from "./TasksSubstore";
Expand All @@ -11,6 +12,7 @@ export default class StorageStore extends Substore {
events = new EventsSubstore(this.store, this);
completed = new CompletedSubstore(this.store, this);
reminders = new RemindersSubstore(this.store, this);
id = new IDSubstore(this.store, this);

updateTasks() {
this.tasks.value = this.store.tasks;
Expand Down
1 change: 1 addition & 0 deletions src/store/storage/TasksSubstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class TasksSubstore extends StorageSubstore<
startDate: task.startDate ? new Date(task.startDate) : null,
chunks: task.chunks,
backloaded: task.backloaded,
id: task.id ?? -1,
lockedChunks: task.lockedChunks?.map((lockedChunk) => {
return {
date: new Date(lockedChunk.date),
Expand Down
6 changes: 6 additions & 0 deletions src/types/Changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,10 @@ Typing a hotkey in the description field in the task modal could open modals/tri
title: "Bug fix",
description: "Fix bug where tasks didn't complete properly",
},
{
version: "3.8.2",
title: "Internal reworking",
description:
"Reworks the internal structure; should be no external changes",
},
];
4 changes: 4 additions & 0 deletions src/types/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default class UserTask {

lockedChunks: { date: Date; number: number }[] = [];

id = 0;

get totalEffort(): number {
return this.effort * this.duration;
}
Expand All @@ -24,6 +26,7 @@ export default class UserTask {
lockedChunks = [] as { date: Date; number: number }[],
backloaded = true,
startDate = null as Date | null,
id = -1,
}) {
this.name = name;
this.duration = duration;
Expand All @@ -34,6 +37,7 @@ export default class UserTask {
this.lockedChunks = lockedChunks;
this.backloaded = backloaded;
this.startDate = startDate;
this.id = id;
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/util/IDUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Store } from "@/store/index.vuex";

export default class IDUtils {
static store: Store | undefined = undefined;

static get lastID(): number {
if (!this.store) {
return -1;
}
try {
return this.store.storage.id.value;
} catch {
return -1;
}
}

static nextID(): number {
if (!this.store) {
return -1;
}
const id = this.lastID + 1;
this.store.storage.id.value = id;
return id;
}
}
19 changes: 0 additions & 19 deletions src/util/TaskUtils.ts

This file was deleted.