Fix Bug 1978: Unable to view the NS Instances on switching between projects from... 44/11844/1
authorSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Tue, 5 Apr 2022 06:30:23 +0000 (12:00 +0530)
committerSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Tue, 5 Apr 2022 06:30:23 +0000 (12:00 +0530)
- On switching between projects assigned to a user from History of operations page,
  redirected to NSInstance page.

Change-Id: I046ddde4b9797dfe6fb747b26fa60ad81281304e
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
src/app/utilities/switch-project/SwitchProjectComponent.ts

index 1df6a16..dffb63a 100644 (file)
@@ -21,6 +21,7 @@
 import { HttpClient, HttpHeaders } from '@angular/common/http';
 import { Component, Injector, Input, OnInit } from '@angular/core';
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { Router } from '@angular/router';
 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
 import { APIURLHEADER, ERRORDATA, LOCALSTORAGE, URLPARAMS } from 'CommonModel';
 import { DataService } from 'DataService';
@@ -73,12 +74,16 @@ export class SwitchProjectComponent implements OnInit {
   /** FormBuilder instance added to the formBuilder @private */
   private formBuilder: FormBuilder;
 
+  /** Service holds the router information @private */
+  private router: Router;
+
   constructor(injector: Injector) {
     this.injector = injector;
     this.dataService = this.injector.get(DataService);
     this.restService = this.injector.get(RestService);
     this.activeModal = this.injector.get(NgbActiveModal);
     this.formBuilder = this.injector.get(FormBuilder);
+    this.router = this.injector.get(Router);
   }
 
   /** convenience getter for easy access to form fields */
@@ -126,10 +131,16 @@ export class SwitchProjectComponent implements OnInit {
           localStorage.setItem('project', data.project_name);
           localStorage.setItem('token_state', data.id);
           this.activeModal.close();
-          location.reload();
+          if (this.router.url.includes('history-operations')) {
+            this.router.navigate(['/instances/ns']).then((): void => {
+              location.reload();
+            }).catch();
+          } else {
+            location.reload();
+          }
           this.isLoadingResults = false;
         }
-      }, (error: ERRORDATA) => {
+      }, (error: ERRORDATA): void => {
         this.isLoadingResults = false;
         this.restService.handleError(error, 'post');
         this.activeModal.close();