From 6187c942bedebeb2f452ed0856652f90cd5c5772 Mon Sep 17 00:00:00 2001 From: Idan Amit Date: Sun, 15 Apr 2018 19:19:08 +0300 Subject: New observable notify design in pubsub Implemented the new subscription mechanism for the pub sub notify function Change-Id: I5e6484adf1a0413d48b54b55048cda1a59b387ee Issue-ID: SDC-1178 Signed-off-by: Idan Amit --- .../view-models/workspace/workspace-view-model.ts | 81 +++++++++++----------- 1 file changed, 41 insertions(+), 40 deletions(-) (limited to 'catalog-ui/src/app/view-models') diff --git a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts index 5d83c34db8..7fa25177f5 100644 --- a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts @@ -283,15 +283,14 @@ export class WorkspaceViewModel { 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(), - mode: WorkspaceMode.VIEW, - components: this.$state.params['components'] - }, {reload: true}); - + this.eventBusService.notify("VERSION_CHANGED", eventData).subscribe(() => { + this.$state.go(this.$state.current.name, { + id: selectedId, + type: this.$scope.componentType.toLowerCase(), + mode: WorkspaceMode.VIEW, + components: this.$state.params['components'] + }, {reload: true}); + }); }; this.$scope.getLatestVersion = ():void => { @@ -472,36 +471,38 @@ export class WorkspaceViewModel { switch (url) { case 'lifecycleState/CHECKOUT': - // only checkOut get the full component from server - // this.$scope.component = component; - // Work around to change the csar version - if (this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) { - (this.$scope.component).csarVersion = this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG); - } - - //when checking out a minor version uuid remains - const bcIdx = _.findIndex(this.components, (item) => { - return item.uuid === component.uuid; - }); - if (bcIdx !== -1) { - this.components[bcIdx] = component; - } else { - //when checking out a major(certified) version - this.components.unshift(component); - } - // this.$state.go(this.$state.current.name, { - // id: component.uniqueId, - // type: component.componentType.toLowerCase(), - // components: this.components - // }); - this.$scope.mode = this.initViewMode(); - this.initChangeLifecycleStateButtons(); - this.initVersionObject(); - this.$scope.isLoading = false; - this.EventListenerService.notifyObservers(EVENTS.ON_CHECKOUT, component); - this.Notification.success({ - message: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TEXT"), - title: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TITLE") + this.eventBusService.notify("CHECK_OUT", eventData).subscribe(() => { + // only checkOut get the full component from server + // this.$scope.component = component; + // Work around to change the csar version + if (this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) { + (this.$scope.component).csarVersion = this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG); + } + + //when checking out a minor version uuid remains + const bcIdx = _.findIndex(this.components, (item) => { + return item.uuid === component.uuid; + }); + if (bcIdx !== -1) { + this.components[bcIdx] = component; + } else { + //when checking out a major(certified) version + this.components.unshift(component); + } + // this.$state.go(this.$state.current.name, { + // id: component.uniqueId, + // type: component.componentType.toLowerCase(), + // components: this.components + // }); + this.$scope.mode = this.initViewMode(); + this.initChangeLifecycleStateButtons(); + this.initVersionObject(); + this.$scope.isLoading = false; + this.EventListenerService.notifyObservers(EVENTS.ON_CHECKOUT, component); + this.Notification.success({ + message: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TEXT"), + title: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TITLE") + }); }); break; case 'lifecycleState/CHECKIN': @@ -512,7 +513,7 @@ export class WorkspaceViewModel { }); break; case 'lifecycleState/UNDOCHECKOUT': - setTimeout(() => { + this.eventBusService.notify("UNDO_CHECK_OUT", eventData).subscribe(() => { defaultActionAfterChangeLifecycleState(); this.Notification.success({ message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"), -- cgit 1.2.3-korg