2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 * Created by obarda on 3/30/2016.
25 import * as _ from 'lodash';
37 MenuItem, ModalsHandler, States, EVENTS, CHANGE_COMPONENT_CSAR_VERSION_FLAG, ResourceType, PREVIOUS_CSAR_COMPONENT,
38 WorkspaceMode, ComponentFactory, ChangeLifecycleStateHandler, Role, ComponentState, MenuItemGroup, MenuHandler
42 LeftPaletteLoaderService,
44 } from 'app/services';
47 } from 'app/services-ng2';
48 import { AutomatedUpgradeService } from '../../ng2/pages/automated-upgrade/automated-upgrade.service';
49 import { CatalogService } from '../../ng2/services/catalog.service';
50 import { ComponentServiceNg2 } from '../../ng2/services/component-services/component.service';
51 import { EventBusService } from '../../ng2/services/event-bus.service';
52 import { HomeService } from '../../ng2/services/home.service';
53 import { PluginsService } from '../../ng2/services/plugins.service';
54 import { IDependenciesServerResponse } from '../../ng2/services/responses/dependencies-server-response';
55 import { WorkspaceNg1BridgeService } from '../../ng2/pages/workspace/workspace-ng1-bridge-service';
56 import { WorkspaceService } from '../../ng2/pages/workspace/workspace.service';
58 export interface IWorkspaceViewModelScope extends ng.IScope {
61 isCreateProgress: boolean;
63 originComponent: Component;
64 componentType: string;
66 leftBarTabs: MenuItemGroup;
68 isFromImport: boolean;
70 isActiveTopBar: boolean;
72 breadcrumbsModel: Array<MenuItemGroup>;
74 changeLifecycleStateButtons: any;
76 versionsList: Array<any>;
78 isComposition: boolean;
79 isDeployment: boolean;
81 $state: ng.ui.IStateService;
82 user: IUserProperties;
84 disabledButtons: boolean;
85 menuComponentTitle: string;
86 progressService: ProgressService;
87 progressMessage: string;
88 ComponentServiceNg2: ComponentServiceNg2;
89 // leftPanelComponents:Array<Models.Components.Component>; //this is in order to load the left panel once, and not wait long time when moving to composition
90 unsavedChanges: boolean;
91 unsavedChangesCallback: Function;
93 hasNoDependencies: boolean;
94 models: Array<string>;
96 startProgress(message: string): void;
98 updateBreadcrumbs(component: Component): void;
99 updateUnsavedFileFlag(isUnsaved: boolean): void;
100 showChangeStateButton(): boolean;
101 getComponent(): Component;
102 setComponent(component: Component): void;
103 setOriginComponent(component: Component): void;
104 onMenuItemPressed(state: string, params: any): ng.IPromise<boolean>;
106 save(): Promise<void>;
107 setValidState(isValid: boolean): void;
108 changeLifecycleState(state: string): void;
109 handleChangeLifecycleState(state: string, newCsarVersion?: string, errorFunction?: Function): void;
110 disableMenuItems(): void;
111 enableMenuItems(): void;
112 isDesigner(): boolean;
113 isViewMode(): boolean;
114 isEditMode(): boolean;
115 isCreateMode(): boolean;
116 isDisableMode(): boolean;
117 isGeneralView(): boolean;
118 goToBreadcrumbHome(): void;
119 onVersionChanged(selectedId: string): void;
120 getLatestVersion(): void;
122 showLifecycleIcon(): boolean;
123 updateSelectedMenuItem(state: string): void;
124 isSelected(menuItem: MenuItem): boolean;
125 uploadFileChangedInGeneralTab(): void;
126 updateMenuComponentName(ComponentName: string): void;
127 getTabTitle(): string;
128 reload(component: Component): void;
131 export class WorkspaceViewModel {
141 'Sdc.Services.CacheService',
142 'ChangeLifecycleStateHandler',
143 'LeftPaletteLoaderService',
145 'EventListenerService',
150 'Sdc.Services.ProgressService',
151 'ComponentServiceNg2',
152 'AutomatedUpgradeService',
155 'WorkspaceNg1BridgeService',
159 constructor(private $scope: IWorkspaceViewModelScope,
160 private injectComponent: Component,
161 private ComponentFactory: ComponentFactory,
162 private $state: ng.ui.IStateService,
163 private sdcMenu: IAppMenu,
164 private $q: ng.IQService,
165 private MenuHandler: MenuHandler,
166 private cacheService: CacheService,
167 private ChangeLifecycleStateHandler: ChangeLifecycleStateHandler,
168 private LeftPaletteLoaderService: LeftPaletteLoaderService,
169 private $filter: ng.IFilterService,
170 private EventListenerService: EventListenerService,
171 private Notification: any,
172 private $stateParams: any,
173 private homeService: HomeService,
174 private catalogService: CatalogService,
175 private progressService: ProgressService,
176 private ComponentServiceNg2: ComponentServiceNg2,
177 private AutomatedUpgradeService: AutomatedUpgradeService,
178 private eventBusService: EventBusService,
179 private pluginsService: PluginsService,
180 private workspaceNg1BridgeService: WorkspaceNg1BridgeService,
181 private workspaceService: WorkspaceService) {
184 // this.initAfterScope();
185 this.$scope.updateSelectedMenuItem(this.$state.current.name);
188 private role: string;
189 private category: string;
190 private components: Component[];
192 private initViewMode = ():WorkspaceMode => {
193 let mode = WorkspaceMode.VIEW;
195 if (!this.$state.params['id']) { //&& !this.$state.params['vspComponent']
196 mode = WorkspaceMode.CREATE;
198 if (this.$scope.component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKOUT &&
199 this.$scope.component.lastUpdaterUserId === this.cacheService.get('user').userId) {
200 if ((this.$scope.component.isService() || this.$scope.component.isResource()) && this.role === Role.DESIGNER) {
201 mode = WorkspaceMode.EDIT;
205 this.workspaceNg1BridgeService.updateIsViewOnly(mode === WorkspaceMode.VIEW);
209 private initChangeLifecycleStateButtons = (): void => {
211 if (this.$scope.component.isService() && this.$scope.component.lifecycleState === 'CERTIFIED') {
212 state = this.$scope.component.distributionStatus;
214 state = this.$scope.component.lifecycleState;
216 this.$scope.changeLifecycleStateButtons = (this.sdcMenu.roles[this.role].changeLifecycleStateButtons[state] || [])[this.$scope.component.componentType.toUpperCase()];
219 private initScope = (): void => {
220 this.$scope.component = this.injectComponent;
221 this.$scope.menuComponentTitle = this.$scope.component.name;
222 this.$scope.disabledButtons = false;
223 this.$scope.originComponent = this.ComponentFactory.createComponent(this.$scope.component);
224 this.$scope.componentType = this.$scope.component.componentType;
225 this.$scope.version = this.cacheService.get('version');
226 this.$scope.user = this.cacheService.get('user');
227 this.role = this.$scope.user.role;
228 this.category = this.$scope.component.selectedCategory;
229 this.$scope.mode = this.initViewMode();
230 this.$scope.isValidForm = true;
231 this.initChangeLifecycleStateButtons();
232 this.initVersionObject();
233 this.$scope.$state = this.$state;
234 this.$scope.isLoading = false;
235 this.$scope.isComposition = (this.$state.current.name.indexOf(States.WORKSPACE_COMPOSITION) > -1);
236 this.$scope.isDeployment = this.$state.current.name == States.WORKSPACE_DEPLOYMENT;
237 this.$scope.progressService = this.progressService;
238 this.$scope.unsavedChanges = false;
240 this.$scope.hasNoDependencies = true;
241 this.verifyIfDependenciesExist();
243 this.EventListenerService.registerObserverCallback(EVENTS.ON_WORKSPACE_UNSAVED_CHANGES, this.setWorkspaceButtonState);
244 this.$scope.getComponent = (): Component => {
245 return this.$scope.component;
248 this.$scope.updateMenuComponentName = (ComponentName:string):void => {
249 this.$scope.menuComponentTitle = ComponentName;
252 this.$scope.sdcMenu = this.sdcMenu;
253 // Will be called from each step after save to update the resource.
254 this.$scope.setComponent = (component:Component):void => {
255 this.$scope.component = component;
258 this.$scope.setOriginComponent = (component:Component):void => {
259 this.$scope.originComponent = component;
262 this.$scope.uploadFileChangedInGeneralTab = ():void => {
263 // In case user select browse file, and in update mode, need to disable submit for testing and checkin buttons.
264 if (this.$scope.isEditMode() && this.$scope.component.isResource() && (<Resource>this.$scope.component).resourceType == ResourceType.VF) {
265 // NOTE: Commented out the disabling of the workspace buttons on CSAR updating due fix of a bug [417534]
266 // this.$scope.disabledButtons = true;
270 this.$scope.archiveComponent = ():void => {
271 this.$scope.isLoading = true;
272 const typeComponent = this.$scope.component.componentType;
273 this.ComponentServiceNg2.archiveComponent(typeComponent, this.$scope.component.uniqueId).subscribe(()=> {
274 this.$scope.isLoading = false;
275 if (this.$state.params.previousState) {
276 switch (this.$state.params.previousState) {
279 this.$state.go(this.$state.params.previousState);
285 this.$scope.component.archived = true;
286 this.deleteArchiveCache();
288 this.Notification.success({
289 message: this.$scope.component.name + ' ' + this.$filter('translate')("ARCHIVE_SUCCESS_MESSAGE_TEXT"),
290 title: this.$filter('translate')("ARCHIVE_SUCCESS_MESSAGE_TITLE")
292 }, (error) => { this.$scope.isLoading = false; });
295 this.$scope.restoreComponent = ():void => {
296 this.$scope.isLoading = true;
297 const typeComponent = this.$scope.component.componentType;
298 this.ComponentServiceNg2.restoreComponent(typeComponent, this.$scope.component.uniqueId).subscribe(()=> {
299 this.$scope.isLoading = false;
300 this.Notification.success({
301 message: this.$scope.component.name + ' ' + this.$filter('translate')("RESTORE_SUCCESS_MESSAGE_TEXT"),
302 title: this.$filter('translate')("RESTORE_SUCCESS_MESSAGE_TITLE")
305 this.$scope.component.archived = false;
306 this.deleteArchiveCache();
309 this.$scope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams) => {
310 if(this.$scope.isEditMode()){
311 if (fromParams.id == toParams.id && this.$state.current.data && this.$state.current.data.unsavedChanges) {
312 event.preventDefault();
313 if(this.$scope.isValidForm){
314 this.$scope.save().then(() => {
315 this.$scope.onMenuItemPressed(toState.name, toParams);
317 console.error("Save failed, unable to navigate to " + toState.name);
320 console.error("Form is invalid, unable to navigate to " + toState.name);
327 this.$scope.$on('$stateChangeSuccess', (event, toState) => {
328 this.$scope.updateSelectedMenuItem(this.$state.current.name);
331 this.$scope.onMenuItemPressed = (state:string, params:any):ng.IPromise<boolean> => {
333 let deferred:ng.IDeferred<boolean> = this.$q.defer();
334 let goToState = ():void => {
335 this.$state.go(state, Object.assign({
336 id: this.$scope.component.uniqueId,
337 type: this.$scope.component.componentType.toLowerCase(),
338 components: this.components
340 deferred.resolve(true);
343 if (this.$scope.isEditMode() && //this is a workaround for amdocs - we need to get the artifact in order to avoid saving the vf when moving from their tabs
344 (this.$state.current.name === States.WORKSPACE_MANAGEMENT_WORKFLOW || this.$state.current.name === States.WORKSPACE_NETWORK_CALL_FLOW)) {
345 let onGetSuccess = (component:Component) => {
346 this.$scope.isLoading = false;
347 // Update the components
348 this.$scope.component = component;
351 let onFailed = () => {
352 this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_ERROR);
353 this.$scope.isLoading = false; // stop the progress.
354 deferred.reject(false);
356 this.$scope.component.getComponent().then(onGetSuccess, onFailed);
360 return deferred.promise;
363 this.$scope.setValidState = (isValid:boolean):void => {
364 this.$scope.isValidForm = isValid;
367 this.$scope.onVersionChanged = (selectedId:string):void => {
368 if (this.$scope.isGeneralView() && this.$state.current.data.unsavedChanges) {
369 this.$scope.changeVersion.selectedVersion = _.find(this.$scope.versionsList, (versionObj)=> {
370 return versionObj.versionId === this.$scope.component.uniqueId;
375 uuid: this.$scope.component.uuid,
376 version: this.$scope.changeVersion.selectedVersion.versionNumber
379 this.eventBusService.notify("VERSION_CHANGED", eventData).subscribe(() => {
380 this.$scope.isLoading = true;
382 this.$state.go(this.$state.current.name, {
384 type: this.$scope.componentType.toLowerCase(),
385 mode: WorkspaceMode.VIEW,
386 components: this.$state.params['components']
391 this.$scope.getLatestVersion = ():void => {
392 this.$scope.onVersionChanged(_.first(this.$scope.versionsList).versionId);
395 this.$scope.create = () => {
397 this.$scope.startProgress("Creating Asset...");
398 _.first(this.$scope.leftBarTabs.menuItems).isDisabled = true;//disabled click on general tab (DE246274)
400 // In case we import CSAR. Notify user that import VF will take long time (the create is performed in the background).
401 if (this.$scope.component.isResource() && (<Resource>this.$scope.component).csarUUID) {
402 this.Notification.info({
403 message: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_TAKES_LONG_TIME_DESCRIPTION"),
404 title: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_TAKES_LONG_TIME_TITLE")
408 let onFailed = () => {
409 this.$scope.stopProgress();
410 this.$scope.isLoading = false; // stop the progress.
411 _.first(this.$scope.leftBarTabs.menuItems).isDisabled = false;//enabled click on general tab (DE246274)
412 this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_ERROR);
413 let modalInstance:ng.ui.bootstrap.IModalServiceInstance;
414 modalInstance && modalInstance.close(); // Close the modal in case it is opened.
415 this.$scope.component.tags = _.without(this.$scope.component.tags, this.$scope.component.name);// for fix DE246217
417 this.$scope.setValidState(true); // Set the form valid (if sent form is valid, the error from server).
420 let onSuccessCreate = (component:Component) => {
422 this.$scope.stopProgress();
423 this.showSuccessNotificationMessage();
425 // Update the components list for breadcrumbs
426 this.components.unshift(component);
428 this.$state.go(States.WORKSPACE_GENERAL, {
429 id: component.uniqueId,
430 type: component.componentType.toLowerCase(),
431 components: this.components
432 }, {inherit: false});
435 console.log(this.$scope.component, "this.$scope.component")
436 if ((<Service>this.$scope.component).serviceType == "Service") {
437 this.ComponentFactory.importComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed);
439 this.ComponentFactory.createComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed);
446 this.$scope.save = ():Promise<void> => {
448 this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_CLICK);
450 this.$scope.startProgress("Updating Asset...");
451 this.$scope.disableMenuItems();
453 return new Promise<void>((resolve, reject) => {
454 let stopProgressAndEnableUI = () => {
455 this.$scope.disabledButtons = false;
456 this.$scope.isLoading = false;
457 this.$scope.enableMenuItems();
458 this.$scope.stopProgress();
461 let onFailed = () => {
462 stopProgressAndEnableUI();
463 this.$scope.updateUnsavedFileFlag(true);
464 this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_ERROR);
469 let onSuccessUpdate = (component:Component) => {
470 stopProgressAndEnableUI();
471 this.showSuccessNotificationMessage();
473 component.tags = _.reject(component.tags, (item)=> {
474 return item === component.name
477 this.$scope.updateBreadcrumbs(component);
479 //update the component
480 this.$scope.setComponent(component);
481 this.$scope.originComponent = this.ComponentFactory.createComponent(this.$scope.component);
483 if (this.cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
484 this.cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
486 if (this.cacheService.contains(PREVIOUS_CSAR_COMPONENT)) {
487 this.cacheService.remove(PREVIOUS_CSAR_COMPONENT);
491 this.$state.current.data.unsavedChanges = false;
492 this.$scope.unsavedFile = false;
493 this.$scope.reload(component);
497 this.$scope.component.updateComponent().then(onSuccessUpdate, onFailed);
502 this.$scope.changeLifecycleState = (state:string):void => {
503 if (this.$scope.isGeneralView() && state !== 'deleteVersion') {
504 this.EventListenerService.notifyObservers(EVENTS.ON_LIFECYCLE_CHANGE_WITH_SAVE, state);
506 this.$scope.handleChangeLifecycleState(state);
510 let defaultActionAfterChangeLifecycleState = ():void => {
511 if (this.$state.current.data && this.$state.current.data.unsavedChanges) {
512 this.$state.current.data.unsavedChanges = false;
514 this.$state.go('dashboard');
517 this.$scope.handleChangeLifecycleState = (state:string, newCsarVersion?:string, onError?: Function) => {
518 if ('monitor' === state) {
519 this.$state.go('workspace.distribution');
523 let data = this.$scope.changeLifecycleStateButtons[state];
524 if (!data && this.$stateParams.componentCsar && !this.$scope.isCreateMode()) {
525 data = {text: 'Check Out', url: 'lifecycleState/CHECKOUT'};
527 const onSuccess = (component, url:string):void => {
528 // Updating the component from server response
530 // Creating the data object to notify the plugins with
531 const eventData: any = {
532 uuid: this.$scope.component.uuid,
533 version: this.$scope.component.version
536 // the server returns only metaData (small component) except checkout (Full component) ,so we update only the statuses of distribution & lifecycle
537 this.$scope.component.lifecycleState = component.lifecycleState;
538 this.$scope.component.distributionStatus = component.distributionStatus;
541 case 'lifecycleState/CHECKOUT':
542 this.workspaceNg1BridgeService.updateIsViewOnly(false);
543 this.eventBusService.notify("CHECK_OUT", eventData, false).subscribe(() => {
544 // only checkOut get the full component from server
545 // this.$scope.component = component;
546 // Work around to change the csar version
548 this.cacheService.set(CHANGE_COMPONENT_CSAR_VERSION_FLAG, newCsarVersion);
549 (this.$scope.component as Resource).csarVersion = newCsarVersion;
552 //when checking out a minor version uuid remains
553 const bcIdx = _.findIndex(this.components, (item) => {
554 return item.uuid === component.uuid;
557 this.components[bcIdx] = component;
559 //when checking out a major(certified) version
560 this.components.unshift(component);
562 this.$scope.mode = this.initViewMode();
563 this.initChangeLifecycleStateButtons();
564 this.initVersionObject();
565 this.$scope.isLoading = false;
566 this.EventListenerService.notifyObservers(EVENTS.ON_CHECKOUT, component);
567 this.workspaceService.setComponentMetadata(component);
569 this.Notification.success({
570 message: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TEXT"),
571 title: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TITLE")
576 case 'lifecycleState/CHECKIN':
577 this.workspaceNg1BridgeService.updateIsViewOnly(true);
578 defaultActionAfterChangeLifecycleState();
579 this.Notification.success({
580 message: this.$filter('translate')("CHECKIN_SUCCESS_MESSAGE_TEXT"),
581 title: this.$filter('translate')("CHECKIN_SUCCESS_MESSAGE_TITLE")
584 case 'lifecycleState/UNDOCHECKOUT':
585 this.eventBusService.notify("UNDO_CHECK_OUT", eventData, false).subscribe(() => {
586 defaultActionAfterChangeLifecycleState();
587 this.Notification.success({
588 message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
589 title: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TITLE")
593 case 'lifecycleState/certify':
594 this.$scope.handleCertification(component);
595 this.verifyIfDependenciesExist();
596 this.$scope.reload(component);
598 case 'distribution/PROD/activate':
599 this.Notification.success({
600 message: this.$filter('translate')("DISTRIBUTE_SUCCESS_MESSAGE_TEXT"),
601 title: this.$filter('translate')("DISTRIBUTE_SUCCESS_MESSAGE_TITLE")
603 this.initChangeLifecycleStateButtons();
606 defaultActionAfterChangeLifecycleState();
608 if (data.url !== 'lifecycleState/CHECKOUT') {
609 this.$scope.isLoading = false;
612 this.ChangeLifecycleStateHandler.changeLifecycleState(this.$scope.component, data, this.$scope, onSuccess);
617 this.$scope.isViewMode = ():boolean => {
618 return this.$scope.mode === WorkspaceMode.VIEW;
621 this.$scope.isDesigner = ():boolean => {
622 return this.role == Role.DESIGNER;
625 this.$scope.isDisableMode = ():boolean => {
626 return this.$scope.mode === WorkspaceMode.VIEW && this.$scope.component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKIN;
629 this.$scope.isGeneralView = ():boolean => {
630 //we show revert and save icons only in general view
631 return this.$state.current.name === States.WORKSPACE_GENERAL;
634 this.$scope.isCreateMode = ():boolean => {
635 return this.$scope.mode === WorkspaceMode.CREATE;
638 this.$scope.checkDisableButton = (button: any):boolean => {
639 // Logic moved from html to component
640 if (this.$scope.isCreateMode() || button.disabled || this.$scope.disabledButtons || !this.$scope.isValidForm || this.$scope.unsavedChanges || this.$scope.component.archived){
644 // Specific verification for Checkout - enabled only in case the component is the latest version.
645 let result: boolean = false;
647 if (button.url === 'lifecycleState/CHECKOUT') {
648 result = !this.$scope.component.isLatestVersion();
653 this.$scope.isEditMode = ():boolean => {
654 return this.$scope.mode === WorkspaceMode.EDIT;
657 this.$scope.goToBreadcrumbHome = ():void => {
658 let bcHome:MenuItemGroup = this.$scope.breadcrumbsModel[0];
659 this.$state.go(bcHome.menuItems[bcHome.selectedIndex].state);
662 this.$scope.showLifecycleIcon = ():boolean => {
663 return this.role == Role.DESIGNER;
666 this.$scope.getStatus = ():string => {
667 if (this.$scope.isCreateMode()) {
671 return this.$scope.component.getStatus(this.sdcMenu);
674 this.initMenuItems();
676 this.$scope.showLatestVersion = (): boolean => {
677 let result: boolean = true;
678 if (!this.$scope.component.isLatestVersion()) {
681 if (ComponentState.NOT_CERTIFIED_CHECKOUT === this.$scope.component.lifecycleState && this.$scope.isViewMode()) {
687 this.$scope.updateSelectedMenuItem = (state:string):void => {
688 let stateArray:Array<string> = state.split('.', 2);
689 let stateWithoutInternalNavigate:string = stateArray[0] + '.' + stateArray[1];
690 let selectedItem:MenuItem = _.find(this.$scope.leftBarTabs.menuItems, (item:MenuItem) => {
691 let itemStateArray:Array<string> = item.state.split('.', 2);
692 let itemStateWithoutNavigation:string = itemStateArray[0] + '.' + itemStateArray[1];
693 return (itemStateWithoutNavigation === stateWithoutInternalNavigate);
696 let selectedIndex = selectedItem ? this.$scope.leftBarTabs.menuItems.indexOf(selectedItem) : 0;
698 if (stateArray[1] === 'plugins') {
699 _.forEach(PluginsConfiguration.plugins, (plugin) => {
700 if (plugin.pluginStateUrl == this.$state.params.path) {
703 else if (this.pluginsService.isPluginDisplayedInContext(plugin, this.role, this.$scope.component.getComponentSubType())) {
709 this.$scope.leftBarTabs.selectedIndex = selectedIndex;
712 this.$scope.isSelected = (menuItem: MenuItem): boolean => {
713 return this.$scope.leftBarTabs.selectedIndex === _.indexOf(this.$scope.leftBarTabs.menuItems, menuItem);
716 this.$scope.$watch('$state.current.name', (newVal: string): void => {
718 this.$scope.isComposition = (newVal.indexOf(States.WORKSPACE_COMPOSITION) > -1);
719 this.$scope.isDeployment = newVal == States.WORKSPACE_DEPLOYMENT;
720 this.$scope.isPlugins = newVal == States.WORKSPACE_PLUGINS;
724 this.$scope.getTabTitle = (): string => {
725 return this.$scope.leftBarTabs.menuItems.find((menuItem: MenuItem) => {
726 return menuItem.state == this.$scope.$state.current.name;
730 this.$scope.reload = (component: Component): void => {
731 const isGeneralTab = this.$state.current.name === 'workspace.general';
732 // nullify the componentCsar in case we are in general tab so we know we didnt came from updateVsp Modal
734 this.$state.go(this.$state.current.name, {id: component.uniqueId, componentCsar: null}, {reload: true});
736 this.$state.go(this.$state.current.name, {id: component.uniqueId}, {reload: true});
740 this.$scope.$on('$destroy', () => {
741 this.EventListenerService.unRegisterObserver(EVENTS.ON_WORKSPACE_UNSAVED_CHANGES);
744 this.$scope.openAutomatedUpgradeModal = ():void => {
745 this.$scope.isLoading = true;
746 this.ComponentServiceNg2.getDependencies(this.$scope.component.componentType, this.$scope.component.uniqueId).subscribe((response:Array<IDependenciesServerResponse>)=> {
747 this.$scope.isLoading = false;
748 this.AutomatedUpgradeService.openAutomatedUpgradeModal(response, this.$scope.component, false);
752 this.$scope.handleCertification = (certifyComponent): void => {
753 if (this.$scope.component.getComponentSubType() === ResourceType.VF || this.$scope.component.isService()) {
754 this.ComponentServiceNg2.getDependencies(this.$scope.component.componentType, this.$scope.component.uniqueId).subscribe((response:Array<IDependenciesServerResponse>) => {
755 this.$scope.isLoading = false;
757 const isUpgradeNeeded = _.filter(response, (componentToUpgrade:IDependenciesServerResponse) => {
758 return componentToUpgrade.dependencies && componentToUpgrade.dependencies.length > 0;
760 if (isUpgradeNeeded.length === 0) {
761 this.onSuccessWithoutUpgradeNeeded();
764 this.refreshDataAfterChangeLifecycleState(certifyComponent);
765 this.AutomatedUpgradeService.openAutomatedUpgradeModal(response, this.$scope.component, true);
768 this.onSuccessWithoutUpgradeNeeded();
772 this.$scope.disableMenuItems = () => {
773 this.$scope.leftBarTabs.menuItems.forEach((item: MenuItem) => {
774 item.isDisabled = (States.WORKSPACE_GENERAL !== item.state);
778 this.$scope.enableMenuItems = () => {
779 this.$scope.leftBarTabs.menuItems.forEach((item: MenuItem) => {
780 item.isDisabled = false;
785 this.$scope.startProgress = (message: string): void => {
786 this.progressService.initCreateComponentProgress(this.$scope.component.uniqueId);
787 this.$scope.isCreateProgress = true;
788 this.$scope.progressMessage = message;
791 this.$scope.stopProgress = (): void => {
792 this.$scope.isCreateProgress = false;
793 this.progressService.deleteProgressValue(this.$scope.component.uniqueId);
796 this.$scope.updateBreadcrumbs = (component: Component): void => {
797 // Update the components list for breadcrumbs
798 const bcIdx = this.MenuHandler.findBreadcrumbComponentIndex(this.components, component);
800 this.components[bcIdx] = component;
801 this.initBreadcrumbs(); // re-calculate breadcrumbs
805 this.$scope.updateUnsavedFileFlag = (isUnsaved:boolean) => {
806 this.$scope.unsavedFile = isUnsaved;
811 private onSuccessWithoutUpgradeNeeded = (): void => {
812 this.$scope.isLoading = false;
813 this.Notification.success({
814 message: this.$filter('translate')('SERVICE_CERTIFICATION_STATUS_TEXT'),
815 title: this.$filter('translate')('SERVICE_CERTIFICATION_STATUS_TITLE')
817 this.initVersionObject();
818 this.initChangeLifecycleStateButtons();
821 private refreshDataAfterChangeLifecycleState = (component:Component):void => {
822 this.$scope.isLoading = false;
823 this.$scope.mode = this.initViewMode();
824 this.initChangeLifecycleStateButtons();
825 this.initVersionObject();
826 this.EventListenerService.notifyObservers(EVENTS.ON_LIFECYCLE_CHANGE, component);
829 private initAfterScope = (): void => {
830 // In case user select csar from the onboarding modal, need to disable checkout and submit for testing.
831 if (this.$state.params['disableButtons'] === true) {
832 this.$scope.uploadFileChangedInGeneralTab();
836 private initVersionObject = (): void => {
837 this.$scope.versionsList = (this.$scope.component.getAllVersionsAsSortedArray()).reverse();
838 this.$scope.changeVersion = {
839 selectedVersion: _.find(this.$scope.versionsList, (versionObj) => {
840 return versionObj.versionId === this.$scope.component.uniqueId;
845 private getNewComponentBreadcrumbItem = (): MenuItem => {
847 if (this.$scope.component.isResource() && (<Resource>this.$scope.component).isCsarComponent()) {
848 text = this.$scope.component.getComponentSubType() + ': ' + this.$scope.component.name;
850 text = 'Create new ' + this.$state.params['type'];
852 return new MenuItem(text, null, States.WORKSPACE_GENERAL, 'goToState', [this.$state.params]);
855 private updateMenuItemByRole = (menuItems: any[], role: string) => {
856 const tempMenuItems: any[] = new Array<any>();
857 menuItems.forEach((item: any) => {
858 //remove item if role is disabled
859 if (!(item.disabledRoles && item.disabledRoles.indexOf(role) > -1)) {
860 tempMenuItems.push(item);
863 return tempMenuItems;
866 private updateMenuItemByCategory = (menuItems:Array<any>, category:string) => {
867 let tempMenuItems:Array<any> = new Array<any>();
868 menuItems.forEach((item:any) => {
869 //update flag disabledCategory to true if category is disabled
870 item.disabledCategory = false;
871 if ((item.disabledCategories && item.disabledCategories.indexOf(category) > -1))
873 item.disabledCategory = true;
875 tempMenuItems.push(item);
877 return tempMenuItems;
881 private deleteArchiveCache = () => {
882 this.cacheService.remove('archiveComponents'); // delete the cache to ensure the archive is reloaded from server
885 private initBreadcrumbs = () => {
886 this.components = this.cacheService.get('breadcrumbsComponents');
887 const breadcrumbsComponentsLvl = this.MenuHandler.generateBreadcrumbsModelFromComponents(this.components, this.$scope.component);
889 if (this.$scope.isCreateMode()) {
890 const createItem = this.getNewComponentBreadcrumbItem();
891 if (!breadcrumbsComponentsLvl.menuItems) {
892 breadcrumbsComponentsLvl.menuItems = [];
894 breadcrumbsComponentsLvl.menuItems.unshift(createItem);
895 breadcrumbsComponentsLvl.selectedIndex = 0;
898 this.$scope.breadcrumbsModel = [breadcrumbsComponentsLvl, this.$scope.leftBarTabs];
901 private initMenuItems() {
903 const inCreateMode = this.$scope.isCreateMode();
904 this.$scope.leftBarTabs = new MenuItemGroup();
905 let menuItemsObjects: any[] = this.updateMenuItemByRole(this.sdcMenu.component_workspace_menu_option[this.$scope.component.getComponentSubType()], this.role);
906 if (this.$scope.component.getComponentSubType() === 'SERVICE') {
907 const menuItemsObjectsCategory: any[] = this.updateMenuItemByCategory(menuItemsObjects, this.category);
908 menuItemsObjects = menuItemsObjectsCategory;
911 // Only adding plugins to the workspace if they can be displayed for the current user role
912 _.each(PluginsConfiguration.plugins, (plugin: Plugin) => {
913 if (this.pluginsService.isPluginDisplayedInContext(plugin, this.role, this.$scope.component.getComponentSubType())) {
914 menuItemsObjects.push({
915 text: plugin.pluginDisplayOptions['context'].displayName,
916 action: 'onMenuItemPressed',
917 state: 'workspace.plugins',
918 params: {path: plugin.pluginStateUrl}
923 this.$scope.leftBarTabs.menuItems = menuItemsObjects.map((item: MenuItem) => {
924 const menuItem = new MenuItem(item.text, item.callback, item.state, item.action, item.params, item.blockedForTypes, item.disabledCategory);
925 if (menuItem.params) {
926 menuItem.params.state = menuItem.state;
929 menuItem.params = {state: menuItem.state};
931 menuItem.callback = () => this.$scope[menuItem.action](menuItem.state, menuItem.params);
932 menuItem.isDisabled = (inCreateMode && States.WORKSPACE_GENERAL !== menuItem.state) ||
933 (States.WORKSPACE_DEPLOYMENT === menuItem.state && this.$scope.component.modules
934 && this.$scope.component.modules.length === 0 && this.$scope.component.isResource()) ||
935 (menuItem.disabledCategory === true);
939 if (this.cacheService.get('breadcrumbsComponents')) {
940 this.initBreadcrumbs();
943 this.initBreadcrumbsComponents();
947 private showSuccessNotificationMessage = ():void => {
948 this.Notification.success({
949 message: this.$filter('translate')('IMPORT_VF_MESSAGE_CREATE_FINISHED_DESCRIPTION'),
950 title: this.$filter('translate')('IMPORT_VF_MESSAGE_CREATE_FINISHED_TITLE')
954 private setWorkspaceButtonState = (newState: boolean, callback?: Function) => {
955 this.$scope.unsavedChanges = newState;
956 this.$scope.unsavedChangesCallback = callback;
959 private initBreadcrumbsComponents = (): void => {
960 let breadcrumbsComponentsObservable;
961 if (this.$stateParams.previousState === 'dashboard') {
962 breadcrumbsComponentsObservable = this.homeService.getAllComponents(true);
963 } else if (this.$stateParams.previousState === 'catalog') {
964 breadcrumbsComponentsObservable = this.catalogService.getCatalog();
966 this.cacheService.remove('breadcrumbsComponentsState');
967 this.cacheService.remove('breadcrumbsComponents');
970 breadcrumbsComponentsObservable.subscribe((components) => {
971 this.cacheService.set('breadcrumbsComponentsState', this.$stateParams.previousState);
972 this.cacheService.set('breadcrumbsComponents', components);
973 this.initBreadcrumbs();
978 private verifyIfDependenciesExist(): void {
979 let containsDependencies = [];
980 if (this.$scope.component.componentType && this.$scope.component.uniqueId &&
981 this.$scope.component.lifecycleState === 'CERTIFIED' && (this.$scope.component.isService() || this.$scope.component.getComponentSubType() === 'VF')) {
982 this.ComponentServiceNg2.getDependencies(this.$scope.component.componentType, this.$scope.component.uniqueId).subscribe((response: IDependenciesServerResponse[]) => {
983 containsDependencies = response.filter((version) => version.dependencies);
984 if (containsDependencies.length > 0) {
985 this.$scope.hasNoDependencies = false;
987 this.$scope.hasNoDependencies = true;