WIP: Fix a bug when changing transition hander; Object 'read only' on method setTransition

This commit is contained in:
Hugaleno Bezerra 2022-04-09 20:51:07 -03:00
parent c33c1dc03c
commit 4e4eb33879
6 changed files with 90 additions and 52 deletions

5
.vscode/launch.json vendored
View File

@ -9,7 +9,8 @@
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
"webRoot": "${workspaceFolder}",
"sourceMaps": true
}
]
}
}

View File

@ -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<{

View File

@ -21,14 +21,14 @@
>
</formly-form>
<h3 class="sub-section-heading">Transition Handling</h3>
<h3 class="sub-section-heading">{{T.F.OPEN_PROJECT.CFG_CMP.TRANSITION|translate}}</h3>
<mat-slide-toggle
[(ngModel)]="cfg.isTransitionIssuesEnabled"
[ngModelOptions]="{standalone: true}"
name="isTransitionIssuesEnabled"
style="margin-bottom: 8px"
>
{{T.F.JIRA.CFG_CMP.ENABLE_TRANSITIONS|translate}}
{{T.F.OPEN_PROJECT.CFG_CMP.ENABLE_TRANSITIONS|translate}}
</mat-slide-toggle>
<section
@ -36,7 +36,9 @@
@expand
>
<mat-form-field>
<mat-label>{{T.F.JIRA.CFG_CMP.SELECT_ISSUE_FOR_TRANSITIONS|translate}}</mat-label>
<mat-label>
{{T.F.OPEN_PROJECT.CFG_CMP.SELECT_ISSUE_FOR_TRANSITIONS|translate}}
</mat-label>
<input
[formControl]="issueSuggestionsCtrl"
[matAutocomplete]="autoEl"
@ -67,11 +69,15 @@
<div *ngFor="let opt of transitionConfigOpts">
<mat-form-field>
<label *ngIf="opt.key==='OPEN'">{{T.F.JIRA.CFG_CMP.OPEN|translate}}</label>
<label *ngIf="opt.key==='IN_PROGRESS'"
>{{T.F.JIRA.CFG_CMP.IN_PROGRESS|translate}}</label
>
<label *ngIf="opt.key==='DONE'">{{T.F.JIRA.CFG_CMP.DONE|translate}}</label>
<label *ngIf="opt.key==='OPEN'">
{{T.F.OPEN_PROJECT.CFG_CMP.OPEN|translate}}
</label>
<label *ngIf="opt.key==='IN_PROGRESS'">
{{T.F.OPEN_PROJECT.CFG_CMP.IN_PROGRESS|translate}}
</label>
<label *ngIf="opt.key==='DONE'">
{{T.F.OPEN_PROJECT.CFG_CMP.DONE|translate}}
</label>
<!-- TODO check for a better way to do this -->
<!-- <mat-select [(ngModel)]="cfg.transitionConfig[opt.key]"-->
@ -80,10 +86,12 @@
[ngModelOptions]="{standalone: true}"
[ngModel]="getTransition(opt.key)"
>
<mat-option value="DO_NOT">{{T.F.JIRA.CFG_CMP.DO_NOT|translate}}</mat-option>
<mat-option value="ALWAYS_ASK"
>{{T.F.JIRA.CFG_CMP.ALWAYS_ASK|translate}}</mat-option
>
<mat-option value="DO_NOT">
{{T.F.OPEN_PROJECT.CFG_CMP.DO_NOT|translate}}
</mat-option>
<mat-option value="ALWAYS_ASK">
{{T.F.OPEN_PROJECT.CFG_CMP.ALWAYS_ASK|translate}}
</mat-option>
<mat-option
*ngFor="let transition of cfg.availableTransitions"
[value]="transition"

View File

@ -89,7 +89,6 @@ export class OpenprojectCfgComponent implements OnInit, OnDestroy {
val: OpenProjectTransitionOption;
}[] = [];
private _cfg?: OpenProjectCfg;
private _subs: Subscription = new Subscription();
constructor(
@ -99,26 +98,7 @@ export class OpenprojectCfgComponent implements OnInit, OnDestroy {
private _workContextService: WorkContextService,
) {}
ngOnInit(): void {
this.fields = (this.section as ConfigFormSection<OpenProjectCfg>).items;
}
ngOnDestroy(): void {
this._subs.unsubscribe();
}
submit(): void {
if (!this.cfg) {
throw new Error(
'No config for ' + (this.section as ConfigFormSection<OpenProjectCfg>).key,
);
} else {
this.save.emit({
sectionKey: (this.section as ConfigFormSection<OpenProjectCfg>).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<OpenProjectCfg>).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<OpenProjectCfg>).key,
);
} else {
this.save.emit({
sectionKey: (this.section as ConfigFormSection<OpenProjectCfg>).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');

View File

@ -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: {

View File

@ -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": {