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( |
Idan Amit | eedaaf9 | 2018-01-31 13:27:33 +0200 | [diff] [blame] | 511 | 'workspace.plugins', { |
| 512 | url: 'plugins/*path', |
Idan Amit | cb1095e | 2018-01-22 20:55:42 +0200 | [diff] [blame] | 513 | parent: 'workspace', |
Idan Amit | eedaaf9 | 2018-01-31 13:27:33 +0200 | [diff] [blame] | 514 | templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html', |
| 515 | controller: viewModelsModuleName + '.PluginsContextViewModel' |
Idan Amit | cb1095e | 2018-01-22 20:55:42 +0200 | [diff] [blame] | 516 | } |
| 517 | ); |
| 518 | |
| 519 | $stateProvider.state( |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 520 | 'adminDashboard', { |
| 521 | url: '/adminDashboard', |
| 522 | templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html', |
| 523 | controller: viewModelsModuleName + '.AdminDashboardViewModel', |
| 524 | permissions: ['ADMIN'] |
| 525 | } |
| 526 | ); |
| 527 | |
| 528 | $stateProvider.state( |
| 529 | 'onboardVendor', { |
| 530 | url: '/onboardVendor', |
| 531 | templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html', |
| 532 | controller: viewModelsModuleName + '.OnboardVendorViewModel'//, |
| 533 | } |
| 534 | ); |
| 535 | |
Idan Amit | 5197c8b | 2018-01-15 14:31:42 +0200 | [diff] [blame] | 536 | $stateProvider.state( |
Idan Amit | eedaaf9 | 2018-01-31 13:27:33 +0200 | [diff] [blame] | 537 | 'plugins', { |
| 538 | url: '/plugins/*path', |
| 539 | templateUrl: './view-models/plugins/plugins-tab-view.html', |
| 540 | controller: viewModelsModuleName + '.PluginsTabViewModel' |
Idan Amit | 5197c8b | 2018-01-15 14:31:42 +0200 | [diff] [blame] | 541 | } |
| 542 | ); |
| 543 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 544 | // Build the states for all hosted apps dynamically |
| 545 | _.each(hostedApplications, (hostedApp)=> { |
| 546 | if (hostedApp.exists) { |
| 547 | $stateProvider.state( |
| 548 | hostedApp.state.name, { |
| 549 | url: hostedApp.state.url, |
| 550 | templateUrl: './view-models/dcae-app/dcae-app-view.html', |
| 551 | controller: viewModelsModuleName + hostedApp.state.controllerName |
| 552 | } |
| 553 | ); |
| 554 | } |
| 555 | }); |
| 556 | |
| 557 | $stateProvider.state( |
| 558 | 'catalog', { |
| 559 | url: '/catalog', |
| 560 | templateUrl: './view-models/catalog/catalog-view.html', |
| 561 | controller: viewModelsModuleName + '.CatalogViewModel', |
| 562 | resolve: { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 563 | auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => { |
| 564 | let userInfo:IUserProperties = userService.getLoggedinUser(); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 565 | if (userInfo) { |
| 566 | return $q.when(userInfo); |
| 567 | } else { |
| 568 | return $q.reject({authenticated: false}); |
| 569 | } |
| 570 | }] |
| 571 | } |
| 572 | } |
| 573 | ); |
| 574 | |
| 575 | $stateProvider.state( |
| 576 | 'support', { |
| 577 | url: '/support', |
| 578 | templateUrl: './view-models/support/support-view.html', |
| 579 | controller: viewModelsModuleName + '.SupportViewModel' |
| 580 | } |
| 581 | ); |
| 582 | |
| 583 | $stateProvider.state( |
| 584 | 'error-403', { |
| 585 | url: '/error-403', |
| 586 | templateUrl: "./view-models/modals/error-modal/error-403-view.html", |
| 587 | controller: viewModelsModuleName + '.ErrorViewModel' |
| 588 | } |
| 589 | ); |
| 590 | |
| 591 | tooltipsConfigProvider.options({ |
| 592 | side: 'bottom', |
| 593 | delay: '600', |
| 594 | class: 'tooltip-custom', |
| 595 | lazy: 0, |
| 596 | try: 0 |
| 597 | }); |
| 598 | |
| 599 | } |
| 600 | ]); |
| 601 | |
| 602 | ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/); |
| 603 | ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone. |
| 604 | ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977 |
| 605 | ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/); |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 606 | 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] | 607 | ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/); |
| 608 | ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 609 | ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/); |
| 610 | ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/); |
| 611 | ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/); |
| 612 | ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/); |
| 613 | ng1appModule.value('UrlValidationPattern', /^(https?|ftp):\/\/(((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([A-Za-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([A-Za-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/); |
| 614 | ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/); |
| 615 | ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/); |
| 616 | ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/); |
| 617 | ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/); |
| 618 | ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/); |
| 619 | ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/); |
| 620 | ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/); |
| 621 | ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/); |
| 622 | |
| 623 | ng1appModule.constant('sdcConfig', sdcConfig); |
| 624 | ng1appModule.constant('sdcMenu', sdcMenu); |
| 625 | |
| 626 | ng1appModule.run([ |
| 627 | '$http', |
| 628 | 'Sdc.Services.CacheService', |
| 629 | 'Sdc.Services.CookieService', |
| 630 | 'Sdc.Services.ConfigurationUiService', |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 631 | 'UserServiceNg2', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 632 | 'Sdc.Services.CategoryResourceService', |
| 633 | 'Sdc.Services.SdcVersionService', |
| 634 | '$state', |
| 635 | '$rootScope', |
| 636 | '$location', |
| 637 | 'sdcMenu', |
| 638 | 'ModalsHandler', |
| 639 | 'Sdc.Services.EcompHeaderService', |
| 640 | 'LeftPaletteLoaderService', |
| 641 | 'Sdc.Services.DataTypesService', |
| 642 | 'AngularJSBridge', |
Michael Lando | 39a4e0c | 2017-07-18 20:46:42 +0300 | [diff] [blame] | 643 | '$templateCache', |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 644 | ($http:ng.IHttpService, |
| 645 | cacheService:CacheService, |
| 646 | cookieService:CookieService, |
| 647 | ConfigurationUi:ConfigurationUiService, |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 648 | userService:UserService, |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 649 | categoryResourceService:ICategoryResourceClass, |
| 650 | sdcVersionService:SdcVersionService, |
| 651 | $state:ng.ui.IStateService, |
| 652 | $rootScope:ng.IRootScopeService, |
| 653 | $location:ng.ILocationService, |
| 654 | sdcMenu:IAppMenu, |
| 655 | ModalsHandler:ModalsHandler, |
| 656 | ecompHeaderService:EcompHeaderService, |
| 657 | LeftPaletteLoaderService:LeftPaletteLoaderService, |
| 658 | DataTypesService:DataTypesService, |
Michael Lando | 39a4e0c | 2017-07-18 20:46:42 +0300 | [diff] [blame] | 659 | AngularJSBridge, |
| 660 | $templateCache:ng.ITemplateCacheService):void => { |
| 661 | $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] | 662 | //handle cache data - version |
| 663 | let initAsdcVersion:Function = ():void => { |
| 664 | |
| 665 | let onFailed = (response) => { |
| 666 | console.info('onFailed initAsdcVersion', response); |
| 667 | cacheService.set('version', 'N/A'); |
| 668 | }; |
| 669 | |
| 670 | let onSuccess = (version:any) => { |
| 671 | let tmpVerArray = version.version.split("."); |
| 672 | let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2]; |
| 673 | cacheService.set('version', ver); |
| 674 | }; |
| 675 | |
| 676 | sdcVersionService.getVersion().then(onSuccess, onFailed); |
| 677 | |
| 678 | }; |
| 679 | |
| 680 | let initEcompMenu:Function = (user):void => { |
| 681 | ecompHeaderService.getMenuItems(user.userId).then((data)=> { |
| 682 | $rootScope['menuItems'] = data; |
| 683 | }); |
| 684 | }; |
| 685 | |
| 686 | let initConfigurationUi:Function = ():void => { |
| 687 | ConfigurationUi |
| 688 | .getConfigurationUi() |
| 689 | .then((configurationUi:any) => { |
| 690 | cacheService.set('UIConfiguration', configurationUi); |
| 691 | }); |
| 692 | }; |
| 693 | |
| 694 | let initCategories:Function = ():void => { |
| 695 | let onError = ():void => { |
| 696 | console.log('Failed to init categories'); |
| 697 | }; |
| 698 | |
| 699 | categoryResourceService.getAllCategories((categories: Categories):void => { |
| 700 | cacheService.set('serviceCategories', categories.serviceCategories); |
| 701 | cacheService.set('resourceCategories', categories.resourceCategories); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 702 | }, onError); |
| 703 | }; |
| 704 | |
| 705 | // Add hosted applications to sdcConfig |
| 706 | sdcConfig.hostedApplications = hostedApplications; |
| 707 | |
| 708 | //handle http config |
| 709 | $http.defaults.withCredentials = true; |
| 710 | $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w'; |
| 711 | $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId(); |
| 712 | |
| 713 | initAsdcVersion(); |
| 714 | initConfigurationUi(); |
| 715 | // initLeftPalette(); |
| 716 | DataTypesService.initDataTypes(); |
| 717 | |
| 718 | //handle stateChangeStart |
| 719 | let internalDeregisterStateChangeStartWatcher:Function = ():void => { |
| 720 | if (deregisterStateChangeStartWatcher) { |
| 721 | deregisterStateChangeStartWatcher(); |
| 722 | deregisterStateChangeStartWatcher = null; |
| 723 | } |
| 724 | }; |
| 725 | |
| 726 | let removeLoader:Function = ():void => { |
| 727 | $(".sdc-loading-page .main-loader").addClass("animated fadeOut"); |
| 728 | $(".sdc-loading-page .caption1").addClass("animated fadeOut"); |
| 729 | $(".sdc-loading-page .caption2").addClass("animated fadeOut"); |
| 730 | window.setTimeout(():void=> { |
| 731 | $(".sdc-loading-page .main-loader").css("display", "none"); |
| 732 | $(".sdc-loading-page .caption1").css("display", "none"); |
| 733 | $(".sdc-loading-page .caption2").css("display", "none"); |
| 734 | $(".sdc-loading-page").addClass("animated fadeOut"); |
| 735 | }, 1000); |
| 736 | }; |
| 737 | |
| 738 | let onNavigateOut:Function = (toState, toParams):void => { |
| 739 | let onOk = ():void => { |
| 740 | $state.current.data.unsavedChanges = false; |
| 741 | $state.go(toState.name, toParams); |
| 742 | }; |
| 743 | |
| 744 | let data = sdcMenu.alertMessages.exitWithoutSaving; |
| 745 | //open notify to user if changes are not saved |
| 746 | ModalsHandler.openAlertModal(data.title, data.message).then(onOk); |
| 747 | }; |
| 748 | |
| 749 | let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => { |
| 750 | console.info((new Date()).getTime()); |
| 751 | console.info('$stateChangeStart', toState.name); |
| 752 | //set body class |
| 753 | $rootScope['bodyClass'] = 'default-class'; |
| 754 | if (toState.data && toState.data.bodyClass) { |
| 755 | $rootScope['bodyClass'] = toState.data.bodyClass; |
| 756 | } |
| 757 | |
| 758 | // Workaround in case we are entering other state then workspace (user move to catalog) |
| 759 | // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update. |
| 760 | if (toState.name.indexOf('workspace') === -1) { |
| 761 | if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) { |
| 762 | cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | //saving last state to params , for breadcrumbs |
| 767 | if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) { |
| 768 | toParams.previousState = fromState.name; |
| 769 | } else { |
| 770 | toParams.previousState = fromParams.previousState; |
| 771 | } |
| 772 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 773 | if (toState.name !== 'error-403' && !userService.getLoggedinUser()) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 774 | internalDeregisterStateChangeStartWatcher(); |
| 775 | event.preventDefault(); |
| 776 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 777 | userService.authorize().subscribe((userInfo:IUserProperties) => { |
| 778 | if (!doesUserHasAccess(toState, userInfo)) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 779 | $state.go('error-403'); |
| 780 | console.info('User has no permissions'); |
| 781 | registerStateChangeStartWatcher(); |
| 782 | return; |
| 783 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 784 | userService.setLoggedinUser(userInfo); |
| 785 | cacheService.set('user', userInfo); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 786 | initCategories(); |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 787 | // initEcompMenu(userInfo); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 788 | setTimeout(function () { |
| 789 | |
| 790 | removeLoader(); |
| 791 | |
| 792 | // initCategories(); |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 793 | if (userService.getLoggedinUser().role === 'ADMIN') { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 794 | // toState.name = "adminDashboard"; |
| 795 | $state.go("adminDashboard", toParams); |
| 796 | registerStateChangeStartWatcher(); |
| 797 | return; |
| 798 | } |
| 799 | |
| 800 | // After user authorized init categories |
| 801 | window.setTimeout(():void=> { |
| 802 | if ($state.current.name === '') { |
| 803 | $state.go(toState.name, toParams); |
| 804 | } |
| 805 | |
| 806 | console.log("------$state.current.name=" + $state.current.name); |
| 807 | console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart'); |
| 808 | registerStateChangeStartWatcher(); |
| 809 | |
| 810 | }, 1000); |
| 811 | |
| 812 | }, 0); |
| 813 | |
| 814 | }, () => { |
| 815 | $state.go('error-403'); |
| 816 | |
| 817 | console.info('registerStateChangeStartWatcher error-403 $stateChangeStart'); |
| 818 | registerStateChangeStartWatcher(); |
| 819 | }); |
| 820 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 821 | else if (userService.getLoggedinUser()) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 822 | internalDeregisterStateChangeStartWatcher(); |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 823 | if (!doesUserHasAccess(toState, userService.getLoggedinUser())) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 824 | event.preventDefault(); |
| 825 | $state.go('error-403'); |
| 826 | console.info('User has no permissions'); |
| 827 | } |
| 828 | if (toState.name === "welcome") { |
| 829 | $state.go("dashboard"); |
| 830 | } |
| 831 | registerStateChangeStartWatcher(); |
| 832 | //if form is dirty and not save - notify to user |
| 833 | if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) { |
| 834 | event.preventDefault(); |
| 835 | onNavigateOut(toState, toParams); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | }; |
| 840 | |
| 841 | let doesUserHasAccess:Function = (toState, user):boolean => { |
| 842 | |
| 843 | let isUserHasAccess = true; |
| 844 | if (toState.permissions && toState.permissions.length > 0) { |
| 845 | isUserHasAccess = _.includes(toState.permissions, user.role); |
| 846 | } |
| 847 | return isUserHasAccess; |
| 848 | }; |
| 849 | let deregisterStateChangeStartWatcher:Function; |
| 850 | |
| 851 | let registerStateChangeStartWatcher:Function = ():void => { |
| 852 | internalDeregisterStateChangeStartWatcher(); |
| 853 | console.info('registerStateChangeStartWatcher $stateChangeStart'); |
| 854 | deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => { |
| 855 | onStateChangeStart(event, toState, toParams, fromState, fromParams); |
| 856 | }); |
| 857 | }; |
| 858 | |
| 859 | registerStateChangeStartWatcher(); |
| 860 | }]); |
| 861 | |