Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-397: Fixed time report round #2389

Merged
merged 5 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/ui/src/components/EditBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import Icon from './Icon.svelte'
import Label from './Label.svelte'
import { resizeObserver } from '../resize'
import { floorFractionDigits } from '../utils'

export let label: IntlString | undefined = undefined
export let icon: Asset | AnySvelteComponent | undefined = undefined
Expand All @@ -30,6 +31,7 @@
export let placeholder: IntlString = plugin.string.EditBoxPlaceholder
export let placeholderParam: any | undefined = undefined
export let format: 'text' | 'password' | 'number' = 'text'
export let maxDigitsAfterPoint: number | undefined = undefined
export let kind: EditStyle = 'editbox'
export let focus: boolean = false
export let focusable: boolean = false
Expand All @@ -43,6 +45,16 @@
let phTraslate: string = ''
let parentWidth: number | undefined

$: {
if (
format === 'number' &&
maxDigitsAfterPoint &&
value &&
!value.toString().match(`^\\d+\\.?\\d{0,${maxDigitsAfterPoint}}$`)
) {
value = floorFractionDigits(Number(value), maxDigitsAfterPoint)
}
}
$: style = `max-width: ${
maxWidth || (parentWidth ? (icon ? `calc(${parentWidth}px - 1.25rem)` : `${parentWidth}px`) : 'max-content')
};`
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export function fetchMetadataLocalStorage<T> (id: Metadata<T>): T | null {
export function checkMobile (): boolean {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|Mobile|Opera Mini/i.test(navigator.userAgent)
}

export function floorFractionDigits (n: number | string, amount: number): number {
return Number(Number(n).toFixed(amount))
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
{kind}
placeholder={tracker.string.Estimation}
focus
maxDigitsAfterPoint={3}
on:keypress={_onkeypress}
on:change={() => {
if (typeof _value === 'number') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
import { AttachedData } from '@hcengineering/core'

import { Issue } from '@hcengineering/tracker'
import { Label } from '@hcengineering/ui'
import { floorFractionDigits, Label } from '@hcengineering/ui'
import tracker from '../../../plugin'
import EstimationProgressCircle from './EstimationProgressCircle.svelte'
import { floorFractionDigits } from '../../../utils'

export let value: Issue | AttachedData<Issue>

$: childReportTime = floorFractionDigits(
value.reportedTime + (value.childInfo ?? []).map((it) => it.reportedTime).reduce((a, b) => a + b, 0),
2
3
)
$: childEstimationTime = (value.childInfo ?? []).map((it) => it.estimation).reduce((a, b) => a + b, 0)
</script>
Expand All @@ -41,24 +40,24 @@
{#if value.reportedTime > 0 || childReportTime > 0}
{#if childReportTime}
{@const rchildReportTime = childReportTime}
{@const reportDiff = floorFractionDigits(rchildReportTime - value.reportedTime, 2)}
{@const reportDiff = floorFractionDigits(rchildReportTime - value.reportedTime, 3)}
{#if reportDiff !== 0 && value.reportedTime !== 0}
<div class="flex flex-nowrap mr-1" class:showError={reportDiff > 0}>
<Label label={tracker.string.TimeSpendValue} params={{ value: rchildReportTime }} />
</div>
<div class="romColor">
(<Label
label={tracker.string.TimeSpendValue}
params={{ value: floorFractionDigits(value.reportedTime, 2) }}
params={{ value: floorFractionDigits(value.reportedTime, 3) }}
/>)
</div>
{:else if value.reportedTime === 0}
<Label label={tracker.string.TimeSpendValue} params={{ value: childReportTime }} />
{:else}
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.reportedTime, 2) }} />
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.reportedTime, 3) }} />
{/if}
{:else}
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.reportedTime, 2) }} />
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.reportedTime, 3) }} />
{/if}
<div class="p-1">/</div>
{/if}
Expand All @@ -73,15 +72,15 @@
<div class="romColor">
(<Label
label={tracker.string.TimeSpendValue}
params={{ value: floorFractionDigits(value.estimation, 2) }}
params={{ value: floorFractionDigits(value.estimation, 3) }}
/>)
</div>
{/if}
{:else}
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.estimation, 2) }} />
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.estimation, 3) }} />
{/if}
{:else}
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.estimation, 2) }} />
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.estimation, 3) }} />
{/if}
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<script lang="ts">
import type { IntlString } from '@hcengineering/platform'
import { Issue } from '@hcengineering/tracker'
import { ActionIcon, eventToHTMLElement, IconAdd, Label, showPopup } from '@hcengineering/ui'
import { floorFractionDigits } from '../../../utils'
import { ActionIcon, eventToHTMLElement, floorFractionDigits, IconAdd, Label, showPopup } from '@hcengineering/ui'
import ReportsPopup from './ReportsPopup.svelte'
import TimeSpendReportPopup from './TimeSpendReportPopup.svelte'

Expand All @@ -39,15 +38,15 @@
}
$: childTime = floorFractionDigits(
(object.childInfo ?? []).map((it) => it.reportedTime).reduce((a, b) => a + b, 0),
2
3
)
</script>

