Skip to content

Commit

Permalink
fix: handling change mode in detail
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Feb 23, 2024
1 parent 6bbb479 commit 910acbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/app/product-store/app-detail/app-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -464,24 +464,24 @@
<ng-template pTemplate="footer">
<div class="flex flex-wrap justify-content-end gap-2 mb-1">
<p-button
*ocxIfNotPermission="'APP#EDIT'"
id="app_search_button_close"
*ngIf="!allowEditing()"
id="app_detail_button_close"
[label]="'ACTIONS.NAVIGATION.CLOSE' | translate"
[title]="'ACTIONS.NAVIGATION.CLOSE.TOOLTIP' | translate"
(onClick)="onDialogHide()"
icon="pi pi-times"
></p-button>
<p-button
*ocxIfPermission="'APP#EDIT'"
id="app_search_button_cancel"
*ngIf="allowEditing()"
id="app_detail_button_cancel"
[label]="'ACTIONS.CANCEL' | translate"
[title]="'ACTIONS.TOOLTIPS.CANCEL' | translate"
(onClick)="onDialogHide()"
icon="pi pi-times"
></p-button>
<p-button
*ocxIfPermission="'APP#EDIT'"
id="app_search_button_save"
*ngIf="allowEditing()"
id="app_detail_button_save"
[label]="'ACTIONS.SAVE' | translate"
[title]="'ACTIONS.TOOLTIPS.SAVE' | translate"
(onClick)="onSave()"
Expand Down
24 changes: 21 additions & 3 deletions src/app/product-store/app-detail/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ export class AppDetailComponent implements OnChanges {
}

ngOnChanges() {
this.enableForms()
if (this.changeMode === 'CREATE') {
this.ms = undefined
this.mfe = undefined
this.formGroupMs.reset()
this.formGroupMfe.reset()
} else if (this.appAbstract?.id) {
}
if (this.appAbstract?.id) {
if (this.appAbstract.appType === 'MFE') this.getMfe()
if (this.appAbstract.appType === 'MS') this.getMs()
}
Expand All @@ -125,6 +127,22 @@ export class AppDetailComponent implements OnChanges {
}
}

public allowEditing(): boolean {
return (
(this.hasEditPermission && this.changeMode === 'EDIT') ||
(this.hasCreatePermission && this.changeMode === 'CREATE')
)
}
private enableForms(): void {
if (this.allowEditing()) {
this.formGroupMs.enable()
this.formGroupMfe.enable()
} else {
this.formGroupMs.disable()
this.formGroupMfe.disable()
}
}

public getMfe() {
this.loading = true
this.mfeApi
Expand All @@ -146,7 +164,7 @@ export class AppDetailComponent implements OnChanges {
this.mfe.modificationDate = undefined
}
this.changeMode = 'CREATE'
} else this.changeMode = 'EDIT'
} else this.enableForms()
}
}
})
Expand All @@ -172,7 +190,7 @@ export class AppDetailComponent implements OnChanges {
this.ms.modificationDate = undefined
}
this.changeMode = 'CREATE'
} else this.changeMode = 'EDIT'
} else this.enableForms()
}
}
})
Expand Down
4 changes: 3 additions & 1 deletion src/app/product-store/app-search/app-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
public displayDetailDialog = false
public displayDeleteDialog = false
public hasCreatePermission = false
public hasEditPermission = false
public hasDeletePermission = false
public limitText = limitText

Expand All @@ -74,6 +75,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
) {
this.hasCreatePermission = this.user.hasPermission('APP#CREATE')
this.hasDeletePermission = this.user.hasPermission('APP#DELETE')
this.hasEditPermission = this.user.hasPermission('APP#EDIT')
this.appSearchCriteriaGroup = new FormGroup<AppSearchCriteria>({
appId: new FormControl<string | null>(null),
//appName: new FormControl<string | null>(null),
Expand Down Expand Up @@ -287,7 +289,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
public onDetail(ev: any, app: AppAbstract) {
ev.stopPropagation()
this.app = app
this.changeMode = 'EDIT'
this.changeMode = this.hasEditPermission ? 'EDIT' : 'VIEW'
this.displayDetailDialog = true
}
public onCopy(ev: any, app: AppAbstract) {
Expand Down

0 comments on commit 910acbd

Please sign in to comment.