diff --git a/packages/ui/src/components/EditBox.svelte b/packages/ui/src/components/EditBox.svelte index f2f032ac6d..87153efa25 100644 --- a/packages/ui/src/components/EditBox.svelte +++ b/packages/ui/src/components/EditBox.svelte @@ -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 @@ -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 @@ -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') };` diff --git a/packages/ui/src/utils.ts b/packages/ui/src/utils.ts index 87799f46cf..522b046654 100644 --- a/packages/ui/src/utils.ts +++ b/packages/ui/src/utils.ts @@ -43,3 +43,7 @@ export function fetchMetadataLocalStorage (id: Metadata): 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)) +} diff --git a/plugins/tracker-resources/src/components/issues/timereport/EstimationPopup.svelte b/plugins/tracker-resources/src/components/issues/timereport/EstimationPopup.svelte index 5322fb5b88..b0b0c441a3 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/EstimationPopup.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/EstimationPopup.svelte @@ -108,6 +108,7 @@ {kind} placeholder={tracker.string.Estimation} focus + maxDigitsAfterPoint={3} on:keypress={_onkeypress} on:change={() => { if (typeof _value === 'number') { diff --git a/plugins/tracker-resources/src/components/issues/timereport/EstimationStatsPresenter.svelte b/plugins/tracker-resources/src/components/issues/timereport/EstimationStatsPresenter.svelte index 20524fe45c..0727f52edb 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/EstimationStatsPresenter.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/EstimationStatsPresenter.svelte @@ -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 $: 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) @@ -41,7 +40,7 @@ {#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}
0}>
diff --git a/plugins/tracker-resources/src/components/issues/timereport/ReportedTimeEditor.svelte b/plugins/tracker-resources/src/components/issues/timereport/ReportedTimeEditor.svelte index 31c475d3bc..ecee99315c 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/ReportedTimeEditor.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/ReportedTimeEditor.svelte @@ -16,8 +16,7 @@ @@ -47,7 +46,7 @@ {:else if value !== undefined} - {floorFractionDigits(value, 2)} + {floorFractionDigits(value, 3)} {#if childTime !== 0} / {childTime} {/if} diff --git a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReport.svelte b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReport.svelte index 803b52e784..23d6b63c21 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReport.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReport.svelte @@ -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 @@ -65,7 +64,7 @@ } : undefined} > - {/if} diff --git a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte index 397e3a5c54..4f1ab3f713 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte @@ -78,7 +78,7 @@ okLabel={value === undefined ? presentation.string.Create : presentation.string.Save} >
- + 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) {#if reports} diff --git a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportsList.svelte b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportsList.svelte index 0c02403e2e..b4e02b3075 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportsList.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportsList.svelte @@ -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' @@ -98,7 +104,7 @@ readonly showNavigate={false} /> - +
diff --git a/plugins/tracker-resources/src/components/sprints/SprintEditor.svelte b/plugins/tracker-resources/src/components/sprints/SprintEditor.svelte index 95ae71ff7d..734554a3d5 100644 --- a/plugins/tracker-resources/src/components/sprints/SprintEditor.svelte +++ b/plugins/tracker-resources/src/components/sprints/SprintEditor.svelte @@ -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' @@ -98,7 +98,7 @@ .reduce((it, cur) => { return it + cur }, 0), - 2 + 3 ) $: totalReported = floorFractionDigits( (noParents ?? [{ reportedTime: 0, childInfo: [] } as unknown as Issue]) @@ -114,7 +114,7 @@ .reduce((it, cur) => { return it + cur }), - 2 + 3 ) const sprintQuery = createQuery() diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index ab23c92e9a..cda914b0ce 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -641,10 +641,3 @@ export async function moveIssuesToAnotherSprint ( return false } } - -/** - * @public - */ -export const floorFractionDigits = (n: number, amount: number): number => { - return Number(n.toFixed(amount)) -}