Browse Source

fix handling of zero-weight items. They're not counted in goals/compositon, but project progress count them as 1.

main
Gisle Aune 4 years ago
parent
commit
173158a514
  1. 21
      svelte-ui/src/components/Composition.svelte
  2. 2
      svelte-ui/src/components/GoalEntry.svelte
  3. 6
      svelte-ui/src/components/ProjectProgress.svelte

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

@ -10,6 +10,7 @@
export let logs: LogResult[] = []; export let logs: LogResult[] = [];
export let mode: GoalCompositionMode = "item"; export let mode: GoalCompositionMode = "item";
export let ignoreZeroWeight: boolean = false;
let list: CompositionItem[] = []; let list: CompositionItem[] = [];
@ -20,19 +21,23 @@
for (const log of logs) { for (const log of logs) {
if (log.itemCounted !== false) { if (log.itemCounted !== false) {
const item = log.item; const item = log.item;
if (!map[item.id]) {
map[item.id] = {name: item.name, amount: log.itemAmount, link: `/items#${item.id}`};
} else {
map[item.id].amount += log.itemAmount;
if (!ignoreZeroWeight || item.groupWeight > 0) {
if (!map[item.id]) {
map[item.id] = {name: item.name, amount: log.itemAmount, link: `/items#${item.id}`};
} else {
map[item.id].amount += log.itemAmount;
}
} }
} }
if (log.secondaryItem && log.secondaryItemCounted !== false) { if (log.secondaryItem && log.secondaryItemCounted !== false) {
const item = log.secondaryItem; const item = log.secondaryItem;
if (!map[item.id]) {
map[item.id] = {name: item.name, amount: log.secondaryItemAmount, link: `/items#${item.id}`};
} else {
map[item.id].amount += log.secondaryItemAmount;
if (!ignoreZeroWeight || item.groupWeight > 0) {
if (!map[item.id]) {
map[item.id] = {name: item.name, amount: log.secondaryItemAmount, link: `/items#${item.id}`};
} else {
map[item.id].amount += log.secondaryItemAmount;
}
} }
} }
} }

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

@ -49,7 +49,7 @@
<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} />
<Composition ignoreZeroWeight logs={goal.logs} mode={goal.compositionMode} />
</ParentEntry> </ParentEntry>
<style> <style>

6
svelte-ui/src/components/ProjectProgress.svelte

@ -13,10 +13,10 @@
let progressTarget: number; let progressTarget: number;
$: progressAmount = (project.tasks||[]).map(t => (t.active || t.statusTag === "to do" || t.statusTag === "on hold") $: progressAmount = (project.tasks||[]).map(t => (t.active || t.statusTag === "to do" || t.statusTag === "on hold")
? Math.min(t.completedAmount, t.itemAmount) * t.item.groupWeight
: t.itemAmount * t.item.groupWeight
? Math.min(t.completedAmount, t.itemAmount) * (t.item.groupWeight || 1)
: t.itemAmount * (t.item.groupWeight || 1)
).reduce((n,m) => n+m, 0); ).reduce((n,m) => n+m, 0);
$: progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * t.item.groupWeight).reduce((n,m) => n+m, 0), 1);
$: progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
</script> </script>
<Progress thin contextColor count={progressAmount} target={progressTarget} /> <Progress thin contextColor count={progressAmount} target={progressTarget} />
Loading…
Cancel
Save