Fix Bug 2294: Incorrect notification in update descriptor
[osm/NG-UI.git] / src / app / roles / roles-create-edit / RolesCreateEditComponent.ts
index 87e1b86..59196ea 100644 (file)
@@ -70,6 +70,15 @@ export class RolesCreateEditComponent implements OnInit {
   /** 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;
 
@@ -193,7 +202,7 @@ export class RolesCreateEditComponent implements OnInit {
       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');
@@ -206,16 +215,15 @@ export class RolesCreateEditComponent implements OnInit {
       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);
         }
@@ -225,6 +233,11 @@ export class RolesCreateEditComponent implements OnInit {
 
   /** 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 : {}
@@ -233,7 +246,7 @@ export class RolesCreateEditComponent implements OnInit {
       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');
@@ -304,10 +317,12 @@ export class RolesCreateEditComponent implements OnInit {
         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');
       });
     }