blob: 67cf66529c71d8a46aaf2ab30cea48a733f079a5 [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(
349 States.WORKSPACE_SERVICE_INPUTS, {
350 url: 'service_inputs',
351 parent: 'workspace',
352 controller: viewModelsModuleName + '.ServiceInputsViewModel',
353 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
354 data: {
355 bodyClass: 'workspace-inputs'
356 }
357 }
358 );
359
360 $stateProvider.state(
361 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
362 url: 'properties_assignment',
363 params: {'component': null},
364 template: '<properties-assignment></properties-assignment>',
365 parent: 'workspace',
366 resolve: {
367 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
368 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
369 $stateParams.component = injectComponent;
370 return injectComponent;
371 }],
372 },
373 data: {
374 bodyClass: 'properties-assignment'
375 }
376 }
377 );
378
379 $stateProvider.state(
380 States.WORKSPACE_RESOURCE_INPUTS, {
381 url: 'resource_inputs',
382 parent: 'workspace',
383 controller: viewModelsModuleName + '.ResourceInputsViewModel',
384 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
385 data: {
386 bodyClass: 'workspace-inputs'
387 }
388 }
389 );
390
391 $stateProvider.state(
392 States.WORKSPACE_ATTRIBUTES, {
393 url: 'attributes',
394 parent: 'workspace',
395 controller: viewModelsModuleName + '.AttributesViewModel',
396 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
397 data: {
398 bodyClass: 'attributes'
399 }
400 }
401 );
402
403 $stateProvider.state(
404 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
405 url: 'req_and_capabilities',
406 parent: 'workspace',
407 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
408 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
409 data: {
410 bodyClass: 'attributes'
411 }
412 }
413 );
414
415
416 $stateProvider.state(
417 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
418 parent: 'workspace',
419 url: 'management_workflow',
420 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
421 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
422 }
423 );
424
425 $stateProvider.state(
426 States.WORKSPACE_NETWORK_CALL_FLOW, {
427 parent: 'workspace',
428 url: 'network_call_flow',
429 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
430 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
431 }
432 );
433
434 $stateProvider.state(
435 States.WORKSPACE_DISTRIBUTION, {
436 parent: 'workspace',
437 url: 'distribution',
438 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
439 controller: viewModelsModuleName + '.DistributionViewModel'
440 }
441 );
442
443 $stateProvider.state(
444 States.WORKSPACE_COMPOSITION, {
445 url: 'composition/',
446 parent: 'workspace',
447 controller: viewModelsModuleName + '.CompositionViewModel',
448 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
449 data: {
450 bodyClass: 'composition'
451 }
452 }
453 );
454
455 // $stateProvider.state(
456 // States.WORKSPACE_NG2, {
457 // url: 'ng2/',
458 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
459 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
460 // }
461 // );
462
463 $stateProvider.state(
464 States.WORKSPACE_DEPLOYMENT, {
465 url: 'deployment/',
466 parent: 'workspace',
467 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
468 controller: viewModelsModuleName + '.DeploymentViewModel',
469 data: {
470 bodyClass: 'composition'
471 }
472 }
473 );
474
475 $stateProvider.state(
476 'workspace.composition.details', {
477 url: 'details',
478 parent: 'workspace.composition',
479 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
480 controller: viewModelsModuleName + '.DetailsViewModel'
481 }
482 );
483
484 $stateProvider.state(
485 'workspace.composition.properties', {
486 url: 'properties',
487 parent: 'workspace.composition',
488 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
489 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
490 }
491 );
492
493 $stateProvider.state(
494 'workspace.composition.artifacts', {
495 url: 'artifacts',
496 parent: 'workspace.composition',
497 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
498 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
499 }
500 );
501
502 $stateProvider.state(
503 'workspace.composition.relations', {
504 url: 'relations',
505 parent: 'workspace.composition',
506 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
507 controller: viewModelsModuleName + '.RelationsViewModel'
508 }
509 );
510
511 $stateProvider.state(
512 'workspace.composition.structure', {
513 url: 'structure',
514 parent: 'workspace.composition',
515 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
516 controller: viewModelsModuleName + '.StructureViewModel'
517 }
518 );
519 $stateProvider.state(
520 'workspace.composition.lifecycle', {
521 url: 'lifecycle',
522 parent: 'workspace.composition',
523 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
524 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
525 }
526 );
527
528 $stateProvider.state(
529 'workspace.composition.api', {
530 url: 'api',
531 parent: 'workspace.composition',
532 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
533 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
534 }
535 );
536 $stateProvider.state(
537 'workspace.composition.deployment', {
538 url: 'deployment',
539 parent: 'workspace.composition',
540 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
541 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
542 }
543 );
544
545 $stateProvider.state(
Arielk802bd2a2018-04-16 15:37:39 +0300546 States.WORKSPACE_INTERFACE_OPERATION, {
547 url: 'interface_operation',
548 parent: 'workspace',
549 controller: viewModelsModuleName + '.InterfaceOperationViewModel',
550 templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
551 data: {
552 bodyClass: 'interface_operation'
553 }
554 }
555 );
556
557 $stateProvider.state(
Idan Amiteedaaf92018-01-31 13:27:33 +0200558 'workspace.plugins', {
559 url: 'plugins/*path',
Idan Amitcb1095e2018-01-22 20:55:42 +0200560 parent: 'workspace',
Arielk802bd2a2018-04-16 15:37:39 +0300561 params: {'queryParams': null},
Idan Amiteedaaf92018-01-31 13:27:33 +0200562 templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html',
563 controller: viewModelsModuleName + '.PluginsContextViewModel'
Idan Amitcb1095e2018-01-22 20:55:42 +0200564 }
565 );
566
567 $stateProvider.state(
Michael Landoed64b5e2017-06-09 03:19:04 +0300568 'adminDashboard', {
569 url: '/adminDashboard',
570 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
571 controller: viewModelsModuleName + '.AdminDashboardViewModel',
572 permissions: ['ADMIN']
573 }
574 );
575
576 $stateProvider.state(
577 'onboardVendor', {
578 url: '/onboardVendor',
579 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
580 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
581 }
582 );
583
Idan Amit5197c8b2018-01-15 14:31:42 +0200584 $stateProvider.state(
Idan Amiteedaaf92018-01-31 13:27:33 +0200585 'plugins', {
586 url: '/plugins/*path',
587 templateUrl: './view-models/plugins/plugins-tab-view.html',
588 controller: viewModelsModuleName + '.PluginsTabViewModel'
Idan Amit5197c8b2018-01-15 14:31:42 +0200589 }
590 );
591
Michael Landoed64b5e2017-06-09 03:19:04 +0300592 // Build the states for all hosted apps dynamically
593 _.each(hostedApplications, (hostedApp)=> {
594 if (hostedApp.exists) {
595 $stateProvider.state(
596 hostedApp.state.name, {
597 url: hostedApp.state.url,
598 templateUrl: './view-models/dcae-app/dcae-app-view.html',
599 controller: viewModelsModuleName + hostedApp.state.controllerName
600 }
601 );
602 }
603 });
604
605 $stateProvider.state(
606 'catalog', {
Michael Lando5b593492018-07-29 16:13:45 +0300607 url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
Michael Landoed64b5e2017-06-09 03:19:04 +0300608 templateUrl: './view-models/catalog/catalog-view.html',
609 controller: viewModelsModuleName + '.CatalogViewModel',
610 resolve: {
Tal Gitelman51d50f02017-12-10 18:55:03 +0200611 auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => {
612 let userInfo:IUserProperties = userService.getLoggedinUser();
Michael Landoed64b5e2017-06-09 03:19:04 +0300613 if (userInfo) {
614 return $q.when(userInfo);
615 } else {
616 return $q.reject({authenticated: false});
617 }
618 }]
619 }
620 }
621 );
622
623 $stateProvider.state(
624 'support', {
625 url: '/support',
626 templateUrl: './view-models/support/support-view.html',
627 controller: viewModelsModuleName + '.SupportViewModel'
628 }
629 );
630
631 $stateProvider.state(
632 'error-403', {
633 url: '/error-403',
634 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
635 controller: viewModelsModuleName + '.ErrorViewModel'
636 }
637 );
638
639 tooltipsConfigProvider.options({
640 side: 'bottom',
641 delay: '600',
642 class: 'tooltip-custom',
643 lazy: 0,
644 try: 0
645 });
646
647 }
648]);
649
650ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
651ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
652ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
653ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
Michael Lando75aacbb2017-07-17 21:12:03 +0300654ng1appModule.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 +0300655ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
656ng1appModule.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 +0300657ng1appModule.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 +0300658ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
659ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
660ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
661ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
662ng1appModule.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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
663ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
664ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
665ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
666ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
667ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
668ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
669ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
670ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
671
672ng1appModule.constant('sdcConfig', sdcConfig);
673ng1appModule.constant('sdcMenu', sdcMenu);
674
675ng1appModule.run([
676 '$http',
677 'Sdc.Services.CacheService',
678 'Sdc.Services.CookieService',
679 'Sdc.Services.ConfigurationUiService',
Tal Gitelman51d50f02017-12-10 18:55:03 +0200680 'UserServiceNg2',
Michael Landoed64b5e2017-06-09 03:19:04 +0300681 'Sdc.Services.CategoryResourceService',
682 'Sdc.Services.SdcVersionService',
683 '$state',
684 '$rootScope',
685 '$location',
686 'sdcMenu',
687 'ModalsHandler',
688 'Sdc.Services.EcompHeaderService',
689 'LeftPaletteLoaderService',
690 'Sdc.Services.DataTypesService',
691 'AngularJSBridge',
Michael Lando39a4e0c2017-07-18 20:46:42 +0300692 '$templateCache',
Michael Landoed64b5e2017-06-09 03:19:04 +0300693 ($http:ng.IHttpService,
694 cacheService:CacheService,
695 cookieService:CookieService,
696 ConfigurationUi:ConfigurationUiService,
Tal Gitelman51d50f02017-12-10 18:55:03 +0200697 userService:UserService,
Michael Landoed64b5e2017-06-09 03:19:04 +0300698 categoryResourceService:ICategoryResourceClass,
699 sdcVersionService:SdcVersionService,
700 $state:ng.ui.IStateService,
701 $rootScope:ng.IRootScopeService,
702 $location:ng.ILocationService,
703 sdcMenu:IAppMenu,
704 ModalsHandler:ModalsHandler,
705 ecompHeaderService:EcompHeaderService,
706 LeftPaletteLoaderService:LeftPaletteLoaderService,
707 DataTypesService:DataTypesService,
Michael Lando39a4e0c2017-07-18 20:46:42 +0300708 AngularJSBridge,
709 $templateCache:ng.ITemplateCacheService):void => {
710 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
Michael Lando5b593492018-07-29 16:13:45 +0300711 $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
Michael Landoed64b5e2017-06-09 03:19:04 +0300712 //handle cache data - version
713 let initAsdcVersion:Function = ():void => {
714
715 let onFailed = (response) => {
716 console.info('onFailed initAsdcVersion', response);
717 cacheService.set('version', 'N/A');
718 };
719
720 let onSuccess = (version:any) => {
721 let tmpVerArray = version.version.split(".");
722 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
723 cacheService.set('version', ver);
724 };
725
726 sdcVersionService.getVersion().then(onSuccess, onFailed);
727
728 };
729
730 let initEcompMenu:Function = (user):void => {
731 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
732 $rootScope['menuItems'] = data;
733 });
734 };
735
736 let initConfigurationUi:Function = ():void => {
737 ConfigurationUi
738 .getConfigurationUi()
739 .then((configurationUi:any) => {
740 cacheService.set('UIConfiguration', configurationUi);
741 });
742 };
743
744 let initCategories:Function = ():void => {
745 let onError = ():void => {
746 console.log('Failed to init categories');
747 };
748
749 categoryResourceService.getAllCategories((categories: Categories):void => {
750 cacheService.set('serviceCategories', categories.serviceCategories);
751 cacheService.set('resourceCategories', categories.resourceCategories);
Michael Landoed64b5e2017-06-09 03:19:04 +0300752 }, onError);
753 };
754
755 // Add hosted applications to sdcConfig
756 sdcConfig.hostedApplications = hostedApplications;
757
758 //handle http config
759 $http.defaults.withCredentials = true;
760 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
761 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
762
763 initAsdcVersion();
764 initConfigurationUi();
765 // initLeftPalette();
766 DataTypesService.initDataTypes();
767
768 //handle stateChangeStart
769 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
770 if (deregisterStateChangeStartWatcher) {
771 deregisterStateChangeStartWatcher();
772 deregisterStateChangeStartWatcher = null;
773 }
Idan Amit8e9598c2018-05-14 16:21:48 +0300774 if (deregisterStateChangeSuccessWatcher) {
775 deregisterStateChangeSuccessWatcher();
776 deregisterStateChangeSuccessWatcher = null;
777 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300778 };
779
780 let removeLoader:Function = ():void => {
781 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
782 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
783 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
784 window.setTimeout(():void=> {
785 $(".sdc-loading-page .main-loader").css("display", "none");
786 $(".sdc-loading-page .caption1").css("display", "none");
787 $(".sdc-loading-page .caption2").css("display", "none");
788 $(".sdc-loading-page").addClass("animated fadeOut");
789 }, 1000);
790 };
791
792 let onNavigateOut:Function = (toState, toParams):void => {
793 let onOk = ():void => {
794 $state.current.data.unsavedChanges = false;
795 $state.go(toState.name, toParams);
796 };
797
798 let data = sdcMenu.alertMessages.exitWithoutSaving;
799 //open notify to user if changes are not saved
800 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
801 };
802
803 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
804 console.info((new Date()).getTime());
805 console.info('$stateChangeStart', toState.name);
Michael Landoed64b5e2017-06-09 03:19:04 +0300806
Tal Gitelman51d50f02017-12-10 18:55:03 +0200807 if (toState.name !== 'error-403' && !userService.getLoggedinUser()) {
Idan Amit5887a422018-05-16 14:32:01 +0300808 if (toState.name !== 'welcome') {
809 event.preventDefault();
810 }
Michael Landoed64b5e2017-06-09 03:19:04 +0300811
Tal Gitelman51d50f02017-12-10 18:55:03 +0200812 userService.authorize().subscribe((userInfo:IUserProperties) => {
813 if (!doesUserHasAccess(toState, userInfo)) {
Michael Landoed64b5e2017-06-09 03:19:04 +0300814 $state.go('error-403');
815 console.info('User has no permissions');
Michael Landoed64b5e2017-06-09 03:19:04 +0300816 return;
817 }
Tal Gitelman51d50f02017-12-10 18:55:03 +0200818 userService.setLoggedinUser(userInfo);
819 cacheService.set('user', userInfo);
Michael Landoed64b5e2017-06-09 03:19:04 +0300820 initCategories();
Tal Gitelman51d50f02017-12-10 18:55:03 +0200821 // initEcompMenu(userInfo);
Michael Landoed64b5e2017-06-09 03:19:04 +0300822 setTimeout(function () {
823
824 removeLoader();
825
826 // initCategories();
Tal Gitelman51d50f02017-12-10 18:55:03 +0200827 if (userService.getLoggedinUser().role === 'ADMIN') {
Michael Landoed64b5e2017-06-09 03:19:04 +0300828 // toState.name = "adminDashboard";
829 $state.go("adminDashboard", toParams);
Michael Landoed64b5e2017-06-09 03:19:04 +0300830 return;
831 }
832
833 // After user authorized init categories
834 window.setTimeout(():void=> {
835 if ($state.current.name === '') {
836 $state.go(toState.name, toParams);
837 }
838
839 console.log("------$state.current.name=" + $state.current.name);
Michael Landoed64b5e2017-06-09 03:19:04 +0300840
841 }, 1000);
842
843 }, 0);
844
845 }, () => {
846 $state.go('error-403');
Michael Landoed64b5e2017-06-09 03:19:04 +0300847 });
848 }
Tal Gitelman51d50f02017-12-10 18:55:03 +0200849 else if (userService.getLoggedinUser()) {
Tal Gitelman51d50f02017-12-10 18:55:03 +0200850 if (!doesUserHasAccess(toState, userService.getLoggedinUser())) {
Michael Landoed64b5e2017-06-09 03:19:04 +0300851 event.preventDefault();
852 $state.go('error-403');
853 console.info('User has no permissions');
854 }
855 if (toState.name === "welcome") {
856 $state.go("dashboard");
857 }
Idan Amit8e9598c2018-05-14 16:21:48 +0300858
Michael Landoed64b5e2017-06-09 03:19:04 +0300859 //if form is dirty and not save - notify to user
860 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
861 event.preventDefault();
862 onNavigateOut(toState, toParams);
863 }
864 }
865
Idan Amit5887a422018-05-16 14:32:01 +0300866 // if enetering workspace, set the previousState param
867 if (toState.name.indexOf('workspace') !== -1) {
868 if (!toParams.previousState) {
869 const tmpPreviousState1 = fromParams && fromParams.previousState;
870 const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
871 toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
872 }
873 }
874
Michael Landoed64b5e2017-06-09 03:19:04 +0300875 };
876
Idan Amit8e9598c2018-05-14 16:21:48 +0300877 let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => {
878 console.info('$stateChangeSuccess', toState.name);
879
Idan Amit8e9598c2018-05-14 16:21:48 +0300880 // Workaround in case we are entering other state then workspace (user move to catalog)
881 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
882 if (toState.name.indexOf('workspace') === -1) {
883 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
884 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
885 }
Michael Lando5b593492018-07-29 16:13:45 +0300886 if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)){
887 cacheService.remove(PREVIOUS_CSAR_COMPONENT);
888 }
Idan Amit8e9598c2018-05-14 16:21:48 +0300889 }
890
891 //set body class
892 $rootScope['bodyClass'] = 'default-class';
893 if (toState.data && toState.data.bodyClass) {
894 $rootScope['bodyClass'] = toState.data.bodyClass;
895 }
896 };
897
Michael Landoed64b5e2017-06-09 03:19:04 +0300898 let doesUserHasAccess:Function = (toState, user):boolean => {
899
900 let isUserHasAccess = true;
901 if (toState.permissions && toState.permissions.length > 0) {
902 isUserHasAccess = _.includes(toState.permissions, user.role);
903 }
904 return isUserHasAccess;
905 };
906 let deregisterStateChangeStartWatcher:Function;
Idan Amit8e9598c2018-05-14 16:21:48 +0300907 let deregisterStateChangeSuccessWatcher:Function;
Michael Landoed64b5e2017-06-09 03:19:04 +0300908
909 let registerStateChangeStartWatcher:Function = ():void => {
910 internalDeregisterStateChangeStartWatcher();
911 console.info('registerStateChangeStartWatcher $stateChangeStart');
912 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
913 onStateChangeStart(event, toState, toParams, fromState, fromParams);
914 });
Idan Amit8e9598c2018-05-14 16:21:48 +0300915 deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams):void => {
916 onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
917 });
Michael Landoed64b5e2017-06-09 03:19:04 +0300918 };
919
920 registerStateChangeStartWatcher();
921 }]);
922