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