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';
33 import {SdcUiComponentsNg1Module} from 'sdc-ui/lib/angular';
37 LeftPaletteLoaderService,
40 ConfigurationUiService,
43 ICategoryResourceClass,
46 import { UserService } from "./ng2/services/user.service";
47 import {forwardRef} from '@angular/core';
48 import {UpgradeAdapter} from '@angular/upgrade';
49 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States, PREVIOUS_CSAR_COMPONENT} from "./utils";
50 import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
51 import {ComponentFactory} from "./utils/component-factory";
52 import {ModalsHandler} from "./utils/modals-handler";
53 import {downgradeComponent} from "@angular/upgrade/static";
55 import {AppModule} from './ng2/app.module';
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 SdcUiComponentsNg1Module.name,
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);
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,
173 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
175 $translateProvider.useStaticFilesLoader({
176 prefix: pathPrefix + 'assets/languages/',
178 suffix: '.json?d=' + (new Date()).getTime()
180 $translateProvider.useSanitizeValueStrategy('escaped');
181 $translateProvider.preferredLanguage('en_US');
183 $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
184 $httpProvider.interceptors.push('Sdc.Services.HttpErrorInterceptor');
185 $urlRouterProvider.otherwise('welcome');
187 $stateProvider.state(
189 url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed',
190 templateUrl: "./view-models/dashboard/dashboard-view.html",
191 controller: viewModelsModuleName + '.DashboardViewModel',
195 $stateProvider.state(
198 templateUrl: "./view-models/welcome/welcome-view.html",
199 controller: viewModelsModuleName + '.WelcomeViewModel'
203 let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => {
204 if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
205 const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
206 if (breadcrumbsComponents) {
207 return breadcrumbsComponents;
210 let breadcrumbsComponentsPromise;
211 if ($stateParams.previousState === 'dashboard') {
212 breadcrumbsComponentsPromise = EntityService.getAllComponents(true);
213 } else if ($stateParams.previousState === 'catalog') {
214 breadcrumbsComponentsPromise = EntityService.getCatalog();
216 cacheService.remove('breadcrumbsComponentsState');
217 cacheService.remove('breadcrumbsComponents');
220 breadcrumbsComponentsPromise.then((components) => {
221 cacheService.set('breadcrumbsComponentsState', $stateParams.previousState);
222 cacheService.set('breadcrumbsComponents', components);
224 return breadcrumbsComponentsPromise;
228 const oldWorkspaceController:Array<any> = ['$location', ($location:ng.ILocationService) => {
229 // redirect old /workspace/* urls to /catalog/workspace/* url
230 const newUrl = '/catalog' + $location.url();
231 console.log('old workspace path - redirecting to:', newUrl);
232 $location.url(newUrl);
235 $stateProvider.state(
237 url: '/workspace/:id/:type/*workspaceInnerPath',
238 controller: oldWorkspaceController
242 $stateProvider.state(
244 url: '/:previousState/workspace/:id/:type/',
245 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
246 templateUrl: './view-models/workspace/workspace-view.html',
247 controller: viewModelsModuleName + '.WorkspaceViewModel',
249 injectComponent: ['$stateParams', 'ComponentFactory', 'Sdc.Services.CacheService', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, cacheService:CacheService, ComponentServiceNg2:ComponentServiceNg2) {
251 if ($stateParams.id && $stateParams.id.length) { //need to check length in case ID is an empty string
252 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
253 (component:Component)=> {
254 if ($stateParams.componentCsar && component.isResource()){
255 if((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) {
256 cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
258 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
262 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
263 return $stateParams.componentCsar;
265 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
266 if (emptyComponent.isResource() && $stateParams.resourceType) {
267 // Set the resource type
268 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
270 if ($stateParams.importedFile) {
271 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
273 return emptyComponent;
276 components: componentsParam
281 $stateProvider.state(
282 States.WORKSPACE_GENERAL, {
285 controller: viewModelsModuleName + '.GeneralViewModel',
286 templateUrl: './view-models/workspace/tabs/general/general-view.html',
287 data: {unsavedChanges: false, bodyClass: 'general'}
291 $stateProvider.state(
292 States.WORKSPACE_ACTIVITY_LOG, {
295 controller: viewModelsModuleName + '.ActivityLogViewModel',
296 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
300 $stateProvider.state(
301 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
302 url: 'deployment_artifacts',
304 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
305 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
307 bodyClass: 'deployment_artifacts'
312 $stateProvider.state(
313 States.WORKSPACE_INFORMATION_ARTIFACTS, {
314 url: 'information_artifacts',
316 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
317 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
319 bodyClass: 'information_artifacts'
324 $stateProvider.state(
325 States.WORKSPACE_TOSCA_ARTIFACTS, {
326 url: 'tosca_artifacts',
328 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
329 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
331 bodyClass: 'tosca_artifacts'
336 $stateProvider.state(
337 States.WORKSPACE_PROPERTIES, {
340 controller: viewModelsModuleName + '.PropertiesViewModel',
341 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
343 bodyClass: 'properties'
348 $stateProvider.state(
349 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
350 url: 'properties_assignment',
351 params: {'component': null},
352 template: '<properties-assignment></properties-assignment>',
355 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
356 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
357 $stateParams.component = injectComponent;
358 return injectComponent;
362 bodyClass: 'properties-assignment'
367 $stateProvider.state(
368 States.WORKSPACE_ATTRIBUTES, {
371 controller: viewModelsModuleName + '.AttributesViewModel',
372 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
374 bodyClass: 'attributes'
379 $stateProvider.state(
380 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
381 url: 'req_and_capabilities',
383 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
384 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
386 bodyClass: 'attributes'
392 $stateProvider.state(
393 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
395 url: 'management_workflow',
396 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
397 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
401 $stateProvider.state(
402 States.WORKSPACE_NETWORK_CALL_FLOW, {
404 url: 'network_call_flow',
405 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
406 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
410 $stateProvider.state(
411 States.WORKSPACE_DISTRIBUTION, {
414 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
415 controller: viewModelsModuleName + '.DistributionViewModel'
419 $stateProvider.state(
420 States.WORKSPACE_COMPOSITION, {
423 controller: viewModelsModuleName + '.CompositionViewModel',
424 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
426 bodyClass: 'composition'
431 // $stateProvider.state(
432 // States.WORKSPACE_NG2, {
434 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
435 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
439 $stateProvider.state(
440 States.WORKSPACE_DEPLOYMENT, {
443 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
444 controller: viewModelsModuleName + '.DeploymentViewModel',
446 bodyClass: 'composition'
451 $stateProvider.state(
452 'workspace.composition.details', {
454 parent: 'workspace.composition',
455 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
456 controller: viewModelsModuleName + '.DetailsViewModel'
460 $stateProvider.state(
461 'workspace.composition.properties', {
463 parent: 'workspace.composition',
464 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
465 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
469 $stateProvider.state(
470 'workspace.composition.artifacts', {
472 parent: 'workspace.composition',
473 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
474 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
478 $stateProvider.state(
479 'workspace.composition.relations', {
481 parent: 'workspace.composition',
482 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
483 controller: viewModelsModuleName + '.RelationsViewModel'
487 $stateProvider.state(
488 'workspace.composition.structure', {
490 parent: 'workspace.composition',
491 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
492 controller: viewModelsModuleName + '.StructureViewModel'
495 $stateProvider.state(
496 'workspace.composition.lifecycle', {
498 parent: 'workspace.composition',
499 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
500 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
504 $stateProvider.state(
505 'workspace.composition.api', {
507 parent: 'workspace.composition',
508 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
509 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
512 $stateProvider.state(
513 'workspace.composition.deployment', {
515 parent: 'workspace.composition',
516 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
517 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
520 $stateProvider.state(
521 'workspace.composition.dependencies', {
523 parent: 'workspace.composition',
524 templateUrl: './view-models/workspace/tabs/composition/tabs/service-dependencies/service-dependencies-view.html',
525 controller: viewModelsModuleName + '.ServiceDependenciesViewModel'
529 $stateProvider.state(
530 States.WORKSPACE_INTERFACE_OPERATION, {
531 url: 'interface_operation',
533 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
534 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
536 bodyClass: 'interface_operation'
541 $stateProvider.state(
542 'workspace.plugins', {
543 url: 'plugins/*path',
545 params: {'queryParams': null},
546 templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html',
547 controller: viewModelsModuleName + '.PluginsContextViewModel'
551 $stateProvider.state(
553 url: '/adminDashboard',
554 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
555 controller: viewModelsModuleName + '.AdminDashboardViewModel',
556 permissions: ['ADMIN']
560 $stateProvider.state(
562 url: '/onboardVendor',
563 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
564 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
568 $stateProvider.state(
570 url: '/plugins/*path',
571 templateUrl: './view-models/plugins/plugins-tab-view.html',
572 controller: viewModelsModuleName + '.PluginsTabViewModel'
576 // Build the states for all hosted apps dynamically
577 _.each(hostedApplications, (hostedApp)=> {
578 if (hostedApp.exists) {
579 $stateProvider.state(
580 hostedApp.state.name, {
581 url: hostedApp.state.url,
582 templateUrl: './view-models/dcae-app/dcae-app-view.html',
583 controller: viewModelsModuleName + hostedApp.state.controllerName
589 $stateProvider.state(
591 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
592 templateUrl: './view-models/catalog/catalog-view.html',
593 controller: viewModelsModuleName + '.CatalogViewModel',
595 auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => {
596 let userInfo:IUserProperties = userService.getLoggedinUser();
598 return $q.when(userInfo);
600 return $q.reject({authenticated: false});
607 $stateProvider.state(
610 templateUrl: './view-models/support/support-view.html',
611 controller: viewModelsModuleName + '.SupportViewModel'
615 $stateProvider.state(
618 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
619 controller: viewModelsModuleName + '.ErrorViewModel'
623 tooltipsConfigProvider.options({
626 class: 'tooltip-custom',
634 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
635 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
636 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
637 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
638 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
639 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
640 ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
641 ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
642 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
643 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
644 ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
645 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
646 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
647 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
648 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
649 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
650 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
651 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
652 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
653 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
654 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
656 ng1appModule.constant('sdcConfig', sdcConfig);
657 ng1appModule.constant('sdcMenu', sdcMenu);
661 'Sdc.Services.CacheService',
662 'Sdc.Services.CookieService',
663 'Sdc.Services.ConfigurationUiService',
665 'Sdc.Services.CategoryResourceService',
666 'Sdc.Services.SdcVersionService',
672 'Sdc.Services.EcompHeaderService',
673 'LeftPaletteLoaderService',
674 'Sdc.Services.DataTypesService',
677 ($http:ng.IHttpService,
678 cacheService:CacheService,
679 cookieService:CookieService,
680 ConfigurationUi:ConfigurationUiService,
681 userService:UserService,
682 categoryResourceService:ICategoryResourceClass,
683 sdcVersionService:SdcVersionService,
684 $state:ng.ui.IStateService,
685 $rootScope:ng.IRootScopeService,
686 $location:ng.ILocationService,
688 ModalsHandler:ModalsHandler,
689 ecompHeaderService:EcompHeaderService,
690 LeftPaletteLoaderService:LeftPaletteLoaderService,
691 DataTypesService:DataTypesService,
693 $templateCache:ng.ITemplateCacheService):void => {
694 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
695 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
696 //handle cache data - version
697 let initAsdcVersion:Function = ():void => {
699 let onFailed = (response) => {
700 console.info('onFailed initAsdcVersion', response);
701 cacheService.set('version', 'N/A');
704 let onSuccess = (version:any) => {
705 let tmpVerArray = version.version.split(".");
706 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
707 cacheService.set('version', ver);
710 sdcVersionService.getVersion().then(onSuccess, onFailed);
714 let initEcompMenu:Function = (user):void => {
715 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
716 $rootScope['menuItems'] = data;
720 let initConfigurationUi:Function = ():void => {
722 .getConfigurationUi()
723 .then((configurationUi:any) => {
724 cacheService.set('UIConfiguration', configurationUi);
728 let initCategories:Function = ():void => {
729 let onError = ():void => {
730 console.log('Failed to init categories');
733 categoryResourceService.getAllCategories((categories: Categories):void => {
734 cacheService.set('serviceCategories', categories.serviceCategories);
735 cacheService.set('resourceCategories', categories.resourceCategories);
739 // Add hosted applications to sdcConfig
740 sdcConfig.hostedApplications = hostedApplications;
743 $http.defaults.withCredentials = true;
744 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
745 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
748 initConfigurationUi();
749 // initLeftPalette();
750 DataTypesService.initDataTypes();
752 //handle stateChangeStart
753 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
754 if (deregisterStateChangeStartWatcher) {
755 deregisterStateChangeStartWatcher();
756 deregisterStateChangeStartWatcher = null;
758 if (deregisterStateChangeSuccessWatcher) {
759 deregisterStateChangeSuccessWatcher();
760 deregisterStateChangeSuccessWatcher = null;
764 let removeLoader:Function = ():void => {
765 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
766 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
767 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
768 window.setTimeout(():void=> {
769 $(".sdc-loading-page .main-loader").css("display", "none");
770 $(".sdc-loading-page .caption1").css("display", "none");
771 $(".sdc-loading-page .caption2").css("display", "none");
772 $(".sdc-loading-page").addClass("animated fadeOut");
776 let onNavigateOut:Function = (toState, toParams):void => {
777 let onOk = ():void => {
778 $state.current.data.unsavedChanges = false;
779 $state.go(toState.name, toParams);
782 let data = sdcMenu.alertMessages.exitWithoutSaving;
783 //open notify to user if changes are not saved
784 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
787 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
788 console.info((new Date()).getTime());
789 console.info('$stateChangeStart', toState.name);
791 if (toState.name !== 'error-403' && !userService.getLoggedinUser()) {
792 if (toState.name !== 'welcome') {
793 event.preventDefault();
796 userService.authorize().subscribe((userInfo:IUserProperties) => {
797 if (!doesUserHasAccess(toState, userInfo)) {
798 $state.go('error-403');
799 console.info('User has no permissions');
802 userService.setLoggedinUser(userInfo);
803 cacheService.set('user', userInfo);
805 // initEcompMenu(userInfo);
806 setTimeout(function () {
811 if (userService.getLoggedinUser().role === 'ADMIN') {
812 // toState.name = "adminDashboard";
813 $state.go("adminDashboard", toParams);
817 // After user authorized init categories
818 window.setTimeout(():void=> {
819 if ($state.current.name === '') {
820 $state.go(toState.name, toParams);
823 console.log("------$state.current.name=" + $state.current.name);
830 $state.go('error-403');
833 else if (userService.getLoggedinUser()) {
834 if (!doesUserHasAccess(toState, userService.getLoggedinUser())) {
835 event.preventDefault();
836 $state.go('error-403');
837 console.info('User has no permissions');
839 if (toState.name === "welcome") {
840 $state.go("dashboard");
843 //if form is dirty and not save - notify to user
844 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
845 event.preventDefault();
846 onNavigateOut(toState, toParams);
850 // if enetering workspace, set the previousState param
851 if (toState.name.indexOf('workspace') !== -1) {
852 if (!toParams.previousState) {
853 const tmpPreviousState1 = fromParams && fromParams.previousState;
854 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
855 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
861 let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => {
862 console.info('$stateChangeSuccess', toState.name);
864 // Workaround in case we are entering other state then workspace (user move to catalog)
865 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
866 if (toState.name.indexOf('workspace') === -1) {
867 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
868 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
870 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)){
871 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
876 $rootScope['bodyClass'] = 'default-class';
877 if (toState.data && toState.data.bodyClass) {
878 $rootScope['bodyClass'] = toState.data.bodyClass;
882 let doesUserHasAccess:Function = (toState, user):boolean => {
884 let isUserHasAccess = true;
885 if (toState.permissions && toState.permissions.length > 0) {
886 isUserHasAccess = _.includes(toState.permissions, user.role);
888 return isUserHasAccess;
890 let deregisterStateChangeStartWatcher:Function;
891 let deregisterStateChangeSuccessWatcher:Function;
893 let registerStateChangeStartWatcher:Function = ():void => {
894 internalDeregisterStateChangeStartWatcher();
895 console.info('registerStateChangeStartWatcher $stateChangeStart');
896 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
897 onStateChangeStart(event, toState, toParams, fromState, fromParams);
899 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams):void => {
900 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
904 registerStateChangeStartWatcher();