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 { SearchWithAutoCompleteComponent } from "./ng2/shared/search-with-autocomplete/search-with-autocomplete.component";
57 import {Component} from "./models/components/component";
58 import {ComponentServiceNg2} from "./ng2/services/component-services/component.service";
59 import {ComponentMetadata} from "./models/component-metadata";
60 import {Categories} from "./models/categories";
63 let moduleName:string = 'sdcApp';
64 let viewModelsModuleName:string = 'Sdc.ViewModels';
65 let directivesModuleName:string = 'Sdc.Directives';
66 let servicesModuleName:string = 'Sdc.Services';
67 let filtersModuleName:string = 'Sdc.Filters';
68 let utilsModuleName:string = 'Sdc.Utils';
70 // Load configuration according to environment.
71 declare var __ENV__:string;
72 let sdcConfig:IAppConfigurtaion;
74 let pathPrefix:string = '';
75 if (__ENV__ === 'dev') {
76 sdcConfig = require('./../../configurations/dev.js');
77 } else if (__ENV__ === 'prod') {
78 sdcConfig = require('./../../configurations/prod.js');
81 console.log("ERROR: Environment configuration not found!");
83 sdcMenu = require('./../../configurations/menu.js');
85 let dependentModules:Array<string> = [
98 'pascalprecht.translate',
104 viewModelsModuleName,
105 directivesModuleName,
111 // ===================== Hosted applications section ====================
112 // Define here new hosted apps
113 let hostedApplications:Array<IHostedApplication> = [
115 "moduleName": "dcaeApp",
117 "defaultState": 'dcae.app.home',
121 "relativeHtmlPath": 'dcae-app/dcae-app-view.html',
122 "controllerName": '.DcaeAppViewModel'
127 // Check if module exists (in case the javascript was not loaded).
128 let isModuleExists = (moduleName:string):boolean => {
130 angular.module(moduleName);
131 dependentModules.push(moduleName);
134 console.log('Module ' + moduleName + ' does not exists');
139 // Check which hosted applications exists
140 _.each(hostedApplications, (hostedApp)=> {
141 if (isModuleExists(hostedApp.moduleName)) {
142 hostedApp['exists'] = true;
145 // ===================== Hosted applications section ====================
147 export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
148 angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory);
149 angular.module('sdcApp').directive('ng2SearchWithAutocomplete',
151 component: SearchWithAutoCompleteComponent,
152 inputs: ['searchPlaceholder', 'searchBarClass', 'autoCompleteValues'],
153 outputs: ['searchChanged', 'searchButtonClicked']
154 }) as angular.IDirectiveFactory);
157 ng1appModule.config([
159 '$translateProvider',
160 '$urlRouterProvider',
162 'tooltipsConfigProvider',
163 'NotificationProvider',
165 $translateProvider:any,
166 $urlRouterProvider:ng.ui.IUrlRouterProvider,
167 $httpProvider:ng.IHttpProvider,
168 tooltipsConfigProvider:any,
169 NotificationProvider:any):void => {
171 NotificationProvider.setOptions({
177 horizontalSpacing: 20,
181 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
183 $translateProvider.useStaticFilesLoader({
184 prefix: pathPrefix + 'assets/languages/',
186 suffix: '.json?d=' + (new Date()).getTime()
188 $translateProvider.useSanitizeValueStrategy('escaped');
189 $translateProvider.preferredLanguage('en_US');
191 $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
192 $httpProvider.interceptors.push('Sdc.Services.HttpErrorInterceptor');
193 $urlRouterProvider.otherwise('welcome');
195 $stateProvider.state(
197 url: '/dashboard?show&folder',
198 templateUrl: "./view-models/dashboard/dashboard-view.html",
199 controller: viewModelsModuleName + '.DashboardViewModel',
203 $stateProvider.state(
206 templateUrl: "./view-models/welcome/welcome-view.html",
207 controller: viewModelsModuleName + '.WelcomeViewModel'
211 let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => {
212 if (cacheService.get('breadcrumbsComponents')) {
213 return cacheService.get('breadcrumbsComponents');
215 return EntityService.getCatalog();
219 $stateProvider.state(
221 url: '/workspace/:id/:type/',
222 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
223 templateUrl: './view-models/workspace/workspace-view.html',
224 controller: viewModelsModuleName + '.WorkspaceViewModel',
226 injectComponent: ['$stateParams', 'ComponentFactory', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, ComponentServiceNg2:ComponentServiceNg2) {
227 if ($stateParams.id) {
228 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id);
229 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
230 return $stateParams.componentCsar;
232 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
233 if (emptyComponent.isResource() && $stateParams.resourceType) {
234 // Set the resource type
235 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
237 if ($stateParams.importedFile) {
238 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
240 return emptyComponent;
243 components: componentsParam
248 $stateProvider.state(
249 States.WORKSPACE_GENERAL, {
252 controller: viewModelsModuleName + '.GeneralViewModel',
253 templateUrl: './view-models/workspace/tabs/general/general-view.html',
254 data: {unsavedChanges: false, bodyClass: 'general'}
258 $stateProvider.state(
259 States.WORKSPACE_ACTIVITY_LOG, {
262 controller: viewModelsModuleName + '.ActivityLogViewModel',
263 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
264 data: {unsavedChanges: false}
268 $stateProvider.state(
269 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
270 url: 'deployment_artifacts',
272 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
273 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
275 bodyClass: 'deployment_artifacts'
280 $stateProvider.state(
281 States.WORKSPACE_INFORMATION_ARTIFACTS, {
282 url: 'information_artifacts',
284 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
285 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
287 bodyClass: 'information_artifacts'
292 $stateProvider.state(
293 States.WORKSPACE_TOSCA_ARTIFACTS, {
294 url: 'tosca_artifacts',
296 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
297 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
299 bodyClass: 'tosca_artifacts'
304 $stateProvider.state(
305 States.WORKSPACE_PROPERTIES, {
308 controller: viewModelsModuleName + '.PropertiesViewModel',
309 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
311 bodyClass: 'properties'
316 $stateProvider.state(
317 States.WORKSPACE_SERVICE_INPUTS, {
318 url: 'service_inputs',
320 controller: viewModelsModuleName + '.ServiceInputsViewModel',
321 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
323 bodyClass: 'workspace-inputs'
328 $stateProvider.state(
329 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
330 url: 'properties_assignment',
331 params: {'component': null},
332 template: '<properties-assignment></properties-assignment>',
335 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
336 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
337 $stateParams.component = injectComponent;
338 return injectComponent;
342 bodyClass: 'properties-assignment'
347 $stateProvider.state(
348 States.WORKSPACE_RESOURCE_INPUTS, {
349 url: 'resource_inputs',
351 controller: viewModelsModuleName + '.ResourceInputsViewModel',
352 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
354 bodyClass: 'workspace-inputs'
359 $stateProvider.state(
360 States.WORKSPACE_ATTRIBUTES, {
363 controller: viewModelsModuleName + '.AttributesViewModel',
364 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
366 bodyClass: 'attributes'
371 $stateProvider.state(
372 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
373 url: 'req_and_capabilities',
375 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
376 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
378 bodyClass: 'attributes'
384 $stateProvider.state(
385 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
387 url: 'management_workflow',
388 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
389 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
393 $stateProvider.state(
394 States.WORKSPACE_NETWORK_CALL_FLOW, {
396 url: 'network_call_flow',
397 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
398 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
402 $stateProvider.state(
403 States.WORKSPACE_DISTRIBUTION, {
406 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
407 controller: viewModelsModuleName + '.DistributionViewModel'
411 $stateProvider.state(
412 States.WORKSPACE_COMPOSITION, {
415 controller: viewModelsModuleName + '.CompositionViewModel',
416 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
418 bodyClass: 'composition'
423 // $stateProvider.state(
424 // States.WORKSPACE_NG2, {
426 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
427 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
431 $stateProvider.state(
432 States.WORKSPACE_DEPLOYMENT, {
435 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
436 controller: viewModelsModuleName + '.DeploymentViewModel',
438 bodyClass: 'composition'
443 $stateProvider.state(
444 'workspace.composition.details', {
446 parent: 'workspace.composition',
447 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
448 controller: viewModelsModuleName + '.DetailsViewModel'
452 $stateProvider.state(
453 'workspace.composition.properties', {
455 parent: 'workspace.composition',
456 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
457 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
461 $stateProvider.state(
462 'workspace.composition.artifacts', {
464 parent: 'workspace.composition',
465 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
466 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
470 $stateProvider.state(
471 'workspace.composition.relations', {
473 parent: 'workspace.composition',
474 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
475 controller: viewModelsModuleName + '.RelationsViewModel'
479 $stateProvider.state(
480 'workspace.composition.structure', {
482 parent: 'workspace.composition',
483 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
484 controller: viewModelsModuleName + '.StructureViewModel'
487 $stateProvider.state(
488 'workspace.composition.lifecycle', {
490 parent: 'workspace.composition',
491 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
492 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
496 $stateProvider.state(
497 'workspace.composition.api', {
499 parent: 'workspace.composition',
500 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
501 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
504 $stateProvider.state(
505 'workspace.composition.deployment', {
507 parent: 'workspace.composition',
508 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
509 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
513 $stateProvider.state(
515 url: '/adminDashboard',
516 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
517 controller: viewModelsModuleName + '.AdminDashboardViewModel',
518 permissions: ['ADMIN']
522 $stateProvider.state(
524 url: '/onboardVendor',
525 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
526 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
530 // Build the states for all hosted apps dynamically
531 _.each(hostedApplications, (hostedApp)=> {
532 if (hostedApp.exists) {
533 $stateProvider.state(
534 hostedApp.state.name, {
535 url: hostedApp.state.url,
536 templateUrl: './view-models/dcae-app/dcae-app-view.html',
537 controller: viewModelsModuleName + hostedApp.state.controllerName
543 $stateProvider.state(
546 templateUrl: './view-models/catalog/catalog-view.html',
547 controller: viewModelsModuleName + '.CatalogViewModel',
549 auth: ["$q", "Sdc.Services.UserResourceService", ($q:any, userResourceService:IUserResourceClass) => {
550 let userInfo:IUserResource = userResourceService.getLoggedinUser();
552 return $q.when(userInfo);
554 return $q.reject({authenticated: false});
561 $stateProvider.state(
564 templateUrl: './view-models/support/support-view.html',
565 controller: viewModelsModuleName + '.SupportViewModel'
569 $stateProvider.state(
572 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
573 controller: viewModelsModuleName + '.ErrorViewModel'
577 tooltipsConfigProvider.options({
580 class: 'tooltip-custom',
588 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
589 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
590 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
591 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
592 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
593 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
594 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
595 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
596 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
597 ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
598 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
599 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
600 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
601 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
602 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
603 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
604 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
605 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
606 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
607 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
609 ng1appModule.constant('sdcConfig', sdcConfig);
610 ng1appModule.constant('sdcMenu', sdcMenu);
614 'Sdc.Services.CacheService',
615 'Sdc.Services.CookieService',
616 'Sdc.Services.ConfigurationUiService',
617 'Sdc.Services.UserResourceService',
618 'Sdc.Services.CategoryResourceService',
619 'Sdc.Services.SdcVersionService',
625 'Sdc.Services.EcompHeaderService',
626 'LeftPaletteLoaderService',
627 'Sdc.Services.DataTypesService',
630 ($http:ng.IHttpService,
631 cacheService:CacheService,
632 cookieService:CookieService,
633 ConfigurationUi:ConfigurationUiService,
634 UserResourceClass:IUserResourceClass,
635 categoryResourceService:ICategoryResourceClass,
636 sdcVersionService:SdcVersionService,
637 $state:ng.ui.IStateService,
638 $rootScope:ng.IRootScopeService,
639 $location:ng.ILocationService,
641 ModalsHandler:ModalsHandler,
642 ecompHeaderService:EcompHeaderService,
643 LeftPaletteLoaderService:LeftPaletteLoaderService,
644 DataTypesService:DataTypesService,
646 $templateCache:ng.ITemplateCacheService):void => {
647 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
648 //handle cache data - version
649 let initAsdcVersion:Function = ():void => {
651 let onFailed = (response) => {
652 console.info('onFailed initAsdcVersion', response);
653 cacheService.set('version', 'N/A');
656 let onSuccess = (version:any) => {
657 let tmpVerArray = version.version.split(".");
658 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
659 cacheService.set('version', ver);
662 sdcVersionService.getVersion().then(onSuccess, onFailed);
666 let initEcompMenu:Function = (user):void => {
667 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
668 $rootScope['menuItems'] = data;
672 let initConfigurationUi:Function = ():void => {
674 .getConfigurationUi()
675 .then((configurationUi:any) => {
676 cacheService.set('UIConfiguration', configurationUi);
680 let initCategories:Function = ():void => {
681 let onError = ():void => {
682 console.log('Failed to init categories');
685 categoryResourceService.getAllCategories((categories: Categories):void => {
686 cacheService.set('serviceCategories', categories.serviceCategories);
687 cacheService.set('resourceCategories', categories.resourceCategories);
691 // Add hosted applications to sdcConfig
692 sdcConfig.hostedApplications = hostedApplications;
695 $http.defaults.withCredentials = true;
696 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
697 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
700 initConfigurationUi();
701 // initLeftPalette();
702 DataTypesService.initDataTypes();
704 //handle stateChangeStart
705 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
706 if (deregisterStateChangeStartWatcher) {
707 deregisterStateChangeStartWatcher();
708 deregisterStateChangeStartWatcher = null;
712 let removeLoader:Function = ():void => {
713 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
714 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
715 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
716 window.setTimeout(():void=> {
717 $(".sdc-loading-page .main-loader").css("display", "none");
718 $(".sdc-loading-page .caption1").css("display", "none");
719 $(".sdc-loading-page .caption2").css("display", "none");
720 $(".sdc-loading-page").addClass("animated fadeOut");
724 let onNavigateOut:Function = (toState, toParams):void => {
725 let onOk = ():void => {
726 $state.current.data.unsavedChanges = false;
727 $state.go(toState.name, toParams);
730 let data = sdcMenu.alertMessages.exitWithoutSaving;
731 //open notify to user if changes are not saved
732 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
735 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
736 console.info((new Date()).getTime());
737 console.info('$stateChangeStart', toState.name);
739 $rootScope['bodyClass'] = 'default-class';
740 if (toState.data && toState.data.bodyClass) {
741 $rootScope['bodyClass'] = toState.data.bodyClass;
744 // Workaround in case we are entering other state then workspace (user move to catalog)
745 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
746 if (toState.name.indexOf('workspace') === -1) {
747 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
748 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
752 //saving last state to params , for breadcrumbs
753 if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
754 toParams.previousState = fromState.name;
756 toParams.previousState = fromParams.previousState;
759 if (toState.name !== 'error-403' && !UserResourceClass.getLoggedinUser()) {
760 internalDeregisterStateChangeStartWatcher();
761 event.preventDefault();
763 UserResourceClass.authorize().$promise.then((user:IUserResource) => {
764 if (!doesUserHasAccess(toState, user)) {
765 $state.go('error-403');
766 console.info('User has no permissions');
767 registerStateChangeStartWatcher();
770 UserResourceClass.setLoggedinUser(user);
771 cacheService.set('user', user);
773 // initEcompMenu(user);
774 setTimeout(function () {
779 if (UserResourceClass.getLoggedinUser().role === 'ADMIN') {
780 // toState.name = "adminDashboard";
781 $state.go("adminDashboard", toParams);
782 registerStateChangeStartWatcher();
786 // After user authorized init categories
787 window.setTimeout(():void=> {
788 if ($state.current.name === '') {
789 $state.go(toState.name, toParams);
792 console.log("------$state.current.name=" + $state.current.name);
793 console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
794 registerStateChangeStartWatcher();
801 $state.go('error-403');
803 console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
804 registerStateChangeStartWatcher();
807 else if (UserResourceClass.getLoggedinUser()) {
808 internalDeregisterStateChangeStartWatcher();
809 if (!doesUserHasAccess(toState, UserResourceClass.getLoggedinUser())) {
810 event.preventDefault();
811 $state.go('error-403');
812 console.info('User has no permissions');
814 if (toState.name === "welcome") {
815 $state.go("dashboard");
817 registerStateChangeStartWatcher();
818 //if form is dirty and not save - notify to user
819 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
820 event.preventDefault();
821 onNavigateOut(toState, toParams);
827 let doesUserHasAccess:Function = (toState, user):boolean => {
829 let isUserHasAccess = true;
830 if (toState.permissions && toState.permissions.length > 0) {
831 isUserHasAccess = _.includes(toState.permissions, user.role);
833 return isUserHasAccess;
835 let deregisterStateChangeStartWatcher:Function;
837 let registerStateChangeStartWatcher:Function = ():void => {
838 internalDeregisterStateChangeStartWatcher();
839 console.info('registerStateChangeStartWatcher $stateChangeStart');
840 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
841 onStateChangeStart(event, toState, toParams, fromState, fromParams);
845 registerStateChangeStartWatcher();