Gisle Aune
4 years ago
6 changed files with 99 additions and 3 deletions
-
9api/task.go
-
3database/postgres/tasks.go
-
4models/task.go
-
78svelte-ui/src/components/ProjectSelect.svelte
-
7svelte-ui/src/forms/TaskForm.svelte
-
1svelte-ui/src/models/task.ts
@ -0,0 +1,78 @@ |
|||||
|
<script lang="ts"> |
||||
|
import type Project from "../models/project"; |
||||
|
import authStore from "../stores/auth"; |
||||
|
import projectStore from "../stores/project"; |
||||
|
|
||||
|
interface OptGroup { |
||||
|
status: string |
||||
|
projects: Project[] |
||||
|
} |
||||
|
|
||||
|
export let value = ""; |
||||
|
export let name = ""; |
||||
|
export let disabled = false; |
||||
|
export let optional = false; |
||||
|
|
||||
|
let optGroups: OptGroup[] |
||||
|
|
||||
|
$: { |
||||
|
if ($projectStore.stale && !$projectStore.loading) { |
||||
|
projectStore.load({}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$: { |
||||
|
optGroups = [ |
||||
|
{ |
||||
|
status: "Deadlines", |
||||
|
projects: $projectStore.projects.filter(p => p.active && p.endTime) |
||||
|
}, |
||||
|
{ |
||||
|
status: "Active", |
||||
|
projects: $projectStore.projects.filter(p => p.active && !p.endTime) |
||||
|
}, |
||||
|
{ |
||||
|
status: "To Do", |
||||
|
projects: $projectStore.projects.filter(p => !p.active && p.statusTag === "to do") |
||||
|
}, |
||||
|
{ |
||||
|
status: "On Hold", |
||||
|
projects: $projectStore.projects.filter(p => !p.active && p.statusTag === "on hold") |
||||
|
}, |
||||
|
{ |
||||
|
status: "Completed", |
||||
|
projects: $projectStore.projects.filter(p => !p.active && p.statusTag === "completed") |
||||
|
}, |
||||
|
{ |
||||
|
status: "Failed", |
||||
|
projects: $projectStore.projects.filter(p => !p.active && p.statusTag === "failed") |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
for (const group of optGroups) { |
||||
|
group.projects.sort((a,b) => a.name.localeCompare(b.name)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$: { |
||||
|
if (optGroups.length > 0 && value === "" && !optional) { |
||||
|
const nonEmpty = optGroups.find(g => g.projects.length > 0); |
||||
|
if (nonEmpty != null) { |
||||
|
value = nonEmpty.projects[0].id; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<select name={name} bind:value={value} disabled={disabled || $projectStore.loading}> |
||||
|
{#if optional} |
||||
|
<option value={""} selected={"" === value}>None</option> |
||||
|
{/if} |
||||
|
{#each optGroups as group (group.status)} |
||||
|
<optgroup label={group.status}> |
||||
|
{#each group.projects as project (project.id)} |
||||
|
<option value={project.id} selected={project.id === value}>{project.name}</option> |
||||
|
{/each} |
||||
|
</optgroup> |
||||
|
{/each} |
||||
|
</select> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue