From 60704357ec33900c76cfd4becabdbc9b0af4928a Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Mon, 3 Jul 2023 07:51:33 +0700 Subject: [PATCH 01/12] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B4=D0=B8=D0=B7=D0=B0=D0=B9=D0=BD=D0=B0=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20wishlist-=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/public/images/anchor BLUE.svg | 1 + .../issues-list-board.module.css | 38 +++++++++++++- .../issues-list-board/issues-list-board.tsx | 11 ++-- .../issues-list-card.module.css | 51 ++++++++++++++++++- .../issues-list-board/issues-list-card.tsx | 47 +++++++++++++---- .../issue-details-dialog.module.css | 4 ++ .../misc-components/issue-details-dialog.tsx | 48 ++++++++--------- frontend/src/misc-components/tags.tsx | 9 ++-- frontend/src/utils/spent-hours-to-fixed.ts | 11 ++++ 9 files changed, 178 insertions(+), 42 deletions(-) create mode 100644 frontend/public/images/anchor BLUE.svg create mode 100644 frontend/src/utils/spent-hours-to-fixed.ts diff --git a/frontend/public/images/anchor BLUE.svg b/frontend/public/images/anchor BLUE.svg new file mode 100644 index 0000000..fce474a --- /dev/null +++ b/frontend/public/images/anchor BLUE.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/src/issues-list-board/issues-list-board.module.css b/frontend/src/issues-list-board/issues-list-board.module.css index 04006f5..37718b3 100644 --- a/frontend/src/issues-list-board/issues-list-board.module.css +++ b/frontend/src/issues-list-board/issues-list-board.module.css @@ -2,5 +2,41 @@ display: flex; flex-direction: column; width: 100%; - background-color: rgb(225, 225, 225); +} + +.boardName { + display: flex; + flex-direction: row; + padding-left: 10px; + padding-right: 10px; +} + +.anchorIcon { + width: 24px; + padding-left: 30px; +} + +.boardName a { + display: flex; +} + +.board { + line-height: 30px; + + background-color: rgb(255, 255, 255); + margin: 0; + padding: 0; + color: rgba(0, 0, 0, 0.8); + font-size: 24px; + font-family: 'Inter', sans-serif; + font-style: normal; + line-height: 40px; + font-weight: 600; + font-size: 24px; + line-height: 30px; +} + +.boardHeader { + color: #202020; + font-family: 'Source Code Pro'; } \ No newline at end of file diff --git a/frontend/src/issues-list-board/issues-list-board.tsx b/frontend/src/issues-list-board/issues-list-board.tsx index 5841192..eb51b8c 100644 --- a/frontend/src/issues-list-board/issues-list-board.tsx +++ b/frontend/src/issues-list-board/issues-list-board.tsx @@ -21,11 +21,16 @@ export const IssuesListBoard = observer((props: Props): JSX.Element => { title = <>{props.store.metainfo.title}; } return ( - <> -

{title} #

+
+
+

{title}

+ + anchor + +
{list}
- +
); }); \ No newline at end of file diff --git a/frontend/src/issues-list-board/issues-list-card.module.css b/frontend/src/issues-list-board/issues-list-card.module.css index 8a8963f..cda112d 100644 --- a/frontend/src/issues-list-board/issues-list-card.module.css +++ b/frontend/src/issues-list-board/issues-list-card.module.css @@ -5,7 +5,56 @@ flex-direction: column; } -.issueSubject {} +.relevanceColor { + width: 30px; +} + +.todoBlock { + display: flex; + flex-direction: row; + padding-left: 10px; + padding-right: 10px; +} + +.todoBlock:hover { + background-color: rgba(0, 0, 0, 0.1); +} + +.importantInformation { + width: 100%; +} + +.timeBox { + color: #393838; + font-weight: 400; + font-size: 11px; +} + +.positionInfo { + list-style-image: relative; + bottom: 3px; + right: 3px; + text-align: right; + float: right; +} + +.priorityBox { + background-color: #FFFFFF; + border-radius: 2px; + padding: 2px 2px 3px 2px; + font-size: 10px; + line-height: 12px; + /* border: 0.5px solid #393838; */ + color: #ffffff; +} + +.issueSubject { + color: #202020; + text-decoration: none; + font-weight: 400; + font-size: 15px; + line-height: 18px; +} .issueStatus {} diff --git a/frontend/src/issues-list-board/issues-list-card.tsx b/frontend/src/issues-list-board/issues-list-card.tsx index fd05210..a64350b 100644 --- a/frontend/src/issues-list-board/issues-list-card.tsx +++ b/frontend/src/issues-list-board/issues-list-card.tsx @@ -7,6 +7,7 @@ import * as TagsNs from '../misc-components/tags'; import * as IssueHrefNs from '../misc-components/issue-href'; import * as IssueDetailsDialogNs from '../misc-components/issue-details-dialog'; import * as UnreadedFlagNs from '../misc-components/unreaded-flag'; +import { SpentHoursToFixed } from '../utils/spent-hours-to-fixed'; export type Props = { store: IIssueStore @@ -19,12 +20,35 @@ export const IssuesListCard = observer((props: Props): JSX.Element => { visible: false, unreadedFlagStore: unreadedStore }); + // return ( + //
{e.stopPropagation(); detailsStore.show();}}> + // + //
+ // + // + // + // + // + // | {props.store.status.name} + // | {props.store.total_spent_hours} / {props.store.total_estimated_hours} + //
+ //
+ // + //
+ //
+ // ); return ( -
{e.stopPropagation(); detailsStore.show();}}> - -
- - +
{ e.stopPropagation(); detailsStore.show(); }}> + +
+ +
+
{ id={props.store.id} /> - | {props.store.status.name} - | {props.store.total_spent_hours} / {props.store.total_estimated_hours} -
-
- + + {SpentHoursToFixed(props.store.total_spent_hours)} / {SpentHoursToFixed(props.store.total_estimated_hours)} + {(props.store.styledTags && props.store.styledTags.hasOwnProperties()) ?
: null} + +
+ {props.store.status.name} + {props.store.priority.name} +
); diff --git a/frontend/src/misc-components/issue-details-dialog.module.css b/frontend/src/misc-components/issue-details-dialog.module.css index 2f24e96..3882587 100644 --- a/frontend/src/misc-components/issue-details-dialog.module.css +++ b/frontend/src/misc-components/issue-details-dialog.module.css @@ -1,3 +1,7 @@ +.reset { + all: initial; +} + .modal { z-index: 1000; position: fixed; diff --git a/frontend/src/misc-components/issue-details-dialog.tsx b/frontend/src/misc-components/issue-details-dialog.tsx index e30cecd..9e8a7a5 100644 --- a/frontend/src/misc-components/issue-details-dialog.tsx +++ b/frontend/src/misc-components/issue-details-dialog.tsx @@ -52,29 +52,31 @@ export const IssueDetailsDialog = observer((props: Props): JSX.Element => { props.store.hide(); }; return ( -
-
-

- - - -

-
-
-

Описание:

-
-						{props.store.issue.description}
-					
-
-
-
-

Комментарии:

- +
+
+
+

+ + + +

+
+
+

Описание:

+
+							{props.store.issue.description}
+						
+
+
+
+

Комментарии:

+ +
diff --git a/frontend/src/misc-components/tags.tsx b/frontend/src/misc-components/tags.tsx index 8852a1d..ae749ab 100644 --- a/frontend/src/misc-components/tags.tsx +++ b/frontend/src/misc-components/tags.tsx @@ -14,13 +14,14 @@ export const Tags = (props: Props): JSX.Element => { if (!props.params.tags) { return (<>); } - const label = props.params.label || 'Tags'; + let label = props.params.label || ''; + if (label) label = `${label}: `; const tags = props.params.tags.map((tag) => { return ; }) || []; return ( -
- {label}: {tags} -
+ <> + {label}{tags} + ); } \ No newline at end of file diff --git a/frontend/src/utils/spent-hours-to-fixed.ts b/frontend/src/utils/spent-hours-to-fixed.ts new file mode 100644 index 0000000..a7e8045 --- /dev/null +++ b/frontend/src/utils/spent-hours-to-fixed.ts @@ -0,0 +1,11 @@ +/** + * Форматирование чисел для вывода трудозатрат + * @param a + * @returns + */ +export const SpentHoursToFixed = (a: number|string|null|undefined): string => { + if (a === null || typeof a === 'undefined') return '-'; + const res = (typeof a === 'number') ? a : Number(a); + if (!Number.isFinite(res)) return '-'; + return `${parseFloat(res.toFixed(1))}`; +}; \ No newline at end of file From b9899bc032ff635f6dae85d3b6624c4a2cf26d24 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Mon, 3 Jul 2023 08:06:01 +0700 Subject: [PATCH 02/12] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D0=BA=D0=B0=20=D0=B2=20react=20=D0=BF=D1=80=D0=B8=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BF=D1=80=D0=BE=D1=84?= =?UTF-8?q?=D0=B8=D0=BB=D0=B5=D0=B9=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=B0=D0=BA=D1=88=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - для разработки включен hotreload - на бакенде включен CORS --- frontend/.env.development | 1 + frontend/.env.production | 1 + frontend/src/issues-list-board/store.ts | 2 +- frontend/src/kanban-board/kanban-boards.tsx | 2 +- frontend/src/kanban-board/store.ts | 2 +- frontend/src/misc-components/issue-details-dialog.tsx | 2 +- frontend/src/utils/service-actions.ts | 2 +- src/main.ts | 2 ++ 8 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 frontend/.env.development create mode 100644 frontend/.env.production diff --git a/frontend/.env.development b/frontend/.env.development new file mode 100644 index 0000000..9ac4f5e --- /dev/null +++ b/frontend/.env.development @@ -0,0 +1 @@ +REACT_APP_BACKEND=http://localhost:3001/ \ No newline at end of file diff --git a/frontend/.env.production b/frontend/.env.production new file mode 100644 index 0000000..e12c5b1 --- /dev/null +++ b/frontend/.env.production @@ -0,0 +1 @@ +REACT_APP_BACKEND=/ \ No newline at end of file diff --git a/frontend/src/issues-list-board/store.ts b/frontend/src/issues-list-board/store.ts index 8353f42..2442ebf 100644 --- a/frontend/src/issues-list-board/store.ts +++ b/frontend/src/issues-list-board/store.ts @@ -61,7 +61,7 @@ export const PageStore = types.model({ }); export async function PageStoreLoadData(store: IPageStore): Promise { - const url = `/simple-kanban-board/${store.type}/${store.name}/raw`; + const url = `${process.env.REACT_APP_BACKEND}simple-kanban-board/${store.type}/${store.name}/raw`; const resp = await axios.get(url); if (!(resp?.data)) return; diff --git a/frontend/src/kanban-board/kanban-boards.tsx b/frontend/src/kanban-board/kanban-boards.tsx index aa2448b..b019b0f 100644 --- a/frontend/src/kanban-board/kanban-boards.tsx +++ b/frontend/src/kanban-board/kanban-boards.tsx @@ -34,7 +34,7 @@ export const KanbanBoards = observer((props: Props) => { const onTreeRefreshClick = (e: React.MouseEvent) => { if (e.target !== e.currentTarget) return; e.stopPropagation(); - axios.get(`/simple-kanban-board/tree/${props.store.name}/refresh`); + axios.get(`${process.env.REACT_APP_BACKEND}simple-kanban-board/tree/${props.store.name}/refresh`); } treeRefreshMenuItem = ; } diff --git a/frontend/src/kanban-board/store.ts b/frontend/src/kanban-board/store.ts index 2152511..1a16812 100644 --- a/frontend/src/kanban-board/store.ts +++ b/frontend/src/kanban-board/store.ts @@ -86,7 +86,7 @@ export const PageStore = types.model({ }); export async function PageStoreLoadData(store: IPageStore): Promise { - const url = `/simple-kanban-board/${store.type}/${store.name}/raw`; + const url = `${process.env.REACT_APP_BACKEND}simple-kanban-board/${store.type}/${store.name}/raw`; const resp = await axios.get(url); if (!(resp?.data)) return; store.setData(resp.data); diff --git a/frontend/src/misc-components/issue-details-dialog.tsx b/frontend/src/misc-components/issue-details-dialog.tsx index e30cecd..3a95e10 100644 --- a/frontend/src/misc-components/issue-details-dialog.tsx +++ b/frontend/src/misc-components/issue-details-dialog.tsx @@ -43,7 +43,7 @@ export type Props = { export const IssueDetailsDialog = observer((props: Props): JSX.Element => { const onUpdateClick = (e: React.MouseEvent) => { - const url = `/redmine-event-emitter/append-issues`; + const url = `${process.env.REACT_APP_BACKEND}redmine-event-emitter/append-issues`; axios.post(url, [props.store.issue.id]); }; const onCloseClick = (e: React.MouseEvent) => { diff --git a/frontend/src/utils/service-actions.ts b/frontend/src/utils/service-actions.ts index 0fb2a32..0c2f950 100644 --- a/frontend/src/utils/service-actions.ts +++ b/frontend/src/utils/service-actions.ts @@ -14,7 +14,7 @@ export const onIssuesRefreshClick = (e: React.MouseEvent) => { export const onGetIssuesQueueSizeClick = async (e: React.MouseEvent): Promise => { if (e.target !== e.currentTarget) return; e.stopPropagation(); - const resp = await axios.get(`/redmine-event-emitter/get-issues-queue-size`); + const resp = await axios.get(`${process.env.REACT_APP_BACKEND}redmine-event-emitter/get-issues-queue-size`); console.debug(`resp -`, resp); // DEBUG if (!resp || typeof resp.data !== 'number') return; alert(`Issues queue size - ${resp.data}`); diff --git a/src/main.ts b/src/main.ts index 18ef801..f47265e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,8 @@ async function bootstrap() { logger: ['debug', 'error', 'warn', 'log', 'verbose'], }); + app.enableCors(); + app.setBaseViewsDir(join(__dirname, '..', 'views')); app.setViewEngine('hbs'); From ac14a4ebdcc105f195373dfd8d48f2d3e259dfde Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Mon, 3 Jul 2023 13:17:12 +0700 Subject: [PATCH 03/12] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=81=D1=82=D0=B8=D0=BB=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=B0=20=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B2?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/misc-components/time-passed.module.css | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/src/misc-components/time-passed.module.css b/frontend/src/misc-components/time-passed.module.css index c34f6ba..55ffeb7 100644 --- a/frontend/src/misc-components/time-passed.module.css +++ b/frontend/src/misc-components/time-passed.module.css @@ -1,27 +1,27 @@ .timepassedDot { - height: 10px; - width: 10px; - background-color: #bbb; + height: 15px; + width: 15px; + background-color: #808080; border-radius: 50%; display: inline-block; } .timepassedDot.hot { - background-color: red; + background-color: #DB2228; } .timepassedDot.warm { - background-color: orange; + background-color: #FA5E26; } .timepassedDot.comfort { - background-color: rgba(255, 255, 0, 0.4); + background-color: #FDAF19; } .timepassedDot.breezy { - background-color: rgba(0, 255, 0, 0.4); + background-color: #117722; } .timepassedDot.cold { - background-color: rgba(0, 0, 255, 0.1); + background-color: #7f97ad; } \ No newline at end of file From 00f7e6eea319e5941f33898aa162d25fefb3a8b7 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Mon, 3 Jul 2023 13:17:44 +0700 Subject: [PATCH 04/12] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=20=D1=82=D0=B5=D0=B3=D0=BE=D0=B2=20=D0=B2=20=D0=BE=D1=82=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/issues-list-board/issues-list-card.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/issues-list-board/issues-list-card.tsx b/frontend/src/issues-list-board/issues-list-card.tsx index a64350b..c9d5ad7 100644 --- a/frontend/src/issues-list-board/issues-list-card.tsx +++ b/frontend/src/issues-list-board/issues-list-card.tsx @@ -42,6 +42,7 @@ export const IssuesListCard = observer((props: Props): JSX.Element => { //
//
// ); + const tagsNewLine = (props.store.styledTags && props.store.styledTags.length > 0) ?
: null; return (
{ e.stopPropagation(); detailsStore.show(); }}> @@ -59,7 +60,7 @@ export const IssuesListCard = observer((props: Props): JSX.Element => { {SpentHoursToFixed(props.store.total_spent_hours)} / {SpentHoursToFixed(props.store.total_estimated_hours)} - {(props.store.styledTags && props.store.styledTags.hasOwnProperties()) ?
: null} + {tagsNewLine}
{props.store.status.name} From ed451557f2873a894295856e5b98da7fad0bb846 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Mon, 3 Jul 2023 13:19:07 +0700 Subject: [PATCH 05/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=B8=D0=BB=D0=B5=D0=B9=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BE=D1=80=D0=B8=D1=82=D0=B5=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=20=D0=B8=D0=B7=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=20=D0=B4=D0=BE=D1=81=D0=BA=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D1=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../priority-styles-enhancer.ts | 102 ++++++++++++++++++ .../list-issues-by-fields.widget.service.ts | 2 + ...ssues-by-users-like-jira.widget.service.ts | 2 + .../list-issues-by-users.widget.service.ts | 2 + .../root-issue-subtrees.widget.service.ts | 2 + .../widgets/issues-by-tags.widget.service.ts | 2 + 6 files changed, 112 insertions(+) create mode 100644 libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts diff --git a/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts b/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts new file mode 100644 index 0000000..6da3687 --- /dev/null +++ b/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts @@ -0,0 +1,102 @@ +import { Injectable } from '@nestjs/common'; +import { RedmineTypes } from '../models/redmine-types'; +import { IssueEnhancerInterface } from './issue-enhancer-interface'; + +export type StyleRule = { + default?: boolean; + priorityName?: string; + style?: string; + className?: string; +}; + +export const defaultRule: StyleRule = { + default: true, + style: 'background-color: gray; color: white;', +}; + +export const defaultKey = 'priorityStyle'; + +export function ValidateStyleRule(rule: StyleRule): boolean { + return ( + // check default prop + (typeof rule.default === 'boolean' || + typeof rule.default === 'undefined') && + // check priority name prop + (rule.default || + (!rule.default && + typeof rule.priorityName === 'string' && + rule.priorityName.length > 0)) && + // check style or className props + ((typeof rule.style === 'string' && rule.style.length > 0) || + (typeof rule.className === 'string' && rule.className.length > 0)) + ); +} + +export function HasDefaultRule(rules: StyleRule[]): boolean { + const hasDefaultRule = rules.find((rule) => rule.default); + return Boolean(hasDefaultRule); +} + +@Injectable() +export class PriorityStylesEnhancer implements IssueEnhancerInterface { + name: string; + + private rules: StyleRule[]; + + private targetKey: string; + + constructor(rules?: StyleRule[], targetKey?: string) { + let validatedRules: StyleRule[] = []; + if (rules && rules.length > 0) { + validatedRules = rules.filter(ValidateStyleRule); + } + if (!HasDefaultRule(validatedRules)) { + validatedRules.push(defaultRule); + } + this.rules = validatedRules; + + this.targetKey = + typeof targetKey === 'string' && targetKey.length > 0 + ? targetKey + : defaultKey; + } + + async enhance( + issue: RedmineTypes.ExtendedIssue, + ): Promise { + const priorityName = issue.priority.name; + const priorityRule = this.findPriorityRule(priorityName); + issue[this.targetKey] = priorityRule.style || priorityRule.className; + return issue; + } + + private findPriorityRule(priority: string): StyleRule { + return (this.rules.find((r) => r.priorityName === priority) || + this.rules.find((r) => r.default)) as StyleRule; + } +} + +export type PrioritiesStyleParams = { + rules: StyleRule[]; + targetKey: string; +}; + +export type ConfigWithPriorityStyles = { + priorities?: PrioritiesStyleParams; + [key: string]: any; +}; + +export function CreatePriorityStylesEnhancer( + cfg: ConfigWithPriorityStyles, +): PriorityStylesEnhancer { + let params: PrioritiesStyleParams; + if (cfg.priorities && cfg.priorities.rules && cfg.priorities.targetKey) { + params = cfg.priorities; + } else { + params = { + rules: [defaultRule], + targetKey: defaultKey, + }; + } + return new PriorityStylesEnhancer(params.rules, params.targetKey); +} diff --git a/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-fields.widget.service.ts b/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-fields.widget.service.ts index 59d3792..3716036 100644 --- a/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-fields.widget.service.ts +++ b/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-fields.widget.service.ts @@ -13,6 +13,7 @@ import { TreeIssuesStore } from '@app/event-emitter/utils/tree-issues-store'; import { Injectable, Logger } from '@nestjs/common'; import nano from 'nano'; import { WidgetInterface } from '../widget-interface'; +import * as PriorityStylesEnhancerNs from '@app/event-emitter/issue-enhancers/priority-styles-enhancer'; export namespace ListIssuesByFieldsWidgetNs { export type Params = { @@ -66,6 +67,7 @@ export class ListIssuesByFieldsWidgetService this.timePassedHighlightEnhancer, this.issueUrlEnhancer, TagStyledEnhancerNs.CreateTagStyledEnhancerForConfig(widgetParams), + PriorityStylesEnhancerNs.CreatePriorityStylesEnhancer(widgetParams), ]); const grouped = store.groupByStatusWithExtra((issue) => { return this.getGroupFromIssue(issue, widgetParams); diff --git a/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users-like-jira.widget.service.ts b/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users-like-jira.widget.service.ts index 173f447..d31eb6e 100644 --- a/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users-like-jira.widget.service.ts +++ b/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users-like-jira.widget.service.ts @@ -12,6 +12,7 @@ import { TreeIssuesStore } from '@app/event-emitter/utils/tree-issues-store'; import { Injectable, Logger } from '@nestjs/common'; import nano from 'nano'; import { WidgetInterface } from '../widget-interface'; +import * as PriorityStylesEnhancerNs from '@app/event-emitter/issue-enhancers/priority-styles-enhancer'; export namespace ListIssuesByUsersLikeJiraWidgetNs { export namespace Models { @@ -61,6 +62,7 @@ export class ListIssuesByUsersLikeJiraWidgetService this.timePassedHighlightEnhancer, this.issueUrlEnhancer, TagStyledEnhancerNs.CreateTagStyledEnhancerForConfig(widgetParams), + PriorityStylesEnhancerNs.CreatePriorityStylesEnhancer(widgetParams), ]); const grouped = store.groupByStatusWithExtraToMultipleStories((issue) => { const users = [] as string[]; diff --git a/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users.widget.service.ts b/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users.widget.service.ts index 9d3fefe..4ba3cbd 100644 --- a/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users.widget.service.ts +++ b/libs/event-emitter/src/project-dashboard/widgets/list-issues-by-users.widget.service.ts @@ -13,6 +13,7 @@ import { TreeIssuesStore } from '@app/event-emitter/utils/tree-issues-store'; import { Injectable, Logger } from '@nestjs/common'; import nano from 'nano'; import { WidgetInterface } from '../widget-interface'; +import * as PriorityStylesEnhancerNs from '@app/event-emitter/issue-enhancers/priority-styles-enhancer'; export namespace ListIssuesByUsersWidgetNs { export namespace Models { @@ -73,6 +74,7 @@ export class ListIssuesByUsersWidgetService this.timePassedHighlightEnhancer, this.issueUrlEnhancer, TagStyledEnhancerNs.CreateTagStyledEnhancerForConfig(widgetParams), + PriorityStylesEnhancerNs.CreatePriorityStylesEnhancer(widgetParams), ]); const grouped = store.groupByStatusWithExtra((issue) => { const res = this.getUserValueByKey(issue, widgetParams.userKey); diff --git a/libs/event-emitter/src/project-dashboard/widgets/root-issue-subtrees.widget.service.ts b/libs/event-emitter/src/project-dashboard/widgets/root-issue-subtrees.widget.service.ts index a28f7ac..94b7974 100644 --- a/libs/event-emitter/src/project-dashboard/widgets/root-issue-subtrees.widget.service.ts +++ b/libs/event-emitter/src/project-dashboard/widgets/root-issue-subtrees.widget.service.ts @@ -12,6 +12,7 @@ import { } from '@app/event-emitter/utils/tree-issues-store'; import { Injectable } from '@nestjs/common'; import { WidgetInterface } from '../widget-interface'; +import * as PriorityStylesEnhancerNs from '@app/event-emitter/issue-enhancers/priority-styles-enhancer'; export namespace RootIssueSubTreesWidgetNs { export namespace Models { @@ -66,6 +67,7 @@ export class RootIssueSubTreesWidgetService this.timePassedHighlightEnhancer, this.issueUrlEnhancer, TagStyledEnhancerNs.CreateTagStyledEnhancerForConfig(widgetParams), + PriorityStylesEnhancerNs.CreatePriorityStylesEnhancer(widgetParams), ]); let stories: TreeIssuesStoreNs.Models.GetFlatStories.Result; if (widgetParams.parentsAsGroups) { diff --git a/src/dashboards/widgets/issues-by-tags.widget.service.ts b/src/dashboards/widgets/issues-by-tags.widget.service.ts index c199eb1..13e2e9c 100644 --- a/src/dashboards/widgets/issues-by-tags.widget.service.ts +++ b/src/dashboards/widgets/issues-by-tags.widget.service.ts @@ -12,6 +12,7 @@ import { GetValueFromObjectByKey } from '@app/event-emitter/utils/get-value-from import { TreeIssuesStore } from '@app/event-emitter/utils/tree-issues-store'; import { Injectable, Logger } from '@nestjs/common'; import nano from 'nano'; +import * as PriorityStylesEnhancerNs from '@app/event-emitter/issue-enhancers/priority-styles-enhancer'; export namespace IssuesByTagsWidgetNs { export type Params = { @@ -59,6 +60,7 @@ export class IssuesByTagsWidgetService this.timePassedHighlightEnhancer, this.issueUrlEnhancer, TagStyledEnhancerNs.CreateTagStyledEnhancerForConfig(widgetParams), + PriorityStylesEnhancerNs.CreatePriorityStylesEnhancer(widgetParams), ]); const grouped = store.groupByStatusWithExtraToMultipleStories((issue) => { if (!issue || !widgetParams.tags || !widgetParams.tags.tagsKeyName) { From 62cb7d15ed614dc94e089c225036d2d4d10d5eb7 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Mon, 3 Jul 2023 23:09:45 +0700 Subject: [PATCH 06/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=81=D1=82=D0=B8=D0=BB=D1=8C=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D1=80=D0=B8=D1=82=D0=B5=D1=82=D0=B0=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D1=87=D0=BA=D1=83=20=D0=B2=20?= =?UTF-8?q?Wishlist-=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../issues-list-board/issues-list-card.tsx | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/frontend/src/issues-list-board/issues-list-card.tsx b/frontend/src/issues-list-board/issues-list-card.tsx index c9d5ad7..242546d 100644 --- a/frontend/src/issues-list-board/issues-list-card.tsx +++ b/frontend/src/issues-list-board/issues-list-card.tsx @@ -8,11 +8,14 @@ import * as IssueHrefNs from '../misc-components/issue-href'; import * as IssueDetailsDialogNs from '../misc-components/issue-details-dialog'; import * as UnreadedFlagNs from '../misc-components/unreaded-flag'; import { SpentHoursToFixed } from '../utils/spent-hours-to-fixed'; +import { getStyleObjectFromString } from '../utils/style'; export type Props = { store: IIssueStore }; +export const defaultPriorityStyleKey = 'priorityStyle'; + export const IssuesListCard = observer((props: Props): JSX.Element => { const unreadedStore = UnreadedFlagNs.CreateStoreFromLocalStorage(props.store); const detailsStore = IssueDetailsDialogNs.Store.create({ @@ -20,28 +23,7 @@ export const IssuesListCard = observer((props: Props): JSX.Element => { visible: false, unreadedFlagStore: unreadedStore }); - // return ( - //
{e.stopPropagation(); detailsStore.show();}}> - // - //
- // - // - // - // - // - // | {props.store.status.name} - // | {props.store.total_spent_hours} / {props.store.total_estimated_hours} - //
- //
- // - //
- //
- // ); + const priorityStyle = getStyleObjectFromString(props.store[defaultPriorityStyleKey]); const tagsNewLine = (props.store.styledTags && props.store.styledTags.length > 0) ?
: null; return (
{ e.stopPropagation(); detailsStore.show(); }}> @@ -63,8 +45,8 @@ export const IssuesListCard = observer((props: Props): JSX.Element => { {tagsNewLine}
- {props.store.status.name} - {props.store.priority.name} + {props.store.status.name} + {props.store.priority.name}
From 37cab4b491fe3e0b9cba356cdaf76020a7b0bf82 Mon Sep 17 00:00:00 2001 From: Gnedov Pavel Date: Fri, 7 Jul 2023 11:21:09 +0700 Subject: [PATCH 07/12] =?UTF-8?q?=D0=A6=D0=B2=D0=B5=D1=82=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=80=D0=B0=D1=81=D1=82=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/misc-components/time-passed.module.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/misc-components/time-passed.module.css b/frontend/src/misc-components/time-passed.module.css index 55ffeb7..59cb373 100644 --- a/frontend/src/misc-components/time-passed.module.css +++ b/frontend/src/misc-components/time-passed.module.css @@ -7,7 +7,7 @@ } .timepassedDot.hot { - background-color: #DB2228; + background-color: #92201A; } .timepassedDot.warm { @@ -15,7 +15,7 @@ } .timepassedDot.comfort { - background-color: #FDAF19; + background-color: #FAD116; } .timepassedDot.breezy { @@ -23,5 +23,5 @@ } .timepassedDot.cold { - background-color: #7f97ad; + background-color: #808080; } \ No newline at end of file From a0e183075fef8016fe0fe58baab89befe17312d9 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Sat, 24 Jun 2023 17:55:20 +0700 Subject: [PATCH 08/12] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/interview-projects.jsonc | 6 +++ configs/interview-projects.jsonc.dist | 4 ++ src/issue-enhancers/interview-enhancer.ts | 59 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 configs/interview-projects.jsonc create mode 100644 configs/interview-projects.jsonc.dist create mode 100644 src/issue-enhancers/interview-enhancer.ts diff --git a/configs/interview-projects.jsonc b/configs/interview-projects.jsonc new file mode 100644 index 0000000..2b2925b --- /dev/null +++ b/configs/interview-projects.jsonc @@ -0,0 +1,6 @@ +{ + "interviewProjects": [ + "Программисты, инженеры HW" + ], + "customFieldDateFormat": "yyyy-MM-dd HH:mm" +} \ No newline at end of file diff --git a/configs/interview-projects.jsonc.dist b/configs/interview-projects.jsonc.dist new file mode 100644 index 0000000..9f49eb9 --- /dev/null +++ b/configs/interview-projects.jsonc.dist @@ -0,0 +1,4 @@ +{ + "interviewProjects": [], + "customFieldDateFormat": "yyyy-MM-dd HH:mm" +} \ No newline at end of file diff --git a/src/issue-enhancers/interview-enhancer.ts b/src/issue-enhancers/interview-enhancer.ts new file mode 100644 index 0000000..06e11c1 --- /dev/null +++ b/src/issue-enhancers/interview-enhancer.ts @@ -0,0 +1,59 @@ +import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface'; +import { RedmineTypes } from '@app/event-emitter/models/redmine-types'; +import { Injectable } from '@nestjs/common'; +import * as Luxon from 'luxon'; + +export type SubjectParserParam = { + regexp: string; + format: string; + type: string; +}; + +export type DescriptionParserParam = {}; + +@Injectable() +export class InterviewEnhancer implements IssueEnhancerInterface { + name = 'interview'; + + constructor( + public interviewProjects: string[] = [], + public customFieldDateFormat: string = 'yyyy-MM-dd HH:mm', + public subjectParserParams: SubjectParserParam[] + ) {} + + async enhance( + issue: RedmineTypes.Issue, + ): Promise> { + const res: RedmineTypes.ExtendedIssue = { ...issue }; + + if (this.interviewProjects.indexOf(res.project.name) < 0) { + return res; + } + + const subject = res.subject; + const nextEventDateField = res.custom_fields.find((cf) => { + return cf.name === 'Дата следующего обновления'; + }); + + if () + + const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat); + + return res; + } + + private getNextEventDate(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null { + const nextEventDateField = issue.custom_fields.find((cf) => { + return cf.name === 'Дата следующего обновления'; + }); + if (!nextEventDateField) return null; + const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat); + if (!nextEventDate.isValid) return null; + return nextEventDate; + } + + private getDateFromSubject(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null { + const subject = issue.subject; + return null; + } +} From 61371282b1a0e99a477bcc303d0afcaef8c52cf6 Mon Sep 17 00:00:00 2001 From: Pavel Gnedov Date: Wed, 23 Aug 2023 02:02:52 +0700 Subject: [PATCH 09/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + configs/calendar-enhancer.jsonc.dist | 17 ++ configs/interview-projects.jsonc | 6 - configs/interview-projects.jsonc.dist | 4 - .../event-emitter/src/event-emitter.module.ts | 19 ++ .../src/issue-enhancers/calendar-enhancer.ts | 164 ++++++++++++++++++ .../src/models/calendar-event.ts | 8 + .../src/utils/string-with-dates-parser.ts | 138 +++++++++++++++ package-lock.json | 24 +++ package.json | 2 + src/app.module.ts | 5 + src/configs/app.ts | 3 + src/configs/calendar-enhancer.config.ts | 23 +++ src/issue-enhancers/interview-enhancer.ts | 59 ------- src/models/app-config.model.ts | 2 +- 15 files changed, 405 insertions(+), 70 deletions(-) create mode 100644 configs/calendar-enhancer.jsonc.dist delete mode 100644 configs/interview-projects.jsonc delete mode 100644 configs/interview-projects.jsonc.dist create mode 100644 libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts create mode 100644 libs/event-emitter/src/models/calendar-event.ts create mode 100644 libs/event-emitter/src/utils/string-with-dates-parser.ts create mode 100644 src/configs/calendar-enhancer.config.ts delete mode 100644 src/issue-enhancers/interview-enhancer.ts diff --git a/.gitignore b/.gitignore index 43607ab..d0f42bc 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ configs/eccm-config.jsonc configs/current-user-rules.jsonc configs/simple-kanban-board-config.jsonc configs/kanban-boards/ +configs/calendar-enhancer.jsonc diff --git a/configs/calendar-enhancer.jsonc.dist b/configs/calendar-enhancer.jsonc.dist new file mode 100644 index 0000000..72f9c8c --- /dev/null +++ b/configs/calendar-enhancer.jsonc.dist @@ -0,0 +1,17 @@ +{ + "useForProjects": [ + "*" // '*' - все, или перечислить отдельные проекты + ], + "customFields": [ + { + "dateFormat": "yyyy-MM-dd HH:mm", + "customFieldName": "Custom field name", + "alias": "" + } + ], + "descriptionCalendarParams": { + "title": "Calendar:", + "lineRegexp": "(?<=\\*\\ ).+" + }, + "calendarEventsKey": "calendar" +} diff --git a/configs/interview-projects.jsonc b/configs/interview-projects.jsonc deleted file mode 100644 index 2b2925b..0000000 --- a/configs/interview-projects.jsonc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "interviewProjects": [ - "Программисты, инженеры HW" - ], - "customFieldDateFormat": "yyyy-MM-dd HH:mm" -} \ No newline at end of file diff --git a/configs/interview-projects.jsonc.dist b/configs/interview-projects.jsonc.dist deleted file mode 100644 index 9f49eb9..0000000 --- a/configs/interview-projects.jsonc.dist +++ /dev/null @@ -1,4 +0,0 @@ -{ - "interviewProjects": [], - "customFieldDateFormat": "yyyy-MM-dd HH:mm" -} \ No newline at end of file diff --git a/libs/event-emitter/src/event-emitter.module.ts b/libs/event-emitter/src/event-emitter.module.ts index 679e6a3..d24ab6a 100644 --- a/libs/event-emitter/src/event-emitter.module.ts +++ b/libs/event-emitter/src/event-emitter.module.ts @@ -28,6 +28,7 @@ import { ListIssuesByUsersLikeJiraWidgetService } from './project-dashboard/widg import { TimePassedHighlightEnhancer } from './issue-enhancers/time-passed-highlight-enhancer'; import { ListIssuesByFieldsWidgetService } from './project-dashboard/widgets/list-issues-by-fields.widget.service'; import { IssuesUpdaterService } from './issues-updater/issues-updater.service'; +import { CalendarEnhancer } from './issue-enhancers/calendar-enhancer'; @Module({}) export class EventEmitterModule implements OnModuleInit { @@ -68,6 +69,20 @@ export class EventEmitterModule implements OnModuleInit { }, inject: [ConfigService], }, + { + provide: 'CALENDAR_ENHANCER', + useFactory: (configService: ConfigService) => { + const calendarEnhancerConfig = + configService.get>('calendarEnhancer'); + return new CalendarEnhancer( + calendarEnhancerConfig.useForProjects, + calendarEnhancerConfig.customFields, + calendarEnhancerConfig.descriptionCalendarParams, + calendarEnhancerConfig.calendarEventsKey, + ); + }, + inject: [ConfigService], + }, ], exports: [ EventEmitterService, @@ -95,6 +110,10 @@ export class EventEmitterModule implements OnModuleInit { provide: 'ISSUES_UPDATER_SERVICE', useExisting: 'ISSUES_UPDATER_SERVICE', }, + { + provide: 'CALENDAR_ENHANCER', + useExisting: 'CALENDAR_ENHANCER', + }, ], controllers: [MainController, UsersController, IssuesController], }; diff --git a/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts b/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts new file mode 100644 index 0000000..5bc8c55 --- /dev/null +++ b/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts @@ -0,0 +1,164 @@ +import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface'; +import { RedmineTypes } from '@app/event-emitter/models/redmine-types'; +import { Injectable } from '@nestjs/common'; +import * as Luxon from 'luxon'; +import { CalendarEvent } from '../models/calendar-event'; +import * as DatesParser from '../utils/string-with-dates-parser'; + +export type DescriptionParserParams = { + title: string; + lineRegexp: string; +}; + +export type CustomFieldParserParams = { + dateFormat: string; + customFieldName: string; + /** Время в минутах */ + interval?: number; + fullDay?: boolean; + alias?: string; +}; + +export const UNKNOWN_CALENDAR_EVENT = 'Unknown calendar event'; + +@Injectable() +export class CalendarEnhancer implements IssueEnhancerInterface { + name = 'calendar'; + + constructor( + public useForProjects: string[], + public customFields: CustomFieldParserParams[], + public descriptionCalendarParams: DescriptionParserParams, + public calendarEventsKey: string, + ) {} + + async enhance( + issue: RedmineTypes.ExtendedIssue, + ): Promise { + const res: RedmineTypes.ExtendedIssue = { ...issue }; + + if (!this.checkProject(issue)) return res; + + issue[this.calendarEventsKey] = this.getCalendarEvents(issue); + + return res; + } + + private checkProject(issue: RedmineTypes.ExtendedIssue): boolean { + if (this.useForProjects.indexOf('*') >= 0) { + return true; + } + if ( + this.useForProjects.length > 0 && + this.useForProjects.indexOf(issue.project.name) >= 0 + ) { + return true; + } + return false; + } + + private getCalendarEvents( + issue: RedmineTypes.ExtendedIssue, + ): CalendarEvent[] { + return [ + ...this.getCalendarEventsFromCustomFields(issue), + ...this.getCalendarEventsFromSubject(issue), + ...this.getCalendarEventsFromDescription(issue), + ]; + } + + private getCalendarEventsFromCustomFields( + issue: RedmineTypes.ExtendedIssue, + ): CalendarEvent[] { + const res: CalendarEvent[] = []; + for (let i = 0; i < this.customFields.length; i++) { + const cfParam = this.customFields[i]; + const event = this.getCalendarEventFromCustomField(issue, cfParam); + if (event) res.push(event); + } + return res; + } + + private getCalendarEventFromCustomField( + issue: RedmineTypes.ExtendedIssue, + params: CustomFieldParserParams, + ): CalendarEvent | null { + if (typeof params.interval !== 'number' && params.fullDay !== true) + return null; + + const cf = issue.custom_fields.find((issueCf) => { + return issueCf.name === params.customFieldName; + }); + if (!cf) return null; + + const from = Luxon.DateTime.fromFormat(cf.value, params.dateFormat); + if (!from.isValid) return null; + + let to: Luxon.DateTime; + if (typeof params.interval === 'number') { + const interval = Luxon.Duration.fromObject({ minutes: params.interval }); + to = from.plus(interval); + } else if (params.fullDay) { + from.set({ hour: 0, minute: 0, second: 0, millisecond: 0 }); + to = from.plus(Luxon.Duration.fromObject({ day: 1 })); + } else { + return null; + } + if (!to.isValid) return null; + + return { + from: from.toISO(), + fromTimestamp: from.toSeconds(), + to: to.toISO(), + toTimestamp: to.toSeconds(), + fullDay: Boolean(params.fullDay), + description: params.alias || cf.name || UNKNOWN_CALENDAR_EVENT, + }; + } + + private getCalendarEventsFromSubject( + issue: RedmineTypes.ExtendedIssue, + ): CalendarEvent[] { + const matches = issue.subject.matchAll(/(?<=\()[^()]*(?=\))/g); + const items = [...matches].map((i) => i[0]).filter((i) => !!i); + + return items + .map((item) => DatesParser.parseToCalendarEvent(item)) + .filter((i) => !!i); + } + + private getCalendarEventsFromDescription( + issue: RedmineTypes.ExtendedIssue, + ): CalendarEvent[] { + const text = issue.description; + + const lines = text.split('\n').map((line) => line.trim()); + + const calendarStartIndex = lines.indexOf('Календарь:'); + if (calendarStartIndex < 0) return []; + + let index = calendarStartIndex + 1; + let line = this.extractFromList(lines[index]); + if (!line) { + index++; + line = this.extractFromList(lines[index]); + } + if (!line) return []; + + const res: string[] = []; + + do { + res.push(line); + index++; + line = this.extractFromList(lines[index]); + } while (line); + + return res.map((line) => DatesParser.parseToCalendarEvent(line)); + } + + private extractFromList(line: string): string | null { + const regexp = new RegExp(this.descriptionCalendarParams.lineRegexp); + const match = line.match(regexp); + return match && match[0] ? match[0] : null; + } +} diff --git a/libs/event-emitter/src/models/calendar-event.ts b/libs/event-emitter/src/models/calendar-event.ts new file mode 100644 index 0000000..3b5e180 --- /dev/null +++ b/libs/event-emitter/src/models/calendar-event.ts @@ -0,0 +1,8 @@ +export type CalendarEvent = { + from: string; + fromTimestamp: number; + to: string; + toTimestamp: number; + fullDay: boolean; + description: string; +}; diff --git a/libs/event-emitter/src/utils/string-with-dates-parser.ts b/libs/event-emitter/src/utils/string-with-dates-parser.ts new file mode 100644 index 0000000..cbfe4c8 --- /dev/null +++ b/libs/event-emitter/src/utils/string-with-dates-parser.ts @@ -0,0 +1,138 @@ +import Moo from 'moo'; +import { CalendarEvent } from '../models/calendar-event'; +import Luxon from 'luxon'; + +export const DEFAULT_PARAMS: Moo.Rules = { + WS: /[ \t]+/, + delimiter: /(?: - |: )/, + delimiter2: /(?:^\* |^- |(?!\d)T(?!>\d))/, + date: /(?:(?:\d{2}\.\d{2}\.(?:\d{2}|\d{4}))|(?:\d{4}-\d{2}-\d{2}))/, + time: /(?:\d{2}\b:\d{2}:\d{2}|\d{2}:\d{2})/, + word: /[\wА-Яа-я]+/, + other: { match: /./, lineBreaks: true }, + NL: { match: /\n/, lineBreaks: true }, +}; + +export const DEFAULT_DATE_FORMATS = ['dd.MM.yy', 'dd.MM.yyyy', 'yyyy-MM-dd']; + +export const DEFAULT_TIME_FORMATS = ['HH:mm', 'HH:mm:ss']; + +export const DEFAULT_EVENT_DURATION = 60 * 60 * 1000; // 1 hour in millis + +export function parse(str: string, params?: Moo.Rules): Moo.Token[] { + if (!params) params = DEFAULT_PARAMS; + try { + const lexer = Moo.compile(params); + lexer.reset(str); + const res: Moo.Token[] = []; + let token = lexer.next(); + while (token) { + res.push(token); + token = lexer.next(); + } + return res; + } catch (ex) { + return []; + } +} + +export type ParserOpts = { + rules?: Moo.Rules; + dateFormats?: string[]; + timeFormats?: string[]; +}; + +export function parseDate( + str: string, + formats?: string[], +): Luxon.DateTime | null { + if (!formats) formats = DEFAULT_DATE_FORMATS; + let res: Luxon.DateTime; + for (let i = 0; i < formats.length; i++) { + const format = formats[i]; + res = Luxon.DateTime.fromFormat(str, format); + if (res.isValid) return res; + } + return null; +} + +export function parseTime( + str: string, + formats?: string[], +): Luxon.Duration | null { + if (!formats) formats = DEFAULT_TIME_FORMATS; + let res: Luxon.DateTime; + for (let i = 0; i < formats.length; i++) { + const format = formats[i]; + res = Luxon.DateTime.fromFormat(str, format); + if (res.isValid) { + const startOfDay = res.set({ + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + }); + return res.diff(startOfDay).shiftToAll(); + } + } + return null; +} + +export function parseToCalendarEvent( + str: string, + opts?: ParserOpts, +): CalendarEvent | null { + const tokens = parse(str, opts?.rules); + + const words = tokens.filter((i) => i.type === 'word'); + + const dates = tokens.filter((i) => i.type === 'date'); + if (dates.length < 0) return null; + const date1 = parseDate(dates[0]?.value, opts?.dateFormats); + const date2 = parseDate(dates[1]?.value, opts?.dateFormats); + + const times = tokens.filter((i) => i.type === 'time'); + const time1 = parseTime(times[0]?.value, opts?.timeFormats); + const time2 = parseTime(times[1]?.value, opts?.timeFormats); + + let from: Luxon.DateTime; + let to: Luxon.DateTime; + let fullDay: boolean; + + if (date1 && time1) { + from = date1.set({ + hour: time1.hours, + minute: time1.minutes, + second: time1.seconds, + }); + fullDay = false; + } else if (date1) { + from = date1; + fullDay = true; + } else { + return null; + } + + if (date2 && time2) { + to = date2.set({ + hour: time2.hours, + minute: time2.minutes, + second: time2.seconds, + }); + } else if (date2) { + to = date2.plus({ day: 1 }); + } else if (fullDay) { + to = from.plus({ day: 1 }); + } else { + to = from.plus(Luxon.Duration.fromMillis(DEFAULT_EVENT_DURATION)); + } + + return { + from: from.toISO(), + fromTimestamp: from.toMillis(), + to: to.toISO(), + toTimestamp: to.toMillis(), + description: words.join(' '), + fullDay: fullDay, + }; +} diff --git a/package-lock.json b/package-lock.json index 1c17d5d..4e33da7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "imap-simple": "^5.1.0", "jsonc-parser": "^3.2.0", "luxon": "^3.1.0", + "moo": "^0.5.2", "nano": "^10.0.0", "node-telegram-bot-api": "^0.59.0", "reflect-metadata": "^0.1.13", @@ -41,6 +42,7 @@ "@types/express": "^4.17.13", "@types/jest": "27.4.0", "@types/luxon": "^3.1.0", + "@types/moo": "^0.5.6", "@types/node": "^16.0.0", "@types/node-telegram-bot-api": "^0.57.1", "@types/supertest": "^2.0.11", @@ -2141,6 +2143,12 @@ "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", "dev": true }, + "node_modules/@types/moo": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/@types/moo/-/moo-0.5.6.tgz", + "integrity": "sha512-Q60hZhulhl2Ox4LjbJvhH+HzsKrwzLPjEB8dZw0fK1MH2HyOLe6LDou68yTfsWasxGv7DPZe5VNM5vgpzOa2nw==", + "dev": true + }, "node_modules/@types/node": { "version": "16.11.49", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.49.tgz", @@ -7452,6 +7460,11 @@ "mkdirp": "bin/cmd.js" } }, + "node_modules/moo": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz", + "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==" + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -12014,6 +12027,12 @@ "integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==", "dev": true }, + "@types/moo": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/@types/moo/-/moo-0.5.6.tgz", + "integrity": "sha512-Q60hZhulhl2Ox4LjbJvhH+HzsKrwzLPjEB8dZw0fK1MH2HyOLe6LDou68yTfsWasxGv7DPZe5VNM5vgpzOa2nw==", + "dev": true + }, "@types/node": { "version": "16.11.49", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.49.tgz", @@ -16024,6 +16043,11 @@ "minimist": "^1.2.6" } }, + "moo": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz", + "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==" + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", diff --git a/package.json b/package.json index a871bf2..ad4a2a9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "imap-simple": "^5.1.0", "jsonc-parser": "^3.2.0", "luxon": "^3.1.0", + "moo": "^0.5.2", "nano": "^10.0.0", "node-telegram-bot-api": "^0.59.0", "reflect-metadata": "^0.1.13", @@ -53,6 +54,7 @@ "@types/express": "^4.17.13", "@types/jest": "27.4.0", "@types/luxon": "^3.1.0", + "@types/moo": "^0.5.6", "@types/node": "^16.0.0", "@types/node-telegram-bot-api": "^0.57.1", "@types/supertest": "^2.0.11", diff --git a/src/app.module.ts b/src/app.module.ts index 686bb56..2afa718 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -50,6 +50,7 @@ import { join } from 'path'; import { SimpleIssuesListController } from './dashboards/simple-issues-list.controller'; import { TagsManagerController } from './tags-manager/tags-manager.controller'; import { CreateTagManagerServiceProvider } from './tags-manager/tags-manager.service'; +import { CalendarEnhancer } from '@app/event-emitter/issue-enhancers/calendar-enhancer'; @Module({ imports: [ @@ -132,6 +133,9 @@ export class AppModule implements OnModuleInit { @Inject('CATEGORY_MERGE_TO_TAGS_ENHANCER') private categoryMergeToTagsEnhancer: CategoryMergeToTagsEnhancer, + + @Inject('CALENDAR_ENHANCER') + private calendarEnhancer: CalendarEnhancer, ) {} onModuleInit() { @@ -148,6 +152,7 @@ export class AppModule implements OnModuleInit { this.currentUserEnhancer, this.issueUrlEnhancer, this.categoryMergeToTagsEnhancer, + this.calendarEnhancer, ]); this.personalNotificationsService.$messages.subscribe((resp) => { diff --git a/src/configs/app.ts b/src/configs/app.ts index 89c3e6c..92146ba 100644 --- a/src/configs/app.ts +++ b/src/configs/app.ts @@ -8,6 +8,7 @@ import RedmineStatusChangesConfigLoader from './status-changes.config'; import RedmineEccmConfig from './eccm.config'; import RedmineCurrentUserRulesConfig from './current-user-rules.config'; import SimpleKanbanBoardConfig from './simple-kanban-board.config'; +import CalendarEnhancer from './calendar-enhancer.config'; const redmineIssueEventEmitterConfig = RedmineIssueEventEmitterConfigLoader(); const redmineStatusesConfig = RedmineStatusesConfigLoader(); @@ -15,6 +16,7 @@ const redmineStatusChanges = RedmineStatusChangesConfigLoader(); const redmineEccm = RedmineEccmConfig(); const redmineCurrentUserRules = RedmineCurrentUserRulesConfig(); const simpleKanbanBoard = SimpleKanbanBoardConfig(); +const calendarEnhancer = CalendarEnhancer(); let appConfig: AppConfig; @@ -39,6 +41,7 @@ export default (): AppConfig => { redmineEccm: redmineEccm, redmineCurrentUserRules: redmineCurrentUserRules, simpleKanbanBoard: simpleKanbanBoard, + calendarEnhancer: calendarEnhancer, }; return appConfig; diff --git a/src/configs/calendar-enhancer.config.ts b/src/configs/calendar-enhancer.config.ts new file mode 100644 index 0000000..1b19e6f --- /dev/null +++ b/src/configs/calendar-enhancer.config.ts @@ -0,0 +1,23 @@ +import { readFileSync } from 'fs'; +import { join } from 'path'; +import { parse } from 'jsonc-parser'; + +let config: Record; + +export default (): Record => { + if (config) { + return config; + } + + const userDefinedConfigPath = + process.env['ELTEX_REDMINE_HELPER_CALENDAR_ENHANCER_CONFIG_PATH']; + const defaultConfigPath = join('configs', 'calendar-enhancer.jsonc'); + + const configPath = userDefinedConfigPath || defaultConfigPath; + + const rawData = readFileSync(configPath, { encoding: 'utf-8' }); + + config = parse(rawData); + + return config; +}; diff --git a/src/issue-enhancers/interview-enhancer.ts b/src/issue-enhancers/interview-enhancer.ts deleted file mode 100644 index 06e11c1..0000000 --- a/src/issue-enhancers/interview-enhancer.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface'; -import { RedmineTypes } from '@app/event-emitter/models/redmine-types'; -import { Injectable } from '@nestjs/common'; -import * as Luxon from 'luxon'; - -export type SubjectParserParam = { - regexp: string; - format: string; - type: string; -}; - -export type DescriptionParserParam = {}; - -@Injectable() -export class InterviewEnhancer implements IssueEnhancerInterface { - name = 'interview'; - - constructor( - public interviewProjects: string[] = [], - public customFieldDateFormat: string = 'yyyy-MM-dd HH:mm', - public subjectParserParams: SubjectParserParam[] - ) {} - - async enhance( - issue: RedmineTypes.Issue, - ): Promise> { - const res: RedmineTypes.ExtendedIssue = { ...issue }; - - if (this.interviewProjects.indexOf(res.project.name) < 0) { - return res; - } - - const subject = res.subject; - const nextEventDateField = res.custom_fields.find((cf) => { - return cf.name === 'Дата следующего обновления'; - }); - - if () - - const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat); - - return res; - } - - private getNextEventDate(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null { - const nextEventDateField = issue.custom_fields.find((cf) => { - return cf.name === 'Дата следующего обновления'; - }); - if (!nextEventDateField) return null; - const nextEventDate = Luxon.DateTime.fromFormat(nextEventDateField.value, this.customFieldDateFormat); - if (!nextEventDate.isValid) return null; - return nextEventDate; - } - - private getDateFromSubject(issue: RedmineTypes.ExtendedIssue): Luxon.DateTime|null { - const subject = issue.subject; - return null; - } -} diff --git a/src/models/app-config.model.ts b/src/models/app-config.model.ts index 38f3873..a60af45 100644 --- a/src/models/app-config.model.ts +++ b/src/models/app-config.model.ts @@ -26,4 +26,4 @@ export type AppConfig = { updateItemsLimit: number; tagsCustomFieldName: string; }; -}; +} & Record; From 4d693156d3671c7090bed8b112f11b2a12215e46 Mon Sep 17 00:00:00 2001 From: Gnedov Pavel Date: Wed, 23 Aug 2023 04:02:29 +0700 Subject: [PATCH 10/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B2=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=BA=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B4=D0=B0=D1=80=D0=BD=D1=8B=D1=85=20=D1=81=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=D1=82=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/issue-enhancers/calendar-enhancer.ts | 25 ++++++++++++++----- .../src/utils/string-with-dates-parser.ts | 21 +++++++++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts b/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts index 5bc8c55..bbda56b 100644 --- a/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts +++ b/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts @@ -1,6 +1,6 @@ import { IssueEnhancerInterface } from '@app/event-emitter/issue-enhancers/issue-enhancer-interface'; import { RedmineTypes } from '@app/event-emitter/models/redmine-types'; -import { Injectable } from '@nestjs/common'; +import { Injectable, Logger } from '@nestjs/common'; import * as Luxon from 'luxon'; import { CalendarEvent } from '../models/calendar-event'; import * as DatesParser from '../utils/string-with-dates-parser'; @@ -23,6 +23,8 @@ export const UNKNOWN_CALENDAR_EVENT = 'Unknown calendar event'; @Injectable() export class CalendarEnhancer implements IssueEnhancerInterface { + private logger = new Logger(CalendarEnhancer.name); + name = 'calendar'; constructor( @@ -30,16 +32,27 @@ export class CalendarEnhancer implements IssueEnhancerInterface { public customFields: CustomFieldParserParams[], public descriptionCalendarParams: DescriptionParserParams, public calendarEventsKey: string, - ) {} + ) { + const initParams = {useForProjects, customFields, descriptionCalendarParams, calendarEventsKey}; + this.logger.debug(`Calendar enhancer init with ${JSON.stringify(initParams)}`); + } async enhance( issue: RedmineTypes.ExtendedIssue, ): Promise { const res: RedmineTypes.ExtendedIssue = { ...issue }; - if (!this.checkProject(issue)) return res; + if (!this.checkProject(res)) { + return res; + } - issue[this.calendarEventsKey] = this.getCalendarEvents(issue); + try { + res[this.calendarEventsKey] = this.getCalendarEvents(res); + } catch (ex) { + this.logger.error(`Error at parsing calendar events, message - ${ex}`); + return res; + } + this.logger.debug(`Calendar events for #${issue.id}: issue.${this.calendarEventsKey} = ${JSON.stringify(res[this.calendarEventsKey])}`); return res; } @@ -108,9 +121,9 @@ export class CalendarEnhancer implements IssueEnhancerInterface { return { from: from.toISO(), - fromTimestamp: from.toSeconds(), + fromTimestamp: from.toMillis(), to: to.toISO(), - toTimestamp: to.toSeconds(), + toTimestamp: to.toMillis(), fullDay: Boolean(params.fullDay), description: params.alias || cf.name || UNKNOWN_CALENDAR_EVENT, }; diff --git a/libs/event-emitter/src/utils/string-with-dates-parser.ts b/libs/event-emitter/src/utils/string-with-dates-parser.ts index cbfe4c8..55b4b46 100644 --- a/libs/event-emitter/src/utils/string-with-dates-parser.ts +++ b/libs/event-emitter/src/utils/string-with-dates-parser.ts @@ -1,6 +1,7 @@ -import Moo from 'moo'; +import * as Moo from 'moo'; import { CalendarEvent } from '../models/calendar-event'; -import Luxon from 'luxon'; +import * as Luxon from 'luxon'; +import { Logger } from '@nestjs/common'; export const DEFAULT_PARAMS: Moo.Rules = { WS: /[ \t]+/, @@ -13,12 +14,14 @@ export const DEFAULT_PARAMS: Moo.Rules = { NL: { match: /\n/, lineBreaks: true }, }; -export const DEFAULT_DATE_FORMATS = ['dd.MM.yy', 'dd.MM.yyyy', 'yyyy-MM-dd']; +export const DEFAULT_DATE_FORMATS = ['yyyy-MM-dd', 'dd.MM.yyyy', 'dd.MM.yy']; -export const DEFAULT_TIME_FORMATS = ['HH:mm', 'HH:mm:ss']; +export const DEFAULT_TIME_FORMATS = ['HH:mm:ss', 'HH:mm']; export const DEFAULT_EVENT_DURATION = 60 * 60 * 1000; // 1 hour in millis +const logger = new Logger('string-with-dates-parser'); + export function parse(str: string, params?: Moo.Rules): Moo.Token[] { if (!params) params = DEFAULT_PARAMS; try { @@ -32,6 +35,7 @@ export function parse(str: string, params?: Moo.Rules): Moo.Token[] { } return res; } catch (ex) { + logger.error(`Error at parse str=${str} with params=${params}, error message - ${ex}`); return []; } } @@ -42,10 +46,17 @@ export type ParserOpts = { timeFormats?: string[]; }; +export const DEFAULT_PARSER_OPTS: ParserOpts = { + rules: DEFAULT_PARAMS, + dateFormats: DEFAULT_DATE_FORMATS, + timeFormats: DEFAULT_TIME_FORMATS, +}; + export function parseDate( str: string, formats?: string[], ): Luxon.DateTime | null { + if (!str) return null; if (!formats) formats = DEFAULT_DATE_FORMATS; let res: Luxon.DateTime; for (let i = 0; i < formats.length; i++) { @@ -60,6 +71,7 @@ export function parseTime( str: string, formats?: string[], ): Luxon.Duration | null { + if (!str) return null; if (!formats) formats = DEFAULT_TIME_FORMATS; let res: Luxon.DateTime; for (let i = 0; i < formats.length; i++) { @@ -82,6 +94,7 @@ export function parseToCalendarEvent( str: string, opts?: ParserOpts, ): CalendarEvent | null { + if (!opts) opts = DEFAULT_PARSER_OPTS; const tokens = parse(str, opts?.rules); const words = tokens.filter((i) => i.type === 'word'); From 4107ae84f31c8215c046a798275760dfd85e34cb Mon Sep 17 00:00:00 2001 From: Gnedov Pavel Date: Thu, 24 Aug 2023 18:40:16 +0700 Subject: [PATCH 11/12] =?UTF-8?q?=D0=92=D1=8B=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B5=20icalen?= =?UTF-8?q?dar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/calendar/calendar.controller.ts | 58 +++++++++ .../src/calendar/calendar.service.ts | 113 ++++++++++++++++++ .../event-emitter/src/event-emitter.module.ts | 16 ++- .../src/issue-enhancers/calendar-enhancer.ts | 5 +- .../src/utils/string-with-dates-parser.ts | 10 +- 5 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 libs/event-emitter/src/calendar/calendar.controller.ts create mode 100644 libs/event-emitter/src/calendar/calendar.service.ts diff --git a/libs/event-emitter/src/calendar/calendar.controller.ts b/libs/event-emitter/src/calendar/calendar.controller.ts new file mode 100644 index 0000000..a62d6c0 --- /dev/null +++ b/libs/event-emitter/src/calendar/calendar.controller.ts @@ -0,0 +1,58 @@ +import { Controller, Get, Inject, Logger, Param, Query } from "@nestjs/common"; +import { CalendarService } from "./calendar.service"; +import nano from 'nano'; +import { UNLIMITED } from "../consts/consts"; + +@Controller('calendar') +export class CalendarController { + private logger = new Logger(CalendarController.name); + + constructor( + @Inject('CALENDAR_SERVICE') + private calendarService: CalendarService + ) {} + + @Get() + async get(@Param('filter') filter: any): Promise { + return await this.calendarService.getICalData(filter); + } + + @Get('/simple') + async simple( + @Query('project') project?: string, + @Query('category') category?: string + ): Promise { + const andSection: any[] = [ + { + "closed_on": { + "$exists": false + } + } + ]; + if (project) { + andSection.push({ + "project.name": { + "$in": [ + project + ] + } + }); + } + if (category) { + andSection.push({ + "category.name": { + "$in": [ + category + ] + } + }); + } + const query: nano.MangoQuery = { + selector: { + "$and": andSection + }, + limit: UNLIMITED + }; + return await this.calendarService.getICalData(query); + } +} \ No newline at end of file diff --git a/libs/event-emitter/src/calendar/calendar.service.ts b/libs/event-emitter/src/calendar/calendar.service.ts new file mode 100644 index 0000000..7f0833c --- /dev/null +++ b/libs/event-emitter/src/calendar/calendar.service.ts @@ -0,0 +1,113 @@ +import { Injectable, Logger } from "@nestjs/common"; +import { CalendarEvent } from "../models/calendar-event"; +import { RedmineTypes } from "../models/redmine-types"; +import * as Luxon from 'luxon'; +import { IssuesService } from "../issues/issues.service"; +import { randomUUID } from 'crypto'; + +/* +BEGIN:VCALENDAR +PRODID:-//Example Corp.//CalDAV Client//EN +VERSION:2.0 +BEGIN:VEVENT +UID:1@example.com +SUMMARY:One-off Meeting +DTSTAMP:20041210T183904Z +DTSTART:20041207T120000Z +DTEND:20041207T130000Z +END:VEVENT +BEGIN:VEVENT +UID:2@example.com +SUMMARY:Weekly Meeting +DTSTAMP:20041210T183838Z +DTSTART:20041206T120000Z +DTEND:20041206T130000Z +RRULE:FREQ=WEEKLY +END:VEVENT +BEGIN:VEVENT +UID:2@example.com +SUMMARY:Weekly Meeting +RECURRENCE-ID:20041213T120000Z +DTSTAMP:20041210T183838Z +DTSTART:20041213T130000Z +DTEND:20041213T140000Z +END:VEVENT +END:VCALENDAR +*/ + +export type IssueAndEvent = { + issue: RedmineTypes.ExtendedIssue; + event: CalendarEvent; +}; + +@Injectable() +export class CalendarService { + private interval = 30 * 24 * 60 * 60 * 1000; // 30 days + + constructor(public calendarEventsKey: string, private issuesService: IssuesService) {} + + async getICalData(filter: any): Promise { + const issues = await this.issuesService.find(filter); + const actualEvents = this.getActualEvents(issues); + const formattedEvents = actualEvents.map((event) => { + return this.generateICalendarEvent(event.issue, event.event); + }).filter((event) => { + return !!event; + }); + const res = this.generateICalendar(formattedEvents); + return res; + } + + private getActualEvents(issues: RedmineTypes.ExtendedIssue[]): IssueAndEvent[] { + const res: IssueAndEvent[] = []; + for (let i = 0; i < issues.length; i++) { + const issue = issues[i]; + if (!issue[this.calendarEventsKey] || issue[this.calendarEventsKey].length <= 0) { + continue; + } + const events = issue[this.calendarEventsKey]; + for (let j = 0; j < events.length; j++) { + const event = events[j]; + if (this.actualEvent(event)) res.push({event: event, issue: issue}); + } + } + return res; + } + + private actualEvent(event: CalendarEvent): boolean { + const now = Luxon.DateTime.now().toMillis(); + const from = now - this.interval; + const to = now + this.interval; + return Boolean( + (from <= event.fromTimestamp && event.fromTimestamp <= to) || + (from <= event.toTimestamp && event.toTimestamp <= to) + ); + } + + private generateICalendarEvent(issue: RedmineTypes.Issue, data: CalendarEvent): string | null { + if (!data) return null; + return `BEGIN:VEVENT +UID:${randomUUID()}@example.com +DTSTAMP:${this.formatTimestamp(data.fromTimestamp, data.fullDay)} +ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com +DTSTART:${this.formatTimestamp(data.fromTimestamp, data.fullDay)} +DTEND:${this.formatTimestamp(data.toTimestamp, data.fullDay)} +SUMMARY:#${issue.id} - ${data.description} - ${issue.subject} +END:VEVENT`; + } + + private formatTimestamp(timestamp: number, fullDay?: boolean): string { + let format: string = fullDay ? "yyyyMMdd" : "yyyyMMdd'T'HHmmss'Z'"; + let datetime = Luxon.DateTime.fromMillis(timestamp); + if (!fullDay) datetime = datetime.setZone('utc'); + return datetime.toFormat(format); + } + + private generateICalendar(events: string[]): string { + return `BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Example Corp.//CalDAV Client//EN +${events.join("\n")} +END:VCALENDAR`; + } +} \ No newline at end of file diff --git a/libs/event-emitter/src/event-emitter.module.ts b/libs/event-emitter/src/event-emitter.module.ts index d24ab6a..7383ec6 100644 --- a/libs/event-emitter/src/event-emitter.module.ts +++ b/libs/event-emitter/src/event-emitter.module.ts @@ -29,6 +29,8 @@ import { TimePassedHighlightEnhancer } from './issue-enhancers/time-passed-highl import { ListIssuesByFieldsWidgetService } from './project-dashboard/widgets/list-issues-by-fields.widget.service'; import { IssuesUpdaterService } from './issues-updater/issues-updater.service'; import { CalendarEnhancer } from './issue-enhancers/calendar-enhancer'; +import { CalendarService } from './calendar/calendar.service'; +import { CalendarController } from './calendar/calendar.controller'; @Module({}) export class EventEmitterModule implements OnModuleInit { @@ -83,6 +85,14 @@ export class EventEmitterModule implements OnModuleInit { }, inject: [ConfigService], }, + { + provide: 'CALENDAR_SERVICE', + useFactory: (calendarEnhancer: CalendarEnhancer, issuesService: IssuesService): CalendarService => { + const calendarEventsKey = calendarEnhancer.calendarEventsKey; + return new CalendarService(calendarEventsKey, issuesService); + }, + inject: ['CALENDAR_ENHANCER', IssuesService] + }, ], exports: [ EventEmitterService, @@ -114,8 +124,12 @@ export class EventEmitterModule implements OnModuleInit { provide: 'CALENDAR_ENHANCER', useExisting: 'CALENDAR_ENHANCER', }, + { + provide: 'CALENDAR_SERVICE', + useExisting: 'CALENDAR_SERVICE', + }, ], - controllers: [MainController, UsersController, IssuesController], + controllers: [MainController, UsersController, IssuesController, CalendarController], }; } diff --git a/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts b/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts index bbda56b..92dfc8c 100644 --- a/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts +++ b/libs/event-emitter/src/issue-enhancers/calendar-enhancer.ts @@ -49,7 +49,7 @@ export class CalendarEnhancer implements IssueEnhancerInterface { try { res[this.calendarEventsKey] = this.getCalendarEvents(res); } catch (ex) { - this.logger.error(`Error at parsing calendar events, message - ${ex}`); + this.logger.error(`Error at parsing calendar events, message - ${ex}: ${(ex as Error)?.stack}`); return res; } this.logger.debug(`Calendar events for #${issue.id}: issue.${this.calendarEventsKey} = ${JSON.stringify(res[this.calendarEventsKey])}`); @@ -147,7 +147,7 @@ export class CalendarEnhancer implements IssueEnhancerInterface { const lines = text.split('\n').map((line) => line.trim()); - const calendarStartIndex = lines.indexOf('Календарь:'); + const calendarStartIndex = lines.indexOf(this.descriptionCalendarParams.title); if (calendarStartIndex < 0) return []; let index = calendarStartIndex + 1; @@ -170,6 +170,7 @@ export class CalendarEnhancer implements IssueEnhancerInterface { } private extractFromList(line: string): string | null { + if (!line || line.length <= 0) return null; const regexp = new RegExp(this.descriptionCalendarParams.lineRegexp); const match = line.match(regexp); return match && match[0] ? match[0] : null; diff --git a/libs/event-emitter/src/utils/string-with-dates-parser.ts b/libs/event-emitter/src/utils/string-with-dates-parser.ts index 55b4b46..b1c39ec 100644 --- a/libs/event-emitter/src/utils/string-with-dates-parser.ts +++ b/libs/event-emitter/src/utils/string-with-dates-parser.ts @@ -7,8 +7,8 @@ export const DEFAULT_PARAMS: Moo.Rules = { WS: /[ \t]+/, delimiter: /(?: - |: )/, delimiter2: /(?:^\* |^- |(?!\d)T(?!>\d))/, - date: /(?:(?:\d{2}\.\d{2}\.(?:\d{2}|\d{4}))|(?:\d{4}-\d{2}-\d{2}))/, - time: /(?:\d{2}\b:\d{2}:\d{2}|\d{2}:\d{2})/, + date: /\b(?:(?:\d{2}\.\d{2}\.(?:\d{2}|\d{4}))|(?:\d{4}-\d{2}-\d{2}))\b/, + time: /\b(?:\d{2}\b:\d{2}:\d{2}|\d{2}:\d{2})\b/, word: /[\wА-Яа-я]+/, other: { match: /./, lineBreaks: true }, NL: { match: /\n/, lineBreaks: true }, @@ -136,6 +136,12 @@ export function parseToCalendarEvent( to = date2.plus({ day: 1 }); } else if (fullDay) { to = from.plus({ day: 1 }); + } else if (time2) { + to = date1.set({ + hour: time2.hours, + minute: time2.minutes, + second: time2.seconds + }); } else { to = from.plus(Luxon.Duration.fromMillis(DEFAULT_EVENT_DURATION)); } From e0d154f2ccdaee9c9ca0e0cb8f3a7d74dfeea13b Mon Sep 17 00:00:00 2001 From: Gnedov Pavel Date: Thu, 24 Aug 2023 19:00:07 +0700 Subject: [PATCH 12/12] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BE=20=D1=81=D1=82=D0=B8=D0=BB=D1=8F=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BE=D1=80=D0=B8=D1=82=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/issue-enhancers/priority-styles-enhancer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts b/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts index 6da3687..95c9416 100644 --- a/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts +++ b/libs/event-emitter/src/issue-enhancers/priority-styles-enhancer.ts @@ -64,7 +64,8 @@ export class PriorityStylesEnhancer implements IssueEnhancerInterface { async enhance( issue: RedmineTypes.ExtendedIssue, ): Promise { - const priorityName = issue.priority.name; + const priorityName = issue?.priority?.name; + if (!priorityName) return issue; const priorityRule = this.findPriorityRule(priorityName); issue[this.targetKey] = priorityRule.style || priorityRule.className; return issue;