blob: 2f7b78169e1c9b412c9861c314e3d44f58b26906 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
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 Amit7363f3d2018-03-21 12:04:57 +020010 *
Michael Landodd603392017-07-12 00:54:52 +030011 * http://www.apache.org/licenses/LICENSE-2.0
Idan Amit7363f3d2018-03-21 12:04:57 +020012 *
Michael Landodd603392017-07-12 00:54:52 +030013 * 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 Landoed64b5e2017-06-09 03:19:04 +030021'use strict';
22
23//import 'restangular';
24//import 'angular-ui-router';
Michael Landoa5445102018-03-04 14:53:33 +020025import * as _ from "lodash";
Michael Landoed64b5e2017-06-09 03:19:04 +030026import "reflect-metadata";
27import 'ng-infinite-scroll';
28import './modules/filters.ts';
29import './modules/utils.ts';
30import './modules/directive-module.ts';
31import './modules/service-module';
32import './modules/view-model-module.ts';
Michael Lando5b593492018-07-29 16:13:45 +030033import {SdcUiComponentsNg1Module} from 'sdc-ui/lib/angular';
Michael Landoed64b5e2017-06-09 03:19:04 +030034
35import {
Michael Landoed64b5e2017-06-09 03:19:04 +030036 DataTypesService,
37 LeftPaletteLoaderService,
38 EcompHeaderService,
39 CookieService,
40 ConfigurationUiService,
41 CacheService,
Michael Landoed64b5e2017-06-09 03:19:04 +030042 SdcVersionService,
43 ICategoryResourceClass,
44 EntityService
45} from "./services";
Tal Gitelman51d50f02017-12-10 18:55:03 +020046import { UserService } from "./ng2/services/user.service";
Michael Landoed64b5e2017-06-09 03:19:04 +030047import {forwardRef} from '@angular/core';
48import {UpgradeAdapter} from '@angular/upgrade';
Michael Lando5b593492018-07-29 16:13:45 +030049import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States, PREVIOUS_CSAR_COMPONENT} from "./utils";
Michael Landoed64b5e2017-06-09 03:19:04 +030050import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
51import {ComponentFactory} from "./utils/component-factory";
52import {ModalsHandler} from "./utils/modals-handler";
53import {downgradeComponent} from "@angular/upgrade/static";
54
55import {AppModule} from './ng2/app.module';
Michael Landoed64b5e2017-06-09 03:19:04 +030056import {Component} from "./models/components/component";
57import {ComponentServiceNg2} from "./ng2/services/component-services/component.service";
58import {ComponentMetadata} from "./models/component-metadata";
59import {Categories} from "./models/categories";
Tal Gitelman51d50f02017-12-10 18:55:03 +020060import {IUserProperties} from "./models/user";
Michael Landoed64b5e2017-06-09 03:19:04 +030061
Michael Landoed64b5e2017-06-09 03:19:04 +030062let moduleName:string = 'sdcApp';
63let viewModelsModuleName:string = 'Sdc.ViewModels';
64let directivesModuleName:string = 'Sdc.Directives';
65let servicesModuleName:string = 'Sdc.Services';
66let filtersModuleName:string = 'Sdc.Filters';
67let utilsModuleName:string = 'Sdc.Utils';
68
69// Load configuration according to environment.
70declare var __ENV__:string;
71let sdcConfig:IAppConfigurtaion;
72let sdcMenu:IAppMenu;
73let pathPrefix:string = '';
74if (__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}
82sdcMenu = require('./../../configurations/menu.js');
83
84let 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 Lando5b593492018-07-29 16:13:45 +0300103 SdcUiComponentsNg1Module.name,
Michael Landoed64b5e2017-06-09 03:19:04 +0300104 viewModelsModuleName,
105 directivesModuleName,
106 servicesModuleName,
107 filtersModuleName,
108 utilsModuleName
109];
110
111// ===================== Hosted applications section ====================
112// Define here new hosted apps
113let 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).
128let 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
147export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
Michael Landoed64b5e2017-06-09 03:19:04 +0300148
149ng1appModule.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 Lando39a4e0c2017-07-18 20:46:42 +0300164 delay: 5000,
Michael Landoed64b5e2017-06-09 03:19:04 +0300165 startTop: 10,
166 startRight: 10,
167 closeOnClick: true,
168 verticalSpacing: 20,
169 horizontalSpacing: 20,
170 positionX: 'right',
171 positionY: 'top'
172 });
Michael Lando39a4e0c2017-07-18 20:46:42 +0300173 NotificationProvider.options.templateUrl = 'notification-custom-template.html';
Michael Landoed64b5e2017-06-09 03:19:04 +0300174
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 Lando5b593492018-07-29 16:13:45 +0300189 url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed',
Michael Landoed64b5e2017-06-09 03:19:04 +0300190 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 Lando5b593492018-07-29 16:13:45 +0300204 if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
205 const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
206 if (breadcrumbsComponents) {
207 return breadcrumbsComponents;
208 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300209 } else {
Michael Lando5b593492018-07-29 16:13:45 +0300210 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 Landoed64b5e2017-06-09 03:19:04 +0300225 }
226 }];
227
Michael Lando5b593492018-07-29 16:13:45 +0300228 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 Landoed64b5e2017-06-09 03:19:04 +0300242 $stateProvider.state(
243 'workspace', {
Michael Lando5b593492018-07-29 16:13:45 +0300244 url: '/:previousState/workspace/:id/:type/',
Michael Landoed64b5e2017-06-09 03:19:04 +0300245 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
246 templateUrl: './view-models/workspace/workspace-view.html',
247 controller: viewModelsModuleName + '.WorkspaceViewModel',
248 resolve: {
Michael Lando5b593492018-07-29 16:13:45 +0300249 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 Gitelman51d50f02017-12-10 18:55:03 +0200252 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
253 (component:Component)=> {
Michael Lando5b593492018-07-29 16:13:45 +0300254 if ($stateParams.componentCsar && component.isResource()){
255 if((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) {
256 cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
257 }
Tal Gitelman51d50f02017-12-10 18:55:03 +0200258 component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
259 }
260 return component;
261 });
Michael Landoed64b5e2017-06-09 03:19:04 +0300262 } 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 Landoed64b5e2017-06-09 03:19:04 +0300290
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 Landoed64b5e2017-06-09 03:19:04 +0300297 }
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 Landoed64b5e2017-06-09 03:19:04 +0300313 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 Landoed64b5e2017-06-09 03:19:04 +0300349 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 Landoed64b5e2017-06-09 03:19:04 +0300368 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
391
392 $stateProvider.state(
393 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
394 parent: 'workspace',
395 url: 'management_workflow',
396 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
397 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
398 }
399 );
400
401 $stateProvider.state(
402 States.WORKSPACE_NETWORK_CALL_FLOW, {
403 parent: 'workspace',
404 url: 'network_call_flow',
405 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
406 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
407 }
408 );
409
410 $stateProvider.state(
411 States.WORKSPACE_DISTRIBUTION, {
412 parent: 'workspace',
413 url: 'distribution',
414 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
415 controller: viewModelsModuleName + '.DistributionViewModel'
416 }
417 );
418
419 $stateProvider.state(
420 States.WORKSPACE_COMPOSITION, {
421 url: 'composition/',
422 parent: 'workspace',
423 controller: viewModelsModuleName + '.CompositionViewModel',
424 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
425 data: {
426 bodyClass: 'composition'
427 }
428 }
429 );
430
431 // $stateProvider.state(
432 // States.WORKSPACE_NG2, {
433 // url: 'ng2/',
434 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
435 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
436 // }
437 // );
438
439 $stateProvider.state(
440 States.WORKSPACE_DEPLOYMENT, {
441 url: 'deployment/',
442 parent: 'workspace',
443 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
444 controller: viewModelsModuleName + '.DeploymentViewModel',
445 data: {
446 bodyClass: 'composition'
447 }
448 }
449 );
450
451 $stateProvider.state(
452 'workspace.composition.details', {
453 url: 'details',
454 parent: 'workspace.composition',
455 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
456 controller: viewModelsModuleName + '.DetailsViewModel'
457 }
458 );
459
460 $stateProvider.state(
461 'workspace.composition.properties', {
462 url: 'properties',
463 parent: 'workspace.composition',
464 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
465 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
466 }
467 );
468
469 $stateProvider.state(
470 'workspace.composition.artifacts', {
471 url: 'artifacts',
472 parent: 'workspace.composition',
473 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
474 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
475 }
476 );
477
478 $stateProvider.state(
479 'workspace.composition.relations', {
480 url: 'relations',
481 parent: 'workspace.composition',
482 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
483 controller: viewModelsModuleName + '.RelationsViewModel'
484 }
485 );
486
487 $stateProvider.state(
488 'workspace.composition.structure', {
489 url: 'structure',
490 parent: 'workspace.composition',
491 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
492 controller: viewModelsModuleName + '.StructureViewModel'
493 }
494 );
495 $stateProvider.state(
496 'workspace.composition.lifecycle', {
497 url: 'lifecycle',
498 parent: 'workspace.composition',
499 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
500 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
501 }
502 );
503
504 $stateProvider.state(
505 'workspace.composition.api', {
506 url: 'api',
507 parent: 'workspace.composition',
508 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
509 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
510 }
511 );
512 $stateProvider.state(
513 'workspace.composition.deployment', {
514 url: 'deployment',
515 parent: 'workspace.composition',
516 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
517 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
518 }
519 );
520
521 $stateProvider.state(
Arielk802bd2a2018-04-16 15:37:39 +0300522 States.WORKSPACE_INTERFACE_OPERATION, {
523 url: 'interface_operation',
524 parent: 'workspace',
525 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
526 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
527 data: {
528 bodyClass: 'interface_operation'
529 }
530 }
531 );
532
533 $stateProvider.state(
Idan Amiteedaaf92018-01-31 13:27:33 +0200534 'workspace.plugins', {
535 url: 'plugins/*path',
Idan Amitcb1095e2018-01-22 20:55:42 +0200536 parent: 'workspace',
Arielk802bd2a2018-04-16 15:37:39 +0300537 params: {'queryParams': null},
Idan Amiteedaaf92018-01-31 13:27:33 +0200538 templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html',
539 controller: viewModelsModuleName + '.PluginsContextViewModel'
Idan Amitcb1095e2018-01-22 20:55:42 +0200540 }
541 );
542
543 $stateProvider.state(
Michael Landoed64b5e2017-06-09 03:19:04 +0300544 'adminDashboard', {
545 url: '/adminDashboard',
546 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
547 controller: viewModelsModuleName + '.AdminDashboardViewModel',
548 permissions: ['ADMIN']
549 }
550 );
551
552 $stateProvider.state(
553 'onboardVendor', {
554 url: '/onboardVendor',
555 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
556 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
557 }
558 );
559
Idan Amit5197c8b2018-01-15 14:31:42 +0200560 $stateProvider.state(
Idan Amiteedaaf92018-01-31 13:27:33 +0200561 'plugins', {
562 url: '/plugins/*path',
563 templateUrl: './view-models/plugins/plugins-tab-view.html',
564 controller: viewModelsModuleName + '.PluginsTabViewModel'
Idan Amit5197c8b2018-01-15 14:31:42 +0200565 }
566 );
567
Michael Landoed64b5e2017-06-09 03:19:04 +0300568 // Build the states for all hosted apps dynamically
569 _.each(hostedApplications, (hostedApp)=> {
570 if (hostedApp.exists) {
571 $stateProvider.state(
572 hostedApp.state.name, {
573 url: hostedApp.state.url,
574 templateUrl: './view-models/dcae-app/dcae-app-view.html',
575 controller: viewModelsModuleName + hostedApp.state.controllerName
576 }
577 );
578 }
579 });
580
581 $stateProvider.state(
582 'catalog', {
Michael Lando5b593492018-07-29 16:13:45 +0300583 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
Michael Landoed64b5e2017-06-09 03:19:04 +0300584 templateUrl: './view-models/catalog/catalog-view.html',
585 controller: viewModelsModuleName + '.CatalogViewModel',
586 resolve: {
Tal Gitelman51d50f02017-12-10 18:55:03 +0200587 auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => {
588 let userInfo:IUserProperties = userService.getLoggedinUser();
Michael Landoed64b5e2017-06-09 03:19:04 +0300589 if (userInfo) {
590 return $q.when(userInfo);
591 } else {
592 return $q.reject({authenticated: false});
593 }
594 }]
595 }
596 }
597 );
598
599 $stateProvider.state(
600 'support', {
601 url: '/support',
602 templateUrl: './view-models/support/support-view.html',
603 controller: viewModelsModuleName + '.SupportViewModel'
604 }
605 );
606
607 $stateProvider.state(
608 'error-403', {
609 url: '/error-403',
610 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
611 controller: viewModelsModuleName + '.ErrorViewModel'
612 }
613 );
614
615 tooltipsConfigProvider.options({
616 side: 'bottom',
617 delay: '600',
618 class: 'tooltip-custom',
619 lazy: 0,
620 try: 0
621 });
622
623 }
624]);
625
626ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
627ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
628ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
629ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
Michael Lando75aacbb2017-07-17 21:12:03 +0300630ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
Tal Gitelman153a3582017-07-03 20:16:55 +0300631ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
632ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
Michael Lando5b593492018-07-29 16:13:45 +0300633ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
Michael Landoed64b5e2017-06-09 03:19:04 +0300634ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
635ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
636ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
637ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
638ng1appModule.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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
639ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
640ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
641ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
642ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
643ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
644ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
645ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
646ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
647
648ng1appModule.constant('sdcConfig', sdcConfig);
649ng1appModule.constant('sdcMenu', sdcMenu);
650
651ng1appModule.run([
652 '$http',
653 'Sdc.Services.CacheService',
654 'Sdc.Services.CookieService',
655 'Sdc.Services.ConfigurationUiService',
Tal Gitelman51d50f02017-12-10 18:55:03 +0200656 'UserServiceNg2',
Michael Landoed64b5e2017-06-09 03:19:04 +0300657 'Sdc.Services.CategoryResourceService',
658 'Sdc.Services.SdcVersionService',
659 '$state',
660 '$rootScope',
661 '$location',
662 'sdcMenu',
663 'ModalsHandler',
664 'Sdc.Services.EcompHeaderService',
665 'LeftPaletteLoaderService',
666 'Sdc.Services.DataTypesService',
667 'AngularJSBridge',
Michael Lando39a4e0c2017-07-18 20:46:42 +0300668 '$templateCache',
Michael Landoed64b5e2017-06-09 03:19:04 +0300669 ($http:ng.IHttpService,
670 cacheService:CacheService,
671 cookieService:CookieService,
672 ConfigurationUi:ConfigurationUiService,
Tal Gitelman51d50f02017-12-10 18:55:03 +0200673 userService:UserService,
Michael Landoed64b5e2017-06-09 03:19:04 +0300674 categoryResourceService:ICategoryResourceClass,
675 sdcVersionService:SdcVersionService,
676 $state:ng.ui.IStateService,
677 $rootScope:ng.IRootScopeService,
678 $location:ng.ILocationService,
679 sdcMenu:IAppMenu,
680 ModalsHandler:ModalsHandler,
681 ecompHeaderService:EcompHeaderService,
682 LeftPaletteLoaderService:LeftPaletteLoaderService,
683 DataTypesService:DataTypesService,
Michael Lando39a4e0c2017-07-18 20:46:42 +0300684 AngularJSBridge,
685 $templateCache:ng.ITemplateCacheService):void => {
686 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
Michael Lando5b593492018-07-29 16:13:45 +0300687 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
Michael Landoed64b5e2017-06-09 03:19:04 +0300688 //handle cache data - version
689 let initAsdcVersion:Function = ():void => {
690
691 let onFailed = (response) => {
692 console.info('onFailed initAsdcVersion', response);
693 cacheService.set('version', 'N/A');
694 };
695
696 let onSuccess = (version:any) => {
697 let tmpVerArray = version.version.split(".");
698 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
699 cacheService.set('version', ver);
700 };
701
702 sdcVersionService.getVersion().then(onSuccess, onFailed);
703
704 };
705
706 let initEcompMenu:Function = (user):void => {
707 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
708 $rootScope['menuItems'] = data;
709 });
710 };
711
712 let initConfigurationUi:Function = ():void => {
713 ConfigurationUi
714 .getConfigurationUi()
715 .then((configurationUi:any) => {
716 cacheService.set('UIConfiguration', configurationUi);
717 });
718 };
719
720 let initCategories:Function = ():void => {
721 let onError = ():void => {
722 console.log('Failed to init categories');
723 };
724
725 categoryResourceService.getAllCategories((categories: Categories):void => {
726 cacheService.set('serviceCategories', categories.serviceCategories);
727 cacheService.set('resourceCategories', categories.resourceCategories);
Michael Landoed64b5e2017-06-09 03:19:04 +0300728 }, onError);
729 };
730
731 // Add hosted applications to sdcConfig
732 sdcConfig.hostedApplications = hostedApplications;
733
734 //handle http config
735 $http.defaults.withCredentials = true;
736 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
737 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
738
739 initAsdcVersion();
740 initConfigurationUi();
741 // initLeftPalette();
742 DataTypesService.initDataTypes();
743
744 //handle stateChangeStart
745 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
746 if (deregisterStateChangeStartWatcher) {
747 deregisterStateChangeStartWatcher();
748 deregisterStateChangeStartWatcher = null;
749 }
Idan Amit8e9598c2018-05-14 16:21:48 +0300750 if (deregisterStateChangeSuccessWatcher) {
751 deregisterStateChangeSuccessWatcher();
752 deregisterStateChangeSuccessWatcher = null;
753 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300754 };
755
756 let removeLoader:Function = ():void => {
757 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
758 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
759 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
760 window.setTimeout(():void=> {
761 $(".sdc-loading-page .main-loader").css("display", "none");
762 $(".sdc-loading-page .caption1").css("display", "none");
763 $(".sdc-loading-page .caption2").css("display", "none");
764 $(".sdc-loading-page").addClass("animated fadeOut");
765 }, 1000);
766 };
767
768 let onNavigateOut:Function = (toState, toParams):void => {
769 let onOk = ():void => {
770 $state.current.data.unsavedChanges = false;
771 $state.go(toState.name, toParams);
772 };
773
774 let data = sdcMenu.alertMessages.exitWithoutSaving;
775 //open notify to user if changes are not saved
776 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
777 };
778
779 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
780 console.info((new Date()).getTime());
781 console.info('$stateChangeStart', toState.name);
Michael Landoed64b5e2017-06-09 03:19:04 +0300782
Tal Gitelman51d50f02017-12-10 18:55:03 +0200783 if (toState.name !== 'error-403' && !userService.getLoggedinUser()) {
Idan Amit5887a422018-05-16 14:32:01 +0300784 if (toState.name !== 'welcome') {
785 event.preventDefault();
786 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300787
Tal Gitelman51d50f02017-12-10 18:55:03 +0200788 userService.authorize().subscribe((userInfo:IUserProperties) => {
789 if (!doesUserHasAccess(toState, userInfo)) {
Michael Landoed64b5e2017-06-09 03:19:04 +0300790 $state.go('error-403');
791 console.info('User has no permissions');
Michael Landoed64b5e2017-06-09 03:19:04 +0300792 return;
793 }
Tal Gitelman51d50f02017-12-10 18:55:03 +0200794 userService.setLoggedinUser(userInfo);
795 cacheService.set('user', userInfo);
Michael Landoed64b5e2017-06-09 03:19:04 +0300796 initCategories();
Tal Gitelman51d50f02017-12-10 18:55:03 +0200797 // initEcompMenu(userInfo);
Michael Landoed64b5e2017-06-09 03:19:04 +0300798 setTimeout(function () {
799
800 removeLoader();
801
802 // initCategories();
Tal Gitelman51d50f02017-12-10 18:55:03 +0200803 if (userService.getLoggedinUser().role === 'ADMIN') {
Michael Landoed64b5e2017-06-09 03:19:04 +0300804 // toState.name = "adminDashboard";
805 $state.go("adminDashboard", toParams);
Michael Landoed64b5e2017-06-09 03:19:04 +0300806 return;
807 }
808
809 // After user authorized init categories
810 window.setTimeout(():void=> {
811 if ($state.current.name === '') {
812 $state.go(toState.name, toParams);
813 }
814
815 console.log("------$state.current.name=" + $state.current.name);
Michael Landoed64b5e2017-06-09 03:19:04 +0300816
817 }, 1000);
818
819 }, 0);
820
821 }, () => {
822 $state.go('error-403');
Michael Landoed64b5e2017-06-09 03:19:04 +0300823 });
824 }
Tal Gitelman51d50f02017-12-10 18:55:03 +0200825 else if (userService.getLoggedinUser()) {
Tal Gitelman51d50f02017-12-10 18:55:03 +0200826 if (!doesUserHasAccess(toState, userService.getLoggedinUser())) {
Michael Landoed64b5e2017-06-09 03:19:04 +0300827 event.preventDefault();
828 $state.go('error-403');
829 console.info('User has no permissions');
830 }
831 if (toState.name === "welcome") {
832 $state.go("dashboard");
833 }
Idan Amit8e9598c2018-05-14 16:21:48 +0300834
Michael Landoed64b5e2017-06-09 03:19:04 +0300835 //if form is dirty and not save - notify to user
836 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
837 event.preventDefault();
838 onNavigateOut(toState, toParams);
839 }
840 }
841
Idan Amit5887a422018-05-16 14:32:01 +0300842 // if enetering workspace, set the previousState param
843 if (toState.name.indexOf('workspace') !== -1) {
844 if (!toParams.previousState) {
845 const tmpPreviousState1 = fromParams && fromParams.previousState;
846 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
847 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
848 }
849 }
850
Michael Landoed64b5e2017-06-09 03:19:04 +0300851 };
852
Idan Amit8e9598c2018-05-14 16:21:48 +0300853 let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => {
854 console.info('$stateChangeSuccess', toState.name);
855
Idan Amit8e9598c2018-05-14 16:21:48 +0300856 // Workaround in case we are entering other state then workspace (user move to catalog)
857 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
858 if (toState.name.indexOf('workspace') === -1) {
859 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
860 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
861 }
Michael Lando5b593492018-07-29 16:13:45 +0300862 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)){
863 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
864 }
Idan Amit8e9598c2018-05-14 16:21:48 +0300865 }
866
867 //set body class
868 $rootScope['bodyClass'] = 'default-class';
869 if (toState.data && toState.data.bodyClass) {
870 $rootScope['bodyClass'] = toState.data.bodyClass;
871 }
872 };
873
Michael Landoed64b5e2017-06-09 03:19:04 +0300874 let doesUserHasAccess:Function = (toState, user):boolean => {
875
876 let isUserHasAccess = true;
877 if (toState.permissions && toState.permissions.length > 0) {
878 isUserHasAccess = _.includes(toState.permissions, user.role);
879 }
880 return isUserHasAccess;
881 };
882 let deregisterStateChangeStartWatcher:Function;
Idan Amit8e9598c2018-05-14 16:21:48 +0300883 let deregisterStateChangeSuccessWatcher:Function;
Michael Landoed64b5e2017-06-09 03:19:04 +0300884
885 let registerStateChangeStartWatcher:Function = ():void => {
886 internalDeregisterStateChangeStartWatcher();
887 console.info('registerStateChangeStartWatcher $stateChangeStart');
888 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
889 onStateChangeStart(event, toState, toParams, fromState, fromParams);
890 });
Idan Amit8e9598c2018-05-14 16:21:48 +0300891 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams):void => {
892 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
893 });
Michael Landoed64b5e2017-06-09 03:19:04 +0300894 };
895
896 registerStateChangeStartWatcher();
897 }]);
898