Fixing bug with router state change 01/47801/3
authorIdan Amit <ia096e@intl.att.com>
Wed, 16 May 2018 11:32:01 +0000 (14:32 +0300)
committerMichael Lando <ml636r@att.com>
Mon, 21 May 2018 20:23:52 +0000 (20:23 +0000)
Fixing a bug on state change to "welcome" page and "previousState" state param.

Change-Id: I12be09166809c862766973be8fc3b567d47f955f
Issue-ID: SDC-1328
Signed-off-by: Idan Amit <ia096e@intl.att.com>
catalog-ui/src/app/app.ts

index e2240ed..723f244 100644 (file)
@@ -768,7 +768,9 @@ ng1appModule.run([
             console.info('$stateChangeStart', toState.name);
 
             if (toState.name !== 'error-403' && !userService.getLoggedinUser()) {
-                event.preventDefault();
+                if (toState.name !== 'welcome') {
+                    event.preventDefault();
+                }
 
                 userService.authorize().subscribe((userInfo:IUserProperties) => {
                     if (!doesUserHasAccess(toState, userInfo)) {
@@ -824,18 +826,20 @@ ng1appModule.run([
                 }
             }
 
+            // if enetering workspace, set the previousState param
+            if (toState.name.indexOf('workspace') !== -1) {
+                if (!toParams.previousState) {
+                    const tmpPreviousState1 = fromParams && fromParams.previousState;
+                    const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
+                    toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
+                }
+            }
+
         };
 
         let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => {
             console.info('$stateChangeSuccess', toState.name);
 
-            //saving last state to params , for breadcrumbs
-            if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
-                toParams.previousState = fromState.name;
-            } else {
-                toParams.previousState = fromParams.previousState;
-            }
-
             // Workaround in case we are entering other state then workspace (user move to catalog)
             // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
             if (toState.name.indexOf('workspace') === -1) {