Browse Source

add goal completion composition.

main
Gisle Aune 4 years ago
parent
commit
5e1a6f7343
  1. 1
      svelte-ui/src/App.svelte
  2. 1
      svelte-ui/src/clients/stufflog.ts
  3. 84
      svelte-ui/src/components/Composition.svelte
  4. 2
      svelte-ui/src/components/GoalEntry.svelte
  5. 2
      svelte-ui/src/components/Menu.svelte
  6. 4
      svelte-ui/src/components/Progress.svelte
  7. 1
      svelte-ui/src/components/ProjectEntry.svelte
  8. 2
      svelte-ui/src/components/TimeProgress.svelte
  9. 4
      svelte-ui/src/models/goal.ts
  10. 4
      svelte-ui/src/pages/FrontPage.svelte
  11. 2
      svelte-ui/src/pages/QLPage.svelte

1
svelte-ui/src/App.svelte

@ -69,7 +69,6 @@
main { main {
text-align: left; text-align: left;
max-width: 99.5%; max-width: 99.5%;
width: 920px;
margin: 1em auto; margin: 1em auto;
padding-bottom: 4em; padding-bottom: 4em;
} }

1
svelte-ui/src/clients/stufflog.ts

@ -232,7 +232,6 @@ export class StufflogClient {
req.body = data; req.body = data;
} }
console.warn("AUTH SKIPPED, remember to change back in prod!")
req.headers["Authorization"] = await getJwt(); req.headers["Authorization"] = await getJwt();
const res = await fetch(fullPath, req); const res = await fetch(fullPath, req);

84
svelte-ui/src/components/Composition.svelte

@ -0,0 +1,84 @@
<script lang="ts">
import type { GoalCompositionMode } from "../models/goal";
import type { LogResult } from "../models/log";
import type { TaskResult } from "../models/task";
interface CompositionItem {
link: string
amount: number
name: string
}
export let logs: LogResult[] = [];
export let mode: GoalCompositionMode = "item";
let list: CompositionItem[] = [];
$: {
const map: {[k: string]: CompositionItem} = {}
if (mode === "item") {
for (const log of logs) {
const item = log.item;
if (!map[item.name]) {
map[item.name] = {name: item.name, amount: log.itemAmount, link: `/items#${item.id}`};
} else {
map[item.name].amount += log.itemAmount;
}
if (log.secondaryItem) {
const item = log.secondaryItem;
if (!map[item.name]) {
map[item.name] = {name: item.name, amount: log.secondaryItemAmount, link: `/items#${item.id}`};
} else {
map[item.name].amount += log.secondaryItemAmount;
}
}
}
} else {
for (const log of logs) {
const task = log.task;
const amount = log.secondaryItem ? log.secondaryItemAmount + log.itemAmount : log.itemAmount;
if (!map[task.name]) {
map[task.name] = {name: task.name, amount, link: `/questlog#${task.projectId}`};
} else {
map[task.name].amount += amount;
}
}
}
list = Object.keys(map).sort((a, b) => map[b].amount - map[a].amount).map(k => map[k]);
}
</script>
<div class="composition">
{#each list as item (item.name)}
<div class="item">
<span class="amount">{item.amount}x&nbsp;</span>
<a href={item.link}>{item.name}</a>
</div>
{/each}
</div>
<style>
div.composition {
padding: 0.25em 0ch;
color: #555;
font-size: 0.75em;
}
div.item {
padding: 0.125em 0.5ch;
display: inline-block;
}
span.amount {
color: #777;
}
a {
color: inherit;
}
</style>

2
svelte-ui/src/components/GoalEntry.svelte

@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { GoalResult } from "../models/goal"; import type { GoalResult } from "../models/goal";
import type { ModalData } from "../stores/modal"; import type { ModalData } from "../stores/modal";
import Composition from "./Composition.svelte";
import EveryMinute from "./EveryMinute.svelte"; import EveryMinute from "./EveryMinute.svelte";
import Option from "./Option.svelte"; import Option from "./Option.svelte";
import OptionRow from "./OptionRow.svelte"; import OptionRow from "./OptionRow.svelte";
@ -34,6 +35,7 @@ import TimeProgress from "./TimeProgress.svelte";
<Progress count={goal.completedAmount} target={goal.amount} /> <Progress count={goal.completedAmount} target={goal.amount} />
<TimeProgress startTime={goal.startTime} endTime={goal.endTime} /> <TimeProgress startTime={goal.startTime} endTime={goal.endTime} />
</div> </div>
<Composition logs={goal.logs} mode={goal.compositionMode} />
</ParentEntry> </ParentEntry>
<style> <style>

2
svelte-ui/src/components/Menu.svelte

@ -10,8 +10,6 @@
}, 0); }, 0);
} }
$: console.log($selectionStore);
$: selected = { $: selected = {
home: $selectionStore.path === "/", home: $selectionStore.path === "/",
goals: $selectionStore.path.startsWith("/goals"), goals: $selectionStore.path.startsWith("/goals"),

4
svelte-ui/src/components/Progress.svelte

@ -78,10 +78,6 @@
title = `${count} / ${target} (${percentage}%)` title = `${count} / ${target} (${percentage}%)`
} }
} }
$: {
console.log(ons, offs);
}
</script> </script>
<div class="bar" title="{title}" class:thin class:thinner> <div class="bar" title="{title}" class:thin class:thinner>

