[sdc] update code of sdc
[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.EventListenerService.notifyObservers(EVENTS.ON_CHECKOUT, component);
428                         // this.$state.go(this.$state.current.name, {
429                         //     id: component.uniqueId,
430                         //     type: component.componentType.toLowerCase(),
431                         //     components: this.components
432                         // });
433                         this.$scope.mode = this.initViewMode();
434                         this.initChangeLifecycleStateButtons();
435                         this.initVersionObject();
436                         this.$scope.isLoading = false;
437
438                         this.Notification.success({
439                             message: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TEXT"),
440                             title: this.$filter('translate')("CHECKOUT_SUCCESS_MESSAGE_TITLE")
441                         });
442                         break;
443                     case 'lifecycleState/CHECKIN':
444                         defaultActionAfterChangeLifecycleState();
445                         this.Notification.success({
446                             message: this.$filter('translate')("CHECKIN_SUCCESS_MESSAGE_TEXT"),
447                             title: this.$filter('translate')("CHECKIN_SUCCESS_MESSAGE_TITLE")
448                         });
449                         break;
450                     case 'lifecycleState/UNDOCHECKOUT':
451                         defaultActionAfterChangeLifecycleState();
452                         this.Notification.success({
453                             message: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TEXT"),
454                             title: this.$filter('translate')("DELETE_SUCCESS_MESSAGE_TITLE")
455                         });
456                         break;
457                     case 'lifecycleState/certificationRequest':
458                         defaultActionAfterChangeLifecycleState();
459                         this.Notification.success({
460                             message: this.$filter('translate')("SUBMIT_FOR_TESTING_SUCCESS_MESSAGE_TEXT"),
461                             title: this.$filter('translate')("SUBMIT_FOR_TESTING_SUCCESS_MESSAGE_TITLE")
462                         });
463                         break;
464                     //Tester Role
465                     case 'lifecycleState/failCertification':
466                         defaultActionAfterChangeLifecycleState();
467                         this.Notification.success({
468                             message: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TEXT"),
469                             title: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TITLE")
470                         });
471                         break;
472                     case 'lifecycleState/certify':
473                         defaultActionAfterChangeLifecycleState();
474                         this.Notification.success({
475                             message: this.$filter('translate')("ACCEPT_TESTING_SUCCESS_MESSAGE_TEXT"),
476                             title: this.$filter('translate')("ACCEPT_TESTING_SUCCESS_MESSAGE_TITLE")
477                         });
478                         break;
479                     //DE203504 Bug Fix Start
480                     case 'lifecycleState/startCertification':
481                         this.initChangeLifecycleStateButtons();
482                         this.Notification.success({
483                             message: this.$filter('translate')("START_TESTING_SUCCESS_MESSAGE_TEXT"),
484                             title: this.$filter('translate')("START_TESTING_SUCCESS_MESSAGE_TITLE")
485                         });
486                         break;
487                     case  'lifecycleState/cancelCertification':
488                         this.initChangeLifecycleStateButtons();
489                         this.Notification.success({
490                             message: this.$filter('translate')("CANCEL_TESTING_SUCCESS_MESSAGE_TEXT"),
491                             title: this.$filter('translate')("CANCEL_TESTING_SUCCESS_MESSAGE_TITLE")
492                         });
493                         break;
494                     //Ops Role
495                     case  'distribution/PROD/activate':
496                         this.initChangeLifecycleStateButtons();
497                         this.Notification.success({
498                             message: this.$filter('translate')("DISTRIBUTE_SUCCESS_MESSAGE_TEXT"),
499                             title: this.$filter('translate')("DISTRIBUTE_SUCCESS_MESSAGE_TITLE")
500                         });
501                         break;
502                     //Governor Role
503                     case  'distribution-state/reject':
504                         this.initChangeLifecycleStateButtons();
505                         this.Notification.success({
506                             message: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TEXT"),
507                             title: this.$filter('translate')("REJECT_SUCCESS_MESSAGE_TITLE")
508                         });
509                         break;
510                     case  'distribution-state/approve':
511                         this.initChangeLifecycleStateButtons();
512                         this.$state.go('catalog');
513                         this.Notification.success({
514                             message: this.$filter('translate')("APPROVE_SUCCESS_MESSAGE_TEXT"),
515                             title: this.$filter('translate')("APPROVE_SUCCESS_MESSAGE_TITLE")
516                         });
517                         break;
518                     //DE203504 Bug Fix End
519
520                     default :
521                         defaultActionAfterChangeLifecycleState();
522
523                 }
524                 if (data.url != 'lifecycleState/CHECKOUT') {
525                     this.$scope.isLoading = false;
526                 }
527             };
528             //this.$scope.isLoading = true;
529             this.ChangeLifecycleStateHandler.changeLifecycleState(this.$scope.component, data, this.$scope, onSuccess);
530         };
531
532         this.$scope.enabledTabs = ():void => {
533             this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
534                 item.isDisabled = false;
535             });
536         };
537
538         this.$scope.isViewMode = ():boolean => {
539             return this.$scope.mode === WorkspaceMode.VIEW;
540         };
541
542         this.$scope.isDesigner = ():boolean => {
543             return this.role == Role.DESIGNER;
544         };
545
546         this.$scope.isProductManager = ():boolean => {
547             return this.role == Role.PRODUCT_MANAGER;
548         };
549
550         this.$scope.isDisableMode = ():boolean => {
551             return this.$scope.mode === WorkspaceMode.VIEW && this.$scope.component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKIN;
552         };
553
554         this.$scope.showFullIcons = ():boolean => {
555             //we show revert and save icons only in general\icon view
556             return this.$state.current.name === States.WORKSPACE_GENERAL ||
557                 this.$state.current.name === States.WORKSPACE_ICONS;
558         };
559
560         this.$scope.isCreateMode = ():boolean => {
561             return this.$scope.mode === WorkspaceMode.CREATE;
562         };
563
564         this.$scope.isEditMode = ():boolean => {
565             return this.$scope.mode === WorkspaceMode.EDIT;
566         };
567
568         this.$scope.goToBreadcrumbHome = ():void => {
569             let bcHome:MenuItemGroup = this.$scope.breadcrumbsModel[0];
570             this.$state.go(bcHome.menuItems[bcHome.selectedIndex].state);
571         };
572
573         this.$scope.showLifecycleIcon = ():boolean => {
574             return this.role == Role.DESIGNER ||
575                 this.role == Role.PRODUCT_MANAGER;
576         };
577
578         this.$scope.getStatus = ():string => {
579             if (this.$scope.isCreateMode()) {
580                 return 'IN DESIGN';
581             }
582
583             return this.$scope.component.getStatus(this.sdcMenu);
584         };
585
586         this.initMenuItems();
587
588         this.$scope.showChangeStateButton = ():boolean => {
589             let result:boolean = true;
590             if (!this.$scope.component.isLatestVersion() && Role.OPS != this.role && Role.GOVERNOR != this.role) {
591                 result = false;
592             }
593             if (this.role === Role.PRODUCT_MANAGER && !this.$scope.component.isProduct()) {
594                 result = false;
595             }
596             if ((this.role === Role.DESIGNER || this.role === Role.TESTER)
597                 && this.$scope.component.isProduct()) {
598                 result = false;
599             }
600             if (ComponentState.NOT_CERTIFIED_CHECKOUT === this.$scope.component.lifecycleState && this.$scope.isViewMode()) {
601                 result = false;
602             }
603             if (ComponentState.CERTIFIED != this.$scope.component.lifecycleState &&
604                 (Role.OPS == this.role || Role.GOVERNOR == this.role)) {
605                 result = false;
606             }
607             return result;
608         };
609
610         this.$scope.updateSelectedMenuItem = ():void => {
611             let selectedItem:MenuItem = _.find(this.$scope.leftBarTabs.menuItems, (item:MenuItem) => {
612                 return item.state === this.$state.current.name;
613             });
614             this.$scope.leftBarTabs.selectedIndex = selectedItem ? this.$scope.leftBarTabs.menuItems.indexOf(selectedItem) : 0;
615         };
616
617         this.$scope.$watch('$state.current.name', (newVal:string):void => {
618             if (newVal) {
619                 this.$scope.isComposition = (newVal.indexOf(States.WORKSPACE_COMPOSITION) > -1);
620                 this.$scope.isDeployment = (newVal.indexOf(States.WORKSPACE_DEPLOYMENT) > -1);
621             }
622         });
623     };
624
625     private initAfterScope = ():void => {
626         // In case user select csar from the onboarding modal, need to disable checkout and submit for testing.
627         if (this.$state.params['disableButtons'] === true) {
628             this.$scope.uploadFileChangedInGeneralTab();
629         }
630     };
631
632     private initVersionObject = ():void => {
633         this.$scope.versionsList = (this.$scope.component.getAllVersionsAsSortedArray()).reverse();
634         this.$scope.changeVersion = {selectedVersion: _.find(this.$scope.versionsList, {versionId: this.$scope.component.uniqueId})};
635     };
636
637     private getNewComponentBreadcrumbItem = ():MenuItem => {
638         let text = "";
639         if (this.$scope.component.isResource() && (<Resource>this.$scope.component).isCsarComponent()) {
640             text = this.$scope.component.getComponentSubType() + ': ' + this.$scope.component.name;
641         } else {
642             text = 'Create new ' + this.$state.params['type'];
643         }
644         return new MenuItem(text, null, States.WORKSPACE_GENERAL, 'goToState', [this.$state.params]);
645     };
646
647     private updateMenuItemByRole = (menuItems:Array<MenuItem>, role:string) => {
648         let tempMenuItems:Array<MenuItem> = new Array<MenuItem>();
649         menuItems.forEach((item:MenuItem) => {
650             //remove item if role is disabled
651             if (!(item.disabledRoles && item.disabledRoles.indexOf(role) > -1)) {
652                 tempMenuItems.push(item);
653             }
654         });
655         return tempMenuItems;
656     };
657
658     private initBreadcrumbs = () => {
659         this.components = this.cacheService.get('breadcrumbsComponents');
660         let breadcrumbsComponentsLvl = this.MenuHandler.generateBreadcrumbsModelFromComponents(this.components, this.$scope.component);
661
662         if (this.$scope.isCreateMode()) {
663             let createItem = this.getNewComponentBreadcrumbItem();
664             if (!breadcrumbsComponentsLvl.menuItems) {
665                 breadcrumbsComponentsLvl.menuItems = [];
666             }
667             breadcrumbsComponentsLvl.menuItems.unshift(createItem);
668             breadcrumbsComponentsLvl.selectedIndex = 0;
669         }
670
671         this.$scope.breadcrumbsModel = [breadcrumbsComponentsLvl, this.$scope.leftBarTabs];
672     };
673
674     private initMenuItems() {
675
676         let inCreateMode = this.$scope.isCreateMode();
677         this.$scope.leftBarTabs = new MenuItemGroup();
678         this.$scope.leftBarTabs.menuItems = this.updateMenuItemByRole(this.sdcMenu.component_workspace_menu_option[this.$scope.component.getComponentSubType()], this.role);
679
680         this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
681             item.params = [item.state];
682             item.callback = this.$scope.onMenuItemPressed;
683             item.isDisabled = (inCreateMode && States.WORKSPACE_GENERAL != item.state) ||
684                 (States.WORKSPACE_DEPLOYMENT === item.state && this.$scope.component.groups && this.$scope.component.groups.length === 0 && this.$scope.component.isResource());
685         });
686
687         if (this.cacheService.get('breadcrumbsComponents')) {
688             this.initBreadcrumbs();
689         } else {
690             let onSuccess = (components:Array<Component>) => {
691                 this.cacheService.set('breadcrumbsComponents', components);
692                 this.initBreadcrumbs();
693             };
694             this.EntityService.getCatalog().then(onSuccess); //getAllComponents() doesnt return components from catalog
695         }
696     }
697
698     private disableMenuItems() {
699         this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
700             item.params = [item.state];
701             item.callback = this.$scope.onMenuItemPressed;
702             item.isDisabled = (States.WORKSPACE_GENERAL != item.state);
703         });
704     }
705
706     private enableMenuItems() {
707         this.$scope.leftBarTabs.menuItems.forEach((item:MenuItem) => {
708             item.params = [item.state];
709             item.callback = this.$scope.onMenuItemPressed;
710             item.isDisabled = false;
711         });
712     }
713
714     private showSuccessNotificationMessage = ():void => {
715         this.Notification.success({
716             message: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_FINISHED_DESCRIPTION"),
717             title: this.$filter('translate')("IMPORT_VF_MESSAGE_CREATE_FINISHED_TITLE")
718         });
719     };
720
721 }
722
723