/** Contains view selection value either text or preview @public */
public viewMode: string = 'text';
+ /** Contains current permissions data @private */
+ private currentPermissions: string;
+
+ /** Contains current role name @private */
+ private currentRoleName: string;
+
+ /** Contains modified role name @private */
+ private modifiedRoleName: string;
+
/** Contains role id value @private */
private roleRef: string;
this.notifierService.notify('success', this.translateService.instant('PAGE.ROLES.CREATEDSUCCESSFULLY'));
this.router.navigate(['/roles/details']).catch((): void => {
// Catch Navigation Error
- });
+ });
}, (error: ERRORDATA) => {
this.isLoadingResults = false;
this.restService.handleError(error, 'post');
url: environment.ROLES_URL + '/' + this.roleRef,
httpOptions: { headers: this.headers }
};
+ this.modifiedRoleName = this.roleForm.value.roleName;
let permissionData: Object = {};
this.sharedService.cleanForm(this.roleForm);
if (!this.roleForm.invalid) {
if (this.viewMode === 'preview') {
- this.isLoadingResults = true;
permissionData = this.generatePermissions();
this.roleEditAPI(apiURLHeader, permissionData);
} else {
if (this.checkPermission()) {
- this.isLoadingResults = true;
permissionData = this.roleForm.value.permissions !== '' ? JSON.parse(this.roleForm.value.permissions) : {};
this.roleEditAPI(apiURLHeader, permissionData);
}
/** Method to handle role edit API call */
public roleEditAPI(apiURLHeader: APIURLHEADER, permissionData: {}): void {
+ if ((JSON.stringify(permissionData, null, '\t') === this.currentPermissions) && (this.modifiedRoleName === this.currentRoleName)) {
+ this.notifierService.notify('warning', this.translateService.instant('PAGE.TOPOLOGY.DATAEMPTY'));
+ return;
+ }
+ this.isLoadingResults = true;
const postData: {} = {
name: this.roleForm.value.roleName,
permissions: !isNullOrUndefined(permissionData) ? permissionData : {}
this.notifierService.notify('success', this.translateService.instant('PAGE.ROLES.UPDATEDSUCCESSFULLY'));
this.router.navigate(['/roles/details']).catch((): void => {
// Catch Navigation Error
- });
+ });
}, (error: ERRORDATA) => {
this.isLoadingResults = false;
this.restService.handleError(error, 'patch');
this.roleForm.setValue({ roleName: data.name, permissions: JSON.stringify(data.permissions, null, '\t') });
this.filterRoleData(data.permissions);
this.isLoadingResults = false;
+ this.currentRoleName = data.name;
+ this.currentPermissions = JSON.stringify(data.permissions, null, '\t');
}, (error: ERRORDATA) => {
this.router.navigate(['/roles/details']).catch((): void => {
// Catch Navigation Error
- });
+ });
this.restService.handleError(error, 'get');
});
}