From 4e4eb338794a6e5d23bf4f3fd7eaf91fda5670d9 Mon Sep 17 00:00:00 2001 From: Hugaleno Bezerra Date: Sat, 9 Apr 2022 20:51:07 -0300 Subject: [PATCH] WIP: Fix a bug when changing transition hander; Object 'read only' on method setTransition --- .vscode/launch.json | 5 +- .../open-project-api-responses.d.ts | 4 +- .../openproject-cfg.component.html | 32 +++++--- .../openproject-cfg.component.ts | 74 ++++++++++--------- src/app/t.const.ts | 13 ++++ src/assets/i18n/en.json | 14 +++- 6 files changed, 90 insertions(+), 52 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ce7c79584..5e8d2e249 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,8 @@ "request": "launch", "name": "Launch Chrome against localhost", "url": "http://localhost:4200", - "webRoot": "${workspaceFolder}" + "webRoot": "${workspaceFolder}", + "sourceMaps": true } ] -} \ No newline at end of file +} diff --git a/src/app/features/issue/providers/open-project/open-project-api-responses.d.ts b/src/app/features/issue/providers/open-project/open-project-api-responses.d.ts index fbe626473..ab090b597 100644 --- a/src/app/features/issue/providers/open-project/open-project-api-responses.d.ts +++ b/src/app/features/issue/providers/open-project/open-project-api-responses.d.ts @@ -43,7 +43,7 @@ interface OpenProjectUser { _type: 'User'; } -export interface OpenProjectOriginalStatus { +export type OpenProjectOriginalStatus = Readonly<{ _type: 'Status'; id: number; name: string; @@ -54,7 +54,7 @@ export interface OpenProjectOriginalStatus { defaultDoneRatio: null; position: number; _links: OpenProjectApiLinks; -} +}>; // NOTE unknown currently means we haven't evaluated the possible values export type OpenProjectOriginalWorkPackageReduced = Readonly<{ diff --git a/src/app/features/issue/providers/open-project/open-project-view-components/openproject-cfg/openproject-cfg.component.html b/src/app/features/issue/providers/open-project/open-project-view-components/openproject-cfg/openproject-cfg.component.html index 5692e8737..f27e8a573 100644 --- a/src/app/features/issue/providers/open-project/open-project-view-components/openproject-cfg/openproject-cfg.component.html +++ b/src/app/features/issue/providers/open-project/open-project-view-components/openproject-cfg/openproject-cfg.component.html @@ -21,14 +21,14 @@ > -

Transition Handling

+

{{T.F.OPEN_PROJECT.CFG_CMP.TRANSITION|translate}}

- {{T.F.JIRA.CFG_CMP.ENABLE_TRANSITIONS|translate}} + {{T.F.OPEN_PROJECT.CFG_CMP.ENABLE_TRANSITIONS|translate}}
- {{T.F.JIRA.CFG_CMP.SELECT_ISSUE_FOR_TRANSITIONS|translate}} + + {{T.F.OPEN_PROJECT.CFG_CMP.SELECT_ISSUE_FOR_TRANSITIONS|translate}} + - - - + + + @@ -80,10 +86,12 @@ [ngModelOptions]="{standalone: true}" [ngModel]="getTransition(opt.key)" > - {{T.F.JIRA.CFG_CMP.DO_NOT|translate}} - {{T.F.JIRA.CFG_CMP.ALWAYS_ASK|translate}} + + {{T.F.OPEN_PROJECT.CFG_CMP.DO_NOT|translate}} + + + {{T.F.OPEN_PROJECT.CFG_CMP.ALWAYS_ASK|translate}} + ).items; - } - - ngOnDestroy(): void { - this._subs.unsubscribe(); - } - - submit(): void { - if (!this.cfg) { - throw new Error( - 'No config for ' + (this.section as ConfigFormSection).key, - ); - } else { - this.save.emit({ - sectionKey: (this.section as ConfigFormSection).key, - config: this.cfg, - }); - } - } + private _cfg?: OpenProjectCfg; get cfg(): OpenProjectCfg { return this._cfg as OpenProjectCfg; @@ -127,7 +107,7 @@ export class OpenprojectCfgComponent implements OnInit, OnDestroy { // NOTE: this is legit because it might be that there is no issue provider cfg yet @Input() set cfg(cfg: OpenProjectCfg) { const newCfg: OpenProjectCfg = cfg ? { ...cfg } : DEFAULT_OPEN_PROJECT_CFG; - + console.log('SET CHUGUEI', cfg); if (!newCfg.transitionConfig) { newCfg.transitionConfig = DEFAULT_OPEN_PROJECT_CFG.transitionConfig; } else { @@ -142,7 +122,7 @@ export class OpenprojectCfgComponent implements OnInit, OnDestroy { if (!Array.isArray(newCfg.availableTransitions)) { newCfg.availableTransitions = DEFAULT_OPEN_PROJECT_CFG.availableTransitions; } - + console.log('SET CFG', newCfg); this._cfg = newCfg; this.transitionConfigOpts = Object.keys(newCfg.transitionConfig).map((k: string) => { @@ -154,6 +134,41 @@ export class OpenprojectCfgComponent implements OnInit, OnDestroy { }); } + ngOnInit(): void { + this.fields = (this.section as ConfigFormSection).items; + } + + ngOnDestroy(): void { + this._subs.unsubscribe(); + } + + getTransition(key: keyof OpenProjectTransitionConfig): OpenProjectTransitionOption { + return this.cfg.transitionConfig[key]; + } + + setTransition( + key: keyof OpenProjectTransitionConfig, + value: OpenProjectTransitionOption, + ): OpenProjectTransitionOption { + const transitionConfig = { ...this.cfg.transitionConfig }; + transitionConfig[key] = value; + this.cfg.transitionConfig = transitionConfig; + return value; + } + + submit(): void { + if (!this.cfg) { + throw new Error( + 'No config for ' + (this.section as ConfigFormSection).key, + ); + } else { + this.save.emit({ + sectionKey: (this.section as ConfigFormSection).key, + config: this.cfg, + }); + } + } + updateTransitionOptions(): void { const searchResultItem = this.issueSuggestionsCtrl.value as SearchResultItem; if (!searchResultItem || typeof (searchResultItem as any) === 'string') { @@ -170,24 +185,13 @@ export class OpenprojectCfgComponent implements OnInit, OnDestroy { this.cfg.availableTransitions = val; this._snackService.open({ type: 'SUCCESS', - msg: T.F.JIRA.S.TRANSITIONS_LOADED, + msg: T.F.OPEN_PROJECT.S.TRANSITIONS_LOADED, }); }), ); } } - getTransition(key: keyof OpenProjectTransitionConfig): OpenProjectTransitionOption { - return this.cfg.transitionConfig[key]; - } - - setTransition( - key: keyof OpenProjectTransitionConfig, - value: OpenProjectTransitionOption, - ): OpenProjectTransitionOption { - return (this.cfg.transitionConfig[key] = value); - } - toggleEnabled(isEnabled: boolean): void { if (this._workContextService.activeWorkContextType !== WorkContextType.PROJECT) { throw new Error('Should only be called when in project context'); diff --git a/src/app/t.const.ts b/src/app/t.const.ts index 214c1d81d..f3bc8d5bb 100644 --- a/src/app/t.const.ts +++ b/src/app/t.const.ts @@ -462,6 +462,18 @@ const T = { DIALOG_INITIAL: { TITLE: 'F.OPEN_PROJECT.DIALOG_INITIAL.TITLE', }, + CFG_CMP: { + ALWAYS_ASK: 'F.OPEN_PROJECT.CFG_CMP.ALWAYS_ASK', + DONE: 'F.OPEN_PROJECT.CFG_CMP.DONE', + DO_NOT: 'F.OPEN_PROJECT.CFG_CMP.DO_NOT', + ENABLE: 'F.OPEN_PROJECT.CFG_CMP.ENABLE', + TRANSITION: 'F.OPEN_PROJECT.CFG_CMP.TRANSITION', + ENABLE_TRANSITIONS: 'F.OPEN_PROJECT.CFG_CMP.ENABLE_TRANSITIONS', + IN_PROGRESS: 'F.OPEN_PROJECT.CFG_CMP.IN_PROGRESS', + OPEN: 'F.OPEN_PROJECT.CFG_CMP.OPEN', + SELECT_ISSUE_FOR_TRANSITIONS: + 'F.OPEN_PROJECT.CFG_CMP.SELECT_ISSUE_FOR_TRANSITIONS', + }, DIALOG_TRACK_TIME: { ACTIVITY: 'F.OPEN_PROJECT.DIALOG_TRACK_TIME.ACTIVITY', CURRENTLY_LOGGED: 'F.OPEN_PROJECT.DIALOG_TRACK_TIME.CURRENTLY_LOGGED', @@ -511,6 +523,7 @@ const T = { S: { ERR_UNKNOWN: 'F.OPEN_PROJECT.S.ERR_UNKNOWN', POST_TIME_SUCCESS: 'F.OPEN_PROJECT.S.POST_TIME_SUCCESS', + TRANSITIONS_LOADED: 'F.OPEN_PROJECT.S.TRANSITIONS_LOADED', }, }, POMODORO: { diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index b584b156e..dba7e2169 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -457,6 +457,17 @@ "DIALOG_INITIAL": { "TITLE": "Setup OpenProject for Project" }, + "CFG_CMP": { + "ALWAYS_ASK": "Always open dialog", + "DONE": "Status for completing task", + "DO_NOT": "Don't transition", + "ENABLE": "Enable Openproject integration", + "TRANSITION": "Transition Handling", + "ENABLE_TRANSITIONS": "Enable Transition Handling", + "IN_PROGRESS": "Status for starting task", + "OPEN": "Status for pausing task", + "SELECT_ISSUE_FOR_TRANSITIONS": "Select issue to load available transitions" + }, "DIALOG_TRACK_TIME": { "ACTIVITY": "Activity", "CURRENTLY_LOGGED": "Currently logged time: ", @@ -502,7 +513,8 @@ }, "S": { "ERR_UNKNOWN": "OpenProject: Unknown error {{statusCode}} {{errorMsg}}. Is CORS properly configured for the server?", - "POST_TIME_SUCCESS": "OpenProject: Successfully created time entry for {{issueTitle}}" + "POST_TIME_SUCCESS": "OpenProject: Successfully created time entry for {{issueTitle}}", + "TRANSITIONS_LOADED": "Transitions loaded. Use the selects below to assign them" } }, "POMODORO": {