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';
32 import {CookieService, DataTypesService, EcompHeaderService, LeftPaletteLoaderService} from "./services";
33 import {CacheService, CatalogService, HomeService} from "./services-ng2";
34 import {AuthenticationService} from "app/ng2/services/authentication.service";
35 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, PREVIOUS_CSAR_COMPONENT, States} from "./utils";
36 import {IAppConfigurtaion, IAppMenu, IHostedApplication, Resource} from "./models";
37 import {ComponentFactory} from "./utils/component-factory";
38 import {Component} from "./models/components/component";
39 import {IUserProperties} from "./models/user";
40 import {WorkspaceService} from "./ng2/pages/workspace/workspace.service";
42 let moduleName: string = 'sdcApp';
43 let viewModelsModuleName: string = 'Sdc.ViewModels';
44 let directivesModuleName: string = 'Sdc.Directives';
45 let servicesModuleName: string = 'Sdc.Services';
46 let filtersModuleName: string = 'Sdc.Filters';
47 let 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 let dependentModules: Array<string> = [
77 'pascalprecht.translate',
90 // ===================== Hosted applications section ====================
91 // Define here new hosted apps
92 let hostedApplications: Array<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 let 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']
174 let componentsParam: Array<any> = ['$stateParams', 'HomeService', 'CatalogService', 'Sdc.Services.CacheService', ($stateParams: any, HomeService: HomeService, CatalogService: CatalogService, cacheService: CacheService) => {
175 if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
176 const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
177 if (breadcrumbsComponents) {
178 return breadcrumbsComponents;
181 let breadcrumbsComponentsObservable;
182 if ($stateParams.previousState === 'dashboard') {
183 breadcrumbsComponentsObservable = HomeService.getAllComponents(true);
184 } else if ($stateParams.previousState === 'catalog') {
185 breadcrumbsComponentsObservable = CatalogService.getCatalog();
187 cacheService.remove('breadcrumbsComponentsState');
188 cacheService.remove('breadcrumbsComponents');
191 breadcrumbsComponentsObservable.subscribe((components) => {
192 cacheService.set('breadcrumbsComponentsState', $stateParams.previousState);
193 cacheService.set('breadcrumbsComponents', components);
195 return breadcrumbsComponentsObservable;
199 const oldWorkspaceController: Array<any> = ['$location', ($location: ng.ILocationService) => {
200 // redirect old /workspace/* urls to /catalog/workspace/* url
201 const newUrl = '/catalog' + $location.url();
202 console.log('old workspace path - redirecting to:', newUrl);
203 $location.url(newUrl);
206 $stateProvider.state(
208 url: '/workspace/:id/:type/*workspaceInnerPath',
209 controller: oldWorkspaceController
213 $stateProvider.state(
214 States.TYPE_WORKSPACE, {
215 url: '/:previousState/type-workspace/:type/:id/:subPage',
216 template: '<app-type-workspace></app-type-workspace>',
220 $stateProvider.state(
222 url: '/:previousState/workspace/:id/:type/',
224 'importedFile': null,
225 'componentCsar': null,
226 'resourceType': null,
227 'disableButtons': null
229 templateUrl: './view-models/workspace/workspace-view.html',
230 controller: viewModelsModuleName + '.WorkspaceViewModel',
232 injectComponent: ['$stateParams', 'ComponentFactory', 'workspaceService', 'Sdc.Services.CacheService', function ($stateParams, ComponentFactory: ComponentFactory, workspaceService: WorkspaceService, cacheService: CacheService) {
233 if ($stateParams.id && $stateParams.id.length) { //need to check length in case ID is an empty string
234 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
235 (component: Component) => {
236 if ($stateParams.componentCsar && component.isResource()) {
237 if ((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) {
238 cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
240 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
242 workspaceService.setComponentMetadata(component.componentMetadata);
245 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
246 return $stateParams.componentCsar;
248 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
249 if (emptyComponent.isResource() && $stateParams.resourceType) {
250 // Set the resource type
251 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
253 if ($stateParams.importedFile) {
254 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
256 return emptyComponent;
259 components: componentsParam
264 $stateProvider.state(
265 States.WORKSPACE_GENERAL, {
268 controller: viewModelsModuleName + '.GeneralViewModel',
269 templateUrl: './view-models/workspace/tabs/general/general-view.html',
270 data: {unsavedChanges: false, bodyClass: 'general'}
275 $stateProvider.state(
276 States.WORKSPACE_INFORMATION_ARTIFACTS, {
277 url: 'information_artifacts',
279 template: '<information-artifact-page></information-artifact-page>'
283 $stateProvider.state(
284 States.WORKSPACE_TOSCA_ARTIFACTS, {
285 url: 'tosca_artifacts',
287 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'
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 $stateParams.component = injectComponent;
405 return injectComponent;
409 bodyClass: 'composition'
414 $stateProvider.state(
415 States.WORKSPACE_ACTIVITY_LOG, {
416 url: 'activity_log/',
418 template: '<activity-log></activity-log>',
422 $stateProvider.state(
423 States.WORKSPACE_DISTRIBUTION, {
426 template: '<distribution></distribution>',
430 $stateProvider.state(
431 States.WORKSPACE_DEPLOYMENT, {
434 template: '<deployment-page></deployment-page>',
439 $stateProvider.state(
440 'workspace.composition.details', {
442 parent: 'workspace.composition',
444 componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
445 $stateParams.component = injectComponent;
446 return injectComponent;
453 $stateProvider.state(
454 'workspace.composition.properties', {
456 parent: 'workspace.composition'
460 $stateProvider.state(
461 'workspace.composition.artifacts', {
463 parent: 'workspace.composition'
468 $stateProvider.state(
469 'workspace.composition.relations', {
471 parent: 'workspace.composition'
475 $stateProvider.state(
476 'workspace.composition.structure', {
478 parent: 'workspace.composition'
481 $stateProvider.state(
482 'workspace.composition.lifecycle', {
484 parent: 'workspace.composition'
488 $stateProvider.state(
489 'workspace.composition.api', {
491 parent: 'workspace.composition'
494 $stateProvider.state(
495 'workspace.composition.deployment', {
497 parent: 'workspace.composition'
501 $stateProvider.state(
502 States.WORKSPACE_INTERFACE_OPERATION, {
503 url: 'interface_operation',
505 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
506 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
508 bodyClass: 'interface_operation'
513 $stateProvider.state(
514 States.WORKSPACE_INTERFACE_DEFINITION, {
515 url: 'interfaceDefinition',
517 controller: viewModelsModuleName + '.InterfaceDefinitionViewModel',
518 templateUrl: './view-models/workspace/tabs/interface-definition/interface-definition-view.html',
520 bodyClass: 'interfaceDefinition'
525 $stateProvider.state(
526 'workspace.plugins', {
527 url: 'plugins/*path',
529 template: '<plugin-context-view></plugin-context-view>',
531 componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
532 $stateParams.component = injectComponent;
533 return injectComponent;
540 $stateProvider.state(
542 url: '/adminDashboard',
543 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
544 controller: viewModelsModuleName + '.AdminDashboardViewModel',
545 permissions: ['ADMIN']
549 $stateProvider.state(
551 url: '/onboardVendor',
552 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
553 controller: viewModelsModuleName + '.OnboardVendorViewModel'
557 $stateProvider.state(
559 url: '/plugins/*path',
560 template: '<plugin-tab-view></plugin-tab-view>'
564 // Build the states for all hosted apps dynamically
565 _.each(hostedApplications, (hostedApp) => {
566 if (hostedApp.exists) {
567 $stateProvider.state(
568 hostedApp.state.name, {
569 url: hostedApp.state.url,
570 templateUrl: './view-models/dcae-app/dcae-app-view.html',
571 controller: viewModelsModuleName + hostedApp.state.controllerName
577 $stateProvider.state(
579 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
580 template: '<catalog-page></catalog-page>',
582 auth: ["$q", "AuthenticationServiceNg2", ($q: any, authService: AuthenticationService) => {
583 let userInfo: IUserProperties = authService.getLoggedinUser();
585 return $q.when(userInfo);
587 return $q.reject({authenticated: false});
594 $stateProvider.state(
597 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
598 controller: viewModelsModuleName + '.ErrorViewModel'
602 tooltipsConfigProvider.options({
605 class: 'tooltip-custom',
613 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
614 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
615 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
616 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
617 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
618 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
619 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
620 ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
621 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
622 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
623 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
624 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
625 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
626 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
627 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
628 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
629 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
630 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
631 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
632 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
634 ng1appModule.constant('sdcConfig', sdcConfig);
635 ng1appModule.constant('sdcMenu', sdcMenu);
639 'Sdc.Services.CacheService',
640 'Sdc.Services.CookieService',
641 'AuthenticationServiceNg2',
646 'Sdc.Services.EcompHeaderService',
647 'LeftPaletteLoaderService',
648 'Sdc.Services.DataTypesService',
652 ($http: ng.IHttpService,
653 cacheService: CacheService,
654 cookieService: CookieService,
655 authService: AuthenticationService,
656 $state: ng.ui.IStateService,
657 $rootScope: ng.IRootScopeService,
658 $location: ng.ILocationService,
660 ecompHeaderService: EcompHeaderService,
661 LeftPaletteLoaderService: LeftPaletteLoaderService,
662 DataTypesService: DataTypesService,
664 $templateCache: ng.ITemplateCacheService,
665 ModalServiceSdcUI: SdcUiServices.ModalService): void => {
666 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
667 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
669 // Add hosted applications to sdcConfig
670 sdcConfig.hostedApplications = hostedApplications;
673 $http.defaults.withCredentials = true;
674 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
676 DataTypesService.loadDataTypesCache(null);
678 //handle stateChangeStart
679 let internalDeregisterStateChangeStartWatcher: Function = (): void => {
680 if (deregisterStateChangeStartWatcher) {
681 deregisterStateChangeStartWatcher();
682 deregisterStateChangeStartWatcher = null;
684 if (deregisterStateChangeSuccessWatcher) {
685 deregisterStateChangeSuccessWatcher();
686 deregisterStateChangeSuccessWatcher = null;
690 let removeLoader: Function = (): void => {
691 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
692 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
693 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
694 window.setTimeout((): void => {
695 $(".sdc-loading-page .main-loader").css("display", "none");
696 $(".sdc-loading-page .caption1").css("display", "none");
697 $(".sdc-loading-page .caption2").css("display", "none");
698 $(".sdc-loading-page").addClass("animated fadeOut");
702 let onNavigateOut: Function = (toState, toParams): void => {
703 let onOk: Function = (): void => {
704 $state.current.data.unsavedChanges = false;
705 $state.go(toState.name, toParams);
708 let data = sdcMenu.alertMessages.exitWithoutSaving;
711 text: sdcMenu.alertMessages.okButton,
712 type: SdcUiCommon.ButtonType.warning,
715 } as SdcUiComponents.ModalButtonComponent;
716 //open notify to user if changes are not saved
717 ModalServiceSdcUI.openWarningModal(data.title,
723 let onStateChangeStart: Function = (event, toState, toParams, fromState, fromParams): void => {
724 console.debug((new Date()).getTime());
725 console.debug('$stateChangeStart', toState.name);
726 if (toState.name !== 'error-403' && !authService.getLoggedinUser()) {
729 authService.authenticate().subscribe((userInfo: IUserProperties) => {
730 if (!doesUserHasAccess(toState, userInfo)) {
731 $state.go('error-403');
732 console.debug('User has no permissions');
735 authService.setLoggedinUser(userInfo);
736 setTimeout(function () {
740 if (authService.getLoggedinUser().role === 'ADMIN') {
741 $state.go("adminDashboard", toParams);
745 // After user authorized init categories
746 window.setTimeout((): void => {
747 if ($state.current.name === '') {
748 $state.go(toState.name, toParams);
751 console.log("------$state.current.name=" + $state.current.name);
758 $state.go('error-403');
760 } else if (authService.getLoggedinUser()) {
761 let user: IUserProperties = authService.getLoggedinUser();
762 if (!cacheService.contains('user')) {
763 cacheService.set('user', user);
766 if (!doesUserHasAccess(toState, authService.getLoggedinUser())) {
767 event.preventDefault();
768 $state.go('error-403');
769 console.debug('User has no permissions');
772 if (authService.getLoggedinUser().role === 'ADMIN') {
773 $state.go("adminDashboard", toParams);
778 //if form is dirty and not save - notify to user
779 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
780 event.preventDefault();
781 onNavigateOut(toState, toParams);
785 // if enetering workspace, set the previousState param
786 if (toState.name.indexOf('workspace') !== -1) {
787 if (!toParams.previousState) {
788 const tmpPreviousState1 = fromParams && fromParams.previousState;
789 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
790 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
796 let onStateChangeSuccess: Function = (event, toState, toParams, fromState, fromParams): void => {
797 console.debug('$stateChangeSuccess', toState.name);
799 // Workaround in case we are entering other state then workspace (user move to catalog)
800 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
801 if (toState.name.indexOf('workspace') === -1) {
802 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
803 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
805 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)) {
806 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
811 $rootScope['bodyClass'] = 'default-class';
812 if (toState.data && toState.data.bodyClass) {
813 $rootScope['bodyClass'] = toState.data.bodyClass;
817 let doesUserHasAccess: Function = (toState, user): boolean => {
819 let isUserHasAccess = true;
820 if (toState.permissions && toState.permissions.length > 0) {
821 isUserHasAccess = _.includes(toState.permissions, user.role);
823 return isUserHasAccess;
825 let deregisterStateChangeStartWatcher: Function;
826 let deregisterStateChangeSuccessWatcher: Function;
828 let registerStateChangeStartWatcher: Function = (): void => {
829 internalDeregisterStateChangeStartWatcher();
830 console.debug('registerStateChangeStartWatcher $stateChangeStart');
831 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams): void => {
832 onStateChangeStart(event, toState, toParams, fromState, fromParams);
834 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams): void => {
835 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
838 registerStateChangeStartWatcher();