Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 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 |
Idan Amit | 7363f3d | 2018-03-21 12:04:57 +0200 | [diff] [blame] | 10 | * |
Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Idan Amit | 7363f3d | 2018-03-21 12:04:57 +0200 | [diff] [blame] | 12 | * |
Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 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========================================================= |
| 19 | */ |
| 20 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 21 | 'use strict'; |
| 22 | |
| 23 | //import 'restangular'; |
| 24 | //import 'angular-ui-router'; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 25 | import * as _ from "lodash"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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'; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 33 | import {SdcUiComponentsNg1Module} from 'sdc-ui/lib/angular'; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 34 | |
| 35 | import { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 36 | DataTypesService, |
| 37 | LeftPaletteLoaderService, |
| 38 | EcompHeaderService, |
| 39 | CookieService, |
| 40 | ConfigurationUiService, |
| 41 | CacheService, |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 42 | SdcVersionService, |
| 43 | ICategoryResourceClass, |
| 44 | EntityService |
| 45 | } from "./services"; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 46 | import { UserService } from "./ng2/services/user.service"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 47 | import {forwardRef} from '@angular/core'; |
| 48 | import {UpgradeAdapter} from '@angular/upgrade'; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 49 | import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States, PREVIOUS_CSAR_COMPONENT} from "./utils"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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"; |
| 54 | |
| 55 | import {AppModule} from './ng2/app.module'; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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"; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 60 | import {IUserProperties} from "./models/user"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 61 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 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'; |
| 68 | |
| 69 | // Load configuration according to environment. |
| 70 | declare var __ENV__:string; |
| 71 | let sdcConfig:IAppConfigurtaion; |
| 72 | let sdcMenu:IAppMenu; |
| 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'); |
| 78 | pathPrefix = 'sdc1/'; |
| 79 | } else { |
| 80 | console.log("ERROR: Environment configuration not found!"); |
| 81 | } |
| 82 | sdcMenu = require('./../../configurations/menu.js'); |
| 83 | |
| 84 | let dependentModules:Array<string> = [ |
| 85 | 'ui.router', |
| 86 | 'ui.bootstrap', |
| 87 | 'ui.bootstrap.tpls', |
| 88 | 'ngDragDrop', |
| 89 | 'ui-notification', |
| 90 | 'ngResource', |
| 91 | 'ngSanitize', |
| 92 | 'naif.base64', |
| 93 | 'base64', |
| 94 | 'uuid4', |
| 95 | 'checklist-model', |
| 96 | 'angular.filter', |
| 97 | 'pascalprecht.translate', |
| 98 | '720kb.tooltips', |
| 99 | 'restangular', |
| 100 | 'angular-clipboard', |
| 101 | 'angularResizable', |
| 102 | 'infinite-scroll', |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 103 | SdcUiComponentsNg1Module.name, |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 104 | viewModelsModuleName, |
| 105 | directivesModuleName, |
| 106 | servicesModuleName, |
| 107 | filtersModuleName, |
| 108 | utilsModuleName |
| 109 | ]; |
| 110 | |
| 111 | // ===================== Hosted applications section ==================== |
| 112 | // Define here new hosted apps |
| 113 | let hostedApplications:Array<IHostedApplication> = [ |
| 114 | { |
| 115 | "moduleName": "dcaeApp", |
| 116 | "navTitle": "DCAE", |
| 117 | "defaultState": 'dcae.app.home', |
| 118 | "state": { |
| 119 | "name": "dcae", |
| 120 | "url": "/dcae", |
| 121 | "relativeHtmlPath": 'dcae-app/dcae-app-view.html', |
| 122 | "controllerName": '.DcaeAppViewModel' |
| 123 | } |
| 124 | } |
| 125 | ]; |
| 126 | |
| 127 | // Check if module exists (in case the javascript was not loaded). |
| 128 | let isModuleExists = (moduleName:string):boolean => { |
| 129 | try { |
| 130 | angular.module(moduleName); |
| 131 | dependentModules.push(moduleName); |
| 132 | return true; |
| 133 | } catch (e) { |
| 134 | console.log('Module ' + moduleName + ' does not exists'); |
| 135 | return false; |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | // Check which hosted applications exists |
| 140 | _.each(hostedApplications, (hostedApp)=> { |
| 141 | if (isModuleExists(hostedApp.moduleName)) { |
| 142 | hostedApp['exists'] = true; |
| 143 | } |
| 144 | }); |
| 145 | // ===================== Hosted applications section ==================== |
| 146 | |
| 147 | export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 148 | |
| 149 | ng1appModule.config([ |
| 150 | '$stateProvider', |
| 151 | '$translateProvider', |
| 152 | '$urlRouterProvider', |
| 153 | '$httpProvider', |
| 154 | 'tooltipsConfigProvider', |
| 155 | 'NotificationProvider', |
| 156 | ($stateProvider:any, |
| 157 | $translateProvider:any, |
| 158 | $urlRouterProvider:ng.ui.IUrlRouterProvider, |
| 159 | $httpProvider:ng.IHttpProvider, |
| 160 | tooltipsConfigProvider:any, |
| 161 | NotificationProvider:any):void => { |
| 162 | |
| 163 | NotificationProvider.setOptions({ |
Michael Lando | 39a4e0c | 2017-07-18 20:46:42 +0300 | [diff] [blame] | 164 | delay: 5000, |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 165 | startTop: 10, |
| 166 | startRight: 10, |
| 167 | closeOnClick: true, |
| 168 | verticalSpacing: 20, |
| 169 | horizontalSpacing: 20, |
| 170 | positionX: 'right', |
| 171 | positionY: 'top' |
| 172 | }); |
Michael Lando | 39a4e0c | 2017-07-18 20:46:42 +0300 | [diff] [blame] | 173 | NotificationProvider.options.templateUrl = 'notification-custom-template.html'; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 174 | |
| 175 | $translateProvider.useStaticFilesLoader({ |
| 176 | prefix: pathPrefix + 'assets/languages/', |
| 177 | langKey: '', |
| 178 | suffix: '.json?d=' + (new Date()).getTime() |
| 179 | }); |
| 180 | $translateProvider.useSanitizeValueStrategy('escaped'); |
| 181 | $translateProvider.preferredLanguage('en_US'); |
| 182 | |
| 183 | $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor'); |
| 184 | $httpProvider.interceptors.push('Sdc.Services.HttpErrorInterceptor'); |
| 185 | $urlRouterProvider.otherwise('welcome'); |
| 186 | |
| 187 | $stateProvider.state( |
| 188 | 'dashboard', { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 189 | url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 190 | templateUrl: "./view-models/dashboard/dashboard-view.html", |
| 191 | controller: viewModelsModuleName + '.DashboardViewModel', |
| 192 | } |
| 193 | ); |
| 194 | |
| 195 | $stateProvider.state( |
| 196 | 'welcome', { |
| 197 | url: '/welcome', |
| 198 | templateUrl: "./view-models/welcome/welcome-view.html", |
| 199 | controller: viewModelsModuleName + '.WelcomeViewModel' |
| 200 | } |
| 201 | ); |
| 202 | |
| 203 | let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 204 | if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) { |
| 205 | const breadcrumbsComponents = cacheService.get('breadcrumbsComponents'); |
| 206 | if (breadcrumbsComponents) { |
| 207 | return breadcrumbsComponents; |
| 208 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 209 | } else { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 210 | let breadcrumbsComponentsPromise; |
| 211 | if ($stateParams.previousState === 'dashboard') { |
| 212 | breadcrumbsComponentsPromise = EntityService.getAllComponents(true); |
| 213 | } else if ($stateParams.previousState === 'catalog') { |
| 214 | breadcrumbsComponentsPromise = EntityService.getCatalog(); |
| 215 | } else { |
| 216 | cacheService.remove('breadcrumbsComponentsState'); |
| 217 | cacheService.remove('breadcrumbsComponents'); |
| 218 | return []; |
| 219 | } |
| 220 | breadcrumbsComponentsPromise.then((components) => { |
| 221 | cacheService.set('breadcrumbsComponentsState', $stateParams.previousState); |
| 222 | cacheService.set('breadcrumbsComponents', components); |
| 223 | }); |
| 224 | return breadcrumbsComponentsPromise; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 225 | } |
| 226 | }]; |
| 227 | |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 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); |
| 233 | }]; |
| 234 | |
| 235 | $stateProvider.state( |
| 236 | 'workspace-old', { |
| 237 | url: '/workspace/:id/:type/*workspaceInnerPath', |
| 238 | controller: oldWorkspaceController |
| 239 | } |
| 240 | ); |
| 241 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 242 | $stateProvider.state( |
| 243 | 'workspace', { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 244 | url: '/:previousState/workspace/:id/:type/', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 245 | params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null}, |
| 246 | templateUrl: './view-models/workspace/workspace-view.html', |
| 247 | controller: viewModelsModuleName + '.WorkspaceViewModel', |
| 248 | resolve: { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 249 | injectComponent: ['$stateParams', 'ComponentFactory', 'Sdc.Services.CacheService', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, cacheService:CacheService, ComponentServiceNg2:ComponentServiceNg2) { |
| 250 | |
| 251 | if ($stateParams.id && $stateParams.id.length) { //need to check length in case ID is an empty string |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 252 | return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then( |
| 253 | (component:Component)=> { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 254 | if ($stateParams.componentCsar && component.isResource()){ |
| 255 | if((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) { |
| 256 | cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component)); |
| 257 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 258 | component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component); |
| 259 | } |
| 260 | return component; |
| 261 | }); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 262 | } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) { |
| 263 | return $stateParams.componentCsar; |
| 264 | } else { |
| 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; |
| 269 | } |
| 270 | if ($stateParams.importedFile) { |
| 271 | (<Resource>emptyComponent).importedFile = $stateParams.importedFile; |
| 272 | } |
| 273 | return emptyComponent; |
| 274 | } |
| 275 | }], |
| 276 | components: componentsParam |
| 277 | } |
| 278 | } |
| 279 | ); |
| 280 | |
| 281 | $stateProvider.state( |
| 282 | States.WORKSPACE_GENERAL, { |
| 283 | url: 'general', |
| 284 | parent: 'workspace', |
| 285 | controller: viewModelsModuleName + '.GeneralViewModel', |
| 286 | templateUrl: './view-models/workspace/tabs/general/general-view.html', |
| 287 | data: {unsavedChanges: false, bodyClass: 'general'} |
| 288 | } |
| 289 | ); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 290 | |
| 291 | $stateProvider.state( |
| 292 | States.WORKSPACE_ACTIVITY_LOG, { |
| 293 | url: 'activity_log', |
| 294 | parent: 'workspace', |
| 295 | controller: viewModelsModuleName + '.ActivityLogViewModel', |
| 296 | templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 297 | } |
| 298 | ); |
| 299 | |
| 300 | $stateProvider.state( |
| 301 | States.WORKSPACE_DEPLOYMENT_ARTIFACTS, { |
| 302 | url: 'deployment_artifacts', |
| 303 | parent: 'workspace', |
| 304 | controller: viewModelsModuleName + '.DeploymentArtifactsViewModel', |
| 305 | templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html', |
| 306 | data: { |
| 307 | bodyClass: 'deployment_artifacts' |
| 308 | } |
| 309 | } |
| 310 | ); |
| 311 | |
| 312 | $stateProvider.state( |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 313 | States.WORKSPACE_INFORMATION_ARTIFACTS, { |
| 314 | url: 'information_artifacts', |
| 315 | parent: 'workspace', |
| 316 | controller: viewModelsModuleName + '.InformationArtifactsViewModel', |
| 317 | templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html', |
| 318 | data: { |
| 319 | bodyClass: 'information_artifacts' |
| 320 | } |
| 321 | } |
| 322 | ); |
| 323 | |
| 324 | $stateProvider.state( |
| 325 | States.WORKSPACE_TOSCA_ARTIFACTS, { |
| 326 | url: 'tosca_artifacts', |
| 327 | parent: 'workspace', |
| 328 | controller: viewModelsModuleName + '.ToscaArtifactsViewModel', |
| 329 | templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html', |
| 330 | data: { |
| 331 | bodyClass: 'tosca_artifacts' |
| 332 | } |
| 333 | } |
| 334 | ); |
| 335 | |
| 336 | $stateProvider.state( |
| 337 | States.WORKSPACE_PROPERTIES, { |
| 338 | url: 'properties', |
| 339 | parent: 'workspace', |
| 340 | controller: viewModelsModuleName + '.PropertiesViewModel', |
| 341 | templateUrl: './view-models/workspace/tabs/properties/properties-view.html', |
| 342 | data: { |
| 343 | bodyClass: 'properties' |
| 344 | } |
| 345 | } |
| 346 | ); |
| 347 | |
| 348 | $stateProvider.state( |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 349 | States.WORKSPACE_PROPERTIES_ASSIGNMENT, { |
| 350 | url: 'properties_assignment', |
| 351 | params: {'component': null}, |
| 352 | template: '<properties-assignment></properties-assignment>', |
| 353 | parent: 'workspace', |
| 354 | resolve: { |
| 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; |
| 359 | }], |
| 360 | }, |
| 361 | data: { |
| 362 | bodyClass: 'properties-assignment' |
| 363 | } |
| 364 | } |
| 365 | ); |
| 366 | |
| 367 | $stateProvider.state( |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 368 | States.WORKSPACE_ATTRIBUTES, { |
| 369 | url: 'attributes', |
| 370 | parent: 'workspace', |
| 371 | controller: viewModelsModuleName + '.AttributesViewModel', |
| 372 | templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html', |
| 373 | data: { |
| 374 | bodyClass: 'attributes' |
| 375 | } |
| 376 | } |
| 377 | ); |
| 378 | |
| 379 | $stateProvider.state( |
| 380 | States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, { |
| 381 | url: 'req_and_capabilities', |
| 382 | parent: 'workspace', |
| 383 | controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel', |
| 384 | templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html', |
| 385 | data: { |
| 386 | bodyClass: 'attributes' |
| 387 | } |
| 388 | } |
| 389 | ); |
| 390 | |
miriame | 41ee9cb | 2019-03-04 13:49:15 +0200 | [diff] [blame] | 391 | $stateProvider.state( |
| 392 | States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES_EDITABLE, { |
| 393 | url: 'req_and_capabilities_editable', |
| 394 | parent: 'workspace', |
| 395 | controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel', |
| 396 | templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-editable-view.html', |
| 397 | data: { |
| 398 | bodyClass: 'attributes' |
| 399 | } |
| 400 | } |
| 401 | ); |
| 402 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 403 | |
| 404 | $stateProvider.state( |
| 405 | States.WORKSPACE_MANAGEMENT_WORKFLOW, { |
| 406 | parent: 'workspace', |
| 407 | url: 'management_workflow', |
| 408 | templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html', |
| 409 | controller: viewModelsModuleName + '.ManagementWorkflowViewModel' |
| 410 | } |
| 411 | ); |
| 412 | |
| 413 | $stateProvider.state( |
| 414 | States.WORKSPACE_NETWORK_CALL_FLOW, { |
| 415 | parent: 'workspace', |
| 416 | url: 'network_call_flow', |
| 417 | templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html', |
| 418 | controller: viewModelsModuleName + '.NetworkCallFlowViewModel' |
| 419 | } |
| 420 | ); |
| 421 | |
| 422 | $stateProvider.state( |
| 423 | States.WORKSPACE_DISTRIBUTION, { |
| 424 | parent: 'workspace', |
| 425 | url: 'distribution', |
| 426 | templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html', |
| 427 | controller: viewModelsModuleName + '.DistributionViewModel' |
| 428 | } |
| 429 | ); |
| 430 | |
| 431 | $stateProvider.state( |
| 432 | States.WORKSPACE_COMPOSITION, { |
| 433 | url: 'composition/', |
| 434 | parent: 'workspace', |
| 435 | controller: viewModelsModuleName + '.CompositionViewModel', |
| 436 | templateUrl: './view-models/workspace/tabs/composition/composition-view.html', |
| 437 | data: { |
| 438 | bodyClass: 'composition' |
| 439 | } |
| 440 | } |
| 441 | ); |
| 442 | |
| 443 | // $stateProvider.state( |
| 444 | // States.WORKSPACE_NG2, { |
| 445 | // url: 'ng2/', |
| 446 | // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example', |
| 447 | // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html' |
| 448 | // } |
| 449 | // ); |
| 450 | |
| 451 | $stateProvider.state( |
| 452 | States.WORKSPACE_DEPLOYMENT, { |
| 453 | url: 'deployment/', |
| 454 | parent: 'workspace', |
| 455 | templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html', |
| 456 | controller: viewModelsModuleName + '.DeploymentViewModel', |
| 457 | data: { |
| 458 | bodyClass: 'composition' |
| 459 | } |
| 460 | } |
| 461 | ); |
| 462 | |
| 463 | $stateProvider.state( |
| 464 | 'workspace.composition.details', { |
| 465 | url: 'details', |
| 466 | parent: 'workspace.composition', |
| 467 | templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html', |
| 468 | controller: viewModelsModuleName + '.DetailsViewModel' |
| 469 | } |
| 470 | ); |
| 471 | |
| 472 | $stateProvider.state( |
| 473 | 'workspace.composition.properties', { |
| 474 | url: 'properties', |
| 475 | parent: 'workspace.composition', |
| 476 | templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html', |
| 477 | controller: viewModelsModuleName + '.ResourcePropertiesViewModel' |
| 478 | } |
| 479 | ); |
| 480 | |
| 481 | $stateProvider.state( |
| 482 | 'workspace.composition.artifacts', { |
| 483 | url: 'artifacts', |
| 484 | parent: 'workspace.composition', |
| 485 | templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html', |
| 486 | controller: viewModelsModuleName + '.ResourceArtifactsViewModel' |
| 487 | } |
| 488 | ); |
| 489 | |
| 490 | $stateProvider.state( |
| 491 | 'workspace.composition.relations', { |
| 492 | url: 'relations', |
| 493 | parent: 'workspace.composition', |
| 494 | templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html', |
| 495 | controller: viewModelsModuleName + '.RelationsViewModel' |
| 496 | } |
| 497 | ); |
| 498 | |
| 499 | $stateProvider.state( |
| 500 | 'workspace.composition.structure', { |
| 501 | url: 'structure', |
| 502 | parent: 'workspace.composition', |
| 503 | templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html', |
| 504 | controller: viewModelsModuleName + '.StructureViewModel' |
| 505 | } |
| 506 | ); |
| 507 | $stateProvider.state( |
| 508 | 'workspace.composition.lifecycle', { |
| 509 | url: 'lifecycle', |
| 510 | parent: 'workspace.composition', |
| 511 | templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html', |
| 512 | controller: viewModelsModuleName + '.ResourceArtifactsViewModel' |
| 513 | } |
| 514 | ); |
| 515 | |
| 516 | $stateProvider.state( |
| 517 | 'workspace.composition.api', { |
| 518 | url: 'api', |
| 519 | parent: 'workspace.composition', |
| 520 | templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html', |
| 521 | controller: viewModelsModuleName + '.ResourceArtifactsViewModel' |
| 522 | } |
| 523 | ); |
| 524 | $stateProvider.state( |
| 525 | 'workspace.composition.deployment', { |
| 526 | url: 'deployment', |
| 527 | parent: 'workspace.composition', |
| 528 | templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html', |
| 529 | controller: viewModelsModuleName + '.ResourceArtifactsViewModel' |
| 530 | } |
| 531 | ); |
miriame | c2ce914 | 2019-02-13 15:17:26 +0200 | [diff] [blame] | 532 | $stateProvider.state( |
ojasdubey | 4192e3c | 2019-03-18 14:15:03 +0530 | [diff] [blame] | 533 | 'workspace.composition.consumption', { |
| 534 | url: 'consumption', |
| 535 | parent: 'workspace.composition', |
| 536 | templateUrl: './view-models/workspace/tabs/composition/tabs/service-consumption/service-consumption-view.html', |
| 537 | controller: viewModelsModuleName + '.ServiceConsumptionViewModel' |
| 538 | } |
| 539 | ); |
| 540 | $stateProvider.state( |
miriame | c2ce914 | 2019-02-13 15:17:26 +0200 | [diff] [blame] | 541 | 'workspace.composition.dependencies', { |
| 542 | url: 'dependencies', |
| 543 | parent: 'workspace.composition', |
| 544 | templateUrl: './view-models/workspace/tabs/composition/tabs/service-dependencies/service-dependencies-view.html', |
| 545 | controller: viewModelsModuleName + '.ServiceDependenciesViewModel' |
| 546 | } |
| 547 | ); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 548 | |
| 549 | $stateProvider.state( |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 550 | States.WORKSPACE_INTERFACE_OPERATION, { |
| 551 | url: 'interface_operation', |
| 552 | parent: 'workspace', |
| 553 | controller: viewModelsModuleName + '.InterfaceOperationViewModel', |
| 554 | templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html', |
| 555 | data: { |
| 556 | bodyClass: 'interface_operation' |
| 557 | } |
| 558 | } |
| 559 | ); |
| 560 | |
| 561 | $stateProvider.state( |
Idan Amit | eedaaf9 | 2018-01-31 13:27:33 +0200 | [diff] [blame] | 562 | 'workspace.plugins', { |
| 563 | url: 'plugins/*path', |
Idan Amit | cb1095e | 2018-01-22 20:55:42 +0200 | [diff] [blame] | 564 | parent: 'workspace', |
Arielk | 802bd2a | 2018-04-16 15:37:39 +0300 | [diff] [blame] | 565 | params: {'queryParams': null}, |
Idan Amit | eedaaf9 | 2018-01-31 13:27:33 +0200 | [diff] [blame] | 566 | templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html', |
| 567 | controller: viewModelsModuleName + '.PluginsContextViewModel' |
Idan Amit | cb1095e | 2018-01-22 20:55:42 +0200 | [diff] [blame] | 568 | } |
| 569 | ); |
| 570 | |
| 571 | $stateProvider.state( |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 572 | 'adminDashboard', { |
| 573 | url: '/adminDashboard', |
| 574 | templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html', |
| 575 | controller: viewModelsModuleName + '.AdminDashboardViewModel', |
| 576 | permissions: ['ADMIN'] |
| 577 | } |
| 578 | ); |
| 579 | |
| 580 | $stateProvider.state( |
| 581 | 'onboardVendor', { |
| 582 | url: '/onboardVendor', |
| 583 | templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html', |
| 584 | controller: viewModelsModuleName + '.OnboardVendorViewModel'//, |
| 585 | } |
| 586 | ); |
| 587 | |
Idan Amit | 5197c8b | 2018-01-15 14:31:42 +0200 | [diff] [blame] | 588 | $stateProvider.state( |
Idan Amit | eedaaf9 | 2018-01-31 13:27:33 +0200 | [diff] [blame] | 589 | 'plugins', { |
| 590 | url: '/plugins/*path', |
| 591 | templateUrl: './view-models/plugins/plugins-tab-view.html', |
| 592 | controller: viewModelsModuleName + '.PluginsTabViewModel' |
Idan Amit | 5197c8b | 2018-01-15 14:31:42 +0200 | [diff] [blame] | 593 | } |
| 594 | ); |
| 595 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 596 | // Build the states for all hosted apps dynamically |
| 597 | _.each(hostedApplications, (hostedApp)=> { |
| 598 | if (hostedApp.exists) { |
| 599 | $stateProvider.state( |
| 600 | hostedApp.state.name, { |
| 601 | url: hostedApp.state.url, |
| 602 | templateUrl: './view-models/dcae-app/dcae-app-view.html', |
| 603 | controller: viewModelsModuleName + hostedApp.state.controllerName |
| 604 | } |
| 605 | ); |
| 606 | } |
| 607 | }); |
| 608 | |
| 609 | $stateProvider.state( |
| 610 | 'catalog', { |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 611 | url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 612 | templateUrl: './view-models/catalog/catalog-view.html', |
| 613 | controller: viewModelsModuleName + '.CatalogViewModel', |
| 614 | resolve: { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 615 | auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => { |
| 616 | let userInfo:IUserProperties = userService.getLoggedinUser(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 617 | if (userInfo) { |
| 618 | return $q.when(userInfo); |
| 619 | } else { |
| 620 | return $q.reject({authenticated: false}); |
| 621 | } |
| 622 | }] |
| 623 | } |
| 624 | } |
| 625 | ); |
| 626 | |
| 627 | $stateProvider.state( |
| 628 | 'support', { |
| 629 | url: '/support', |
| 630 | templateUrl: './view-models/support/support-view.html', |
| 631 | controller: viewModelsModuleName + '.SupportViewModel' |
| 632 | } |
| 633 | ); |
| 634 | |
| 635 | $stateProvider.state( |
| 636 | 'error-403', { |
| 637 | url: '/error-403', |
| 638 | templateUrl: "./view-models/modals/error-modal/error-403-view.html", |
| 639 | controller: viewModelsModuleName + '.ErrorViewModel' |
| 640 | } |
| 641 | ); |
| 642 | |
| 643 | tooltipsConfigProvider.options({ |
| 644 | side: 'bottom', |
| 645 | delay: '600', |
| 646 | class: 'tooltip-custom', |
| 647 | lazy: 0, |
| 648 | try: 0 |
| 649 | }); |
| 650 | |
| 651 | } |
| 652 | ]); |
| 653 | |
| 654 | ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/); |
| 655 | ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone. |
| 656 | ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977 |
| 657 | ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/); |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 658 | ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/); |
Tal Gitelman | 153a358 | 2017-07-03 20:16:55 +0300 | [diff] [blame] | 659 | ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/); |
| 660 | ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/); |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 661 | ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 662 | ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/); |
| 663 | ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/); |
| 664 | ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/); |
| 665 | ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/); |
| 666 | 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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/); |
| 667 | ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/); |
| 668 | ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/); |
| 669 | ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/); |
| 670 | ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/); |
| 671 | ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/); |
| 672 | ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/); |
| 673 | ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/); |
| 674 | ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/); |
| 675 | |
| 676 | ng1appModule.constant('sdcConfig', sdcConfig); |
| 677 | ng1appModule.constant('sdcMenu', sdcMenu); |
| 678 | |
| 679 | ng1appModule.run([ |
| 680 | '$http', |
| 681 | 'Sdc.Services.CacheService', |
| 682 | 'Sdc.Services.CookieService', |
| 683 | 'Sdc.Services.ConfigurationUiService', |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 684 | 'UserServiceNg2', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 685 | 'Sdc.Services.CategoryResourceService', |
| 686 | 'Sdc.Services.SdcVersionService', |
| 687 | '$state', |
| 688 | '$rootScope', |
| 689 | '$location', |
| 690 | 'sdcMenu', |
| 691 | 'ModalsHandler', |
| 692 | 'Sdc.Services.EcompHeaderService', |
| 693 | 'LeftPaletteLoaderService', |
| 694 | 'Sdc.Services.DataTypesService', |
| 695 | 'AngularJSBridge', |
Michael Lando | 39a4e0c | 2017-07-18 20:46:42 +0300 | [diff] [blame] | 696 | '$templateCache', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 697 | ($http:ng.IHttpService, |
| 698 | cacheService:CacheService, |
| 699 | cookieService:CookieService, |
| 700 | ConfigurationUi:ConfigurationUiService, |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 701 | userService:UserService, |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 702 | categoryResourceService:ICategoryResourceClass, |
| 703 | sdcVersionService:SdcVersionService, |
| 704 | $state:ng.ui.IStateService, |
| 705 | $rootScope:ng.IRootScopeService, |
| 706 | $location:ng.ILocationService, |
| 707 | sdcMenu:IAppMenu, |
| 708 | ModalsHandler:ModalsHandler, |
| 709 | ecompHeaderService:EcompHeaderService, |
| 710 | LeftPaletteLoaderService:LeftPaletteLoaderService, |
| 711 | DataTypesService:DataTypesService, |
Michael Lando | 39a4e0c | 2017-07-18 20:46:42 +0300 | [diff] [blame] | 712 | AngularJSBridge, |
| 713 | $templateCache:ng.ITemplateCacheService):void => { |
| 714 | $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html')); |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 715 | $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html')); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 716 | //handle cache data - version |
| 717 | let initAsdcVersion:Function = ():void => { |
| 718 | |
| 719 | let onFailed = (response) => { |
| 720 | console.info('onFailed initAsdcVersion', response); |
| 721 | cacheService.set('version', 'N/A'); |
| 722 | }; |
| 723 | |
| 724 | let onSuccess = (version:any) => { |
| 725 | let tmpVerArray = version.version.split("."); |
| 726 | let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2]; |
| 727 | cacheService.set('version', ver); |
| 728 | }; |
| 729 | |
| 730 | sdcVersionService.getVersion().then(onSuccess, onFailed); |
| 731 | |
| 732 | }; |
| 733 | |
| 734 | let initEcompMenu:Function = (user):void => { |
| 735 | ecompHeaderService.getMenuItems(user.userId).then((data)=> { |
| 736 | $rootScope['menuItems'] = data; |
| 737 | }); |
| 738 | }; |
| 739 | |
| 740 | let initConfigurationUi:Function = ():void => { |
| 741 | ConfigurationUi |
| 742 | .getConfigurationUi() |
| 743 | .then((configurationUi:any) => { |
| 744 | cacheService.set('UIConfiguration', configurationUi); |
| 745 | }); |
| 746 | }; |
| 747 | |
| 748 | let initCategories:Function = ():void => { |
| 749 | let onError = ():void => { |
| 750 | console.log('Failed to init categories'); |
| 751 | }; |
| 752 | |
| 753 | categoryResourceService.getAllCategories((categories: Categories):void => { |
| 754 | cacheService.set('serviceCategories', categories.serviceCategories); |
| 755 | cacheService.set('resourceCategories', categories.resourceCategories); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 756 | }, onError); |
| 757 | }; |
| 758 | |
| 759 | // Add hosted applications to sdcConfig |
| 760 | sdcConfig.hostedApplications = hostedApplications; |
| 761 | |
| 762 | //handle http config |
| 763 | $http.defaults.withCredentials = true; |
| 764 | $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w'; |
| 765 | $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId(); |
| 766 | |
| 767 | initAsdcVersion(); |
| 768 | initConfigurationUi(); |
| 769 | // initLeftPalette(); |
| 770 | DataTypesService.initDataTypes(); |
| 771 | |
| 772 | //handle stateChangeStart |
| 773 | let internalDeregisterStateChangeStartWatcher:Function = ():void => { |
| 774 | if (deregisterStateChangeStartWatcher) { |
| 775 | deregisterStateChangeStartWatcher(); |
| 776 | deregisterStateChangeStartWatcher = null; |
| 777 | } |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 778 | if (deregisterStateChangeSuccessWatcher) { |
| 779 | deregisterStateChangeSuccessWatcher(); |
| 780 | deregisterStateChangeSuccessWatcher = null; |
| 781 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 782 | }; |
| 783 | |
| 784 | let removeLoader:Function = ():void => { |
| 785 | $(".sdc-loading-page .main-loader").addClass("animated fadeOut"); |
| 786 | $(".sdc-loading-page .caption1").addClass("animated fadeOut"); |
| 787 | $(".sdc-loading-page .caption2").addClass("animated fadeOut"); |
| 788 | window.setTimeout(():void=> { |
| 789 | $(".sdc-loading-page .main-loader").css("display", "none"); |
| 790 | $(".sdc-loading-page .caption1").css("display", "none"); |
| 791 | $(".sdc-loading-page .caption2").css("display", "none"); |
| 792 | $(".sdc-loading-page").addClass("animated fadeOut"); |
| 793 | }, 1000); |
| 794 | }; |
| 795 | |
| 796 | let onNavigateOut:Function = (toState, toParams):void => { |
| 797 | let onOk = ():void => { |
| 798 | $state.current.data.unsavedChanges = false; |
| 799 | $state.go(toState.name, toParams); |
| 800 | }; |
| 801 | |
| 802 | let data = sdcMenu.alertMessages.exitWithoutSaving; |
| 803 | //open notify to user if changes are not saved |
| 804 | ModalsHandler.openAlertModal(data.title, data.message).then(onOk); |
| 805 | }; |
| 806 | |
| 807 | let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => { |
| 808 | console.info((new Date()).getTime()); |
| 809 | console.info('$stateChangeStart', toState.name); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 810 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 811 | if (toState.name !== 'error-403' && !userService.getLoggedinUser()) { |
Idan Amit | 5887a42 | 2018-05-16 14:32:01 +0300 | [diff] [blame] | 812 | if (toState.name !== 'welcome') { |
| 813 | event.preventDefault(); |
| 814 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 815 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 816 | userService.authorize().subscribe((userInfo:IUserProperties) => { |
| 817 | if (!doesUserHasAccess(toState, userInfo)) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 818 | $state.go('error-403'); |
| 819 | console.info('User has no permissions'); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 820 | return; |
| 821 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 822 | userService.setLoggedinUser(userInfo); |
| 823 | cacheService.set('user', userInfo); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 824 | initCategories(); |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 825 | // initEcompMenu(userInfo); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 826 | setTimeout(function () { |
| 827 | |
| 828 | removeLoader(); |
| 829 | |
| 830 | // initCategories(); |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 831 | if (userService.getLoggedinUser().role === 'ADMIN') { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 832 | // toState.name = "adminDashboard"; |
| 833 | $state.go("adminDashboard", toParams); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 834 | return; |
| 835 | } |
| 836 | |
| 837 | // After user authorized init categories |
| 838 | window.setTimeout(():void=> { |
| 839 | if ($state.current.name === '') { |
| 840 | $state.go(toState.name, toParams); |
| 841 | } |
| 842 | |
| 843 | console.log("------$state.current.name=" + $state.current.name); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 844 | |
| 845 | }, 1000); |
| 846 | |
| 847 | }, 0); |
| 848 | |
| 849 | }, () => { |
| 850 | $state.go('error-403'); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 851 | }); |
| 852 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 853 | else if (userService.getLoggedinUser()) { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 854 | if (!doesUserHasAccess(toState, userService.getLoggedinUser())) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 855 | event.preventDefault(); |
| 856 | $state.go('error-403'); |
| 857 | console.info('User has no permissions'); |
| 858 | } |
| 859 | if (toState.name === "welcome") { |
| 860 | $state.go("dashboard"); |
| 861 | } |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 862 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 863 | //if form is dirty and not save - notify to user |
| 864 | if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) { |
| 865 | event.preventDefault(); |
| 866 | onNavigateOut(toState, toParams); |
| 867 | } |
| 868 | } |
| 869 | |
Idan Amit | 5887a42 | 2018-05-16 14:32:01 +0300 | [diff] [blame] | 870 | // if enetering workspace, set the previousState param |
| 871 | if (toState.name.indexOf('workspace') !== -1) { |
| 872 | if (!toParams.previousState) { |
| 873 | const tmpPreviousState1 = fromParams && fromParams.previousState; |
| 874 | const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog'; |
| 875 | toParams.previousState = tmpPreviousState1 || tmpPreviousState2; |
| 876 | } |
| 877 | } |
| 878 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 879 | }; |
| 880 | |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 881 | let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => { |
| 882 | console.info('$stateChangeSuccess', toState.name); |
| 883 | |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 884 | // Workaround in case we are entering other state then workspace (user move to catalog) |
| 885 | // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update. |
| 886 | if (toState.name.indexOf('workspace') === -1) { |
| 887 | if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) { |
| 888 | cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG); |
| 889 | } |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 890 | if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)){ |
| 891 | cacheService.remove(PREVIOUS_CSAR_COMPONENT); |
| 892 | } |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | //set body class |
| 896 | $rootScope['bodyClass'] = 'default-class'; |
| 897 | if (toState.data && toState.data.bodyClass) { |
| 898 | $rootScope['bodyClass'] = toState.data.bodyClass; |
| 899 | } |
| 900 | }; |
| 901 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 902 | let doesUserHasAccess:Function = (toState, user):boolean => { |
| 903 | |
| 904 | let isUserHasAccess = true; |
| 905 | if (toState.permissions && toState.permissions.length > 0) { |
| 906 | isUserHasAccess = _.includes(toState.permissions, user.role); |
| 907 | } |
| 908 | return isUserHasAccess; |
| 909 | }; |
| 910 | let deregisterStateChangeStartWatcher:Function; |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 911 | let deregisterStateChangeSuccessWatcher:Function; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 912 | |
| 913 | let registerStateChangeStartWatcher:Function = ():void => { |
| 914 | internalDeregisterStateChangeStartWatcher(); |
| 915 | console.info('registerStateChangeStartWatcher $stateChangeStart'); |
| 916 | deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => { |
| 917 | onStateChangeStart(event, toState, toParams, fromState, fromParams); |
| 918 | }); |
Idan Amit | 8e9598c | 2018-05-14 16:21:48 +0300 | [diff] [blame] | 919 | deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams):void => { |
| 920 | onStateChangeSuccess(event, toState, toParams, fromState, fromParams); |
| 921 | }); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 922 | }; |
| 923 | |
| 924 | registerStateChangeStartWatcher(); |
| 925 | }]); |
| 926 | |