{#if kind === 'link'}
<div id="ReportedTimeEditor" class="link-container flex-between" on:click={showReports}>
{#if value !== undefined}
<span class="overflow-label">
{floorFractionDigits(value, 2)}
{floorFractionDigits(value, 3)}
{#if childTime !== 0}
/ {childTime}
{/if}
Expand All @@ -61,7 +60,7 @@
</div>
{:else if value !== undefined}
<span class="overflow-label">
{floorFractionDigits(value, 2)}
{floorFractionDigits(value, 3)}
{#if childTime !== 0}
/ {childTime}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import { WithLookup } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation'
import type { TimeSpendReport } from '@hcengineering/tracker'
import { eventToHTMLElement, Label, showPopup, tooltip } from '@hcengineering/ui'
import { eventToHTMLElement, floorFractionDigits, Label, showPopup, tooltip } from '@hcengineering/ui'
import view, { AttributeModel } from '@hcengineering/view'
import { getObjectPresenter } from '@hcengineering/view-resources'
import tracker from '../../../plugin'
import { floorFractionDigits } from '../../../utils'
import TimeSpendReportPopup from './TimeSpendReportPopup.svelte'

export let value: WithLookup<TimeSpendReport>
Expand Down Expand Up @@ -65,7 +64,7 @@
}
: undefined}
>
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.value, 2) }} />
<Label label={tracker.string.TimeSpendValue} params={{ value: floorFractionDigits(value.value, 3) }} />
</span>
{/if}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
okLabel={value === undefined ? presentation.string.Create : presentation.string.Save}
>
<div class="flex-row-center gap-2">
<EditBox focus bind:value={data.value} {placeholder} format={'number'} kind={'editbox'} />
<EditBox focus bind:value={data.value} {placeholder} format={'number'} maxDigitsAfterPoint={3} kind={'editbox'} />
<UserBox
_class={contact.class.Employee}
label={contact.string.Employee}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import { DocumentQuery, Ref, SortingOrder } from '@hcengineering/core'
import { createQuery } from '@hcengineering/presentation'
import { Issue, Team, TimeSpendReport } from '@hcengineering/tracker'
import { Label, Scroller, Spinner } from '@hcengineering/ui'
import { floorFractionDigits, Label, Scroller, Spinner } from '@hcengineering/ui'
import tracker from '../../../plugin'
import { floorFractionDigits } from '../../../utils'
import TimeSpendReportsList from './TimeSpendReportsList.svelte'

export let issue: Issue
Expand All @@ -36,11 +35,8 @@
}
})

$: total = floorFractionDigits(
(reports ?? []).reduce((a, b) => a + b.value, 0),
2
)
$: reportedTime = floorFractionDigits(issue.reportedTime, 2)
$: total = (reports ?? []).reduce((a, b) => a + floorFractionDigits(b.value, 3), 0)
$: reportedTime = floorFractionDigits(issue.reportedTime, 3)
</script>

{#if reports}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
import { Doc, Ref, Space, WithLookup } from '@hcengineering/core'
import UserBox from '@hcengineering/presentation/src/components/UserBox.svelte'
import { Team, TimeSpendReport } from '@hcengineering/tracker'
import { eventToHTMLElement, getEventPositionElement, ListView, showPopup } from '@hcengineering/ui'
import {
eventToHTMLElement,
floorFractionDigits,
getEventPositionElement,
ListView,
showPopup
} from '@hcengineering/ui'
import DatePresenter from '@hcengineering/ui/src/components/calendar/DatePresenter.svelte'
import { ContextMenu, FixedColumn, ListSelectionProvider, SelectDirection } from '@hcengineering/view-resources'
import { getIssueId } from '../../../issues'
Expand Down Expand Up @@ -98,7 +104,7 @@
readonly
showNavigate={false}
/>
<EstimationPresenter value={report.value} />
<EstimationPresenter value={floorFractionDigits(report.value, 3)} />
<DatePresenter value={report.date} />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import { IntlString } from '@hcengineering/platform'
import { createQuery, getClient } from '@hcengineering/presentation'
import { Issue, IssueStatus, IssueTemplate, Sprint } from '@hcengineering/tracker'
import type { ButtonKind, ButtonSize, ButtonShape } from '@hcengineering/ui'
import { ButtonKind, ButtonSize, ButtonShape, floorFractionDigits } from '@hcengineering/ui'
import { Label, deviceOptionsStore as deviceInfo } from '@hcengineering/ui'
import DatePresenter from '@hcengineering/ui/src/components/calendar/DatePresenter.svelte'
import { activeSprint } from '../../issues'
import tracker from '../../plugin'
import { floorFractionDigits, getDayOfSprint } from '../../utils'
import { getDayOfSprint } from '../../utils'
import EstimationProgressCircle from '../issues/timereport/EstimationProgressCircle.svelte'
import SprintSelector from './SprintSelector.svelte'

Expand Down Expand Up @@ -98,7 +98,7 @@
.reduce((it, cur) => {
return it + cur
}, 0),
2
3
)
$: totalReported = floorFractionDigits(
(noParents ?? [{ reportedTime: 0, childInfo: [] } as unknown as Issue])
Expand All @@ -114,7 +114,7 @@
.reduce((it, cur) => {
return it + cur
}),
2
3
)

const sprintQuery = createQuery()
Expand Down
7 changes: 0 additions & 7 deletions plugins/tracker-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,3 @@ export async function moveIssuesToAnotherSprint (
return false
}
}

/**
* @public
*/
export const floorFractionDigits = (n: number, amount: number): number => {
return Number(n.toFixed(amount))
}