[sdc] update to the current code base
[sdc.git] / catalog-ui / src / app / view-models / workspace / workspace-view-model.ts
1 /**
2  * Created by obarda on 3/30/2016.
3  */
4 'use strict';
5 import {IUserProperties, IAppMenu, Resource, Component} from "app/models";
6 import {
7     WorkspaceMode, ComponentFactory, ChangeLifecycleStateHandler, Role, ComponentState, MenuItemGroup, MenuHandler,
8     MenuItem, ModalsHandler, States, EVENTS, CHANGE_COMPONENT_CSAR_VERSION_FLAG, ResourceType
9 } from "app/utils";
10 import {
11     EventListenerService,
12     EntityService,
13     ProgressService,
14     CacheService,
15     LeftPaletteLoaderService
16 } from "app/services";
17 import {FileUploadModel} from "../../directives/file-upload/file-upload";
18
19
20 export interface IWorkspaceViewModelScope extends ng.IScope {
21
22     isLoading:boolean;
23     isCreateProgress:boolean;
24     component:Component;
25     originComponent:Component;
26     componentType:string;
27     importFile:any;
28     leftBarTabs:MenuItemGroup;
29     isNew:boolean;
30     isFromImport:boolean;
31     isValidForm:boolean;
32     mode:WorkspaceMode;
33     breadcrumbsModel:Array<MenuItemGroup>;
34     sdcMenu:IAppMenu;
35     changeLifecycleStateButtons:any;
36     version:string;
37     versionsList:Array<any>;
38     changeVersion:any;
39     isComposition:boolean;
40     isDeployment:boolean;
41     $state:ng.ui.IStateService;
42     user:IUserProperties;
43     thirdParty:boolean;
44     disabledButtons:boolean;
45     menuComponentTitle:string;
46     progressService:ProgressService;
47     progressMessage:string;
48     // leftPanelComponents:Array<Models.Components.Component>; //this is in order to load the left panel once, and not wait long time when moving to composition
49
50     showChangeStateButton():boolean;
51     getComponent():Component;
52     setComponent(component:Component):void;
53     onMenuItemPressed(state:string):ng.IPromise<boolean>;
54     save():ng.IPromise<boolean>;
55     setValidState(isValid:boolean):void;
56     revert():void;
57     changeLifecycleState(state:string):void;
58     enabledTabs():void
59     isDesigner():boolean;
60     isProductManager():boolean;
61     isViewMode():boolean;
62     isEditMode():boolean;
63     isCreateMode():boolean;
64     isDisableMode():boolean;
65     showFullIcons():boolean;
66     goToBreadcrumbHome():void;
67     onVersionChanged(selectedId:string):void;
68     getLatestVersion():void;
69     getStatus():string;
70     showLifecycleIcon():boolean;
71     updateSelectedMenuItem():void;
72     uploadFileChangedInGeneralTab():void;
73     updateMenuComponentName(ComponentName:string):void;
74 }
75
76 export class WorkspaceViewModel {
77
78     static '$inject' = [
79         '$scope',
80         'injectComponent',
81         'ComponentFactory',
82         '$state',
83         'sdcMenu',
84         '$q',
85         'MenuHandler',
86         'Sdc.Services.CacheService',
87         'ChangeLifecycleStateHandler',
88         'ModalsHandler',
89         'LeftPaletteLoaderService',
90         '$filter',
91         'EventListenerService',
92         'Sdc.Services.EntityService',
93         'Notification',
94         '$stateParams',
95         'Sdc.Services.ProgressService'
96     ];
97
98     constructor(private $scope:IWorkspaceViewModelScope,
99                 private injectComponent:Component,
100                 private ComponentFactory:ComponentFactory,
101                 private $state:ng.ui.IStateService,
102                 private sdcMenu:IAppMenu,
103                 private $q:ng.IQService,
104                 private MenuHandler:MenuHandler,
105                 private cacheService:CacheService,
106                 private ChangeLifecycleStateHandler:ChangeLifecycleStateHandler,
107                 private ModalsHandler:ModalsHandler,
108                 private LeftPaletteLoaderService:LeftPaletteLoaderService,
109                 private $filter:ng.IFilterService,
110                 private EventListenerService:EventListenerService,
111                 private EntityService:EntityService,
112                 private Notification:any,
113                 private $stateParams:any,
114                 private progressService:ProgressService) {
115
116         this.initScope();
117         this.initAfterScope();
118     }
119
120     private role:string;
121     private components:Array<Component>;
122
123     private initViewMode = ():WorkspaceMode => {
124         let mode = WorkspaceMode.VIEW;
125
126         if (!this.$state.params['id']) {   //&& !this.$state.params['vspComponent']
127             mode = WorkspaceMode.CREATE;
128         } else {
129             if (this.$scope.component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKOUT &&
130                 this.$scope.component.lastUpdaterUserId === this.cacheService.get("user").userId) {
131                 if (this.$scope.component.isProduct() && this.role == Role.PRODUCT_MANAGER) {
132                     mode = WorkspaceMode.EDIT;
133                 }
134                 if ((this.$scope.component.isService() || this.$scope.component.isResource()) && this.role == Role.DESIGNER) {
135                     mode = WorkspaceMode.EDIT;
136                 }
137             }
138         }
139         return mode;
140     };
141
142     private initChangeLifecycleStateButtons = ():void => {
143         let state = this.$scope.component.isService() && (Role.OPS == this.role || Role.GOVERNOR == this.role) ? this.$scope.component.distributionStatus : this.$scope.component.lifecycleState;
144         this.$scope.changeLifecycleStateButtons = this.sdcMenu.roles[this.role].changeLifecycleStateButtons[state];
145     };
146
147     private isNeedSave = ():boolean => {
148         return this.$scope.isEditMode() &&
149             this.$state.current.data && this.$state.current.data.unsavedChanges;
150     };
151
152     private initLeftPalette = ():void => {
153         this.LeftPaletteLoaderService.loadLeftPanel(this.$scope.component.componentType);
154     };
155
156     private initScope = ():void => {
157
158         this.$scope.component = this.injectComponent;
159         this.initLeftPalette();
160         this.$scope.menuComponentTitle = this.$scope.component.name;
161         this.$scope.disabledButtons = false;
162         this.$scope.originComponent = this.ComponentFactory.createComponent(this.$scope.component);
163         this.$scope.componentType = this.$scope.component.componentType;
164         this.$scope.version = this.cacheService.get('version');
165         this.$scope.user = this.cacheService.get("user");
166         this.role = this.$scope.user.role;
167         this.$scope.mode = this.initViewMode();
168         this.$scope.isValidForm = true;
169         this.initChangeLifecycleStateButtons();
170         this.initVersionObject();
171         this.$scope.$state = this.$state;
172         this.$scope.isLoading = false;
173         this.$scope.isComposition = (this.$state.current.name.indexOf(States.WORKSPACE_COMPOSITION) > -1);
174         this.$scope.isDeployment = (this.$state.current.name.indexOf(States.WORKSPACE_DEPLOYMENT) > -1);
175         this.$scope.progressService = this.progressService;
176
177         this.$scope.getComponent = ():Component => {
178             return this.$scope.component;
179         };
180
181         this.$scope.updateMenuComponentName = (ComponentName:string):void => {
182             this.$scope.menuComponentTitle = ComponentName;
183         };
184
185         this.$scope.sdcMenu = this.sdcMenu;
186         // Will be called from each step after save to update the resource.
187         this.$scope.setComponent = (component:Component):void => {
188             this.$scope.component = component;
189         };
190
191         this.$scope.uploadFileChangedInGeneralTab = ():void => {
192             // In case user select browse file, and in update mode, need to disable submit for testing and checkin buttons.
193             if (this.$scope.isEditMode() && this.$scope.component.isResource() && (<Resource>this.$scope.component).resourceType == ResourceType.VF) {
194                 this.$scope.disabledButtons = true;
195             }
196         };
197
198         this.$scope.onMenuItemPressed = (state:string):ng.IPromise<boolean> => {
199             let deferred = this.$q.defer();
200             let goToState = ():void => {
201                 this.$state.go(state, {
202                     id: this.$scope.component.uniqueId,
203                     type: this.$scope.component.componentType.toLowerCase(),
204                     components: this.components
205                 });
206                 deferred.resolve(true);
207             };
208             if (this.isNeedSave()) {
209                 if (this.$scope.isValidForm) {
210                     this.$scope.save().then(goToState);
211                 } else {
212                     console.log('form is not valid');
213                     deferred.reject(false);
214                 }
215             } else 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
216                 (this.$state.current.name === States.WORKSPACE_MANAGEMENT_WORKFLOW || this.$state.current.name === States.WORKSPACE_NETWORK_CALL_FLOW)) {
217                 let onGetSuccess = (component:Component) => {
218                     this.$scope.isLoading = false;
219                     // Update the components
220                     this.$scope.component = component;
221                     goToState();
222                 };
223                 let onFailed = () => {
224                     this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_ERROR);
225                     this.$scope.isLoading = false; // stop the progress.
226                     deferred.reject(false);
227                 };
228                 this.$scope.component.getComponent().then(onGetSuccess, onFailed);
229             } else {
230                 goToState();
231             }
232             return deferred.promise;
233         };
234
235         this.$scope.setValidState = (isValid:boolean):void => {
236             this.$scope.isValidForm = isValid;
237         };
238
239         this.$scope.onVersionChanged = (selectedId:string):void => {
240             if (this.$state.current.data && this.$state.current.data.unsavedChanges) {
241                 this.$scope.changeVersion.selectedVersion = _.find(this.$scope.versionsList, {versionId: this.$scope.component.uniqueId});
242             }
243             this.$scope.isLoading = true;
244             this.$state.go(this.$state.current.name, {
245                 id: selectedId,
246                 type: this.$scope.componentType.toLowerCase(),
247                 mode: WorkspaceMode.VIEW,
248                 components: this.$state.params['components']
249             },{reload: true});
250
251         };
252
253         this.$scope.getLatestVersion = ():void => {
254             this.$scope.onVersionChanged(_.first(this.$scope.versionsList).versionId);
255         };
256
257         this.$scope.save = (state?:string):ng.IPromise<boolean> => {
258             this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_CLICK);
259
260             this.progressService.initCreateComponentProgress(this.$scope.component.uniqueId);
261
262             let deferred = this.$q.defer();
263             let modalInstance:ng.ui.bootstrap.IModalServiceInstance;
264
265             let onFailed = () => {
266                 _.first(this.$scope.leftBarTabs.menuItems).isDisabled = false;//enabled click on general tab (DE246274)
267                 this.EventListenerService.notifyObservers(EVENTS.ON_WORKSPACE_SAVE_BUTTON_ERROR);
268                 this.progressService.deleteProgressValue(this.$scope.component.uniqueId);
269                 modalInstance && modalInstance.close();  // Close the modal in case it is opened.
270                 this.$scope.component.tags = _.without(this.$scope.component.tags, this.$scope.component.name);// for fix DE246217
271                 this.$scope.isCreateProgress = false;
272                 this.$scope.isLoading = false; // stop the progress.
273
274                 this.$scope.setValidState(true);  // Set the form valid (if sent form is valid, the error from server).
275                 if (!this.$scope.isCreateMode()) {
276                     this.$scope.component = this.ComponentFactory.createComponent(this.$scope.originComponent); // Set the component back to the original.
277                     this.enableMenuItems();  // Enable the menu items (left tabs), so user can press on them.
278                     this.$scope.disabledButtons = false;  // Enable "submit for testing" & checking buttons.
279                 }
280
281                 deferred.reject(false);
282             };
283
284             let onSuccessCreate = (component:Component) => {
285
286                 this.showSuccessNotificationMessage();
287                 this.progressService.deleteProgressValue(this.$scope.component.uniqueId);
288                 //update components for breadcrumbs
289                 this.components.unshift(component);
290                 this.$state.go(States.WORKSPACE_GENERAL, {
291                     id: component.uniqueId,
292                     type: component.componentType.toLowerCase(),
293                     components: this.components
294                 });
295
296                 deferred.resolve(true);
297             };
298
299             let onSuccessUpdate = (component:Component) => {
300                 this.$scope.isCreateProgress = false;
301                 this.$scope.disabledButtons = false;
302                 this.showSuccessNotificationMessage();
303                 this.progressService.deleteProgressValue(this.$scope.component.uniqueId);
304
305                 // Stop the circle loader.
306                 this.$scope.isLoading = false;
307
308                 component.tags = _.reject(component.tags, (item)=> {
309                     return item === component.name
310                 });
311
312                 // Update the components
313                 this.$scope.component = component;
314                 this.$scope.originComponent = this.ComponentFactory.createComponent(this.$scope.component);
315
316                 //update components for breadcrumbs
317                 this.components.unshift(component);
318
319                 // Enable left tags
320                 this.$scope.enabledTabs();
321
322
323                 if (this.$state.current.data) {
324                     this.$state.current.data.unsavedChanges = false;
325                 }
326
327                 deferred.resolve(true);
328             };
329
330             if (this.$scope.isCreateMode()) {
331                 this.$scope.progressMessage = "Creating Asset...";
332                 // CREATE MODE
333                 this.$scope.isCreateProgress = true;
334
335                 _.first(this.$scope.leftBarTabs.menuItems).isDisabled = true;//disabled click on general tab (DE246274)
336
337                 // Start creating the component
338                 this.ComponentFactory.createComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed);
339
340                 // In case we import CSAR. Notify user that import VF will take long time (the create is performed in the background).
341                 if (this.$scope.component.isResource() && (<Resource>this.$scope.component).csarUUID) {
342                     this.Notification.info({
343                         message: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_TAKES_LONG_TIME_DESCRIPTION"),
344                         title: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_TAKES_LONG_TIME_TITLE")
345                     });
346                 }
347             } else {
348                 // UPDATE MODE
349                 this.$scope.isCreateProgress = true;
350                 this.$scope.progressMessage = "Updating Asset...";
351                 this.disableMenuItems();
352
353
354                 // Work around to change the csar version
355                 if (this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
356                     (<Resource>this.$scope.component).csarVersion = this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
357                     this.cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
358                 }
359
360                 this.$scope.component.updateComponent().then(onSuccessUpdate, onFailed);
361             }
362             return deferred.promise;
363         };
364
365         this.$scope.revert = ():void => {
366             //in state of import file leave the file in place
367             if (this.$scope.component.isResource() && (<Resource>this.$scope.component).importedFile) {
368                 let tempFile:FileUploadModel = (<Resource>this.$scope.component).importedFile;
369                 this.$scope.component = this.ComponentFactory.createComponent(this.$scope.originComponent);
370                 (<Resource>this.$scope.component).importedFile = tempFile;
371             } else {
372                 this.$scope.component = this.ComponentFactory.createComponent(this.$scope.originComponent);
373             }
374
375         };
376
377         this.$scope.changeLifecycleState = (state:string):void => {
378             if (this.isNeedSave() && state !== 'deleteVersion') {
379                 this.$scope.save().then(() => {
380                     changeLifecycleState(state);
381                 })
382             } else {
383                 changeLifecycleState(state);
384             }
385         };
386
387         let defaultActionAfterChangeLifecycleState = ():void => {
388             if (this.$state.current.data && this.$state.current.data.unsavedChanges) {
389                 this.$state.current.data.unsavedChanges = false;
390             }
391             this.$state.go('dashboard');
392         };
393
394         let changeLifecycleState = (state:string) => {
395             if ('monitor' === state) {
396                 this.$state.go('workspace.distribution');
397                 return;
398             }
399
400             let data = this.$scope.changeLifecycleStateButtons[state];
401             let onSuccess = (component:Component, url:string):void => {
402                 //Updating the component from server response
403
404                 //the server returns only metaData (small component) except checkout (Full component)  ,so we update only the statuses of distribution & lifecycle
405                 this.$scope.component.lifecycleState = component.lifecycleState;
406                 this.$scope.component.distributionStatus = component.distributionStatus;
407
408                 switch (url) {
409                     case 'lifecycleState/CHECKOUT':
410                         // only checkOut get the full component from server
411                      //   this.$scope.component = component;
412                         // Work around to change the csar version
413                         if (this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
414                             (<Resource>this.$scope.component).csarVersion = this.cacheService.get(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
415                         }
416
417                         //when checking out a minor version uuid remains
418                         let bcComponent:Component = _.find(this.components, (item) => {
419                             return item.uuid === component.uuid;
420                         });
421                         if (bcComponent) {
422                             this.components[this.components.indexOf(bcComponent)] = component;
423                         } else {
424                             //when checking out a major(certified) version
425                             this.components.unshift(component);
426                         }
427                         // this.$state.go(this.$state.current.name, {
428                         //     id: component.uniqueId,
429                         //     type: component.componentType.toLowerCase(),
430                         //     components: this.components
431                         // });
432                         this.$scope.mode = this.initViewMode();
433                         this.initChangeLifecycleStateButtons();
434                         this.initVersionObject();
435                         this.$scope.isLoading = false;
436                         this.EventListenerService.notifyObservers(EVENTS.ON_CHECKOUT, component);
437                         this.Notification.success({
438                             message: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TEXT"),
439                             title: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TITLE")
440                         });
441                         break;
442                     case 'lifecycleState/CHECKIN':
443                         defaultActionAfterChangeLifecycleState();
444                         this.Notification.success({
445                             message: this.$filter('translate')("CHECKIN_SUCCESS_MESSAGE_TEXT"),
446                             title: this.$filter('translate')("CHECKIN_SUCCESS_MESSAGE_TITLE")
447                         });
448                         break;
449                     case 'lifecycleState/UNDOCHECKOUT':
450                         defaultActionAfterChangeLifecycleState();
451                         this.Notification.success({
452                             message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
453                             title: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TITLE")
454                         });
455                         break;
456                     case 'lifecycleState/certificationRequest':
457                         defaultActionAfterChangeLifecycleState();
458                         this.Notification.success({
459                             message: this.$filter('translate')("SUBMIT_FOR_TESTING_SUCCESS_MESSAGE_TEXT"),
460                             title: this.$filter('translate')("SUBMIT_FOR_TESTING_SUCCESS_MESSAGE_TITLE")
461                         });
462                         break;
463                     //Tester Role
464                     case 'lifecycleState/failCertification':
465                         defaultActionAfterChangeLifecycleState();
466                         this.Notification.success({
467                             message: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TEXT"),
468                             title: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TITLE")
469                         });
470                         break;
471                     case 'lifecycleState/certify':
472                         defaultActionAfterChangeLifecycleState();
473                         this.Notification.success({
474                             message: this.$filter('translate')("ACCEPT_TESTING_SUCCESS_MESSAGE_TEXT"),
475                             title: this.$filter('translate')("ACCEPT_TESTING_SUCCESS_MESSAGE_TITLE")
476                         });
477                         break;
478                     //DE203504 Bug Fix Start
479                     case 'lifecycleState/startCertification':
480                         this.initChangeLifecycleStateButtons();
481                         this.Notification.success({
482                             message: this.$filter('translate')("START_TESTING_SUCCESS_MESSAGE_TEXT"),
483                             title: this.$filter('translate')("START_TESTING_SUCCESS_MESSAGE_TITLE")
484                         });
485                         break;
486                     case  'lifecycleState/cancelCertification':
487                         this.initChangeLifecycleStateButtons();
488                         this.Notification.success({
489                             message: this.$filter('translate')("CANCEL_TESTING_SUCCESS_MESSAGE_TEXT"),
490                             title: this.$filter('translate')("CANCEL_TESTING_SUCCESS_MESSAGE_TITLE")
491                         });
492                         break;
493                     //Ops Role
494                     case  'distribution/PROD/activate':
495                         this.initChangeLifecycleStateButtons();
496                         this.Notification.success({
497                             message: this.$filter('translate')("DISTRIBUTE_SUCCESS_MESSAGE_TEXT"),
498                             title: this.$filter('translate')("DISTRIBUTE_SUCCESS_MESSAGE_TITLE")
499                         });
500                         break;
501                     //Governor Role
502                     case  'distribution-state/reject':
503                         this.initChangeLifecycleStateButtons();
504                         this.Notification.success({
505                             message: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TEXT"),
506                             title: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TITLE")
507                         });
508                         break;
509                     case  'distribution-state/approve':
510                         this.initChangeLifecycleStateButtons();
511                         this.$state.go('catalog');
512                         this.Notification.success({
513                             message: this.$filter('translate')("APPROVE_SUCCESS_MESSAGE_TEXT"),
514                             title: this.$filter('translate')("APPROVE_SUCCESS_MESSAGE_TITLE")
515                         });
516                         break;
517                     //DE203504 Bug Fix End
518
519                     default :
520                         defaultActionAfterChangeLifecycleState();
521
522                 }
523                 if (data.url != 'lifecycleState/CHECKOUT') {
524                     this.$scope.isLoading = false;
525                 }
526             };
527             //this.$scope.isLoading = true;
528             this.ChangeLifecycleStateHandler.changeLifecycleState(this.$scope.component, data, this.$scope, onSuccess);
529         };
530
531         this.$scope.enabledTabs = ():void => {
532             this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
533                 item.isDisabled = false;
534             });
535         };
536
537         this.$scope.isViewMode = ():boolean => {
538             return this.$scope.mode === WorkspaceMode.VIEW;
539         };
540
541         this.$scope.isDesigner = ():boolean => {
542             return this.role == Role.DESIGNER;
543         };
544
545         this.$scope.isProductManager = ():boolean => {
546             return this.role == Role.PRODUCT_MANAGER;
547         };
548
549         this.$scope.isDisableMode = ():boolean => {
550             return this.$scope.mode === WorkspaceMode.VIEW && this.$scope.component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKIN;
551         };
552
553         this.$scope.showFullIcons = ():boolean => {
554             //we show revert and save icons only in general\icon view
555             return this.$state.current.name === States.WORKSPACE_GENERAL ||
556                 this.$state.current.name === States.WORKSPACE_ICONS;
557         };
558
559         this.$scope.isCreateMode = ():boolean => {
560             return this.$scope.mode === WorkspaceMode.CREATE;
561         };
562
563         this.$scope.isEditMode = ():boolean => {
564             return this.$scope.mode === WorkspaceMode.EDIT;
565         };
566
567         this.$scope.goToBreadcrumbHome = ():void => {
568             let bcHome:MenuItemGroup = this.$scope.breadcrumbsModel[0];
569             this.$state.go(bcHome.menuItems[bcHome.selectedIndex].state);
570         };
571
572         this.$scope.showLifecycleIcon = ():boolean => {
573             return this.role == Role.DESIGNER ||
574                 this.role == Role.PRODUCT_MANAGER;
575         };
576
577         this.$scope.getStatus = ():string => {
578             if (this.$scope.isCreateMode()) {
579                 return 'IN DESIGN';
580             }
581
582             return this.$scope.component.getStatus(this.sdcMenu);
583         };
584
585         this.initMenuItems();
586
587         this.$scope.showChangeStateButton = ():boolean => {
588             let result:boolean = true;
589             if (!this.$scope.component.isLatestVersion() && Role.OPS != this.role && Role.GOVERNOR != this.role) {
590                 result = false;
591             }
592             if (this.role === Role.PRODUCT_MANAGER && !this.$scope.component.isProduct()) {
593                 result = false;
594             }
595             if ((this.role === Role.DESIGNER || this.role === Role.TESTER)
596                 && this.$scope.component.isProduct()) {
597                 result = false;
598             }
599             if (ComponentState.NOT_CERTIFIED_CHECKOUT === this.$scope.component.lifecycleState && this.$scope.isViewMode()) {
600                 result = false;
601             }
602             if (ComponentState.CERTIFIED != this.$scope.component.lifecycleState &&
603                 (Role.OPS == this.role || Role.GOVERNOR == this.role)) {
604                 result = false;
605             }
606             return result;
607         };
608
609         this.$scope.updateSelectedMenuItem = ():void => {
610             let selectedItem:MenuItem = _.find(this.$scope.leftBarTabs.menuItems, (item:MenuItem) => {
611                 return item.state === this.$state.current.name;
612             });
613             this.$scope.leftBarTabs.selectedIndex = selectedItem ? this.$scope.leftBarTabs.menuItems.indexOf(selectedItem) : 0;
614         };
615
616         this.$scope.$watch('$state.current.name', (newVal:string):void => {
617             if (newVal) {
618                 this.$scope.isComposition = (newVal.indexOf(States.WORKSPACE_COMPOSITION) > -1);
619                 this.$scope.isDeployment = (newVal.indexOf(States.WORKSPACE_DEPLOYMENT) > -1);
620             }
621         });
622     };
623
624     private initAfterScope = ():void => {
625         // In case user select csar from the onboarding modal, need to disable checkout and submit for testing.
626         if (this.$state.params['disableButtons'] === true) {
627             this.$scope.uploadFileChangedInGeneralTab();
628         }
629     };
630
631     private initVersionObject = ():void => {
632         this.$scope.versionsList = (this.$scope.component.getAllVersionsAsSortedArray()).reverse();
633         this.$scope.changeVersion = {selectedVersion: _.find(this.$scope.versionsList, {versionId: this.$scope.component.uniqueId})};
634     };
635
636     private getNewComponentBreadcrumbItem = ():MenuItem => {
637         let text = "";
638         if (this.$scope.component.isResource() && (<Resource>this.$scope.component).isCsarComponent()) {
639             text = this.$scope.component.getComponentSubType() + ': ' + this.$scope.component.name;
640         } else {
641             text = 'Create new ' + this.$state.params['type'];
642         }
643         return new MenuItem(text, null, States.WORKSPACE_GENERAL, 'goToState', [this.$state.params]);
644     };
645
646     private updateMenuItemByRole = (menuItems:Array<MenuItem>, role:string) => {
647         let tempMenuItems:Array<MenuItem> = new Array<MenuItem>();
648         menuItems.forEach((item:MenuItem) => {
649             //remove item if role is disabled
650             if (!(item.disabledRoles && item.disabledRoles.indexOf(role) > -1)) {
651                 tempMenuItems.push(item);
652             }
653         });
654         return tempMenuItems;
655     };
656
657     private initBreadcrumbs = () => {
658         this.components = this.cacheService.get('breadcrumbsComponents');
659         let breadcrumbsComponentsLvl = this.MenuHandler.generateBreadcrumbsModelFromComponents(this.components, this.$scope.component);
660
661         if (this.$scope.isCreateMode()) {
662             let createItem = this.getNewComponentBreadcrumbItem();
663             if (!breadcrumbsComponentsLvl.menuItems) {
664                 breadcrumbsComponentsLvl.menuItems = [];
665             }
666             breadcrumbsComponentsLvl.menuItems.unshift(createItem);
667             breadcrumbsComponentsLvl.selectedIndex = 0;
668         }
669
670         this.$scope.breadcrumbsModel = [breadcrumbsComponentsLvl, this.$scope.leftBarTabs];
671     };
672
673     private initMenuItems() {
674
675         let inCreateMode = this.$scope.isCreateMode();
676         this.$scope.leftBarTabs = new MenuItemGroup();
677         this.$scope.leftBarTabs.menuItems = this.updateMenuItemByRole(this.sdcMenu.component_workspace_menu_option[this.$scope.component.getComponentSubType()], this.role);
678
679         this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
680             item.params = [item.state];
681             item.callback = this.$scope.onMenuItemPressed;
682             item.isDisabled = (inCreateMode && States.WORKSPACE_GENERAL != item.state) ||
683                 (States.WORKSPACE_DEPLOYMENT === item.state && this.$scope.component.groups && this.$scope.component.groups.length === 0 && this.$scope.component.isResource());
684         });
685
686         if (this.cacheService.get('breadcrumbsComponents')) {
687             this.initBreadcrumbs();
688         } else {
689             let onSuccess = (components:Array<Component>) => {
690                 this.cacheService.set('breadcrumbsComponents', components);
691                 this.initBreadcrumbs();
692             };
693             this.EntityService.getCatalog().then(onSuccess); //getAllComponents() doesnt return components from catalog
694         }
695     }
696
697     private disableMenuItems() {
698         this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
699             item.params = [item.state];
700             item.callback = this.$scope.onMenuItemPressed;
701             item.isDisabled = (States.WORKSPACE_GENERAL != item.state);
702         });
703     }
704
705     private enableMenuItems() {
706         this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
707             item.params = [item.state];
708             item.callback = this.$scope.onMenuItemPressed;
709             item.isDisabled = false;
710         });
711     }
712
713     private showSuccessNotificationMessage = ():void => {
714         this.Notification.success({
715             message: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_FINISHED_DESCRIPTION"),
716             title: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_FINISHED_TITLE")
717         });
718     };
719
720 }
721
722