Browse Source
clean up logs modals and fix progress bars counting on completed but N<M/M task progress.
main
clean up logs modals and fix progress bars counting on completed but N<M/M task progress.
main
Gisle Aune
4 years ago
7 changed files with 146 additions and 211 deletions
-
12svelte-ui/src/App.svelte
-
5svelte-ui/src/components/ProjectEntry.svelte
-
72svelte-ui/src/forms/LogAddForm.svelte
-
64svelte-ui/src/forms/LogDeleteForm.svelte
-
67svelte-ui/src/forms/LogEditForm.svelte
-
106svelte-ui/src/forms/LogForm.svelte
-
31svelte-ui/src/stores/markStale.ts
@ -1,72 +0,0 @@ |
|||||
<script lang="ts"> |
|
||||
import stuffLogClient from "../clients/stufflog"; |
|
||||
import Checkbox from "../components/Checkbox.svelte"; |
|
||||
import Modal from "../components/Modal.svelte"; |
|
||||
import goalStore, { fpGoalStore } from "../stores/goal"; |
|
||||
import logStore from "../stores/logs"; |
|
||||
import modalStore from "../stores/modal"; |
|
||||
import projectStore, { fpProjectStore } from "../stores/project"; |
|
||||
import taskStore, { fpTaskStore } from "../stores/tasks"; |
|
||||
import { formatFormTime } from "../utils/time"; |
|
||||
|
|
||||
const md = $modalStore; |
|
||||
if (md.name !== "log.add") { |
|
||||
throw new Error("Wrong form"); |
|
||||
} |
|
||||
const task = md.task; |
|
||||
|
|
||||
let loggedTime = formatFormTime(new Date); |
|
||||
let description = ""; |
|
||||
let markInactive = task.completedAmount >= (task.itemAmount - 1); |
|
||||
let error = null; |
|
||||
let loading = false; |
|
||||
|
|
||||
function onSubmit() { |
|
||||
loading = true; |
|
||||
|
|
||||
stuffLogClient.createLog({ |
|
||||
taskId: task.id, |
|
||||
loggedTime: new Date(loggedTime).toISOString(), |
|
||||
description, |
|
||||
}).then(() => { |
|
||||
if (markInactive) { |
|
||||
return stuffLogClient.updateTask(task.id, {active: false}) |
|
||||
} |
|
||||
}).then(() => { |
|
||||
modalStore.close(); |
|
||||
}).finally(() => { |
|
||||
projectStore.markStale(); |
|
||||
fpProjectStore.markStale(); |
|
||||
goalStore.markStale(); |
|
||||
fpGoalStore.markStale(); |
|
||||
taskStore.markStale(); |
|
||||
fpTaskStore.markStale(); |
|
||||
logStore.markStale(); |
|
||||
}).finally(() => { |
|
||||
loading = false; |
|
||||
}) |
|
||||
|
|
||||
error = null; |
|
||||
} |
|
||||
|
|
||||
function onClose() { |
|
||||
modalStore.close(); |
|
||||
} |
|
||||
</script> |
|
||||
|
|
||||
<Modal show title="Add Log" error={error} closable on:close={onClose}> |
|
||||
<form on:submit|preventDefault={onSubmit}> |
|
||||
<label for="taskName">Task</label> |
|
||||
<input disabled name="taskName" type="text" bind:value={task.name} /> |
|
||||
|
|
||||
<label for="loggedTime">Logged Time</label> |
|
||||
<input name="loggedTime" type="datetime-local" bind:value={loggedTime} /> |
|
||||
<label for="description">Description</label> |
|
||||
<textarea name="description" bind:value={description} /> |
|
||||
<Checkbox bind:checked={markInactive} label="Mark task inactive/completed." /> |
|
||||
|
|
||||
<hr /> |
|
||||
|
|
||||
<button disabled={loading} type="submit">Add Log</button> |
|
||||
</form> |
|
||||
</Modal> |
|
@ -1,64 +0,0 @@ |
|||||
<script lang="ts"> |
|
||||
import stuffLogClient from "../clients/stufflog"; |
|
||||
import Modal from "../components/Modal.svelte"; |
|
||||
import modalStore from "../stores/modal"; |
|
||||
import goalStore, { fpGoalStore } from "../stores/goal"; |
|
||||
import projectStore, { fpProjectStore } from "../stores/project"; |
|
||||
import { formatFormTime } from "../utils/time"; |
|
||||
import logStore from "../stores/logs"; |
|
||||
import taskStore, { fpTaskStore } from "../stores/tasks"; |
|
||||
|
|
||||
const md = $modalStore; |
|
||||
if (md.name !== "log.delete") { |
|
||||
throw new Error("Wrong form"); |
|
||||
} |
|
||||
|
|
||||
let loggedTime = formatFormTime(new Date(md.log.loggedTime)); |
|
||||
let description = md.log.description; |
|
||||
let error = null; |
|
||||
let loading = false; |
|
||||
|
|
||||
function onSubmit() { |
|
||||
const md = $modalStore; |
|
||||
if (md.name !== "log.delete") { |
|
||||
throw new Error("Wrong form"); |
|
||||
} |
|
||||
|
|
||||
loading = true; |
|
||||
|
|
||||
stuffLogClient.deleteLog(md.log.id).then(() => { |
|
||||
projectStore.markStale(); |
|
||||
fpProjectStore.markStale(); |
|
||||
goalStore.markStale(); |
|
||||
fpGoalStore.markStale(); |
|
||||
logStore.markStale(); |
|
||||
taskStore.markStale(); |
|
||||
fpTaskStore.markStale(); |
|
||||
|
|
||||
modalStore.close(); |
|
||||
}).finally(() => { |
|
||||
loading = false; |
|
||||
}) |
|
||||
|
|
||||
error = null; |
|
||||
} |
|
||||
|
|
||||
function onClose() { |
|
||||
modalStore.close(); |
|
||||
} |
|
||||
</script> |
|
||||
|
|
||||
<Modal show title="Delete Log" error={error} closable on:close={onClose}> |
|
||||
<form on:submit|preventDefault={onSubmit}> |
|
||||
<label for="taskName">Task</label> |
|
||||
<input disabled name="taskName" type="text" bind:value={md.log.task.name} /> |
|
||||
<label for="loggedTime">Logged Time</label> |
|
||||
<input disabled name="loggedTime" type="datetime-local" bind:value={loggedTime} /> |
|
||||
<label for="description">Description</label> |
|
||||
<textarea disabled name="description" bind:value={description} /> |
|
||||
|
|
||||
<hr /> |
|
||||
|
|
||||
<button disabled={loading} type="submit">Delete Log</button> |
|
||||
</form> |
|
||||
</Modal> |
|
@ -1,67 +0,0 @@ |
|||||
<script lang="ts"> |
|
||||
import stuffLogClient from "../clients/stufflog"; |
|
||||
import Modal from "../components/Modal.svelte"; |
|
||||
import modalStore from "../stores/modal"; |
|
||||
import goalStore, { fpGoalStore } from "../stores/goal"; |
|
||||
import projectStore, { fpProjectStore } from "../stores/project"; |
|
||||
import { formatFormTime } from "../utils/time"; |
|
||||
import logStore from "../stores/logs"; |
|
||||
import taskStore, { fpTaskStore } from "../stores/tasks"; |
|
||||
|
|
||||
const md = $modalStore; |
|
||||
if (md.name !== "log.edit") { |
|
||||
throw new Error("Wrong form"); |
|
||||
} |
|
||||
|
|
||||
let loggedTime = formatFormTime(new Date(md.log.loggedTime)); |
|
||||
let description = md.log.description; |
|
||||
let error = null; |
|
||||
let loading = false; |
|
||||
|
|
||||
function onSubmit() { |
|
||||
const md = $modalStore; |
|
||||
if (md.name !== "log.edit") { |
|
||||
throw new Error("Wrong form"); |
|
||||
} |
|
||||
|
|
||||
loading = true; |
|
||||
|
|
||||
stuffLogClient.updateLog(md.log.id, { |
|
||||
loggedTime: new Date(loggedTime).toISOString(), |
|
||||
description, |
|
||||
}).then(() => { |
|
||||
projectStore.markStale(); |
|
||||
fpProjectStore.markStale(); |
|
||||
goalStore.markStale(); |
|
||||
fpGoalStore.markStale(); |
|
||||
taskStore.markStale(); |
|
||||
fpTaskStore.markStale(); |
|
||||
logStore.markStale(); |
|
||||
|
|
||||
modalStore.close(); |
|
||||
}).finally(() => { |
|
||||
loading = false; |
|
||||
}) |
|
||||
|
|
||||
error = null; |
|
||||
} |
|
||||
|
|
||||
function onClose() { |
|
||||
modalStore.close(); |
|
||||
} |
|
||||
</script> |
|
||||
|
|
||||
<Modal show title="Edit Log" error={error} closable on:close={onClose}> |
|
||||
<form on:submit|preventDefault={onSubmit}> |
|
||||
<label for="taskName">Task</label> |
|
||||
<input disabled name="taskName" type="text" bind:value={md.log.task.name} /> |
|
||||
<label for="loggedTime">Logged Time</label> |
|
||||
<input name="loggedTime" type="datetime-local" bind:value={loggedTime} /> |
|
||||
<label for="description">Description</label> |
|
||||
<textarea name="description" bind:value={description} /> |
|
||||
|
|
||||
<hr /> |
|
||||
|
|
||||
<button disabled={loading} type="submit">Edit Log</button> |
|
||||
</form> |
|
||||
</Modal> |
|
@ -0,0 +1,106 @@ |
|||||
|
<script lang="ts"> |
||||
|
import stuffLogClient from "../clients/stufflog"; |
||||
|
import Checkbox from "../components/Checkbox.svelte"; |
||||
|
import Modal from "../components/Modal.svelte"; |
||||
|
import type { LogResult } from "../models/log"; |
||||
|
import markStale from "../stores/markStale"; |
||||
|
import modalStore from "../stores/modal"; |
||||
|
import { formatFormTime } from "../utils/time"; |
||||
|
|
||||
|
export let deletion = false; |
||||
|
export let creation = false; |
||||
|
|
||||
|
const md = $modalStore; |
||||
|
let log: LogResult = { |
||||
|
id: "", |
||||
|
taskId: "", |
||||
|
itemId: "", |
||||
|
loggedTime: new Date().toISOString(), |
||||
|
description: "", |
||||
|
task: null, |
||||
|
item: null, |
||||
|
} |
||||
|
let defaultMarkInactive = false; |
||||
|
let verb = "Add"; |
||||
|
if (md.name === "log.edit" || md.name === "log.delete") { |
||||
|
log = md.log; |
||||
|
verb = (md.name === "log.edit") ? "Edit" : "Delete"; |
||||
|
} else if (md.name === "log.add") { |
||||
|
defaultMarkInactive = md.task.completedAmount >= (md.task.itemAmount - 1); |
||||
|
log.task = md.task; |
||||
|
} else { |
||||
|
throw new Error("Wrong form") |
||||
|
} |
||||
|
|
||||
|
let loggedTime = formatFormTime(log.loggedTime); |
||||
|
let description = log.description; |
||||
|
let markInactive = defaultMarkInactive; |
||||
|
let error = null; |
||||
|
let loading = false; |
||||
|
|
||||
|
function onSubmit() { |
||||
|
loading = true; |
||||
|
error = null; |
||||
|
|
||||
|
if (creation) { |
||||
|
stuffLogClient.createLog({ |
||||
|
taskId: log.task.id, |
||||
|
loggedTime: new Date(loggedTime).toISOString(), |
||||
|
description, |
||||
|
}).then(() => { |
||||
|
markStale("project", "task", "goal", "log"); |
||||
|
|
||||
|
if (markInactive) { |
||||
|
return stuffLogClient.updateTask(log.task.id, {active: false}); |
||||
|
} |
||||
|
}).then(() => { |
||||
|
markStale("project", "task"); |
||||
|
|
||||
|
modalStore.close(); |
||||
|
}).catch(err => { |
||||
|
error = err.message ? err.message : err.toString(); |
||||
|
}).finally(() => { |
||||
|
loading = false; |
||||
|
}) |
||||
|
} else if (deletion) { |
||||
|
stuffLogClient.deleteLog(log.id).then(() => { |
||||
|
markStale("project", "task", "goal", "log"); |
||||
|
modalStore.close(); |
||||
|
}).catch(err => { |
||||
|
error = err.message ? err.message : err.toString(); |
||||
|
}).finally(() => { |
||||
|
loading = false; |
||||
|
}) |
||||
|
} else { |
||||
|
stuffLogClient.updateLog(log.id, { |
||||
|
loggedTime: new Date(loggedTime).toISOString(), |
||||
|
description, |
||||
|
}).then(() => { |
||||
|
markStale("project", "task", "goal", "log"); |
||||
|
modalStore.close(); |
||||
|
}).finally(() => { |
||||
|
loading = false; |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function onClose() { |
||||
|
modalStore.close(); |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<Modal show title="Add Log" error={error} closable on:close={onClose}> |
||||
|
<form on:submit|preventDefault={onSubmit}> |
||||
|
<label for="taskName">Task</label> |
||||
|
<input disabled name="taskName" type="text" value={log.task.name} /> |
||||
|
<label for="loggedTime">Logged Time</label> |
||||
|
<input disabled={deletion} name="loggedTime" type="datetime-local" bind:value={loggedTime} /> |
||||
|
<label for="description">Description</label> |
||||
|
<textarea disabled={deletion} name="description" bind:value={description} /> |
||||
|
<Checkbox disabled={deletion} bind:checked={markInactive} label="Mark task inactive/completed." /> |
||||
|
|
||||
|
<hr /> |
||||
|
|
||||
|
<button disabled={loading} type="submit">Add Log</button> |
||||
|
</form> |
||||
|
</Modal> |
@ -0,0 +1,31 @@ |
|||||
|
import goalStore, { fpGoalStore } from "./goal"; |
||||
|
import groupStore from "./group"; |
||||
|
import logStore from "./logs"; |
||||
|
import projectStore, { fpProjectStore } from "./project"; |
||||
|
import taskStore, { fpTaskStore } from "./tasks"; |
||||
|
|
||||
|
type ModelName = "goal" | "project" | "task" | "group" | "item" | "log" |
||||
|
|
||||
|
export default function markStale(...models: ModelName[]) { |
||||
|
if (models.includes("goal")) { |
||||
|
goalStore.markStale(); |
||||
|
fpGoalStore.markStale(); |
||||
|
} |
||||
|
if (models.includes("project")) { |
||||
|
projectStore.markStale(); |
||||
|
fpProjectStore.markStale(); |
||||
|
} |
||||
|
if (models.includes("task")) { |
||||
|
taskStore.markStale(); |
||||
|
fpTaskStore.markStale(); |
||||
|
} |
||||
|
if (models.includes("group")) { |
||||
|
groupStore.markStale(); |
||||
|
} |
||||
|
if (models.includes("item")) { |
||||
|
// Do nothing.
|
||||
|
} |
||||
|
if (models.includes("log")) { |
||||
|
logStore.markStale(); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue