From 34c3d07e5c4ccffbffe5ebb95128734e85baac64 Mon Sep 17 00:00:00 2001 From: mrsadman99 <60566490+mrsadman99@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:50:55 +0300 Subject: [PATCH] TSK-418: Added working day option (#2393) Signed-off-by: Anton Brechka --- packages/ui/lang/en.json | 3 +- packages/ui/lang/ru.json | 3 +- .../src/components/DropdownLabelsIntl.svelte | 6 ++- packages/ui/src/components/EditBox.svelte | 3 +- packages/ui/src/plugin.ts | 3 +- plugins/tracker-assets/lang/en.json | 6 ++- plugins/tracker-assets/lang/ru.json | 6 ++- .../timereport/TimeSpendReportPopup.svelte | 5 +- .../issues/timereport/WorkDaysDropdown.svelte | 46 +++++++++++++++++++ .../issues/timereport/WorkDaysIcon.svelte | 19 ++++++++ plugins/tracker-resources/src/plugin.ts | 6 ++- plugins/tracker-resources/src/types.ts | 5 ++ plugins/tracker-resources/src/utils.ts | 35 +++++++++++++- 13 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 plugins/tracker-resources/src/components/issues/timereport/WorkDaysDropdown.svelte create mode 100644 plugins/tracker-resources/src/components/issues/timereport/WorkDaysIcon.svelte diff --git a/packages/ui/lang/en.json b/packages/ui/lang/en.json index bcdcbf5666..b7d853ffa1 100644 --- a/packages/ui/lang/en.json +++ b/packages/ui/lang/en.json @@ -39,6 +39,7 @@ "NoActionsDefined": "No actions applicable", "Incoming": "Incoming", "HoursLabel": "Hours", - "Back": "Back" + "Back": "Back", + "DropdownDefaultLabel": "Select Item" } } diff --git a/packages/ui/lang/ru.json b/packages/ui/lang/ru.json index 064351c5b6..0309f5a695 100644 --- a/packages/ui/lang/ru.json +++ b/packages/ui/lang/ru.json @@ -39,6 +39,7 @@ "NoActionsDefined": "Нет доступных действий", "Incoming": "Входящие", "HoursLabel": "Часы", - "Back": "Назад" + "Back": "Назад", + "DropdownDefaultLabel": "Выберите Элемент" } } diff --git a/packages/ui/src/components/DropdownLabelsIntl.svelte b/packages/ui/src/components/DropdownLabelsIntl.svelte index 11eba54e5e..9675aff9aa 100644 --- a/packages/ui/src/components/DropdownLabelsIntl.svelte +++ b/packages/ui/src/components/DropdownLabelsIntl.svelte @@ -22,9 +22,10 @@ import Button from './Button.svelte' import DropdownLabelsPopupIntl from './DropdownLabelsPopupIntl.svelte' import Label from './Label.svelte' + import ui from '../plugin' export let icon: Asset | AnySvelteComponent | undefined = undefined - export let label: IntlString + export let label: IntlString = ui.string.DropdownDefaultLabel export let items: DropdownIntlItem[] export let selected: DropdownIntlItem['id'] | undefined = undefined export let disabled: boolean = false @@ -33,12 +34,13 @@ export let justify: 'left' | 'center' = 'center' export let width: string | undefined = undefined export let labelDirection: TooltipAlignment | undefined = undefined + export let shouldUpdateUndefined: boolean = true let container: HTMLElement let opened: boolean = false $: selectedItem = items.find((x) => x.id === selected) - $: if (selected === undefined && items[0] !== undefined) { + $: if (shouldUpdateUndefined && selected === undefined && items[0] !== undefined) { selected = items[0].id dispatch('selected', selected) } diff --git a/packages/ui/src/components/EditBox.svelte b/packages/ui/src/components/EditBox.svelte index 87153efa25..7f5d4ae428 100644 --- a/packages/ui/src/components/EditBox.svelte +++ b/packages/ui/src/components/EditBox.svelte @@ -117,7 +117,8 @@
{ input.focus() }} diff --git a/packages/ui/src/plugin.ts b/packages/ui/src/plugin.ts index 0a749dc8f1..5edf3046c8 100644 --- a/packages/ui/src/plugin.ts +++ b/packages/ui/src/plugin.ts @@ -64,7 +64,8 @@ export const uis = plugin(uiId, { NoActionsDefined: '' as IntlString, Incoming: '' as IntlString, HoursLabel: '' as IntlString, - Back: '' as IntlString + Back: '' as IntlString, + DropdownDefaultLabel: '' as IntlString }, metadata: { DefaultApplication: '' as Metadata, diff --git a/plugins/tracker-assets/lang/en.json b/plugins/tracker-assets/lang/en.json index f71b99238e..67bc774f7d 100644 --- a/plugins/tracker-assets/lang/en.json +++ b/plugins/tracker-assets/lang/en.json @@ -245,7 +245,11 @@ "SaveProcess": "Save Process", "NoIssueTemplate": "No Process", "TemplateReplace": "You you replace applied process?", - "TemplateReplaceConfirm": "All changes to template values will be lost." + "TemplateReplaceConfirm": "All changes to template values will be lost.", + + "WorkDayCurrent": "Current Working Day", + "WorkDayPrevious": "Previous Working Day", + "WorkDayLabel": "Select Working Day Type" }, "status": {} } diff --git a/plugins/tracker-assets/lang/ru.json b/plugins/tracker-assets/lang/ru.json index c7e4022be5..069f622145 100644 --- a/plugins/tracker-assets/lang/ru.json +++ b/plugins/tracker-assets/lang/ru.json @@ -245,7 +245,11 @@ "SaveProcess": "Сохранить процесс", "NoIssueTemplate": "Без процесса", "TemplateReplace": "Вы хотите заменить выбранный процесс?", - "TemplateReplaceConfirm": "Все внесенные изменения в задачу будут потеряны" + "TemplateReplaceConfirm": "Все внесенные изменения в задачу будут потеряны", + + "WorkDayCurrent": "Текущий Рабочий День", + "WorkDayPrevious": "Предыдущий Рабочий День", + "WorkDayLabel": "Выберите Тип Рабочего Дня" }, "status": {} } diff --git a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte index 4f1ab3f713..b9ee0e8e93 100644 --- a/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte +++ b/plugins/tracker-resources/src/components/issues/timereport/TimeSpendReportPopup.svelte @@ -20,6 +20,8 @@ import { Issue, TimeSpendReport } from '@hcengineering/tracker' import { DatePresenter, EditBox } from '@hcengineering/ui' import tracker from '../../../plugin' + import { getWorkDate, WorkDaysType } from '../../../utils' + import WorkDaysDropdown from './WorkDaysDropdown.svelte' export let issueId: Ref export let issueClass: Ref> @@ -34,7 +36,7 @@ } const data = { - date: value?.date ?? Date.now(), + date: value?.date ?? getWorkDate(WorkDaysType.PREVIOUS), description: value?.description ?? '', value: value?.value, employee: value?.employee ?? assignee ?? null @@ -86,6 +88,7 @@ bind:value={data.employee} showNavigate={false} /> +
diff --git a/plugins/tracker-resources/src/components/issues/timereport/WorkDaysDropdown.svelte b/plugins/tracker-resources/src/components/issues/timereport/WorkDaysDropdown.svelte new file mode 100644 index 0000000000..1a9bb8a041 --- /dev/null +++ b/plugins/tracker-resources/src/components/issues/timereport/WorkDaysDropdown.svelte @@ -0,0 +1,46 @@ + + + + (dateTimestamp = getWorkDate(detail))} +/> diff --git a/plugins/tracker-resources/src/components/issues/timereport/WorkDaysIcon.svelte b/plugins/tracker-resources/src/components/issues/timereport/WorkDaysIcon.svelte new file mode 100644 index 0000000000..41de5e046d --- /dev/null +++ b/plugins/tracker-resources/src/components/issues/timereport/WorkDaysIcon.svelte @@ -0,0 +1,19 @@ + + + + + + + + diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index 9bd1dfbcf9..3b7eb790f0 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -261,7 +261,11 @@ export default mergeIds(trackerId, tracker, { SaveProcess: '' as IntlString, NoIssueTemplate: '' as IntlString, TemplateReplace: '' as IntlString, - TemplateReplaceConfirm: '' as IntlString + TemplateReplaceConfirm: '' as IntlString, + + WorkDayCurrent: '' as IntlString, + WorkDayPrevious: '' as IntlString, + WorkDayLabel: '' as IntlString }, component: { NopeComponent: '' as AnyComponent, diff --git a/plugins/tracker-resources/src/types.ts b/plugins/tracker-resources/src/types.ts index 32bbc72aaa..5f599a9dbf 100644 --- a/plugins/tracker-resources/src/types.ts +++ b/plugins/tracker-resources/src/types.ts @@ -104,3 +104,8 @@ export const issuesGroupBySorting: Record> = [IssuesGrouping.Sprint]: { '$lookup.sprint.label': SortingOrder.Ascending }, [IssuesGrouping.NoGrouping]: {} } + +export enum WorkDaysType { + CURRENT = 'current', + PREVIOUS = 'previous' +} diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index cda914b0ce..35d62efe96 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -33,12 +33,19 @@ import { ViewOptionModel } from '@hcengineering/view-resources' import { AnyComponent, AnySvelteComponent, + areDatesEqual, getMillisecondsInMonth, isWeekend, MILLISECONDS_IN_WEEK } from '@hcengineering/ui' import tracker from './plugin' -import { defaultPriorities, defaultProjectStatuses, defaultSprintStatuses, issuePriorities } from './types' +import { + defaultPriorities, + defaultProjectStatuses, + defaultSprintStatuses, + issuePriorities, + WorkDaysType +} from './types' export * from './types' @@ -641,3 +648,29 @@ export async function moveIssuesToAnotherSprint ( return false } } + +export function getWorkDate (type: WorkDaysType): number { + const date = new Date(Date.now()) + if (type === WorkDaysType.PREVIOUS) { + date.setDate(date.getDate() - 1) + } + + // if currentDate is day off then set date to last working day + while (isWeekend(date)) { + date.setDate(date.getDate() - 1) + } + + return date.valueOf() +} + +export function getWorkDayType (timestamp: number): WorkDaysType | undefined { + const date = new Date(timestamp) + const currentWorkDate = new Date(getWorkDate(WorkDaysType.CURRENT)) + const previousWorkDate = new Date(getWorkDate(WorkDaysType.PREVIOUS)) + + if (areDatesEqual(date, currentWorkDate)) { + return WorkDaysType.CURRENT + } else if (areDatesEqual(date, previousWorkDate)) { + return WorkDaysType.PREVIOUS + } +}