Add events hub notify calls 59/34259/2
authorIdan Amit <ia096e@intl.att.com>
Tue, 6 Mar 2018 11:52:58 +0000 (13:52 +0200)
committerMichael Lando <ml636r@att.com>
Wed, 7 Mar 2018 06:56:36 +0000 (06:56 +0000)
Added events hub notify calls.
Fixed issues raised by development across the publish subscribe mechanism development

Change-Id: I0768bdcb2d89f99634cdb6bc7cb75e20263f5c00
Issue-ID: SDC-1029
Signed-off-by: Idan Amit <ia096e@intl.att.com>
15 files changed:
catalog-ui/src/app/app.ts
catalog-ui/src/app/models/base-pubsub.ts
catalog-ui/src/app/modules/service-module.ts
catalog-ui/src/app/ng2/app.module.ts
catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts
catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.module.ts
catalog-ui/src/app/ng2/utils/ng1-upgraded-provider.ts
catalog-ui/src/app/services/components/component-service.ts
catalog-ui/src/app/services/components/resource-service.ts
catalog-ui/src/app/services/components/service-service.ts
catalog-ui/src/app/view-models/plugins/plugins-tab-view-model.ts
catalog-ui/src/app/view-models/plugins/plugins-tab-view.html
catalog-ui/src/app/view-models/workspace/tabs/plugins/plugins-context-view-model.ts
catalog-ui/src/app/view-models/workspace/tabs/plugins/plugins-context-view.html
catalog-ui/src/app/view-models/workspace/workspace-view-model.ts

index d67f158..e44e4ee 100644 (file)
@@ -153,7 +153,7 @@ angular.module('sdcApp').directive('ng2SearchWithAutocomplete',
         inputs: ['searchPlaceholder', 'searchBarClass', 'autoCompleteValues'],
         outputs: ['searchChanged', 'searchButtonClicked']
     }) as angular.IDirectiveFactory);
