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 'restangular';
24 //import 'angular-ui-router';
25 import "reflect-metadata";
26 import 'ng-infinite-scroll';
27 import './modules/filters.ts';
28 import './modules/utils.ts';
29 import './modules/directive-module.ts';
30 import './modules/service-module';
31 import './modules/view-model-module.ts';
36 LeftPaletteLoaderService,
39 ConfigurationUiService,
43 ICategoryResourceClass,
46 import {forwardRef} from '@angular/core';
47 import {UpgradeAdapter} from '@angular/upgrade';
48 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States} from "./utils";
49 import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
50 import {ComponentFactory} from "./utils/component-factory";
51 import {ModalsHandler} from "./utils/modals-handler";
52 import {downgradeComponent} from "@angular/upgrade/static";
54 import {AppModule} from './ng2/app.module';
55 import {PropertiesAssignmentComponent} from "./ng2/pages/properties-assignment/properties-assignment.page.component";
56 import {Component} from "./models/components/component";
57 import {ComponentServiceNg2} from "./ng2/services/component-services/component.service";
58 import {ComponentMetadata} from "./models/component-metadata";
59 import {Categories} from "./models/categories";
62 let moduleName:string = 'sdcApp';
63 let viewModelsModuleName:string = 'Sdc.ViewModels';
64 let directivesModuleName:string = 'Sdc.Directives';
65 let servicesModuleName:string = 'Sdc.Services';
66 let filtersModuleName:string = 'Sdc.Filters';
67 let utilsModuleName:string = 'Sdc.Utils';
69 // Load configuration according to environment.
70 declare var __ENV__:string;
71 let sdcConfig:IAppConfigurtaion;
73 let pathPrefix:string = '';
74 if (__ENV__ === 'dev') {
75 sdcConfig = require('./../../configurations/dev.js');
76 } else if (__ENV__ === 'prod') {
77 sdcConfig = require('./../../configurations/prod.js');
80 console.log("ERROR: Environment configuration not found!");
82 sdcMenu = require('./../../configurations/menu.js');
84 let dependentModules:Array<string> = [
97 'pascalprecht.translate',
103 viewModelsModuleName,
104 directivesModuleName,
110 // ===================== Hosted applications section ====================
111 // Define here new hosted apps
112 let hostedApplications:Array<IHostedApplication> = [
114 "moduleName": "dcaeApp",
116 "defaultState": 'dcae.app.home',
120 "relativeHtmlPath": 'dcae-app/dcae-app-view.html',
121 "controllerName": '.DcaeAppViewModel'
126 // Check if module exists (in case the javascript was not loaded).
127 let isModuleExists = (moduleName:string):boolean => {
129 angular.module(moduleName);
130 dependentModules.push(moduleName);
133 console.log('Module ' + moduleName + ' does not exists');
138 // Check which hosted applications exists
139 _.each(hostedApplications, (hostedApp)=> {
140 if (isModuleExists(hostedApp.moduleName)) {
141 hostedApp['exists'] = true;
144 // ===================== Hosted applications section ====================
146 export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
147 angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory);
149 ng1appModule.config([
151 '$translateProvider',
152 '$urlRouterProvider',
154 'tooltipsConfigProvider',
155 'NotificationProvider',
157 $translateProvider:any,
158 $urlRouterProvider:ng.ui.IUrlRouterProvider,
159 $httpProvider:ng.IHttpProvider,
160 tooltipsConfigProvider:any,
161 NotificationProvider:any):void => {
163 NotificationProvider.setOptions({
169 horizontalSpacing: 20,
174 $translateProvider.useStaticFilesLoader({
175 prefix: pathPrefix + 'assets/languages/',
177 suffix: '.json?d=' + (new Date()).getTime()
179 $translateProvider.useSanitizeValueStrategy('escaped');
180 $translateProvider.preferredLanguage('en_US');
182 $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
183 $httpProvider.interceptors.push('Sdc.Services.HttpErrorInterceptor');
184 $urlRouterProvider.otherwise('welcome');
186 $stateProvider.state(
188 url: '/dashboard?show&folder',
189 templateUrl: "./view-models/dashboard/dashboard-view.html",
190 controller: viewModelsModuleName + '.DashboardViewModel',
194 $stateProvider.state(
197 templateUrl: "./view-models/welcome/welcome-view.html",
198 controller: viewModelsModuleName + '.WelcomeViewModel'
202 let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => {
203 if (cacheService.get('breadcrumbsComponents')) {
204 return cacheService.get('breadcrumbsComponents');
206 return EntityService.getCatalog();
210 $stateProvider.state(
212 url: '/workspace/:id/:type/',
213 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
214 templateUrl: './view-models/workspace/workspace-view.html',
215 controller: viewModelsModuleName + '.WorkspaceViewModel',
217 injectComponent: ['$stateParams', 'ComponentFactory', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, ComponentServiceNg2:ComponentServiceNg2) {
218 if ($stateParams.id) {
219 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id);
220 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
221 return $stateParams.componentCsar;
223 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
224 if (emptyComponent.isResource() && $stateParams.resourceType) {
225 // Set the resource type
226 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
228 if ($stateParams.importedFile) {
229 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
231 return emptyComponent;
234 components: componentsParam
239 $stateProvider.state(
240 States.WORKSPACE_GENERAL, {
243 controller: viewModelsModuleName + '.GeneralViewModel',
244 templateUrl: './view-models/workspace/tabs/general/general-view.html',
245 data: {unsavedChanges: false, bodyClass: 'general'}
249 $stateProvider.state(
250 States.WORKSPACE_ACTIVITY_LOG, {
253 controller: viewModelsModuleName + '.ActivityLogViewModel',
254 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
255 data: {unsavedChanges: false}
259 $stateProvider.state(
260 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
261 url: 'deployment_artifacts',
263 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
264 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
266 bodyClass: 'deployment_artifacts'
271 $stateProvider.state(
272 States.WORKSPACE_INFORMATION_ARTIFACTS, {
273 url: 'information_artifacts',
275 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
276 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
278 bodyClass: 'information_artifacts'
283 $stateProvider.state(
284 States.WORKSPACE_TOSCA_ARTIFACTS, {
285 url: 'tosca_artifacts',
287 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
288 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
290 bodyClass: 'tosca_artifacts'
295 $stateProvider.state(
296 States.WORKSPACE_PROPERTIES, {
299 controller: viewModelsModuleName + '.PropertiesViewModel',
300 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
302 bodyClass: 'properties'
307 $stateProvider.state(
308 States.WORKSPACE_SERVICE_INPUTS, {
309 url: 'service_inputs',
311 controller: viewModelsModuleName + '.ServiceInputsViewModel',
312 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
314 bodyClass: 'workspace-inputs'
319 $stateProvider.state(
320 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
321 url: 'properties_assignment',
322 params: {'component': null},
323 template: '<properties-assignment></properties-assignment>',
326 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
327 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
328 $stateParams.component = injectComponent;
329 return injectComponent;
333 bodyClass: 'properties-assignment'
338 $stateProvider.state(
339 States.WORKSPACE_RESOURCE_INPUTS, {
340 url: 'resource_inputs',
342 controller: viewModelsModuleName + '.ResourceInputsViewModel',
343 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
345 bodyClass: 'workspace-inputs'
350 $stateProvider.state(
351 States.WORKSPACE_ATTRIBUTES, {
354 controller: viewModelsModuleName + '.AttributesViewModel',
355 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
357 bodyClass: 'attributes'
362 $stateProvider.state(
363 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
364 url: 'req_and_capabilities',
366 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
367 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
369 bodyClass: 'attributes'
375 $stateProvider.state(
376 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
378 url: 'management_workflow',
379 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
380 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
384 $stateProvider.state(
385 States.WORKSPACE_NETWORK_CALL_FLOW, {
387 url: 'network_call_flow',
388 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
389 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
393 $stateProvider.state(
394 States.WORKSPACE_DISTRIBUTION, {
397 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
398 controller: viewModelsModuleName + '.DistributionViewModel'
402 $stateProvider.state(
403 States.WORKSPACE_COMPOSITION, {
406 controller: viewModelsModuleName + '.CompositionViewModel',
407 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
409 bodyClass: 'composition'
414 // $stateProvider.state(
415 // States.WORKSPACE_NG2, {
417 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
418 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
422 $stateProvider.state(
423 States.WORKSPACE_DEPLOYMENT, {
426 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
427 controller: viewModelsModuleName + '.DeploymentViewModel',
429 bodyClass: 'composition'
434 $stateProvider.state(
435 'workspace.composition.details', {
437 parent: 'workspace.composition',
438 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
439 controller: viewModelsModuleName + '.DetailsViewModel'
443 $stateProvider.state(
444 'workspace.composition.properties', {
446 parent: 'workspace.composition',
447 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
448 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
452 $stateProvider.state(
453 'workspace.composition.artifacts', {
455 parent: 'workspace.composition',
456 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
457 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
461 $stateProvider.state(
462 'workspace.composition.relations', {
464 parent: 'workspace.composition',
465 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
466 controller: viewModelsModuleName + '.RelationsViewModel'
470 $stateProvider.state(
471 'workspace.composition.structure', {
473 parent: 'workspace.composition',
474 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
475 controller: viewModelsModuleName + '.StructureViewModel'
478 $stateProvider.state(
479 'workspace.composition.lifecycle', {
481 parent: 'workspace.composition',
482 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
483 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
487 $stateProvider.state(
488 'workspace.composition.api', {
490 parent: 'workspace.composition',
491 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
492 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
495 $stateProvider.state(
496 'workspace.composition.deployment', {
498 parent: 'workspace.composition',
499 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
500 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
504 $stateProvider.state(
506 url: '/adminDashboard',
507 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
508 controller: viewModelsModuleName + '.AdminDashboardViewModel',
509 permissions: ['ADMIN']
513 $stateProvider.state(
515 url: '/onboardVendor',
516 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
517 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
521 // Build the states for all hosted apps dynamically
522 _.each(hostedApplications, (hostedApp)=> {
523 if (hostedApp.exists) {
524 $stateProvider.state(
525 hostedApp.state.name, {
526 url: hostedApp.state.url,
527 templateUrl: './view-models/dcae-app/dcae-app-view.html',
528 controller: viewModelsModuleName + hostedApp.state.controllerName
534 $stateProvider.state(
537 templateUrl: './view-models/catalog/catalog-view.html',
538 controller: viewModelsModuleName + '.CatalogViewModel',
540 auth: ["$q", "Sdc.Services.UserResourceService", ($q:any, userResourceService:IUserResourceClass) => {
541 let userInfo:IUserResource = userResourceService.getLoggedinUser();
543 return $q.when(userInfo);
545 return $q.reject({authenticated: false});
552 $stateProvider.state(
555 templateUrl: './view-models/support/support-view.html',
556 controller: viewModelsModuleName + '.SupportViewModel'
560 $stateProvider.state(
563 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
564 controller: viewModelsModuleName + '.ErrorViewModel'
568 tooltipsConfigProvider.options({
571 class: 'tooltip-custom',
579 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
580 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
581 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
582 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
583 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
584 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
585 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
586 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
587 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
588 ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
589 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
590 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
591 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
592 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
593 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
594 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
595 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
596 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
597 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
598 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
600 ng1appModule.constant('sdcConfig', sdcConfig);
601 ng1appModule.constant('sdcMenu', sdcMenu);
605 'Sdc.Services.CacheService',
606 'Sdc.Services.CookieService',
607 'Sdc.Services.ConfigurationUiService',
608 'Sdc.Services.UserResourceService',
609 'Sdc.Services.CategoryResourceService',
610 'Sdc.Services.SdcVersionService',
616 'Sdc.Services.EcompHeaderService',
617 'LeftPaletteLoaderService',
618 'Sdc.Services.DataTypesService',
620 ($http:ng.IHttpService,
621 cacheService:CacheService,
622 cookieService:CookieService,
623 ConfigurationUi:ConfigurationUiService,
624 UserResourceClass:IUserResourceClass,
625 categoryResourceService:ICategoryResourceClass,
626 sdcVersionService:SdcVersionService,
627 $state:ng.ui.IStateService,
628 $rootScope:ng.IRootScopeService,
629 $location:ng.ILocationService,
631 ModalsHandler:ModalsHandler,
632 ecompHeaderService:EcompHeaderService,
633 LeftPaletteLoaderService:LeftPaletteLoaderService,
634 DataTypesService:DataTypesService,
635 AngularJSBridge):void => {
637 //handle cache data - version
638 let initAsdcVersion:Function = ():void => {
640 let onFailed = (response) => {
641 console.info('onFailed initAsdcVersion', response);
642 cacheService.set('version', 'N/A');
645 let onSuccess = (version:any) => {
646 let tmpVerArray = version.version.split(".");
647 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
648 cacheService.set('version', ver);
651 sdcVersionService.getVersion().then(onSuccess, onFailed);
655 let initEcompMenu:Function = (user):void => {
656 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
657 $rootScope['menuItems'] = data;
661 let initConfigurationUi:Function = ():void => {
663 .getConfigurationUi()
664 .then((configurationUi:any) => {
665 cacheService.set('UIConfiguration', configurationUi);
669 let initCategories:Function = ():void => {
670 let onError = ():void => {
671 console.log('Failed to init categories');
674 categoryResourceService.getAllCategories((categories: Categories):void => {
675 cacheService.set('serviceCategories', categories.serviceCategories);
676 cacheService.set('resourceCategories', categories.resourceCategories);
680 // Add hosted applications to sdcConfig
681 sdcConfig.hostedApplications = hostedApplications;
684 $http.defaults.withCredentials = true;
685 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
686 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
689 initConfigurationUi();
690 // initLeftPalette();
691 DataTypesService.initDataTypes();
693 //handle stateChangeStart
694 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
695 if (deregisterStateChangeStartWatcher) {
696 deregisterStateChangeStartWatcher();
697 deregisterStateChangeStartWatcher = null;
701 let removeLoader:Function = ():void => {
702 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
703 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
704 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
705 window.setTimeout(():void=> {
706 $(".sdc-loading-page .main-loader").css("display", "none");
707 $(".sdc-loading-page .caption1").css("display", "none");
708 $(".sdc-loading-page .caption2").css("display", "none");
709 $(".sdc-loading-page").addClass("animated fadeOut");
713 let onNavigateOut:Function = (toState, toParams):void => {
714 let onOk = ():void => {
715 $state.current.data.unsavedChanges = false;
716 $state.go(toState.name, toParams);
719 let data = sdcMenu.alertMessages.exitWithoutSaving;
720 //open notify to user if changes are not saved
721 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
724 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
725 console.info((new Date()).getTime());
726 console.info('$stateChangeStart', toState.name);
728 $rootScope['bodyClass'] = 'default-class';
729 if (toState.data && toState.data.bodyClass) {
730 $rootScope['bodyClass'] = toState.data.bodyClass;
733 // Workaround in case we are entering other state then workspace (user move to catalog)
734 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
735 if (toState.name.indexOf('workspace') === -1) {
736 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
737 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
741 //saving last state to params , for breadcrumbs
742 if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
743 toParams.previousState = fromState.name;
745 toParams.previousState = fromParams.previousState;
748 if (toState.name !== 'error-403' && !UserResourceClass.getLoggedinUser()) {
749 internalDeregisterStateChangeStartWatcher();
750 event.preventDefault();
752 UserResourceClass.authorize().$promise.then((user:IUserResource) => {
753 if (!doesUserHasAccess(toState, user)) {
754 $state.go('error-403');
755 console.info('User has no permissions');
756 registerStateChangeStartWatcher();
759 UserResourceClass.setLoggedinUser(user);
760 cacheService.set('user', user);
762 // initEcompMenu(user);
763 setTimeout(function () {
768 if (UserResourceClass.getLoggedinUser().role === 'ADMIN') {
769 // toState.name = "adminDashboard";
770 $state.go("adminDashboard", toParams);
771 registerStateChangeStartWatcher();
775 // After user authorized init categories
776 window.setTimeout(():void=> {
777 if ($state.current.name === '') {
778 $state.go(toState.name, toParams);
781 console.log("------$state.current.name=" + $state.current.name);
782 console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
783 registerStateChangeStartWatcher();
790 $state.go('error-403');
792 console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
793 registerStateChangeStartWatcher();
796 else if (UserResourceClass.getLoggedinUser()) {
797 internalDeregisterStateChangeStartWatcher();
798 if (!doesUserHasAccess(toState, UserResourceClass.getLoggedinUser())) {
799 event.preventDefault();
800 $state.go('error-403');
801 console.info('User has no permissions');
803 if (toState.name === "welcome") {
804 $state.go("dashboard");
806 registerStateChangeStartWatcher();
807 //if form is dirty and not save - notify to user
808 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
809 event.preventDefault();
810 onNavigateOut(toState, toParams);
816 let doesUserHasAccess:Function = (toState, user):boolean => {
818 let isUserHasAccess = true;
819 if (toState.permissions && toState.permissions.length > 0) {
820 isUserHasAccess = _.includes(toState.permissions, user.role);
822 return isUserHasAccess;
824 let deregisterStateChangeStartWatcher:Function;
826 let registerStateChangeStartWatcher:Function = ():void => {
827 internalDeregisterStateChangeStartWatcher();
828 console.info('registerStateChangeStartWatcher $stateChangeStart');
829 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
830 onStateChangeStart(event, toState, toParams, fromState, fromParams);
834 registerStateChangeStartWatcher();