fix handling of zero-weight items. They're not counted in goals/compositon, but project progress count them as 1.
This commit is contained in:
@@ -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]) {
|
if (!ignoreZeroWeight || item.groupWeight > 0) {
|
||||||
map[item.id] = {name: item.name, amount: log.itemAmount, link: `/items#${item.id}`};
|
if (!map[item.id]) {
|
||||||
} else {
|
map[item.id] = {name: item.name, amount: log.itemAmount, link: `/items#${item.id}`};
|
||||||
map[item.id].amount += log.itemAmount;
|
} 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]) {
|
if (!ignoreZeroWeight || item.groupWeight > 0) {
|
||||||
map[item.id] = {name: item.name, amount: log.secondaryItemAmount, link: `/items#${item.id}`};
|
if (!map[item.id]) {
|
||||||
} else {
|
map[item.id] = {name: item.name, amount: log.secondaryItemAmount, link: `/items#${item.id}`};
|
||||||
map[item.id].amount += log.secondaryItemAmount;
|
} else {
|
||||||
|
map[item.id].amount += log.secondaryItemAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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
|
? Math.min(t.completedAmount, t.itemAmount) * (t.item.groupWeight || 1)
|
||||||
: t.itemAmount * t.item.groupWeight
|
: 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} />
|
||||||
|
|||||||
Reference in New Issue
Block a user