-angular.module('sdcApp').directive('pluginFrame', downgradeComponent( {component: PluginFrameComponent, inputs: ['plugin', 'queryParams']} ) as angular.IDirectiveFactory);
+angular.module('sdcApp').directive('pluginFrame', downgradeComponent( {component: PluginFrameComponent, inputs: ['plugin', 'queryParams'], outputs: ['onLoadingDone']} ) as angular.IDirectiveFactory);
 
 ng1appModule.config([
     '$stateProvider',
index ca500ca..ca313b1 100644 (file)
@@ -37,7 +37,7 @@ export class BasePubSub {
         this.eventsCallbacks.splice(index, 1)
     }
 
-    public notify(eventType:string, eventData:any) {
+    public notify(eventType:string, eventData?:any) {
         let eventObj = {
             type: eventType,
             data: eventData,
@@ -60,9 +60,9 @@ export class BasePubSub {
 
 export class PluginPubSub extends BasePubSub {
 
-    constructor(pluginId: string, subscriberUrl: string) {
+    constructor(pluginId: string, parentUrl: string) {
         super(pluginId);
-        this.register('sdc-hub', window.parent, subscriberUrl);
+        this.register('sdc-hub', window.parent, parentUrl);
         this.subscribe();
     }
 
index 87a435d..387332c 100644 (file)
@@ -52,6 +52,7 @@ import {ConnectionWizardService} from "../ng2/pages/connection-wizard/connection
 import {ComponentInstanceServiceNg2} from "../ng2/services/component-instance-services/component-instance.service";
 import {UserService as UserServiceNg2} from "../ng2/services/user.service";
 import {PluginsService} from "../ng2/services/plugins.service";
+import {EventBusService} from "../ng2/services/event-bus.service";
 
 let moduleName:string = 'Sdc.Services';
 let serviceModule:ng.IModule = angular.module(moduleName, []);
@@ -97,3 +98,4 @@ serviceModule.factory('ConnectionWizardServiceNg2', downgradeInjectable(Connecti
 serviceModule.factory('ComponentInstanceServiceNg2', downgradeInjectable(ComponentInstanceServiceNg2));
 serviceModule.factory('UserServiceNg2', downgradeInjectable(UserServiceNg2));
 serviceModule.factory('PluginsService', downgradeInjectable(PluginsService));
+serviceModule.factory('EventBusService', downgradeInjectable(EventBusService));
index 0346b10..ffeb1fd 100644 (file)
@@ -28,7 +28,7 @@ import {UpgradeModule} from '@angular/upgrade/static';
 import {PropertiesAssignmentModule} from './pages/properties-assignment/properties-assignment.module';
 import {
     DataTypesServiceProvider, SharingServiceProvider, CookieServiceProvider, StateServiceFactory,
-    StateParamsServiceFactory, CacheServiceProvider, EventListenerServiceProvider
+    StateParamsServiceFactory, CacheServiceProvider, EventListenerServiceProvider, ScopeServiceFactory
 } from "./utils/ng1-upgraded-provider";
 import {ConfigService} from "./services/config.service";
 import {HttpModule} from '@angular/http';
@@ -85,6 +85,7 @@ export function configServiceFactory(config:ConfigService) {
         SharingServiceProvider,
         CookieServiceProvider,
         StateServiceFactory,
+        ScopeServiceFactory,
         StateParamsServiceFactory,
         CacheServiceProvider,
         EventListenerServiceProvider,
index 801dfa9..eb7d138 100644 (file)
@@ -1,27 +1,32 @@
-import {Component, OnInit, Input} from "@angular/core";
-import { URLSearchParams } from '@angular/http';
+import {Component, Inject, Input, Output, OnInit, EventEmitter, ViewChild, ElementRef} from "@angular/core";
+import {URLSearchParams} from '@angular/http';
 import {Plugin} from "app/models";
+import {EventBusService} from "../../../services/event-bus.service";
 
 @Component({
     selector: 'plugin-frame',
     templateUrl: './plugin-frame.component.html',
-    styleUrls:['plugin-frame.component.less']
+    styleUrls: ['plugin-frame.component.less']
 })
 
 export class PluginFrameComponent implements OnInit {
 
     @Input() plugin: Plugin;
     @Input() queryParams: Object;
+    @Output() onLoadingDone: EventEmitter<void> = new EventEmitter<void>();
     pluginUrl: string;
     private urlSearchParams: URLSearchParams;
+    private isClosed: boolean;
 
-    constructor() {
+    constructor(private eventBusService: EventBusService,
+                @Inject('$scope') private $scope: ng.IScope,
+                @Inject('$state') private $state: ng.ui.IStateService) {
         this.urlSearchParams = new URLSearchParams();
     }
 
     ngOnInit(): void {
-
         this.pluginUrl = this.plugin.pluginSourceUrl;
+        this.isClosed = false;
 
         if (this.queryParams && !_.isEmpty(this.queryParams)) {
             _.forOwn(this.queryParams, (value, key) => {
@@ -31,5 +36,31 @@ export class PluginFrameComponent implements OnInit {
             this.pluginUrl += '?';
             this.pluginUrl += this.urlSearchParams.toString();
         }
+
+        this.eventBusService.on((eventData) => {
+            if (eventData.originId === this.plugin.pluginId) {
+                if (eventData.type == "READY") {
+                    this.onLoadingDone.emit();
+                }
+            }
+        });
+
+        // Listening to the stateChangeStart event in order to notify the plugin about it being closed
+        // before moving to a new state
+        this.$scope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
+            if (fromState.name !== toState.name) {
+                if (!this.isClosed) {
+                    event.preventDefault();
+
+                    this.eventBusService.notify("WINDOW_OUT");
+
+                    this.isClosed = true;
+
+                    setTimeout(() => {
+                        this.$state.go(toState.name, toParams);
+                    });
+                }
+            }
+        });
     }
 }
index 81b99cc..9eebd5c 100644 (file)
@@ -3,6 +3,7 @@ import { CommonModule } from '@angular/common';
 import {PluginFrameComponent} from "./plugin-frame.component";
 import {LayoutModule} from "../../layout/layout.module";
 import {GlobalPipesModule} from "../../../pipes/global-pipes.module";
+import {UiElementsModule} from "../ui-elements.module";
 
 
 @NgModule({
@@ -12,7 +13,8 @@ import {GlobalPipesModule} from "../../../pipes/global-pipes.module";
     imports: [
         CommonModule,
         LayoutModule,
-        GlobalPipesModule
+        GlobalPipesModule,
+        UiElementsModule
     ],
     entryComponents: [PluginFrameComponent],
     exports: [
index c21817c..51314c0 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -46,6 +46,10 @@ export function stateServiceFactory(cacheObj: ICacheObject) {
     return cacheObj.get('$state');
 }
 
+export function scopeServiceFactory(cacheObj: ICacheObject) {
+    return cacheObj.get('$scope');
+}
+
 export function stateParamsServiceFactory(cacheObj: ICacheObject) {
     return cacheObj.get('$stateParams');
 }
@@ -84,6 +88,12 @@ export const StateServiceFactory = {
     deps: ['$injector']
 };
 
+export const ScopeServiceFactory= {
+    provide: '$scope',
+    useFactory: scopeServiceFactory,
+    deps: ['$injector']
+};
+
 export const StateParamsServiceFactory = {
     provide: '$stateParams',
     useFactory: stateParamsServiceFactory,
index 90ae850..1b2b9f2 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,6 +23,7 @@ import {ArtifactModel, IFileDownload, InstancesInputsPropertiesMap, InputModel,
 import {ComponentInstanceFactory, CommonUtils} from "app/utils";
 import {SharingService} from "../sharing-service";
 import {ComponentMetadata} from "../../models/component-metadata";
+import {EventBusService} from "../../ng2/services/event-bus.service";
 
 export interface IComponentService {
 
@@ -79,14 +80,16 @@ export class ComponentService implements IComponentService {
         'sdcConfig',
         'Sdc.Services.SharingService',
         '$q',
-        '$base64'
+        '$base64',
+        'EventBusService'
     ];
 
     constructor(protected restangular:restangular.IElement,
                 protected sdcConfig:IAppConfigurtaion,
                 protected sharingService:SharingService,
                 protected $q:ng.IQService,
-                protected $base64:any
+                protected $base64:any,
+                protected eventBusService:EventBusService
                ) {
 
         this.restangular.setBaseUrl(sdcConfig.api.root + sdcConfig.api.component_api_root);
@@ -224,6 +227,17 @@ export class ComponentService implements IComponentService {
         }, (err)=> {
             deferred.reject(err);
         });
+
+        // Notifying about events before executing the actual actions
+        switch (state) {
+            case "checkIn":
+                this.eventBusService.notify("CHECK_IN");
+                break;
+            case "submitForTesting":
+                this.eventBusService.notify("SUBMIT_FOR_TESTING");
+                break;
+        }
+
         return deferred.promise;
     };
 
index 472775e..641d7cb 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,6 +25,7 @@
 import {IComponentService, ComponentService} from "./component-service";
 import {PropertyModel, IAppConfigurtaion, Resource, Component} from "../../models";
 import {SharingService} from "../sharing-service";
+import {EventBusService} from "../../ng2/services/event-bus.service";
 
 export interface IResourceService extends IComponentService {
     updateResourceGroupProperties(uniqueId:string, groupId:string, properties:Array<PropertyModel>):ng.IPromise<Array<PropertyModel>>
@@ -37,16 +38,18 @@ export class ResourceService extends ComponentService implements IResourceServic
         'sdcConfig',
         'Sdc.Services.SharingService',
         '$q',
-        '$base64'
+        '$base64',
+        'EventBusService'
     ];
 
     constructor(protected restangular:restangular.IElement,
                 protected sdcConfig:IAppConfigurtaion,
                 protected sharingService:SharingService,
                 protected $q:ng.IQService,
-                protected $base64:any
+                protected $base64:any,
+                protected eventBusService:EventBusService
                 ) {
-        super(restangular, sdcConfig, sharingService, $q, $base64);
+        super(restangular, sdcConfig, sharingService, $q, $base64, eventBusService);
 
         this.restangular = restangular.one("resources");
     }
index f92f569..4229c4a 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,6 +25,7 @@
 import {IComponentService, ComponentService} from "./component-service";
 import {Distribution, DistributionComponent, Service, PropertyModel, Component, IAppConfigurtaion} from "app/models";
 import {SharingService} from "../sharing-service";
+import {EventBusService} from "../../ng2/services/event-bus.service";
 
 export interface IServiceService extends IComponentService {
     getDistributionsList(uuid:string):ng.IPromise<Array<Distribution>>;
@@ -49,8 +50,9 @@ export class ServiceService extends ComponentService implements IServiceService
                 protected sdcConfig:IAppConfigurtaion,
                 protected sharingService:SharingService,
                 protected $q:ng.IQService,
-                protected $base64:any) {
-        super(restangular, sdcConfig, sharingService, $q, $base64);
+                protected $base64:any,
+                protected eventBusService:EventBusService) {
+        super(restangular, sdcConfig, sharingService, $q, $base64, eventBusService);
 
         this.restangular = restangular.one("services");
     }
index 5e2a599..438cf4a 100644 (file)
@@ -8,6 +8,9 @@ interface IPluginsTabViewModelScope extends ng.IScope {
     user: IUserProperties;
     version: string;
     queryParams: Object;
+    isLoading: boolean;
+
+    onLoadingDone(plugin: Plugin): void;
 }
 
 export class PluginsTabViewModel {
@@ -27,17 +30,23 @@ export class PluginsTabViewModel {
     }
 
     private initScope = ():void => {
+        this.$scope.isLoading = true;
         this.$scope.plugin = this.pluginsService.getPluginByStateUrl(this.$stateParams.path);
-
         this.$scope.version = this.cacheService.get('version');
-
         this.$scope.user = this.cacheService.get('user');
 
         this.$scope.queryParams = {
             userId: this.$scope.user.userId,
             userRole: this.$scope.user.role,
             displayType: "tab",
-            parentUrl: window.location.origin
+            parentUrl: window.location.origin,
+            eventsClientId: this.$scope.plugin.pluginId
+        };
+
+        this.$scope.onLoadingDone = (plugin: Plugin) => {
+            if (plugin.pluginId == this.$scope.plugin.pluginId) {
+                this.$scope.isLoading = false;
+            }
         };
     }
 }
index 3695434..bc404b4 100644 (file)
@@ -1,7 +1,5 @@
 <div class="sdc-catalog-container">
-
+    <loader display="isLoading"></loader>
     <top-nav [version]="version" [hide-search]="true"></top-nav>
-
-    <plugin-frame [plugin]="plugin" [query-params]="queryParams"></plugin-frame>
-
+    <plugin-frame (on-loading-done)="onLoadingDone(plugin)" [plugin]="plugin" [query-params]="queryParams"></plugin-frame>
 </div>
index 959aead..550fb84 100644 (file)
@@ -8,6 +8,9 @@ interface IPluginsContextViewModelScope extends IWorkspaceViewModelScope {
     plugin: Plugin;
     user:IUserProperties;
     queryParams: Object;
+    isLoading: boolean;
+
+    onLoadingDone(plugin: Plugin): void;
 }
 
 export class PluginsContextViewModel {
@@ -27,8 +30,8 @@ export class PluginsContextViewModel {
     }
 
     private initScope = ():void => {
+        this.$scope.isLoading = true;
         this.$scope.plugin = this.pluginsService.getPluginByStateUrl(this.$stateParams.path);
-
         this.$scope.user = this.cacheService.get('user');
 
         this.$scope.queryParams = {
@@ -40,7 +43,14 @@ export class PluginsContextViewModel {
             lifecycleState: this.$scope.component.lifecycleState,
             isOwner: this.$scope.component.lastUpdaterUserId === this.$scope.user.userId,
             version: this.$scope.component.version ,
-            parentUrl: window.location.origin
+            parentUrl: window.location.origin,
+            eventsClientId: this.$scope.plugin.pluginId
+        };
+
+        this.$scope.onLoadingDone = (plugin: Plugin) => {
+            if (plugin.pluginId == this.$scope.plugin.pluginId) {
+                this.$scope.isLoading = false;
+            }
         };
 
     }
index e155370..d70717a 100644 (file)
@@ -1,5 +1,4 @@
+<loader display="isLoading"></loader>
 <div class="workspace-plugins">
-
-    <plugin-frame [plugin]="plugin" [query-params]="queryParams"></plugin-frame>
-
+    <plugin-frame (on-loading-done)="onLoadingDone(plugin)" [plugin]="plugin" [query-params]="queryParams"></plugin-frame>
 </div>
index 0f9d759..ca34d6f 100644 (file)
@@ -35,6 +35,7 @@ import {
     LeftPaletteLoaderService
 } from "app/services";
 import {FileUploadModel} from "../../directives/file-upload/file-upload";
+import {EventBusService} from "../../ng2/services/event-bus.service";
 
 
 export interface IWorkspaceViewModelScope extends ng.IScope {
@@ -115,7 +116,8 @@ export class WorkspaceViewModel {
         'Sdc.Services.EntityService',
         'Notification',
         '$stateParams',
-        'Sdc.Services.ProgressService'
+        'Sdc.Services.ProgressService',
+        'EventBusService'
     ];
 
     constructor(private $scope:IWorkspaceViewModelScope,
@@ -134,7 +136,8 @@ export class WorkspaceViewModel {
                 private EntityService:EntityService,
                 private Notification:any,
                 private $stateParams:any,
-                private progressService:ProgressService) {
+                private progressService:ProgressService,
+                private eventBusService:EventBusService) {
 
         this.initScope();
         this.initAfterScope();
@@ -216,6 +219,10 @@ export class WorkspaceViewModel {
             }
         };
 
+        this.$scope.$on('$stateChangeSuccess', (event, toState) => {
+            this.$scope.updateSelectedMenuItem(this.$state.current.name);
+        });
+
         this.$scope.onMenuItemPressed = (state:string, params:any):ng.IPromise<boolean> => {
             let deferred = this.$q.defer();
             let goToState = ():void => {
@@ -223,9 +230,7 @@ export class WorkspaceViewModel {
                     id: this.$scope.component.uniqueId,
                     type: this.$scope.component.componentType.toLowerCase(),
                     components: this.components
-                }, params)).then(() => {
-                    this.$scope.updateSelectedMenuItem(state);
-                });
+                }, params));
                 deferred.resolve(true);
             };
             if (this.isNeedSave()) {
@@ -266,6 +271,14 @@ export class WorkspaceViewModel {
                 });
             }
             this.$scope.isLoading = true;
+
+            let eventData = {
+                uuid: this.$scope.component.uuid,
+                version: this.$scope.changeVersion.selectedVersion.versionNumber
+            };
+
+            this.eventBusService.notify("VERSION_CHANGED", eventData);
+
             this.$state.go(this.$state.current.name, {
                 id: selectedId,
                 type: this.$scope.componentType.toLowerCase(),
@@ -426,6 +439,22 @@ export class WorkspaceViewModel {
             let onSuccess = (component:Component, url:string):void => {
                 //Updating the component from server response
 
+                // Creating the data object to notify the plugins with
+                let eventData: any = {
+                    uuid: this.$scope.component.uuid,
+                    version: this.$scope.component.version
+                };
+
+                // Notifying about events after successfully executing the actions
+                switch (state) {
+                    case "checkOut":
+                        this.eventBusService.notify("CHECK_OUT", eventData);
+                        break;
+                    case "deleteVersion":
+                        this.eventBusService.notify("UNDO_CHECK_OUT", eventData);
+                        break;
+                }
+
                 //the server returns only metaData (small component) except checkout (Full component)  ,so we update only the statuses of distribution & lifecycle
                 this.$scope.component.lifecycleState = component.lifecycleState;
                 this.$scope.component.distributionStatus = component.distributionStatus;
@@ -472,10 +501,12 @@ export class WorkspaceViewModel {
                         });
                         break;
                     case 'lifecycleState/UNDOCHECKOUT':
-                        defaultActionAfterChangeLifecycleState();
-                        this.Notification.success({
-                            message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
-                            title: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TITLE")
+                        setTimeout(() => {
+                            defaultActionAfterChangeLifecycleState();
+                            this.Notification.success({
+                                message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
+                                title: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TITLE")
+                            });
                         });
                         break;
                     case 'lifecycleState/certificationRequest':
@@ -550,6 +581,7 @@ export class WorkspaceViewModel {
                 }
             };
             //this.$scope.isLoading = true;
+
             this.ChangeLifecycleStateHandler.changeLifecycleState(this.$scope.component, data, this.$scope, onSuccess);
         };