1
svelte-ui/src/components/ProjectEntry.svelte

@ -4,6 +4,7 @@ import type { TaskResult } from "../models/task";
import type { ModalData } from "../stores/modal"; import type { ModalData } from "../stores/modal";
import projectStore from "../stores/project"; import projectStore from "../stores/project";
import taskStore from "../stores/tasks"; import taskStore from "../stores/tasks";
import Composition from "./Composition.svelte";
import Option from "./Option.svelte"; import Option from "./Option.svelte";
import OptionRow from "./OptionRow.svelte"; import OptionRow from "./OptionRow.svelte";
import ParentEntry from "./ParentEntry.svelte"; import ParentEntry from "./ParentEntry.svelte";

2
svelte-ui/src/components/TimeProgress.svelte

@ -24,8 +24,6 @@
} }
} }
} }
$: console.log(startTime, endTime, msLength, msElapsed, msElapsed < msLength)
</script> </script>
<EveryMinute bind:now={now} /> <EveryMinute bind:now={now} />

4
svelte-ui/src/models/goal.ts

@ -2,6 +2,8 @@ import type Group from "./group";
import type Item from "./item"; import type Item from "./item";
import type { LogResult } from "./log"; import type { LogResult } from "./log";
export type GoalCompositionMode = "task" | "item"
export default interface Goal { export default interface Goal {
id: string id: string
groupId: string groupId: string
@ -12,7 +14,7 @@ export default interface Goal {
name: string name: string
description: string description: string
unweighted: boolean unweighted: boolean
compositionMode: string
compositionMode: GoalCompositionMode
} }
export interface GoalFilter { export interface GoalFilter {

4
svelte-ui/src/pages/FrontPage.svelte

@ -93,10 +93,12 @@
div.page { div.page {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: 100%;
max-width: 100%;
padding: 0 1ch; padding: 0 1ch;
margin: 0; margin: 0;
width: 1020px;
box-sizing: border-box; box-sizing: border-box;
margin: 1em auto;
} }
div.left, div.right { div.left, div.right {
width: 50%; width: 50%;

2
svelte-ui/src/pages/QLPage.svelte

@ -26,7 +26,7 @@
display: block; display: block;
margin: auto; margin: auto;
max-width: 100%; max-width: 100%;
width: 1600px;
width: 1020px;
margin-top: 0; margin-top: 0;
box-sizing: border-box; box-sizing: border-box;
} }
Loading…
Cancel
Save