Browse Source

add total for overview item list.

master
Gisle Aune 2 years ago
parent
commit
acaaca1b48
  1. 7
      frontend/src/lib/components/layout/Row.svelte
  2. 22
      frontend/src/lib/components/scope/ItemListRow.svelte
  3. 2
      frontend/src/routes/[scope=prettyid]/overview.svelte
  4. 2
      frontend/src/routes/index.svelte

7
frontend/src/lib/components/layout/Row.svelte

@ -14,6 +14,9 @@
</div>
<style lang="sass">
@import "../../css/colors.sass"
div.row
margin: 0.5em 1ch
padding: 0.5em 1ch
@ -21,6 +24,8 @@
div.header-row
display: flex
flex-direction: row
padding-bottom: 0.1em
border-bottom: 1px solid $color-entry2-transparent
&:empty
display: none
@ -28,6 +33,6 @@
> h2
font-size: 1.25em
margin: 0
margin-bottom: 0.25em
margin-bottom: 0.05em
margin-right: auto
</style>

22
frontend/src/lib/components/scope/ItemListRow.svelte

@ -1,4 +1,6 @@
<script lang="ts">
import { significantDecimals } from "$lib/utils/numbers";
import { getItemMultiListContext } from "../contexts/ItemMultiListContext.svelte";
import Row from "../layout/Row.svelte";
import ItemSubSection from "../project/ItemSubSection.svelte";
@ -6,15 +8,33 @@
export let key: string;
export let title: string;
export let showAcquiredTime: boolean = false;
export let useAcquiredTotal: boolean = false;
const {lists} = getItemMultiListContext();
let totalStr = "";
$: {
totalStr = significantDecimals(($lists[key]||[]).map(v => useAcquiredTotal ? v.weightedAcquired : v.weightedRequired).reduce((p,c) => p + c, 0));
if (Number(totalStr) < 0.01) {
totalStr = "";
}
}
</script>
{#if ($lists[key]||[]).length > 0}
<Row title={title}>
<div class="total" slot="right">{totalStr}</div>
{#each $lists[key] as item (item.id)}
<ItemSubSection showAcquiredTime={showAcquiredTime} item={item} />
{/each}
</Row>
{/if}
{/if}
<style lang="sass">
@import "../../css/colors.sass"
div.total
color: $color-entry5
margin-top: 0.25em
</style>

2
frontend/src/routes/[scope=prettyid]/overview.svelte

@ -105,7 +105,7 @@
<Card on:click={openDeleteScope} pointerCursor><CardHeader>Delete Scope</CardHeader></Card>
</Row>
<ItemListRow title="Scheduled" key="scheduledItems" />
<ItemListRow title="Today" key="acquiredItems" showAcquiredTime />
<ItemListRow title="Today" key="acquiredItems" showAcquiredTime useAcquiredTotal />
<ItemListRow title="Loose" key="looseItems" />
</Column>
<Column>

2
frontend/src/routes/index.svelte

@ -92,7 +92,7 @@
<ScopeLinkList />
</Row>
<ItemListRow title="Scheduled" key="scheduledItems" />
<ItemListRow title="Today" key="acquiredItems" showAcquiredTime />
<ItemListRow title="Today" key="acquiredItems" showAcquiredTime useAcquiredTotal />
<ItemListRow title="Loose" key="looseItems" />
</Column>
<Column>

Loading…
Cancel
Save