Fix Bug 2294: Incorrect notification in update descriptor 58/13958/3
authorSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Thu, 12 Oct 2023 09:01:00 +0000 (14:31 +0530)
committerSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Tue, 7 Nov 2023 05:47:43 +0000 (11:17 +0530)
- Fixed the update descriptor issue to show 'Please Change something'
  when no changes is made.

Change-Id: I042835c1934c1b94a8e8d880dae8d97b289750df
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
src/app/osm-repositories/osm-repo-create-update/OsmRepoCreateUpdateComponent.ts
src/app/projects/project-create-update/ProjectCreateUpdateComponent.ts
src/app/roles/roles-create-edit/RolesCreateEditComponent.ts
src/app/users/project-role/ProjectRoleComponent.ts
src/app/utilities/edit-packages/EditPackagesComponent.ts

index e653e7c..16ecadd 100644 (file)
@@ -139,7 +139,6 @@ export class OsmRepoCreateUpdateComponent implements OnInit {
     if (this.osmrepoForm.invalid) {
       return;
     }
-    this.isLoadingResults = true;
     const modalData: MODALCLOSERESPONSEDATA = {
       message: 'Done'
     };
@@ -160,10 +159,11 @@ export class OsmRepoCreateUpdateComponent implements OnInit {
 
   /** This function used to add the osm repo @public */
   public addOsmRepo(apiURLHeader: APIURLHEADER, modalData: MODALCLOSERESPONSEDATA): void {
+    this.isLoadingResults = true;
     this.restService.postResource(apiURLHeader, this.osmrepoForm.value).subscribe(() => {
+      this.isLoadingResults = false;
       this.activeModal.close(modalData);
       this.notifierService.notify('success', this.translateService.instant('PAGE.OSMREPO.CREATEDSUCCESSFULLY'));
-      this.isLoadingResults = false;
     }, (error: ERRORDATA) => {
       this.isLoadingResults = false;
       this.restService.handleError(error, 'post');
@@ -172,10 +172,15 @@ export class OsmRepoCreateUpdateComponent implements OnInit {
 
   /** This function used to Edit the osm repo @public */
   public editOsmRepo(apiURLHeader: APIURLHEADER, modalData: MODALCLOSERESPONSEDATA): void {
+    if (!this.osmrepoForm.dirty) {
+      this.notifierService.notify('warning', this.translateService.instant('PAGE.TOPOLOGY.DATAEMPTY'));
+      return;
+    }
+    this.isLoadingResults = true;
     this.restService.patchResource(apiURLHeader, this.osmrepoForm.value).subscribe(() => {
-      this.activeModal.close(modalData);
-      this.notifierService.notify('success', this.translateService.instant('PAGE.OSMREPO.UPDATEDSUCCESSFULLY'));
       this.isLoadingResults = false;
+      this.notifierService.notify('success', this.translateService.instant('PAGE.OSMREPO.UPDATEDSUCCESSFULLY'));
+      this.activeModal.close(modalData);
     }, (error: ERRORDATA) => {
       this.isLoadingResults = false;
       this.restService.handleError(error, 'patch');
index 9f8cc83..af6388d 100644 (file)
@@ -213,6 +213,10 @@ export class ProjectCreateUpdateComponent implements OnInit {
     }
     /** Edit project @public */
     public editProject(): void {
+        if (!this.projectForm.dirty) {
+            this.notifierService.notify('warning', this.translateService.instant('PAGE.TOPOLOGY.DATAEMPTY'));
+            return;
+        }
         this.isLoadingResults = true;
         const apiURLHeader: APIURLHEADER = {
             url: environment.PROJECTS_URL + '/' + this.projectRef
@@ -226,6 +230,7 @@ export class ProjectCreateUpdateComponent implements OnInit {
             this.isLoadingResults = false;
             this.projectService.setHeaderProjects();
             this.notifierService.notify('success', this.translateService.instant('PAGE.PROJECT.UPDATEDSUCCESSFULLY'));
+            this.activeModal.close(this.modalData);
         }, (error: ERRORDATA): void => {
             this.restService.handleError(error, 'patch');
             this.isLoadingResults = false;
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');
       });
     }
index 3a7e612..0c1121b 100644 (file)
@@ -210,6 +210,10 @@ export class ProjectRoleComponent implements OnInit {
             this.projectRoleMap.project_role_mappings.push({ project: res.project_name, role: res.role_name });
         });
         if (this.projectRoleMap.project_role_mappings.length !== 0) {
+            if (!this.projectRoleForm.dirty) {
+                this.notifierService.notify('warning', this.translateService.instant('PAGE.TOPOLOGY.DATAEMPTY'));
+                return;
+            }
             this.isLoadingResults = true;
             this.restService.patchResource(apiURLHeader, this.projectRoleMap).subscribe((result: {}): void => {
                 this.isLoadingResults = false;
index 42998b8..3cf75c9 100644 (file)
@@ -141,6 +141,9 @@ export class EditPackagesComponent implements OnInit {
   /** Data @private */
   private data: string = '';
 
+  /** Contains updated data @private */
+  private updateData: string;
+
   /** contains http options @private */
   private httpOptions: HttpHeaders;
 
@@ -239,7 +242,7 @@ export class EditPackagesComponent implements OnInit {
 
   /** Update function @public */
   public update(showgraph: boolean): void {
-    if (this.data === '') {
+    if (this.data === '' || this.data === this.updateData) {
       this.notifierService.notify('warning', this.translateService.instant('PAGE.TOPOLOGY.DATAEMPTY'));
     } else {
       this.updateCheck(showgraph);
@@ -255,11 +258,11 @@ export class EditPackagesComponent implements OnInit {
         if (packageType === 'nsd') {
           this.router.navigate(['/packages/ns/compose/' + this.paramsID]).catch((): void => {
             // Catch Navigation Error
-        });
+          });
         } else if (packageType === 'vnf') {
           this.router.navigate(['/packages/vnf/compose/' + this.paramsID]).catch((): void => {
             // Catch Navigation Error
-        });
+          });
         }
       }
       this.getEditFileData();
@@ -277,10 +280,11 @@ export class EditPackagesComponent implements OnInit {
     };
     let descriptorInfo: string = '';
     if (this.mode === 'text/json') {
-      descriptorInfo = jsyaml.dump(JSON.parse(this.data), {sortKeys: true});
+      descriptorInfo = jsyaml.dump(JSON.parse(this.data), { sortKeys: true });
     } else {
       descriptorInfo = this.data;
     }
+    this.updateData = this.data;
     if (this.getFileContentType !== 'nst') {
       this.sharedService.targzFile({ packageType: this.pacakgeType, id: this.paramsID, descriptor: descriptorInfo })
         .then((content: ArrayBuffer): void => {
@@ -309,10 +313,10 @@ export class EditPackagesComponent implements OnInit {
         this.isLoadingResults = false;
       }, (error: ERRORDATA) => {
         error.error = typeof error.error === 'string' ? jsyaml.load(error.error) : error.error;
-        if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED  ) {
+        if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) {
           this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => {
             // Catch Navigation Error
-        });
+          });
         } else {
           this.restService.handleError(error, 'get');
         }