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=========================================================
23 import * as _ from "lodash";
24 import "reflect-metadata";
25 import 'ng-infinite-scroll';
26 import './modules/filters.ts';
27 import './modules/utils.ts';
28 import './modules/directive-module.ts';
29 import './modules/service-module';
30 import './modules/view-model-module.ts';
31 import {SdcUiCommon, SdcUiComponents, SdcUiServices} from 'onap-ui-angular';
37 LeftPaletteLoaderService
39 import {CacheService, CatalogService, HomeService} from "./services-ng2";
40 import {AuthenticationService} from "app/ng2/services/authentication.service";
41 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, PREVIOUS_CSAR_COMPONENT, States} from "./utils";
42 import {IAppConfigurtaion, IAppMenu, IHostedApplication, Resource} from "./models";
43 import {ComponentFactory} from "./utils/component-factory";
44 import {Component} from "./models/components/component";
45 import {IUserProperties} from "./models/user";
46 import {WorkspaceService} from "./ng2/pages/workspace/workspace.service";
48 let moduleName:string = 'sdcApp';
49 let viewModelsModuleName:string = 'Sdc.ViewModels';
50 let directivesModuleName:string = 'Sdc.Directives';
51 let servicesModuleName:string = 'Sdc.Services';
52 let filtersModuleName:string = 'Sdc.Filters';
53 let utilsModuleName:string = 'Sdc.Utils';
55 // Load configuration according to environment.
56 declare var __ENV__:string;
57 let sdcConfig:IAppConfigurtaion;
59 let pathPrefix:string = '';
60 if (__ENV__ === 'dev') {
61 sdcConfig = require('./../../configurations/dev.js');
62 } else if (__ENV__ === 'prod') {
63 sdcConfig = require('./../../configurations/prod.js');
66 console.log("ERROR: Environment configuration not found!");
68 sdcMenu = require('./../../configurations/menu.js');
70 let dependentModules:Array<string> = [
83 'pascalprecht.translate',
96 // ===================== Hosted applications section ====================
97 // Define here new hosted apps
98 let hostedApplications:Array<IHostedApplication> = [
100 "moduleName": "dcaeApp",
102 "defaultState": 'dcae.app.home',
106 "relativeHtmlPath": 'dcae-app/dcae-app-view.html',
107 "controllerName": '.DcaeAppViewModel'
112 // Check if module exists (in case the javascript was not loaded).
113 let isModuleExists = (moduleName:string):boolean => {
115 angular.module(moduleName);
116 dependentModules.push(moduleName);
119 console.log('Module ' + moduleName + ' does not exists');
124 // Check which hosted applications exists
125 _.each(hostedApplications, (hostedApp)=> {
126 if (isModuleExists(hostedApp.moduleName)) {
127 hostedApp['exists'] = true;
130 // ===================== Hosted applications section ====================
132 export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
134 ng1appModule.config([
136 '$translateProvider',
137 '$urlRouterProvider',
139 'tooltipsConfigProvider',
140 'NotificationProvider',
142 $translateProvider:any,
143 $urlRouterProvider:ng.ui.IUrlRouterProvider,
144 $httpProvider:ng.IHttpProvider,
145 tooltipsConfigProvider:any,
146 NotificationProvider:any):void => {
148 NotificationProvider.setOptions({
154 horizontalSpacing: 20,
158 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
160 $translateProvider.useStaticFilesLoader({
161 prefix: pathPrefix + 'assets/languages/',
163 suffix: '.json?d=' + (new Date()).getTime()
165 $translateProvider.useSanitizeValueStrategy('escaped');
166 $translateProvider.preferredLanguage('en_US');
168 $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
169 $urlRouterProvider.otherwise('dashboard');
171 $stateProvider.state(
173 url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed',
174 template: '<home-page></home-page>',
175 permissions: ['DESIGNER']
181 let componentsParam:Array<any> = ['$stateParams', 'HomeService', 'CatalogService', 'Sdc.Services.CacheService', ($stateParams:any, HomeService:HomeService, CatalogService:CatalogService, cacheService:CacheService) => {
182 if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
183 const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
184 if (breadcrumbsComponents) {
185 return breadcrumbsComponents;
188 let breadcrumbsComponentsObservable;
189 if ($stateParams.previousState === 'dashboard') {
190 breadcrumbsComponentsObservable = HomeService.getAllComponents(true);
191 } else if ($stateParams.previousState === 'catalog') {
192 breadcrumbsComponentsObservable = CatalogService.getCatalog();
194 cacheService.remove('breadcrumbsComponentsState');
195 cacheService.remove('breadcrumbsComponents');
198 breadcrumbsComponentsObservable.subscribe((components) => {
199 cacheService.set('breadcrumbsComponentsState', $stateParams.previousState);
200 cacheService.set('breadcrumbsComponents', components);
202 return breadcrumbsComponentsObservable;
206 const oldWorkspaceController:Array<any> = ['$location', ($location:ng.ILocationService) => {
207 // redirect old /workspace/* urls to /catalog/workspace/* url
208 const newUrl = '/catalog' + $location.url();
209 console.log('old workspace path - redirecting to:', newUrl);
210 $location.url(newUrl);
213 $stateProvider.state(
215 url: '/workspace/:id/:type/*workspaceInnerPath',
216 controller: oldWorkspaceController
220 $stateProvider.state(
222 url: '/:previousState/workspace/:id/:type/',
223 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
224 templateUrl: './view-models/workspace/workspace-view.html',
225 controller: viewModelsModuleName + '.WorkspaceViewModel',
227 injectComponent: ['$stateParams', 'ComponentFactory', 'workspaceService', 'Sdc.Services.CacheService', function ($stateParams, ComponentFactory:ComponentFactory, workspaceService:WorkspaceService, cacheService: CacheService) {
229 if ($stateParams.id && $stateParams.id.length) { //need to check length in case ID is an empty string
230 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
231 (component:Component)=> {
232 if ($stateParams.componentCsar && component.isResource()){
233 if((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) {
234 cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
236 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
238 workspaceService.setComponentMetadata(component.componentMetadata);
241 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
242 return $stateParams.componentCsar;
244 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
245 if (emptyComponent.isResource() && $stateParams.resourceType) {
246 // Set the resource type
247 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
249 if ($stateParams.importedFile) {
250 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
252 return emptyComponent;
255 components: componentsParam
260 $stateProvider.state(
261 States.WORKSPACE_GENERAL, {
264 controller: viewModelsModuleName + '.GeneralViewModel',
265 templateUrl: './view-models/workspace/tabs/general/general-view.html',
266 data: {unsavedChanges: false, bodyClass: 'general'}
271 $stateProvider.state(
272 States.WORKSPACE_INFORMATION_ARTIFACTS, {
273 url: 'information_artifacts',
275 template:'<information-artifact-page></information-artifact-page>'
279 $stateProvider.state(
280 States.WORKSPACE_TOSCA_ARTIFACTS, {
281 url: 'tosca_artifacts',
283 template:'<tosca-artifact-page></tosca-artifact-page>'
288 $stateProvider.state(
289 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
290 url: 'deployment_artifacts',
292 template:'<deployment-artifact-page></deployment-artifact-page>'
296 $stateProvider.state(
297 States.WORKSPACE_PROPERTIES, {
300 controller: viewModelsModuleName + '.PropertiesViewModel',
301 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
303 bodyClass: 'properties'
308 $stateProvider.state(
309 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
310 url: 'properties_assignment',
311 params: {'component': null},
312 template: '<properties-assignment></properties-assignment>',
315 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
316 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
317 $stateParams.component = injectComponent;
318 return injectComponent;
322 bodyClass: 'properties-assignment'
327 $stateProvider.state(
328 States.WORKSPACE_ATTRIBUTES, {
331 template: '<attributes></attributes>',
335 $stateProvider.state(
336 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
337 url: 'req_and_capabilities',
339 template: '<req-and-capabilities></req-and-capabilities>',
341 bodyClass: 'attributes'
345 $stateProvider.state(
346 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES_EDITABLE, {
347 url: 'req_and_capabilities_editable',
349 template: '<req-and-capabilities></req-and-capabilities>',
351 bodyClass: 'attributes'
357 $stateProvider.state(
358 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
360 url: 'management_workflow',
361 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
362 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
366 $stateProvider.state(
367 States.WORKSPACE_NETWORK_CALL_FLOW, {
369 url: 'network_call_flow',
370 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
371 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
376 $stateProvider.state(
377 States.WORKSPACE_COMPOSITION, {
379 params: {'component': null},
381 template: '<composition-page></composition-page>',
383 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
384 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
385 $stateParams.component = injectComponent;
386 return injectComponent;
390 bodyClass: 'composition'
395 $stateProvider.state(
396 States.WORKSPACE_ACTIVITY_LOG, {
397 url: 'activity_log/',
399 template: '<activity-log></activity-log>',
404 $stateProvider.state(
405 States.WORKSPACE_DISTRIBUTION, {
408 template: '<distribution></distribution>',
413 $stateProvider.state(
414 States.WORKSPACE_DEPLOYMENT, {
417 template: '<deployment-page></deployment-page>',
422 $stateProvider.state(
423 'workspace.composition.details', {
425 parent: 'workspace.composition',
427 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
428 $stateParams.component = injectComponent;
429 return injectComponent;
436 $stateProvider.state(
437 'workspace.composition.properties', {
439 parent: 'workspace.composition'
443 $stateProvider.state(
444 'workspace.composition.artifacts', {
446 parent: 'workspace.composition'
451 $stateProvider.state(
452 'workspace.composition.relations', {
454 parent: 'workspace.composition'
458 $stateProvider.state(
459 'workspace.composition.structure', {
461 parent: 'workspace.composition'
464 $stateProvider.state(
465 'workspace.composition.lifecycle', {
467 parent: 'workspace.composition'
471 $stateProvider.state(
472 'workspace.composition.api', {
474 parent: 'workspace.composition'
477 $stateProvider.state(
478 'workspace.composition.deployment', {
480 parent: 'workspace.composition'
484 $stateProvider.state(
485 States.WORKSPACE_INTERFACE_OPERATION, {
486 url: 'interface_operation',
488 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
489 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
491 bodyClass: 'interface_operation'
496 $stateProvider.state(
497 'workspace.plugins', {
498 url: 'plugins/*path',
500 template: '<plugin-context-view></plugin-context-view>',
502 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
503 $stateParams.component = injectComponent;
504 return injectComponent;
511 $stateProvider.state(
513 url: '/adminDashboard',
514 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
515 controller: viewModelsModuleName + '.AdminDashboardViewModel',
516 permissions: ['ADMIN']
520 $stateProvider.state(
522 url: '/onboardVendor',
523 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
524 controller: viewModelsModuleName + '.OnboardVendorViewModel'
528 $stateProvider.state(
530 url: '/plugins/*path',
531 template: '<plugin-tab-view></plugin-tab-view>'
535 // Build the states for all hosted apps dynamically
536 _.each(hostedApplications, (hostedApp)=> {
537 if (hostedApp.exists) {
538 $stateProvider.state(
539 hostedApp.state.name, {
540 url: hostedApp.state.url,
541 templateUrl: './view-models/dcae-app/dcae-app-view.html',
542 controller: viewModelsModuleName + hostedApp.state.controllerName
548 $stateProvider.state(
550 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
551 template: '<catalog-page></catalog-page>',
553 auth: ["$q", "AuthenticationServiceNg2", ($q:any, authService:AuthenticationService) => {
554 let userInfo:IUserProperties = authService.getLoggedinUser();
556 return $q.when(userInfo);
558 return $q.reject({authenticated: false});
565 $stateProvider.state(
568 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
569 controller: viewModelsModuleName + '.ErrorViewModel'
573 tooltipsConfigProvider.options({
576 class: 'tooltip-custom',
584 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
585 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
586 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
587 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
588 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
589 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
590 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
591 ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
592 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
593 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
594 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
595 ng1appModule.value('UrlValidationPattern', /^(https?|ftp):\/\/(((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([A-Za-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([A-Za-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
596 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
597 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
598 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
599 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
600 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
601 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
602 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
603 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
605 ng1appModule.constant('sdcConfig', sdcConfig);
606 ng1appModule.constant('sdcMenu', sdcMenu);
610 'Sdc.Services.CacheService',
611 'Sdc.Services.CookieService',
612 'AuthenticationServiceNg2',
617 'Sdc.Services.EcompHeaderService',
618 'LeftPaletteLoaderService',
619 'Sdc.Services.DataTypesService',
623 ($http:ng.IHttpService,
624 cacheService:CacheService,
625 cookieService:CookieService,
626 authService:AuthenticationService,
627 $state:ng.ui.IStateService,
628 $rootScope:ng.IRootScopeService,
629 $location:ng.ILocationService,
631 ecompHeaderService:EcompHeaderService,
632 LeftPaletteLoaderService:LeftPaletteLoaderService,
633 DataTypesService:DataTypesService,
635 $templateCache:ng.ITemplateCacheService,
636 ModalServiceSdcUI:SdcUiServices.ModalService):void => {
637 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
638 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
640 // Add hosted applications to sdcConfig
641 sdcConfig.hostedApplications = hostedApplications;
644 $http.defaults.withCredentials = true;
645 // $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
646 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
648 DataTypesService.initDataTypes();
650 //handle stateChangeStart
651 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
652 if (deregisterStateChangeStartWatcher) {
653 deregisterStateChangeStartWatcher();
654 deregisterStateChangeStartWatcher = null;
656 if (deregisterStateChangeSuccessWatcher) {
657 deregisterStateChangeSuccessWatcher();
658 deregisterStateChangeSuccessWatcher = null;
662 let removeLoader:Function = ():void => {
663 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
664 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
665 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
666 window.setTimeout(():void=> {
667 $(".sdc-loading-page .main-loader").css("display", "none");
668 $(".sdc-loading-page .caption1").css("display", "none");
669 $(".sdc-loading-page .caption2").css("display", "none");
670 $(".sdc-loading-page").addClass("animated fadeOut");
674 let onNavigateOut:Function = (toState, toParams):void => {
675 let onOk:Function = ():void => {
676 $state.current.data.unsavedChanges = false;
677 $state.go(toState.name, toParams);
680 let data = sdcMenu.alertMessages.exitWithoutSaving;
683 text: sdcMenu.alertMessages.okButton,
684 type: SdcUiCommon.ButtonType.warning,
687 } as SdcUiComponents.ModalButtonComponent;
688 //open notify to user if changes are not saved
689 ModalServiceSdcUI.openWarningModal(data.title,
695 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
696 console.info((new Date()).getTime());
697 console.info('$stateChangeStart', toState.name);
698 if (toState.name !== 'error-403' && !authService.getLoggedinUser()) {
701 authService.authenticate().subscribe((userInfo:IUserProperties) => {
702 if (!doesUserHasAccess(toState, userInfo)) {
703 $state.go('error-403');
704 console.info('User has no permissions');
707 authService.setLoggedinUser(userInfo);
708 setTimeout(function () {
712 if (authService.getLoggedinUser().role === 'ADMIN') {
713 // toState.name = "adminDashboard";
714 $state.go("adminDashboard", toParams);
718 // After user authorized init categories
719 window.setTimeout(():void=> {
720 if ($state.current.name === '') {
721 $state.go(toState.name, toParams);
724 console.log("------$state.current.name=" + $state.current.name);
731 $state.go('error-403');
734 else if (authService.getLoggedinUser()) {
735 let user:IUserProperties = authService.getLoggedinUser();
736 if(!cacheService.contains('user')){
737 cacheService.set('user', user);
740 if (!doesUserHasAccess(toState, authService.getLoggedinUser())) {
741 event.preventDefault();
742 $state.go('error-403');
743 console.info('User has no permissions');
746 if (authService.getLoggedinUser().role === 'ADMIN') {
747 // toState.name = "adminDashboard";
748 $state.go("adminDashboard", toParams);
753 //if form is dirty and not save - notify to user
754 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
755 event.preventDefault();
756 onNavigateOut(toState, toParams);
760 // if enetering workspace, set the previousState param
761 if (toState.name.indexOf('workspace') !== -1) {
762 if (!toParams.previousState) {
763 const tmpPreviousState1 = fromParams && fromParams.previousState;
764 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
765 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
771 let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => {
772 console.info('$stateChangeSuccess', toState.name);
774 // Workaround in case we are entering other state then workspace (user move to catalog)
775 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
776 if (toState.name.indexOf('workspace') === -1) {
777 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
778 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
780 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)){
781 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
786 $rootScope['bodyClass'] = 'default-class';
787 if (toState.data && toState.data.bodyClass) {
788 $rootScope['bodyClass'] = toState.data.bodyClass;
792 let doesUserHasAccess:Function = (toState, user):boolean => {
794 let isUserHasAccess = true;
795 if (toState.permissions && toState.permissions.length > 0) {
796 isUserHasAccess = _.includes(toState.permissions, user.role);
798 return isUserHasAccess;
800 let deregisterStateChangeStartWatcher:Function;
801 let deregisterStateChangeSuccessWatcher:Function;
803 let registerStateChangeStartWatcher:Function = ():void => {
804 internalDeregisterStateChangeStartWatcher();
805 console.info('registerStateChangeStartWatcher $stateChangeStart');
806 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
807 onStateChangeStart(event, toState, toParams, fromState, fromParams);
809 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams):void => {
810 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
813 registerStateChangeStartWatcher();