|
|
@ -1,7 +1,9 @@ |
|
|
|
<script lang="ts"> |
|
|
|
import { significantDecimals } from "$lib/utils/numbers"; |
|
|
|
|
|
|
|
import { addDays, endOfDay, formatWeekdayDate, formatWeekdayTitle, startOfDay } from "$lib/utils/date"; |
|
|
|
import { significantDecimals } from "$lib/utils/numbers"; |
|
|
|
import { morningOf } from "$lib/utils/timeinterval"; |
|
|
|
import { getItemMultiListContext } from "../contexts/ItemMultiListContext.svelte"; |
|
|
|
import { getTimeContext } from "../contexts/TimeContext.svelte"; |
|
|
|
import Row from "../layout/Row.svelte"; |
|
|
|
import ItemSubSection, { type ItemSubSectionEvent } from "../project/ItemSubSection.svelte"; |
|
|
|
|
|
|
@ -9,13 +11,27 @@ import { significantDecimals } from "$lib/utils/numbers"; |
|
|
|
export let title: string; |
|
|
|
export let showAcquiredTime: boolean = false; |
|
|
|
export let useAcquiredTotal: boolean = false; |
|
|
|
export let useDayFilter: number | null = null; |
|
|
|
export let selectedDay: number = 0; |
|
|
|
export let event: ItemSubSectionEvent = "none"; |
|
|
|
|
|
|
|
const {now} = getTimeContext(); |
|
|
|
const {lists} = getItemMultiListContext(); |
|
|
|
|
|
|
|
let dayTitle = ""; |
|
|
|
let filteredList = []; |
|
|
|
$: if (useDayFilter != null) { |
|
|
|
const maxTime = addDays(morningOf($now), -(selectedDay - 1)).toISOString(); |
|
|
|
const minTime = addDays(morningOf($now), -selectedDay).toISOString(); |
|
|
|
filteredList = $lists[key].filter(i => i.acquiredTime >= minTime && i.acquiredTime <= maxTime) |
|
|
|
dayTitle = formatWeekdayTitle($now, new Date(minTime)) |
|
|
|
} else { |
|
|
|
filteredList = $lists[key] || []; |
|
|
|
} |
|
|
|
|
|
|
|
let totalStr = ""; |
|
|
|
$: { |
|
|
|
totalStr = significantDecimals(($lists[key]||[]).map(v => useAcquiredTotal ? v.weightedAcquired : v.weightedRequired).reduce((p,c) => p + c, 0)); |
|
|
|
totalStr = significantDecimals(filteredList.map(v => useAcquiredTotal ? v.weightedAcquired : v.weightedRequired).reduce((p,c) => p + c, 0)); |
|
|
|
if (Number(totalStr) < 0.01) { |
|
|
|
totalStr = ""; |
|
|
|
} |
|
|
@ -23,10 +39,19 @@ import { significantDecimals } from "$lib/utils/numbers"; |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
{#if ($lists[key]||[]).length > 0} |
|
|
|
<Row title={title}> |
|
|
|
{#if (filteredList.length > 0 || useDayFilter != null)} |
|
|
|
<Row title={title || dayTitle}> |
|
|
|
<div class="total" slot="right">{totalStr}</div> |
|
|
|
{#each $lists[key] as item (item.id)} |
|
|
|
<div class="day-filters" slot="over"> |
|
|
|
{#if (useDayFilter != null)} |
|
|
|
{#each {length: useDayFilter} as _, i} |
|
|
|
<div on:click={() => selectedDay = i} class="option" class:selected={i === selectedDay}> |
|
|
|
<div class="inner"></div> |
|
|
|
</div> |
|
|
|
{/each} |
|
|
|
{/if} |
|
|
|
</div> |
|
|
|
{#each filteredList as item (item.id)} |
|
|
|
<ItemSubSection event={event} showAcquiredTime={showAcquiredTime} item={item} /> |
|
|
|
{/each} |
|
|
|
</Row> |
|
|
@ -38,4 +63,36 @@ import { significantDecimals } from "$lib/utils/numbers"; |
|
|
|
div.total |
|
|
|
color: $color-entry5 |
|
|
|
margin-top: 0.25em |
|
|
|
|
|
|
|
div.day-filters |
|
|
|
display: flex |
|
|
|
flex-direction: row |
|
|
|
max-width: 100% |
|
|
|
flex-wrap: wrap |
|
|
|
|
|
|
|
div.option |
|
|
|
padding: 0.1em 0.25em |
|
|
|
cursor: pointer |
|
|
|
|
|
|
|
&:first-child |
|
|
|
margin-left: -0.25em |
|
|
|
@media screen and (max-width: 749px) |
|
|
|
margin-left: 0 |
|
|
|
|
|
|
|
> div.inner |
|
|
|
width: 1.25ch |
|
|
|
height: 1.25ch |
|
|
|
border: 1px solid $color-entry2 |
|
|
|
|
|
|
|
@media screen and (max-width: 749px) |
|
|
|
width: 2.5ch |
|
|
|
height: 2.5ch |
|
|
|
|
|
|
|
|
|
|
|
&.selected > div.inner |
|
|
|
border-color: $color-entry7 |
|
|
|
background-color: $color-entry7 |
|
|
|
|
|
|
|
&:hover > div.inner |
|
|
|
border-color: $color-entry9 |
|
|
|
</style> |