3 //import 'restangular';
4 //import 'angular-ui-router';
5 import "reflect-metadata";
6 import 'ng-infinite-scroll';
7 import './modules/filters.ts';
8 import './modules/utils.ts';
9 import './modules/directive-module.ts';
10 import './modules/service-module';
11 import './modules/view-model-module.ts';
16 LeftPaletteLoaderService,
19 ConfigurationUiService,
23 ICategoryResourceClass,
26 import {forwardRef} from '@angular/core';
27 import {UpgradeAdapter} from '@angular/upgrade';
28 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States} from "./utils";
29 import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
30 import {ComponentFactory} from "./utils/component-factory";
31 import {ModalsHandler} from "./utils/modals-handler";
32 import {downgradeComponent} from "@angular/upgrade/static";
34 import {AppModule} from './ng2/app.module';
35 import {PropertiesAssignmentComponent} from "./ng2/pages/properties-assignment/properties-assignment.page.component";
36 import {Component} from "./models/components/component";
37 import {ComponentServiceNg2} from "./ng2/services/component-services/component.service";
38 import {ComponentMetadata} from "./models/component-metadata";
39 import {Categories} from "./models/categories";
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;
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);
127 angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory);
129 ng1appModule.config([
131 '$translateProvider',
132 '$urlRouterProvider',
134 'tooltipsConfigProvider',
135 'NotificationProvider',
137 $translateProvider:any,
138 $urlRouterProvider:ng.ui.IUrlRouterProvider,
139 $httpProvider:ng.IHttpProvider,
140 tooltipsConfigProvider:any,
141 NotificationProvider:any):void => {
143 NotificationProvider.setOptions({
149 horizontalSpacing: 20,
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 $httpProvider.interceptors.push('Sdc.Services.HttpErrorInterceptor');
164 $urlRouterProvider.otherwise('welcome');
166 $stateProvider.state(
168 url: '/dashboard?show&folder',
169 templateUrl: "./view-models/dashboard/dashboard-view.html",
170 controller: viewModelsModuleName + '.DashboardViewModel',
174 $stateProvider.state(
177 templateUrl: "./view-models/welcome/welcome-view.html",
178 controller: viewModelsModuleName + '.WelcomeViewModel'
182 let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => {
183 if (cacheService.get('breadcrumbsComponents')) {
184 return cacheService.get('breadcrumbsComponents');
186 return EntityService.getCatalog();
190 $stateProvider.state(
192 url: '/workspace/:id/:type/',
193 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
194 templateUrl: './view-models/workspace/workspace-view.html',
195 controller: viewModelsModuleName + '.WorkspaceViewModel',
197 injectComponent: ['$stateParams', 'ComponentFactory', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, ComponentServiceNg2:ComponentServiceNg2) {
198 if ($stateParams.id) {
199 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id);
200 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
201 return $stateParams.componentCsar;
203 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
204 if (emptyComponent.isResource() && $stateParams.resourceType) {
205 // Set the resource type
206 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
208 if ($stateParams.importedFile) {
209 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
211 return emptyComponent;
214 components: componentsParam
219 $stateProvider.state(
220 States.WORKSPACE_GENERAL, {
223 controller: viewModelsModuleName + '.GeneralViewModel',
224 templateUrl: './view-models/workspace/tabs/general/general-view.html',
225 data: {unsavedChanges: false, bodyClass: 'general'}
229 $stateProvider.state(
230 States.WORKSPACE_ICONS, {
233 controller: viewModelsModuleName + '.IconsViewModel',
234 templateUrl: './view-models/workspace/tabs/icons/icons-view.html',
235 data: {unsavedChanges: false, bodyClass: 'icons'}
240 $stateProvider.state(
241 States.WORKSPACE_ACTIVITY_LOG, {
244 controller: viewModelsModuleName + '.ActivityLogViewModel',
245 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
246 data: {unsavedChanges: false}
250 $stateProvider.state(
251 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
252 url: 'deployment_artifacts',
254 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
255 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
257 bodyClass: 'deployment_artifacts'
262 $stateProvider.state(
263 States.WORKSPACE_HIERARCHY, {
266 controller: viewModelsModuleName + '.ProductHierarchyViewModel',
267 templateUrl: './view-models/workspace/tabs/product-hierarchy/product-hierarchy-view.html',
268 data: {unsavedChanges: false}
273 $stateProvider.state(
274 States.WORKSPACE_INFORMATION_ARTIFACTS, {
275 url: 'information_artifacts',
277 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
278 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
280 bodyClass: 'information_artifacts'
285 $stateProvider.state(
286 States.WORKSPACE_TOSCA_ARTIFACTS, {
287 url: 'tosca_artifacts',
289 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
290 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
292 bodyClass: 'tosca_artifacts'
297 $stateProvider.state(
298 States.WORKSPACE_PROPERTIES, {
301 controller: viewModelsModuleName + '.PropertiesViewModel',
302 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
304 bodyClass: 'properties'
309 $stateProvider.state(
310 States.WORKSPACE_SERVICE_INPUTS, {
311 url: 'service_inputs',
313 controller: viewModelsModuleName + '.ServiceInputsViewModel',
314 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
316 bodyClass: 'workspace-inputs'
321 $stateProvider.state(
322 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
323 url: 'properties_assignment',
324 params: {'component': null},
325 template: '<properties-assignment></properties-assignment>',
328 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
329 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
330 $stateParams.component = injectComponent;
331 return injectComponent;
335 bodyClass: 'properties-assignment'
340 $stateProvider.state(
341 States.WORKSPACE_RESOURCE_INPUTS, {
342 url: 'resource_inputs',
344 controller: viewModelsModuleName + '.ResourceInputsViewModel',
345 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
347 bodyClass: 'workspace-inputs'
352 $stateProvider.state(
353 States.WORKSPACE_ATTRIBUTES, {
356 controller: viewModelsModuleName + '.AttributesViewModel',
357 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
359 bodyClass: 'attributes'
364 $stateProvider.state(
365 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
366 url: 'req_and_capabilities',
368 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
369 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
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'
395 $stateProvider.state(
396 States.WORKSPACE_DISTRIBUTION, {
399 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
400 controller: viewModelsModuleName + '.DistributionViewModel'
404 $stateProvider.state(
405 States.WORKSPACE_COMPOSITION, {
408 controller: viewModelsModuleName + '.CompositionViewModel',
409 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
411 bodyClass: 'composition'
416 // $stateProvider.state(
417 // States.WORKSPACE_NG2, {
419 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
420 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
424 $stateProvider.state(
425 States.WORKSPACE_DEPLOYMENT, {
428 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
429 controller: viewModelsModuleName + '.DeploymentViewModel',
431 bodyClass: 'composition'
436 $stateProvider.state(
437 'workspace.composition.details', {
439 parent: 'workspace.composition',
440 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
441 controller: viewModelsModuleName + '.DetailsViewModel'
445 $stateProvider.state(
446 'workspace.composition.properties', {
448 parent: 'workspace.composition',
449 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
450 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
454 $stateProvider.state(
455 'workspace.composition.artifacts', {
457 parent: 'workspace.composition',
458 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
459 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
463 $stateProvider.state(
464 'workspace.composition.relations', {
466 parent: 'workspace.composition',
467 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
468 controller: viewModelsModuleName + '.RelationsViewModel'
472 $stateProvider.state(
473 'workspace.composition.structure', {
475 parent: 'workspace.composition',
476 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
477 controller: viewModelsModuleName + '.StructureViewModel'
480 $stateProvider.state(
481 'workspace.composition.lifecycle', {
483 parent: 'workspace.composition',
484 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
485 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
489 $stateProvider.state(
490 'workspace.composition.api', {
492 parent: 'workspace.composition',
493 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
494 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
497 $stateProvider.state(
498 'workspace.composition.deployment', {
500 parent: 'workspace.composition',
501 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
502 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
506 $stateProvider.state(
508 url: '/adminDashboard',
509 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
510 controller: viewModelsModuleName + '.AdminDashboardViewModel',
511 permissions: ['ADMIN']
515 $stateProvider.state(
517 url: '/onboardVendor',
518 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
519 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
523 // Build the states for all hosted apps dynamically
524 _.each(hostedApplications, (hostedApp)=> {
525 if (hostedApp.exists) {
526 $stateProvider.state(
527 hostedApp.state.name, {
528 url: hostedApp.state.url,
529 templateUrl: './view-models/dcae-app/dcae-app-view.html',
530 controller: viewModelsModuleName + hostedApp.state.controllerName
536 $stateProvider.state(
539 templateUrl: './view-models/catalog/catalog-view.html',
540 controller: viewModelsModuleName + '.CatalogViewModel',
542 auth: ["$q", "Sdc.Services.UserResourceService", ($q:any, userResourceService:IUserResourceClass) => {
543 let userInfo:IUserResource = userResourceService.getLoggedinUser();
545 return $q.when(userInfo);
547 return $q.reject({authenticated: false});
554 $stateProvider.state(
557 templateUrl: './view-models/support/support-view.html',
558 controller: viewModelsModuleName + '.SupportViewModel'
562 $stateProvider.state(
565 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
566 controller: viewModelsModuleName + '.ErrorViewModel'
570 tooltipsConfigProvider.options({
573 class: 'tooltip-custom',
581 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
582 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
583 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
584 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
585 ng1appModule.value('VendorValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
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);
677 cacheService.set('productCategories', categories.productCategories);
681 // Add hosted applications to sdcConfig
682 sdcConfig.hostedApplications = hostedApplications;
685 $http.defaults.withCredentials = true;
686 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
687 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
690 initConfigurationUi();
691 // initLeftPalette();
692 DataTypesService.initDataTypes();
694 //handle stateChangeStart
695 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
696 if (deregisterStateChangeStartWatcher) {
697 deregisterStateChangeStartWatcher();
698 deregisterStateChangeStartWatcher = null;
702 let removeLoader:Function = ():void => {
703 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
704 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
705 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
706 window.setTimeout(():void=> {
707 $(".sdc-loading-page .main-loader").css("display", "none");
708 $(".sdc-loading-page .caption1").css("display", "none");
709 $(".sdc-loading-page .caption2").css("display", "none");
710 $(".sdc-loading-page").addClass("animated fadeOut");
714 let onNavigateOut:Function = (toState, toParams):void => {
715 let onOk = ():void => {
716 $state.current.data.unsavedChanges = false;
717 $state.go(toState.name, toParams);
720 let data = sdcMenu.alertMessages.exitWithoutSaving;
721 //open notify to user if changes are not saved
722 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
725 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
726 console.info((new Date()).getTime());
727 console.info('$stateChangeStart', toState.name);
729 $rootScope['bodyClass'] = 'default-class';
730 if (toState.data && toState.data.bodyClass) {
731 $rootScope['bodyClass'] = toState.data.bodyClass;
734 // Workaround in case we are entering other state then workspace (user move to catalog)
735 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
736 if (toState.name.indexOf('workspace') === -1) {
737 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
738 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
742 //saving last state to params , for breadcrumbs
743 if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
744 toParams.previousState = fromState.name;
746 toParams.previousState = fromParams.previousState;
749 if (toState.name !== 'error-403' && !UserResourceClass.getLoggedinUser()) {
750 internalDeregisterStateChangeStartWatcher();
751 event.preventDefault();
753 UserResourceClass.authorize().$promise.then((user:IUserResource) => {
754 if (!doesUserHasAccess(toState, user)) {
755 $state.go('error-403');
756 console.info('User has no permissions');
757 registerStateChangeStartWatcher();
760 UserResourceClass.setLoggedinUser(user);
761 cacheService.set('user', user);
763 // initEcompMenu(user);
764 setTimeout(function () {
769 if (UserResourceClass.getLoggedinUser().role === 'ADMIN') {
770 // toState.name = "adminDashboard";
771 $state.go("adminDashboard", toParams);
772 registerStateChangeStartWatcher();
776 // After user authorized init categories
777 window.setTimeout(():void=> {
778 if ($state.current.name === '') {
779 $state.go(toState.name, toParams);
782 console.log("------$state.current.name=" + $state.current.name);
783 console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
784 registerStateChangeStartWatcher();
791 $state.go('error-403');
793 console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
794 registerStateChangeStartWatcher();
797 else if (UserResourceClass.getLoggedinUser()) {
798 internalDeregisterStateChangeStartWatcher();
799 if (!doesUserHasAccess(toState, UserResourceClass.getLoggedinUser())) {
800 event.preventDefault();
801 $state.go('error-403');
802 console.info('User has no permissions');
804 if (toState.name === "welcome") {
805 $state.go("dashboard");
807 registerStateChangeStartWatcher();
808 //if form is dirty and not save - notify to user
809 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
810 event.preventDefault();
811 onNavigateOut(toState, toParams);
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;
827 let registerStateChangeStartWatcher:Function = ():void => {
828 internalDeregisterStateChangeStartWatcher();
829 console.info('registerStateChangeStartWatcher $stateChangeStart');
830 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
831 onStateChangeStart(event, toState, toParams, fromState, fromParams);
835 registerStateChangeStartWatcher();