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 { AuthenticationService } from 'app/ng2/services/authentication.service';
24 import * as _ from 'lodash';
25 import 'ng-infinite-scroll';
26 import { SdcUiCommon, SdcUiComponents, SdcUiServices } from 'onap-ui-angular';
27 import 'reflect-metadata';
28 import { IAppConfigurtaion, IAppMenu, IHostedApplication, Resource } from './models';
29 import { Component } from './models/components/component';
30 import { IUserProperties } from './models/user';
31 import './modules/directive-module.ts';
32 import './modules/filters.ts';
33 import './modules/service-module';
34 import './modules/utils.ts';
35 import './modules/view-model-module.ts';
36 import { WorkspaceService } from './ng2/pages/workspace/workspace.service';
37 import { CookieService, DataTypesService, EcompHeaderService, LeftPaletteLoaderService } from './services';
38 import { CacheService, CatalogService, HomeService } from './services-ng2';
39 import { CHANGE_COMPONENT_CSAR_VERSION_FLAG, PREVIOUS_CSAR_COMPONENT, States } from './utils';
40 import { ComponentFactory } from './utils/component-factory';
42 const moduleName: string = 'sdcApp';
43 const viewModelsModuleName: string = 'Sdc.ViewModels';
44 const directivesModuleName: string = 'Sdc.Directives';
45 const servicesModuleName: string = 'Sdc.Services';
46 const filtersModuleName: string = 'Sdc.Filters';
47 const utilsModuleName: string = 'Sdc.Utils';
49 // Load configuration according to environment.
50 declare var __ENV__: string;
51 let sdcConfig: IAppConfigurtaion;
52 let sdcMenu: IAppMenu;
53 let pathPrefix: string = '';
54 if (__ENV__ === 'dev') {
55 sdcConfig = require('./../../configurations/dev.js');
56 } else if (__ENV__ === 'prod') {
57 sdcConfig = require('./../../configurations/prod.js');
60 console.log('ERROR: Environment configuration not found!');
62 sdcMenu = require('./../../configurations/menu.js');
64 const dependentModules: string[] = [
77 'pascalprecht.translate',
90 // ===================== Hosted applications section ====================
91 // Define here new hosted apps
92 const hostedApplications: IHostedApplication[] = [
94 moduleName: 'dcaeApp',
96 defaultState: 'dcae.app.home',
100 relativeHtmlPath: 'dcae-app/dcae-app-view.html',
101 controllerName: '.DcaeAppViewModel'
106 // Check if module exists (in case the javascript was not loaded).
107 const isModuleExists = (moduleName: string): boolean => {
109 angular.module(moduleName);
110 dependentModules.push(moduleName);
113 console.log('Module ' + moduleName + ' does not exists');
118 // Check which hosted applications exists
119 _.each(hostedApplications, (hostedApp) => {
120 if (isModuleExists(hostedApp.moduleName)) {
121 hostedApp.exists = true;
124 // ===================== Hosted applications section ====================
126 export const ng1appModule: ng.IModule = angular.module(moduleName, dependentModules);
128 ng1appModule.config([
130 '$translateProvider',
131 '$urlRouterProvider',
133 'tooltipsConfigProvider',
134 'NotificationProvider',
135 ($stateProvider: any,
136 $translateProvider: any,
137 $urlRouterProvider: ng.ui.IUrlRouterProvider,
138 $httpProvider: ng.IHttpProvider,
139 tooltipsConfigProvider: any,
140 NotificationProvider: any): void => {
142 NotificationProvider.setOptions({
148 horizontalSpacing: 20,
152 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
154 $translateProvider.useStaticFilesLoader({
155 prefix: pathPrefix + 'assets/languages/',
157 suffix: '.json?d=' + (new Date()).getTime()
159 $translateProvider.useSanitizeValueStrategy('escaped');
160 $translateProvider.preferredLanguage('en_US');
162 $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
163 $urlRouterProvider.otherwise('dashboard');
165 $stateProvider.state(
167 url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed',
168 template: '<home-page></home-page>',
169 permissions: ['DESIGNER']
173 const componentsParam: any[] = ['$stateParams', 'HomeService', 'CatalogService', 'Sdc.Services.CacheService', ($stateParams: any, HomeService: HomeService, CatalogService: CatalogService, cacheService: CacheService) => {
174 if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
175 const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
176 if (breadcrumbsComponents) {
177 return breadcrumbsComponents;
180 let breadcrumbsComponentsObservable;
181 if ($stateParams.previousState === 'dashboard') {
182 breadcrumbsComponentsObservable = HomeService.getAllComponents(true);
183 } else if ($stateParams.previousState === 'catalog') {
184 breadcrumbsComponentsObservable = CatalogService.getCatalog();
186 cacheService.remove('breadcrumbsComponentsState');
187 cacheService.remove('breadcrumbsComponents');
190 breadcrumbsComponentsObservable.subscribe((components) => {
191 cacheService.set('breadcrumbsComponentsState', $stateParams.previousState);
192 cacheService.set('breadcrumbsComponents', components);
194 return breadcrumbsComponentsObservable;
198 const oldWorkspaceController: any[] = ['$location', ($location: ng.ILocationService) => {
199 // redirect old /workspace/* urls to /catalog/workspace/* url
200 const newUrl = '/catalog' + $location.url();
201 console.log('old workspace path - redirecting to:', newUrl);
202 $location.url(newUrl);
205 $stateProvider.state(
207 url: '/workspace/:id/:type/*workspaceInnerPath',
208 controller: oldWorkspaceController
212 $stateProvider.state(
213 States.TYPE_WORKSPACE, {
214 url: '/:previousState/type-workspace/:type/:id/:subPage',
218 template: '<app-type-workspace></app-type-workspace>'
222 $stateProvider.state(
224 url: '/:previousState/workspace/:id/:type/',
231 templateUrl: './view-models/workspace/workspace-view.html',
232 controller: viewModelsModuleName + '.WorkspaceViewModel',
234 injectComponent: ['$stateParams', 'ComponentFactory', 'workspaceService', 'Sdc.Services.CacheService', function($stateParams, ComponentFactory: ComponentFactory, workspaceService: WorkspaceService, cacheService: CacheService) {
235 if ($stateParams.id && $stateParams.id.length) { // need to check length in case ID is an empty string
236 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
237 (component: Component) => {
238 if ($stateParams.componentCsar && component.isResource()) {
239 if ((component as Resource).csarVersion != $stateParams.componentCsar.csarVersion) {
240 cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
242 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, component as Resource);
244 workspaceService.setComponentMetadata(component.componentMetadata);
247 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
248 return $stateParams.componentCsar;
250 const emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
251 if (emptyComponent.isResource() && $stateParams.resourceType) {
252 // Set the resource type
253 (emptyComponent as Resource).resourceType = $stateParams.resourceType;
255 if ($stateParams.importedFile) {
256 (emptyComponent as Resource).importedFile = $stateParams.importedFile;
258 return emptyComponent;
261 components: componentsParam
266 $stateProvider.state(
267 States.WORKSPACE_GENERAL, {
270 controller: viewModelsModuleName + '.GeneralViewModel',
271 templateUrl: './view-models/workspace/tabs/general/general-view.html',
272 data: {unsavedChanges: false, bodyClass: 'general'}
276 $stateProvider.state(
277 States.WORKSPACE_INFORMATION_ARTIFACTS, {
278 url: 'information_artifacts',
280 template: '<information-artifact-page></information-artifact-page>'
284 $stateProvider.state(
285 States.WORKSPACE_TOSCA_ARTIFACTS, {
286 url: 'tosca_artifacts',
288 template: '<tosca-artifact-page></tosca-artifact-page>'
292 $stateProvider.state(
293 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
294 url: 'deployment_artifacts',
296 template: '<deployment-artifact-page></deployment-artifact-page>'
300 $stateProvider.state(
301 States.WORKSPACE_PROPERTIES, {
304 controller: viewModelsModuleName + '.PropertiesViewModel',
305 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
307 bodyClass: 'properties'
312 $stateProvider.state(
313 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
314 url: 'properties_assignment',
315 params: {component: null},
316 template: '<properties-assignment></properties-assignment>',
319 componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
320 $stateParams.component = injectComponent;
321 return injectComponent;
325 bodyClass: 'properties-assignment'
330 $stateProvider.state(
331 States.WORKSPACE_ATTRIBUTES, {
334 template: '<attributes></attributes>',
338 $stateProvider.state(
339 States.WORKSPACE_ATTRIBUTES_OUTPUTS, {
340 url: 'attributes_outputs',
342 template: '<attributes-outputs></attributes-outputs>',
344 componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
345 $stateParams.component = injectComponent;
346 return injectComponent;
350 bodyClass: 'attributes-outputs'
355 $stateProvider.state(
356 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
357 url: 'req_and_capabilities',
359 template: '<req-and-capabilities></req-and-capabilities>',
361 bodyClass: 'attributes'
365 $stateProvider.state(
366 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES_EDITABLE, {
367 url: 'req_and_capabilities_editable',
369 template: '<req-and-capabilities></req-and-capabilities>',
371 bodyClass: 'attributes'
376 $stateProvider.state(
377 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
379 url: 'management_workflow',
380 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
381 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
385 $stateProvider.state(
386 States.WORKSPACE_NETWORK_CALL_FLOW, {
388 url: 'network_call_flow',
389 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
390 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
394 $stateProvider.state(
395 States.WORKSPACE_COMPOSITION, {
397 params: {component: null},
399 template: '<composition-page></composition-page>',
401 componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
402 $stateParams.component = injectComponent;
403 return injectComponent;
407 bodyClass: 'composition'
412 $stateProvider.state(
413 States.WORKSPACE_ACTIVITY_LOG, {
414 url: 'activity_log/',
416 template: '<activity-log></activity-log>',
420 $stateProvider.state(
421 States.WORKSPACE_DISTRIBUTION, {
424 template: '<distribution></distribution>',
428 $stateProvider.state(
429 States.WORKSPACE_DEPLOYMENT, {
432 template: '<deployment-page></deployment-page>',
437 $stateProvider.state(
438 'workspace.composition.details', {
440 parent: 'workspace.composition',
442 componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
443 $stateParams.component = injectComponent;
444 return injectComponent;
451 $stateProvider.state(
452 'workspace.composition.properties', {
454 parent: 'workspace.composition'
458 $stateProvider.state(
459 'workspace.composition.artifacts', {
461 parent: 'workspace.composition'
466 $stateProvider.state(
467 'workspace.composition.relations', {
469 parent: 'workspace.composition'
473 $stateProvider.state(
474 'workspace.composition.structure', {
476 parent: 'workspace.composition'
479 $stateProvider.state(
480 'workspace.composition.lifecycle', {
482 parent: 'workspace.composition'
486 $stateProvider.state(
487 'workspace.composition.api', {
489 parent: 'workspace.composition'
492 $stateProvider.state(
493 'workspace.composition.deployment', {
495 parent: 'workspace.composition'
499 $stateProvider.state(
500 States.WORKSPACE_INTERFACE_OPERATION, {
501 url: 'interface_operation',
503 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
504 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
506 bodyClass: 'interface_operation'
511 $stateProvider.state(
512 States.WORKSPACE_INTERFACE_DEFINITION, {
513 url: 'interfaceDefinition',
515 controller: viewModelsModuleName + '.InterfaceDefinitionViewModel',
516 templateUrl: './view-models/workspace/tabs/interface-definition/interface-definition-view.html',
518 bodyClass: 'interfaceDefinition'
523 $stateProvider.state(
524 'workspace.plugins', {
525 url: 'plugins/*path',
527 template: '<plugin-context-view></plugin-context-view>',
529 componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
530 $stateParams.component = injectComponent;
531 return injectComponent;
538 $stateProvider.state(
540 url: '/adminDashboard',
541 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
542 controller: viewModelsModuleName + '.AdminDashboardViewModel',
543 permissions: ['ADMIN']
547 $stateProvider.state(
549 url: '/onboardVendor',
550 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
551 controller: viewModelsModuleName + '.OnboardVendorViewModel'
555 $stateProvider.state(
557 url: '/plugins/*path',
558 template: '<plugin-tab-view></plugin-tab-view>'
562 // Build the states for all hosted apps dynamically
563 _.each(hostedApplications, (hostedApp) => {
564 if (hostedApp.exists) {
565 $stateProvider.state(
566 hostedApp.state.name, {
567 url: hostedApp.state.url,
568 templateUrl: './view-models/dcae-app/dcae-app-view.html',
569 controller: viewModelsModuleName + hostedApp.state.controllerName
575 $stateProvider.state(
577 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
578 template: '<catalog-page></catalog-page>',
580 auth: ['$q', 'AuthenticationServiceNg2', ($q: any, authService: AuthenticationService) => {
581 const userInfo: IUserProperties = authService.getLoggedinUser();
583 return $q.when(userInfo);
585 return $q.reject({authenticated: false});
592 $stateProvider.state(
595 templateUrl: './view-models/modals/error-modal/error-403-view.html',
596 controller: viewModelsModuleName + '.ErrorViewModel'
600 tooltipsConfigProvider.options({
603 class: 'tooltip-custom',
611 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
612 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); // DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
613 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9._:\-@]{1,100}$/); // DE210977
614 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
615 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
616 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
617 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
618 ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
619 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
620 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
621 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
622 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
623 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
624 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
625 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
626 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
627 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
628 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
629 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
630 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
632 ng1appModule.constant('sdcConfig', sdcConfig);
633 ng1appModule.constant('sdcMenu', sdcMenu);
637 'Sdc.Services.CacheService',
638 'Sdc.Services.CookieService',
639 'AuthenticationServiceNg2',
644 'Sdc.Services.EcompHeaderService',
645 'LeftPaletteLoaderService',
646 'Sdc.Services.DataTypesService',
650 ($http: ng.IHttpService,
651 cacheService: CacheService,
652 cookieService: CookieService,
653 authService: AuthenticationService,
654 $state: ng.ui.IStateService,
655 $rootScope: ng.IRootScopeService,
656 $location: ng.ILocationService,
658 ecompHeaderService: EcompHeaderService,
659 LeftPaletteLoaderService: LeftPaletteLoaderService,
660 DataTypesService: DataTypesService,
662 $templateCache: ng.ITemplateCacheService,
663 ModalServiceSdcUI: SdcUiServices.ModalService): void => {
664 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
665 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
667 // Add hosted applications to sdcConfig
668 sdcConfig.hostedApplications = hostedApplications;
670 // handle http config
671 $http.defaults.withCredentials = true;
672 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
674 DataTypesService.loadDataTypesCache(null);
676 // handle stateChangeStart
677 const internalDeregisterStateChangeStartWatcher: Function = (): void => {
678 if (deregisterStateChangeStartWatcher) {
679 deregisterStateChangeStartWatcher();
680 deregisterStateChangeStartWatcher = null;
682 if (deregisterStateChangeSuccessWatcher) {
683 deregisterStateChangeSuccessWatcher();
684 deregisterStateChangeSuccessWatcher = null;
688 const removeLoader: Function = (): void => {
689 $('.sdc-loading-page .main-loader').addClass('animated fadeOut');
690 $('.sdc-loading-page .caption1').addClass('animated fadeOut');
691 $('.sdc-loading-page .caption2').addClass('animated fadeOut');
692 window.setTimeout((): void => {
693 $('.sdc-loading-page .main-loader').css('display', 'none');
694 $('.sdc-loading-page .caption1').css('display', 'none');
695 $('.sdc-loading-page .caption2').css('display', 'none');
696 $('.sdc-loading-page').addClass('animated fadeOut');
700 const onNavigateOut: Function = (toState, toParams): void => {
701 const onOk: Function = (): void => {
702 $state.current.data.unsavedChanges = false;
703 $state.go(toState.name, toParams);
706 const data = sdcMenu.alertMessages.exitWithoutSaving;
709 text: sdcMenu.alertMessages.okButton,
710 type: SdcUiCommon.ButtonType.warning,
713 } as SdcUiComponents.ModalButtonComponent;
714 // open notify to user if changes are not saved
715 ModalServiceSdcUI.openWarningModal(data.title,
721 const onStateChangeStart: Function = (event, toState, toParams, fromState, fromParams): void => {
722 console.debug((new Date()).getTime());
723 console.debug('$stateChangeStart', toState.name);
724 if (toState.name !== 'error-403' && !authService.getLoggedinUser()) {
726 authService.authenticate().subscribe((userInfo: IUserProperties) => {
727 if (!doesUserHasAccess(toState, userInfo)) {
728 $state.go('error-403');
729 console.debug('User has no permissions');
732 authService.setLoggedinUser(userInfo);
733 setTimeout(function() {
737 if (authService.getLoggedinUser().role === 'ADMIN') {
738 $state.go('adminDashboard', toParams);
742 // After user authorized init categories
743 window.setTimeout((): void => {
744 if ($state.current.name === '') {
745 $state.go(toState.name, toParams);
748 console.log('------$state.current.name=' + $state.current.name);
755 $state.go('error-403');
757 } else if (authService.getLoggedinUser()) {
758 const user: IUserProperties = authService.getLoggedinUser();
759 if (!cacheService.contains('user')) {
760 cacheService.set('user', user);
763 if (!doesUserHasAccess(toState, authService.getLoggedinUser())) {
764 event.preventDefault();
765 $state.go('error-403');
766 console.debug('User has no permissions');
769 if (authService.getLoggedinUser().role === 'ADMIN') {
770 $state.go('adminDashboard', toParams);
774 // if form is dirty and not save - notify to user
775 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
776 event.preventDefault();
777 onNavigateOut(toState, toParams);
781 // if enetering workspace, set the previousState param
782 if (toState.name.indexOf('workspace') !== -1) {
783 if (!toParams.previousState) {
784 const tmpPreviousState1 = fromParams && fromParams.previousState;
785 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
786 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
792 const onStateChangeSuccess: Function = (event, toState, toParams, fromState, fromParams): void => {
793 console.debug('$stateChangeSuccess', toState.name);
795 // Workaround in case we are entering other state then workspace (user move to catalog)
796 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
797 if (toState.name.indexOf('workspace') === -1) {
798 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
799 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
801 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)) {
802 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
807 $rootScope.bodyClass = 'default-class';
808 if (toState.data && toState.data.bodyClass) {
809 $rootScope.bodyClass = toState.data.bodyClass;
813 const doesUserHasAccess: Function = (toState, user): boolean => {
815 let isUserHasAccess = true;
816 if (toState.permissions && toState.permissions.length > 0) {
817 isUserHasAccess = _.includes(toState.permissions, user.role);
819 return isUserHasAccess;
821 let deregisterStateChangeStartWatcher: Function;
822 let deregisterStateChangeSuccessWatcher: Function;
824 const registerStateChangeStartWatcher: Function = (): void => {
825 internalDeregisterStateChangeStartWatcher();
826 console.debug('registerStateChangeStartWatcher $stateChangeStart');
827 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams): void => {
828 onStateChangeStart(event, toState, toParams, fromState, fromParams);
830 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams): void => {
831 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
834 registerStateChangeStartWatcher();