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';
36 LeftPaletteLoaderService
38 import {CacheService, CatalogService, HomeService} from "./services-ng2";
39 import {AuthenticationService} from "app/ng2/services/authentication.service";
40 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, PREVIOUS_CSAR_COMPONENT, States} from "./utils";
41 import {IAppConfigurtaion, IAppMenu, IHostedApplication, Resource} from "./models";
42 import {ComponentFactory} from "./utils/component-factory";
43 import {Component} from "./models/components/component";
44 import {IUserProperties} from "./models/user";
45 import {WorkspaceService} from "./ng2/pages/workspace/workspace.service";
47 let moduleName: string = 'sdcApp';
48 let viewModelsModuleName: string = 'Sdc.ViewModels';
49 let directivesModuleName: string = 'Sdc.Directives';
50 let servicesModuleName: string = 'Sdc.Services';
51 let filtersModuleName: string = 'Sdc.Filters';
52 let utilsModuleName: string = 'Sdc.Utils';
54 // Load configuration according to environment.
55 declare var __ENV__: string;
56 let sdcConfig: IAppConfigurtaion;
57 let sdcMenu: IAppMenu;
58 let pathPrefix: string = '';
59 if (__ENV__ === 'dev') {
60 sdcConfig = require('./../../configurations/dev.js');
61 } else if (__ENV__ === 'prod') {
62 sdcConfig = require('./../../configurations/prod.js');
65 console.log("ERROR: Environment configuration not found!");
67 sdcMenu = require('./../../configurations/menu.js');
69 let dependentModules: Array<string> = [
82 'pascalprecht.translate',
95 // ===================== Hosted applications section ====================
96 // Define here new hosted apps
97 let hostedApplications: Array<IHostedApplication> = [
99 "moduleName": "dcaeApp",
101 "defaultState": 'dcae.app.home',
105 "relativeHtmlPath": 'dcae-app/dcae-app-view.html',
106 "controllerName": '.DcaeAppViewModel'
111 // Check if module exists (in case the javascript was not loaded).
112 let isModuleExists = (moduleName: string): boolean => {
114 angular.module(moduleName);
115 dependentModules.push(moduleName);
118 console.log('Module ' + moduleName + ' does not exists');
123 // Check which hosted applications exists
124 _.each(hostedApplications, (hostedApp) => {
125 if (isModuleExists(hostedApp.moduleName)) {
126 hostedApp['exists'] = true;
129 // ===================== Hosted applications section ====================
131 export const ng1appModule: ng.IModule = angular.module(moduleName, dependentModules);
133 ng1appModule.config([
135 '$translateProvider',
136 '$urlRouterProvider',
138 'tooltipsConfigProvider',
139 'NotificationProvider',
140 ($stateProvider: any,
141 $translateProvider: any,
142 $urlRouterProvider: ng.ui.IUrlRouterProvider,
143 $httpProvider: ng.IHttpProvider,
144 tooltipsConfigProvider: any,
145 NotificationProvider: any): void => {
147 NotificationProvider.setOptions({
153 horizontalSpacing: 20,
157 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
159 $translateProvider.useStaticFilesLoader({
160 prefix: pathPrefix + 'assets/languages/',
162 suffix: '.json?d=' + (new Date()).getTime()
164 $translateProvider.useSanitizeValueStrategy('escaped');
165 $translateProvider.preferredLanguage('en_US');
167 $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
168 $urlRouterProvider.otherwise('dashboard');
170 $stateProvider.state(
172 url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed',
173 template: '<home-page></home-page>',
174 permissions: ['DESIGNER']
179 let componentsParam: Array<any> = ['$stateParams', 'HomeService', 'CatalogService', 'Sdc.Services.CacheService', ($stateParams: any, HomeService: HomeService, CatalogService: CatalogService, cacheService: CacheService) => {
180 if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
181 const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
182 if (breadcrumbsComponents) {
183 return breadcrumbsComponents;
186 let breadcrumbsComponentsObservable;
187 if ($stateParams.previousState === 'dashboard') {
188 breadcrumbsComponentsObservable = HomeService.getAllComponents(true);
189 } else if ($stateParams.previousState === 'catalog') {
190 breadcrumbsComponentsObservable = CatalogService.getCatalog();
192 cacheService.remove('breadcrumbsComponentsState');
193 cacheService.remove('breadcrumbsComponents');
196 breadcrumbsComponentsObservable.subscribe((components) => {
197 cacheService.set('breadcrumbsComponentsState', $stateParams.previousState);
198 cacheService.set('breadcrumbsComponents', components);
200 return breadcrumbsComponentsObservable;
204 const oldWorkspaceController: Array<any> = ['$location', ($location: ng.ILocationService) => {
205 // redirect old /workspace/* urls to /catalog/workspace/* url
206 const newUrl = '/catalog' + $location.url();
207 console.log('old workspace path - redirecting to:', newUrl);
208 $location.url(newUrl);
211 $stateProvider.state(
213 url: '/workspace/:id/:type/*workspaceInnerPath',
214 controller: oldWorkspaceController
218 $stateProvider.state(
220 url: '/:previousState/workspace/:id/:type/',
222 'importedFile': null,
223 'componentCsar': null,
224 'resourceType': null,
225 'disableButtons': null
227 templateUrl: './view-models/workspace/workspace-view.html',
228 controller: viewModelsModuleName + '.WorkspaceViewModel',
230 injectComponent: ['$stateParams', 'ComponentFactory', 'workspaceService', 'Sdc.Services.CacheService', function ($stateParams, ComponentFactory: ComponentFactory, workspaceService: WorkspaceService, cacheService: CacheService) {
232 if ($stateParams.id && $stateParams.id.length) { //need to check length in case ID is an empty string
233 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
234 (component: Component) => {
235 if ($stateParams.componentCsar && component.isResource()) {
236 if ((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) {
237 cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
239 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
241 workspaceService.setComponentMetadata(component.componentMetadata);
244 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
245 return $stateParams.componentCsar;
247 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
248 if (emptyComponent.isResource() && $stateParams.resourceType) {
249 // Set the resource type
250 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
252 if ($stateParams.importedFile) {
253 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
255 return emptyComponent;
258 components: componentsParam
263 $stateProvider.state(
264 States.WORKSPACE_GENERAL, {
267 controller: viewModelsModuleName + '.GeneralViewModel',
268 templateUrl: './view-models/workspace/tabs/general/general-view.html',
269 data: {unsavedChanges: false, bodyClass: 'general'}
274 $stateProvider.state(
275 States.WORKSPACE_INFORMATION_ARTIFACTS, {
276 url: 'information_artifacts',
278 template: '<information-artifact-page></information-artifact-page>'
282 $stateProvider.state(
283 States.WORKSPACE_TOSCA_ARTIFACTS, {
284 url: 'tosca_artifacts',
286 template: '<tosca-artifact-page></tosca-artifact-page>'
291 $stateProvider.state(
292 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
293 url: 'deployment_artifacts',
295 template: '<deployment-artifact-page></deployment-artifact-page>'
299 $stateProvider.state(
300 States.WORKSPACE_PROPERTIES, {
303 controller: viewModelsModuleName + '.PropertiesViewModel',
304 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
306 bodyClass: 'properties'
311 $stateProvider.state(
312 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
313 url: 'properties_assignment',
314 params: {'component': null},
315 template: '<properties-assignment></properties-assignment>',
318 componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
319 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
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'
377 $stateProvider.state(
378 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
380 url: 'management_workflow',
381 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
382 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
386 $stateProvider.state(
387 States.WORKSPACE_NETWORK_CALL_FLOW, {
389 url: 'network_call_flow',
390 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
391 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
396 $stateProvider.state(
397 States.WORKSPACE_COMPOSITION, {
399 params: {'component': null},
401 template: '<composition-page></composition-page>',
403 componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
404 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
405 $stateParams.component = injectComponent;
406 return injectComponent;
410 bodyClass: 'composition'
415 $stateProvider.state(
416 States.WORKSPACE_ACTIVITY_LOG, {
417 url: 'activity_log/',
419 template: '<activity-log></activity-log>',
423 $stateProvider.state(
424 States.WORKSPACE_DISTRIBUTION, {
427 template: '<distribution></distribution>',
431 $stateProvider.state(
432 States.WORKSPACE_DEPLOYMENT, {
435 template: '<deployment-page></deployment-page>',
440 $stateProvider.state(
441 'workspace.composition.details', {
443 parent: 'workspace.composition',
445 componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
446 $stateParams.component = injectComponent;
447 return injectComponent;
454 $stateProvider.state(
455 'workspace.composition.properties', {
457 parent: 'workspace.composition'
461 $stateProvider.state(
462 'workspace.composition.artifacts', {
464 parent: 'workspace.composition'
469 $stateProvider.state(
470 'workspace.composition.relations', {
472 parent: 'workspace.composition'
476 $stateProvider.state(
477 'workspace.composition.structure', {
479 parent: 'workspace.composition'
482 $stateProvider.state(
483 'workspace.composition.lifecycle', {
485 parent: 'workspace.composition'
489 $stateProvider.state(
490 'workspace.composition.api', {
492 parent: 'workspace.composition'
495 $stateProvider.state(
496 'workspace.composition.deployment', {
498 parent: 'workspace.composition'
502 $stateProvider.state(
503 States.WORKSPACE_INTERFACE_OPERATION, {
504 url: 'interface_operation',
506 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
507 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
509 bodyClass: 'interface_operation'
514 $stateProvider.state(
515 States.WORKSPACE_INTERFACE_DEFINITION, {
516 url: 'interfaceDefinition',
518 controller: viewModelsModuleName + '.InterfaceDefinitionViewModel',
519 templateUrl: './view-models/workspace/tabs/interface-definition/interface-definition-view.html',
521 bodyClass: 'interfaceDefinition'
526 $stateProvider.state(
527 'workspace.plugins', {
528 url: 'plugins/*path',
530 template: '<plugin-context-view></plugin-context-view>',
532 componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
533 $stateParams.component = injectComponent;
534 return injectComponent;
541 $stateProvider.state(
543 url: '/adminDashboard',
544 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
545 controller: viewModelsModuleName + '.AdminDashboardViewModel',
546 permissions: ['ADMIN']
550 $stateProvider.state(
552 url: '/onboardVendor',
553 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
554 controller: viewModelsModuleName + '.OnboardVendorViewModel'
558 $stateProvider.state(
560 url: '/plugins/*path',
561 template: '<plugin-tab-view></plugin-tab-view>'
565 // Build the states for all hosted apps dynamically
566 _.each(hostedApplications, (hostedApp) => {
567 if (hostedApp.exists) {
568 $stateProvider.state(
569 hostedApp.state.name, {
570 url: hostedApp.state.url,
571 templateUrl: './view-models/dcae-app/dcae-app-view.html',
572 controller: viewModelsModuleName + hostedApp.state.controllerName
578 $stateProvider.state(
580 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
581 template: '<catalog-page></catalog-page>',
583 auth: ["$q", "AuthenticationServiceNg2", ($q: any, authService: AuthenticationService) => {
584 let userInfo: IUserProperties = authService.getLoggedinUser();
586 return $q.when(userInfo);
588 return $q.reject({authenticated: false});
595 $stateProvider.state(
598 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
599 controller: viewModelsModuleName + '.ErrorViewModel'
603 tooltipsConfigProvider.options({
606 class: 'tooltip-custom',
614 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
615 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
616 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
617 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
618 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
619 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
620 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
621 ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
622 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
623 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
624 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
625 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
626 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
627 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
628 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
629 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
630 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
631 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
632 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
633 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
635 ng1appModule.constant('sdcConfig', sdcConfig);
636 ng1appModule.constant('sdcMenu', sdcMenu);
640 'Sdc.Services.CacheService',
641 'Sdc.Services.CookieService',
642 'AuthenticationServiceNg2',
647 'Sdc.Services.EcompHeaderService',
648 'LeftPaletteLoaderService',
649 'Sdc.Services.DataTypesService',
653 ($http: ng.IHttpService,
654 cacheService: CacheService,
655 cookieService: CookieService,
656 authService: AuthenticationService,
657 $state: ng.ui.IStateService,
658 $rootScope: ng.IRootScopeService,
659 $location: ng.ILocationService,
661 ecompHeaderService: EcompHeaderService,
662 LeftPaletteLoaderService: LeftPaletteLoaderService,
663 DataTypesService: DataTypesService,
665 $templateCache: ng.ITemplateCacheService,
666 ModalServiceSdcUI: SdcUiServices.ModalService): void => {
667 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
668 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
670 // Add hosted applications to sdcConfig
671 sdcConfig.hostedApplications = hostedApplications;
674 $http.defaults.withCredentials = true;
675 // $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
676 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
678 DataTypesService.loadDataTypesCache(null);
680 //handle stateChangeStart
681 let internalDeregisterStateChangeStartWatcher: Function = (): void => {
682 if (deregisterStateChangeStartWatcher) {
683 deregisterStateChangeStartWatcher();
684 deregisterStateChangeStartWatcher = null;
686 if (deregisterStateChangeSuccessWatcher) {
687 deregisterStateChangeSuccessWatcher();
688 deregisterStateChangeSuccessWatcher = null;
692 let removeLoader: Function = (): void => {
693 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
694 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
695 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
696 window.setTimeout((): void => {
697 $(".sdc-loading-page .main-loader").css("display", "none");
698 $(".sdc-loading-page .caption1").css("display", "none");
699 $(".sdc-loading-page .caption2").css("display", "none");
700 $(".sdc-loading-page").addClass("animated fadeOut");
704 let onNavigateOut: Function = (toState, toParams): void => {
705 let onOk: Function = (): void => {
706 $state.current.data.unsavedChanges = false;
707 $state.go(toState.name, toParams);
710 let data = sdcMenu.alertMessages.exitWithoutSaving;
713 text: sdcMenu.alertMessages.okButton,
714 type: SdcUiCommon.ButtonType.warning,
717 } as SdcUiComponents.ModalButtonComponent;
718 //open notify to user if changes are not saved
719 ModalServiceSdcUI.openWarningModal(data.title,
725 let onStateChangeStart: Function = (event, toState, toParams, fromState, fromParams): void => {
726 console.info((new Date()).getTime());
727 console.info('$stateChangeStart', toState.name);
728 if (toState.name !== 'error-403' && !authService.getLoggedinUser()) {
731 authService.authenticate().subscribe((userInfo: IUserProperties) => {
732 if (!doesUserHasAccess(toState, userInfo)) {
733 $state.go('error-403');
734 console.info('User has no permissions');
737 authService.setLoggedinUser(userInfo);
738 setTimeout(function () {
742 if (authService.getLoggedinUser().role === 'ADMIN') {
743 // toState.name = "adminDashboard";
744 $state.go("adminDashboard", toParams);
748 // After user authorized init categories
749 window.setTimeout((): void => {
750 if ($state.current.name === '') {
751 $state.go(toState.name, toParams);
754 console.log("------$state.current.name=" + $state.current.name);
761 $state.go('error-403');
763 } else if (authService.getLoggedinUser()) {
764 let user: IUserProperties = authService.getLoggedinUser();
765 if (!cacheService.contains('user')) {
766 cacheService.set('user', user);
769 if (!doesUserHasAccess(toState, authService.getLoggedinUser())) {
770 event.preventDefault();
771 $state.go('error-403');
772 console.info('User has no permissions');
775 if (authService.getLoggedinUser().role === 'ADMIN') {
776 // toState.name = "adminDashboard";
777 $state.go("adminDashboard", toParams);
782 //if form is dirty and not save - notify to user
783 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
784 event.preventDefault();
785 onNavigateOut(toState, toParams);
789 // if enetering workspace, set the previousState param
790 if (toState.name.indexOf('workspace') !== -1) {
791 if (!toParams.previousState) {
792 const tmpPreviousState1 = fromParams && fromParams.previousState;
793 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
794 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
800 let onStateChangeSuccess: Function = (event, toState, toParams, fromState, fromParams): void => {
801 console.info('$stateChangeSuccess', toState.name);
803 // Workaround in case we are entering other state then workspace (user move to catalog)
804 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
805 if (toState.name.indexOf('workspace') === -1) {
806 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
807 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
809 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)) {
810 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
815 $rootScope['bodyClass'] = 'default-class';
816 if (toState.data && toState.data.bodyClass) {
817 $rootScope['bodyClass'] = toState.data.bodyClass;
821 let doesUserHasAccess: Function = (toState, user): boolean => {
823 let isUserHasAccess = true;
824 if (toState.permissions && toState.permissions.length > 0) {
825 isUserHasAccess = _.includes(toState.permissions, user.role);
827 return isUserHasAccess;
829 let deregisterStateChangeStartWatcher: Function;
830 let deregisterStateChangeSuccessWatcher: Function;
832 let registerStateChangeStartWatcher: Function = (): void => {
833 internalDeregisterStateChangeStartWatcher();
834 console.info('registerStateChangeStartWatcher $stateChangeStart');
835 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams): void => {
836 onStateChangeStart(event, toState, toParams, fromState, fromParams);
838 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams): void => {
839 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
842 registerStateChangeStartWatcher();