Developed disable navigation mechanism 03/46603/2
authorIdan Amit <ia096e@intl.att.com>
Mon, 7 May 2018 12:55:00 +0000 (15:55 +0300)
committerMichael Lando <ml636r@att.com>
Tue, 8 May 2018 13:33:05 +0000 (13:33 +0000)
Added a mechanism to disable and enable the navigation when waiting for a response from a plugin

Change-Id: I11cba9a7fc2a32e3d3d32fb9cf9f0590900fe73b
Issue-ID: SDC-1277
Signed-off-by: Idan Amit <ia096e@intl.att.com>
catalog-ui/src/app/models/base-pubsub.ts
catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.less
catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts
catalog-ui/src/app/ng2/services/event-bus.service.ts
catalog-ui/src/app/ng2/services/plugins.service.ts
catalog-ui/src/app/view-models/workspace/workspace-view-model.ts
catalog-ui/src/app/view-models/workspace/workspace.less

index b9ff788..c4b109f 100644 (file)
@@ -97,6 +97,12 @@ export class BasePubSub {
         }
     }
 
+    public isWaitingForEvent(eventName: string) : boolean {
+        return Array.from(this.eventsToWait.values()).some((eventsList: Array<string>) =>
+            eventsList.indexOf(eventName) !== -1
+        );
+    }
+
     protected onMessage(event: any) {
         if (this.subscribers.has(event.data.originId)) {
             this.eventsCallbacks.forEach((callback: Function) => {
index 4234987..d2d4c98 100644 (file)
@@ -4,5 +4,9 @@
         width: 100%;
         height: 100%;
         border: none;
+        top: 3px;
+        left: 2px;
+        position: relative;
+        z-index: 1030
     }
 }
index 4759721..83d302b 100644 (file)
@@ -1,4 +1,4 @@
-import {Component, Inject, Input, Output, OnInit, EventEmitter, ViewChild, ElementRef} from "@angular/core";
+import {Component, Inject, Input, Output, OnInit, EventEmitter} from "@angular/core";
 import {URLSearchParams} from '@angular/http';
 import {Plugin} from "app/models";
 import {EventBusService} from "../../../services/event-bus.service";
@@ -63,7 +63,6 @@ export class PluginFrameComponent implements OnInit {
 
                     this.eventBusService.notify("WINDOW_OUT").subscribe(() => {
                         this.isClosed = true;
-
                         this.eventBusService.unregister(this.plugin.pluginId);
 
                         this.$state.go(toState.name, toParams);
index 438437d..cff18e1 100644 (file)
@@ -49,4 +49,48 @@ export class EventBusService extends BasePubSub {
             this.handlePluginRegistration(event.data, event);
         }
     }
+
+    public disableNavigation(isDisable: boolean) {
+        if (isDisable) {
+            let disableDiv = document.createElement('div');
+            disableDiv.style.cssText = "position: fixed;\n" +
+                "z-index: 1029;\n" +
+                "background: rgba(0,0,0,0.5);\n" +
+                "width: 100%;\n" +
+                "height: 100%;\n" +
+                "top: 0;\n" +
+                "left: 0;";
+            disableDiv.setAttribute("class", "disable-navigation-div");
+            document.body.appendChild(disableDiv);
+        }
+        else {
+            document.getElementsByClassName("disable-navigation-div")[0].remove();
+        }
+    }
+
+    public notify(eventType:string, eventData?:any, disableOnWaiting:boolean=true) {
+        let doDisable = false;
+
+        if (disableOnWaiting) {
+            doDisable = this.isWaitingForEvent(eventType);
+
+            if (doDisable) {
+                this.disableNavigation(true);
+            }
+        }
+
+        const origSubscribe = super.notify(eventType, eventData).subscribe;
+
+        return {
+            subscribe: function (callbackFn) {
+                origSubscribe(() => {
+                    if (doDisable) {
+                        this.disableNavigation(false);
+                    }
+
+                    callbackFn();
+                });
+            }.bind(this)
+        };
+    }
 }
index 4ec90d1..7a85b6e 100644 (file)
@@ -19,5 +19,5 @@ export class PluginsService {
         return plugin.pluginDisplayOptions["context"] &&
                plugin.pluginDisplayOptions["context"].displayRoles.includes(userRole) &&
                plugin.pluginDisplayOptions["context"].displayContext.indexOf(contextType) !== -1
-    }
+    };
 }
index 3797707..9abd713 100644 (file)
@@ -276,7 +276,6 @@ export class WorkspaceViewModel {
                     return versionObj.versionId === this.$scope.component.uniqueId;
                 });
             }
-            this.$scope.isLoading = true;
 
             let eventData = {
                 uuid: this.$scope.component.uuid,
@@ -284,6 +283,8 @@ export class WorkspaceViewModel {
             };
 
             this.eventBusService.notify("VERSION_CHANGED", eventData).subscribe(() => {
+                this.$scope.isLoading = true;
+
                 this.$state.go(this.$state.current.name, {
                     id: selectedId,
                     type: this.$scope.componentType.toLowerCase(),
@@ -461,7 +462,7 @@ export class WorkspaceViewModel {
 
                 switch (url) {
                     case 'lifecycleState/CHECKOUT':
-                        this.eventBusService.notify("CHECK_OUT", eventData).subscribe(() => {
+                        this.eventBusService.notify("CHECK_OUT", eventData, false).subscribe(() => {
                             // only checkOut get the full component from server
                             //   this.$scope.component = component;
                             // Work around to change the csar version
@@ -503,7 +504,7 @@ export class WorkspaceViewModel {
                         });
                         break;
                     case 'lifecycleState/UNDOCHECKOUT':
-                        this.eventBusService.notify("UNDO_CHECK_OUT", eventData).subscribe(() => {
+                        this.eventBusService.notify("UNDO_CHECK_OUT", eventData, false).subscribe(() => {
                             defaultActionAfterChangeLifecycleState();
                             this.Notification.success({
                                 message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
index 84a3599..cee146a 100644 (file)
@@ -79,7 +79,7 @@
 
         padding: 0px 0px 0px 0px;
         background-color: @main_color_p;
-        z-index: 1;
+        //z-index: 1;
 
         .sdc-workspace-top-bar {
             height: @action_nav_height;