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 * as _ from "lodash";
26 import "reflect-metadata";
27 import 'ng-infinite-scroll';
28 import './modules/filters.ts';
29 import './modules/utils.ts';
30 import './modules/directive-module.ts';
31 import './modules/service-module';
32 import './modules/view-model-module.ts';
36 LeftPaletteLoaderService,
39 ConfigurationUiService,
42 ICategoryResourceClass,
45 import { UserService } from "./ng2/services/user.service";
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";
60 import {IUserProperties} from "./models/user";
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);
148 ng1appModule.config([
150 '$translateProvider',
151 '$urlRouterProvider',
153 'tooltipsConfigProvider',
154 'NotificationProvider',
156 $translateProvider:any,
157 $urlRouterProvider:ng.ui.IUrlRouterProvider,
158 $httpProvider:ng.IHttpProvider,
159 tooltipsConfigProvider:any,
160 NotificationProvider:any):void => {
162 NotificationProvider.setOptions({
168 horizontalSpacing: 20,
172 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
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).then(
220 (component:Component)=> {
221 if ($stateParams.componentCsar){
222 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
226 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
227 return $stateParams.componentCsar;
229 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
230 if (emptyComponent.isResource() && $stateParams.resourceType) {
231 // Set the resource type
232 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
234 if ($stateParams.importedFile) {
235 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
237 return emptyComponent;
240 components: componentsParam
245 $stateProvider.state(
246 States.WORKSPACE_GENERAL, {
249 controller: viewModelsModuleName + '.GeneralViewModel',
250 templateUrl: './view-models/workspace/tabs/general/general-view.html',
251 data: {unsavedChanges: false, bodyClass: 'general'}
255 $stateProvider.state(
256 States.WORKSPACE_ACTIVITY_LOG, {
259 controller: viewModelsModuleName + '.ActivityLogViewModel',
260 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
261 data: {unsavedChanges: false}
265 $stateProvider.state(
266 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
267 url: 'deployment_artifacts',
269 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
270 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
272 bodyClass: 'deployment_artifacts'
277 $stateProvider.state(
278 States.WORKSPACE_INFORMATION_ARTIFACTS, {
279 url: 'information_artifacts',
281 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
282 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
284 bodyClass: 'information_artifacts'
289 $stateProvider.state(
290 States.WORKSPACE_TOSCA_ARTIFACTS, {
291 url: 'tosca_artifacts',
293 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
294 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
296 bodyClass: 'tosca_artifacts'
301 $stateProvider.state(
302 States.WORKSPACE_PROPERTIES, {
305 controller: viewModelsModuleName + '.PropertiesViewModel',
306 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
308 bodyClass: 'properties'
313 $stateProvider.state(
314 States.WORKSPACE_SERVICE_INPUTS, {
315 url: 'service_inputs',
317 controller: viewModelsModuleName + '.ServiceInputsViewModel',
318 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
320 bodyClass: 'workspace-inputs'
325 $stateProvider.state(
326 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
327 url: 'properties_assignment',
328 params: {'component': null},
329 template: '<properties-assignment></properties-assignment>',
332 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
333 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
334 $stateParams.component = injectComponent;
335 return injectComponent;
339 bodyClass: 'properties-assignment'
344 $stateProvider.state(
345 States.WORKSPACE_RESOURCE_INPUTS, {
346 url: 'resource_inputs',
348 controller: viewModelsModuleName + '.ResourceInputsViewModel',
349 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
351 bodyClass: 'workspace-inputs'
356 $stateProvider.state(
357 States.WORKSPACE_ATTRIBUTES, {
360 controller: viewModelsModuleName + '.AttributesViewModel',
361 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
363 bodyClass: 'attributes'
368 $stateProvider.state(
369 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
370 url: 'req_and_capabilities',
372 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
373 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
375 bodyClass: 'attributes'
381 $stateProvider.state(
382 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
384 url: 'management_workflow',
385 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
386 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
390 $stateProvider.state(
391 States.WORKSPACE_NETWORK_CALL_FLOW, {
393 url: 'network_call_flow',
394 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
395 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
399 $stateProvider.state(
400 States.WORKSPACE_DISTRIBUTION, {
403 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
404 controller: viewModelsModuleName + '.DistributionViewModel'
408 $stateProvider.state(
409 States.WORKSPACE_COMPOSITION, {
412 controller: viewModelsModuleName + '.CompositionViewModel',
413 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
415 bodyClass: 'composition'
420 // $stateProvider.state(
421 // States.WORKSPACE_NG2, {
423 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
424 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
428 $stateProvider.state(
429 States.WORKSPACE_DEPLOYMENT, {
432 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
433 controller: viewModelsModuleName + '.DeploymentViewModel',
435 bodyClass: 'composition'
440 $stateProvider.state(
441 'workspace.composition.details', {
443 parent: 'workspace.composition',
444 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
445 controller: viewModelsModuleName + '.DetailsViewModel'
449 $stateProvider.state(
450 'workspace.composition.properties', {
452 parent: 'workspace.composition',
453 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
454 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
458 $stateProvider.state(
459 'workspace.composition.artifacts', {
461 parent: 'workspace.composition',
462 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
463 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
467 $stateProvider.state(
468 'workspace.composition.relations', {
470 parent: 'workspace.composition',
471 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
472 controller: viewModelsModuleName + '.RelationsViewModel'
476 $stateProvider.state(
477 'workspace.composition.structure', {
479 parent: 'workspace.composition',
480 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
481 controller: viewModelsModuleName + '.StructureViewModel'
484 $stateProvider.state(
485 'workspace.composition.lifecycle', {
487 parent: 'workspace.composition',
488 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
489 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
493 $stateProvider.state(
494 'workspace.composition.api', {
496 parent: 'workspace.composition',
497 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
498 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
501 $stateProvider.state(
502 'workspace.composition.deployment', {
504 parent: 'workspace.composition',
505 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
506 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
510 $stateProvider.state(
511 'workspace.plugins', {
512 url: 'plugins/*path',
514 templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html',
515 controller: viewModelsModuleName + '.PluginsContextViewModel'
519 $stateProvider.state(
521 url: '/adminDashboard',
522 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
523 controller: viewModelsModuleName + '.AdminDashboardViewModel',
524 permissions: ['ADMIN']
528 $stateProvider.state(
530 url: '/onboardVendor',
531 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
532 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
536 $stateProvider.state(
538 url: '/plugins/*path',
539 templateUrl: './view-models/plugins/plugins-tab-view.html',
540 controller: viewModelsModuleName + '.PluginsTabViewModel'
544 // Build the states for all hosted apps dynamically
545 _.each(hostedApplications, (hostedApp)=> {
546 if (hostedApp.exists) {
547 $stateProvider.state(
548 hostedApp.state.name, {
549 url: hostedApp.state.url,
550 templateUrl: './view-models/dcae-app/dcae-app-view.html',
551 controller: viewModelsModuleName + hostedApp.state.controllerName
557 $stateProvider.state(
560 templateUrl: './view-models/catalog/catalog-view.html',
561 controller: viewModelsModuleName + '.CatalogViewModel',
563 auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => {
564 let userInfo:IUserProperties = userService.getLoggedinUser();
566 return $q.when(userInfo);
568 return $q.reject({authenticated: false});
575 $stateProvider.state(
578 templateUrl: './view-models/support/support-view.html',
579 controller: viewModelsModuleName + '.SupportViewModel'
583 $stateProvider.state(
586 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
587 controller: viewModelsModuleName + '.ErrorViewModel'
591 tooltipsConfigProvider.options({
594 class: 'tooltip-custom',
602 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
603 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
604 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
605 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
606 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
607 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
608 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
609 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
610 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
611 ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
612 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
613 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
614 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
615 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
616 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
617 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
618 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
619 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
620 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
621 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
623 ng1appModule.constant('sdcConfig', sdcConfig);
624 ng1appModule.constant('sdcMenu', sdcMenu);
628 'Sdc.Services.CacheService',
629 'Sdc.Services.CookieService',
630 'Sdc.Services.ConfigurationUiService',
632 'Sdc.Services.CategoryResourceService',
633 'Sdc.Services.SdcVersionService',
639 'Sdc.Services.EcompHeaderService',
640 'LeftPaletteLoaderService',
641 'Sdc.Services.DataTypesService',
644 ($http:ng.IHttpService,
645 cacheService:CacheService,
646 cookieService:CookieService,
647 ConfigurationUi:ConfigurationUiService,
648 userService:UserService,
649 categoryResourceService:ICategoryResourceClass,
650 sdcVersionService:SdcVersionService,
651 $state:ng.ui.IStateService,
652 $rootScope:ng.IRootScopeService,
653 $location:ng.ILocationService,
655 ModalsHandler:ModalsHandler,
656 ecompHeaderService:EcompHeaderService,
657 LeftPaletteLoaderService:LeftPaletteLoaderService,
658 DataTypesService:DataTypesService,
660 $templateCache:ng.ITemplateCacheService):void => {
661 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
662 //handle cache data - version
663 let initAsdcVersion:Function = ():void => {
665 let onFailed = (response) => {
666 console.info('onFailed initAsdcVersion', response);
667 cacheService.set('version', 'N/A');
670 let onSuccess = (version:any) => {
671 let tmpVerArray = version.version.split(".");
672 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
673 cacheService.set('version', ver);
676 sdcVersionService.getVersion().then(onSuccess, onFailed);
680 let initEcompMenu:Function = (user):void => {
681 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
682 $rootScope['menuItems'] = data;
686 let initConfigurationUi:Function = ():void => {
688 .getConfigurationUi()
689 .then((configurationUi:any) => {
690 cacheService.set('UIConfiguration', configurationUi);
694 let initCategories:Function = ():void => {
695 let onError = ():void => {
696 console.log('Failed to init categories');
699 categoryResourceService.getAllCategories((categories: Categories):void => {
700 cacheService.set('serviceCategories', categories.serviceCategories);
701 cacheService.set('resourceCategories', categories.resourceCategories);
705 // Add hosted applications to sdcConfig
706 sdcConfig.hostedApplications = hostedApplications;
709 $http.defaults.withCredentials = true;
710 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
711 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
714 initConfigurationUi();
715 // initLeftPalette();
716 DataTypesService.initDataTypes();
718 //handle stateChangeStart
719 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
720 if (deregisterStateChangeStartWatcher) {
721 deregisterStateChangeStartWatcher();
722 deregisterStateChangeStartWatcher = null;
726 let removeLoader:Function = ():void => {
727 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
728 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
729 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
730 window.setTimeout(():void=> {
731 $(".sdc-loading-page .main-loader").css("display", "none");
732 $(".sdc-loading-page .caption1").css("display", "none");
733 $(".sdc-loading-page .caption2").css("display", "none");
734 $(".sdc-loading-page").addClass("animated fadeOut");
738 let onNavigateOut:Function = (toState, toParams):void => {
739 let onOk = ():void => {
740 $state.current.data.unsavedChanges = false;
741 $state.go(toState.name, toParams);
744 let data = sdcMenu.alertMessages.exitWithoutSaving;
745 //open notify to user if changes are not saved
746 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
749 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
750 console.info((new Date()).getTime());
751 console.info('$stateChangeStart', toState.name);
753 $rootScope['bodyClass'] = 'default-class';
754 if (toState.data && toState.data.bodyClass) {
755 $rootScope['bodyClass'] = toState.data.bodyClass;
758 // Workaround in case we are entering other state then workspace (user move to catalog)
759 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
760 if (toState.name.indexOf('workspace') === -1) {
761 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
762 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
766 //saving last state to params , for breadcrumbs
767 if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
768 toParams.previousState = fromState.name;
770 toParams.previousState = fromParams.previousState;
773 if (toState.name !== 'error-403' && !userService.getLoggedinUser()) {
774 internalDeregisterStateChangeStartWatcher();
775 event.preventDefault();
777 userService.authorize().subscribe((userInfo:IUserProperties) => {
778 if (!doesUserHasAccess(toState, userInfo)) {
779 $state.go('error-403');
780 console.info('User has no permissions');
781 registerStateChangeStartWatcher();
784 userService.setLoggedinUser(userInfo);
785 cacheService.set('user', userInfo);
787 // initEcompMenu(userInfo);
788 setTimeout(function () {
793 if (userService.getLoggedinUser().role === 'ADMIN') {
794 // toState.name = "adminDashboard";
795 $state.go("adminDashboard", toParams);
796 registerStateChangeStartWatcher();
800 // After user authorized init categories
801 window.setTimeout(():void=> {
802 if ($state.current.name === '') {
803 $state.go(toState.name, toParams);
806 console.log("------$state.current.name=" + $state.current.name);
807 console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
808 registerStateChangeStartWatcher();
815 $state.go('error-403');
817 console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
818 registerStateChangeStartWatcher();
821 else if (userService.getLoggedinUser()) {
822 internalDeregisterStateChangeStartWatcher();
823 if (!doesUserHasAccess(toState, userService.getLoggedinUser())) {
824 event.preventDefault();
825 $state.go('error-403');
826 console.info('User has no permissions');
828 if (toState.name === "welcome") {
829 $state.go("dashboard");
831 registerStateChangeStartWatcher();
832 //if form is dirty and not save - notify to user
833 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
834 event.preventDefault();
835 onNavigateOut(toState, toParams);
841 let doesUserHasAccess:Function = (toState, user):boolean => {
843 let isUserHasAccess = true;
844 if (toState.permissions && toState.permissions.length > 0) {
845 isUserHasAccess = _.includes(toState.permissions, user.role);
847 return isUserHasAccess;
849 let deregisterStateChangeStartWatcher:Function;
851 let registerStateChangeStartWatcher:Function = ():void => {
852 internalDeregisterStateChangeStartWatcher();
853 console.info('registerStateChangeStartWatcher $stateChangeStart');
854 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
855 onStateChangeStart(event, toState, toParams, fromState, fromParams);
859 registerStateChangeStartWatcher();