blob: 707d7e456eb8dc68f6f613181b564683722d00aa [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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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 Landoed64b5e2017-06-09 03:19:04 +030021'use strict';
22
23//import 'restangular';
24//import 'angular-ui-router';
25import "reflect-metadata";
26import 'ng-infinite-scroll';
27import './modules/filters.ts';
28import './modules/utils.ts';
29import './modules/directive-module.ts';
30import './modules/service-module';
31import './modules/view-model-module.ts';
32
33import {
34 IUserResourceClass,
35 DataTypesService,
36 LeftPaletteLoaderService,
37 EcompHeaderService,
38 CookieService,
39 ConfigurationUiService,
40 CacheService,
41 IUserResource,
42 SdcVersionService,
43 ICategoryResourceClass,
44 EntityService
45} from "./services";
46import {forwardRef} from '@angular/core';
47import {UpgradeAdapter} from '@angular/upgrade';
48import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States} from "./utils";
49import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
50import {ComponentFactory} from "./utils/component-factory";
51import {ModalsHandler} from "./utils/modals-handler";
52import {downgradeComponent} from "@angular/upgrade/static";
53
54import {AppModule} from './ng2/app.module';
55import {PropertiesAssignmentComponent} from "./ng2/pages/properties-assignment/properties-assignment.page.component";
56import {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";
60
61
62let 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',
103 viewModelsModuleName,
104 directivesModuleName,
105 servicesModuleName,
106 filtersModuleName,
107 utilsModuleName
108];
109
110// ===================== Hosted applications section ====================
111// Define here new hosted apps
112let 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).
127let 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
146export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
147angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory);
148
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({
164 delay: 10000,
165 startTop: 10,
166 startRight: 10,
167 closeOnClick: true,
168 verticalSpacing: 20,
169 horizontalSpacing: 20,
170 positionX: 'right',
171 positionY: 'top'
172 });
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) {
219 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id);
220 } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
221 return $stateParams.componentCsar;
222 } else {
223 let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
224 if (emptyComponent.isResource() && $stateParams.resourceType) {
225 // Set the resource type
226 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
227 }
228 if ($stateParams.importedFile) {
229 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
230 }
231 return emptyComponent;
232 }
233 }],
234 components: componentsParam
235 }
236 }
237 );
238
239 $stateProvider.state(
240 States.WORKSPACE_GENERAL, {
241 url: 'general',
242 parent: 'workspace',
243 controller: viewModelsModuleName + '.GeneralViewModel',
244 templateUrl: './view-models/workspace/tabs/general/general-view.html',
245 data: {unsavedChanges: false, bodyClass: 'general'}
246 }
247 );
Michael Landoed64b5e2017-06-09 03:19:04 +0300248
249 $stateProvider.state(
250 States.WORKSPACE_ACTIVITY_LOG, {
251 url: 'activity_log',
252 parent: 'workspace',
253 controller: viewModelsModuleName + '.ActivityLogViewModel',
254 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
255 data: {unsavedChanges: false}
256 }
257 );
258
259 $stateProvider.state(
260 States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
261 url: 'deployment_artifacts',
262 parent: 'workspace',
263 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
264 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
265 data: {
266 bodyClass: 'deployment_artifacts'
267 }
268 }
269 );
270
271 $stateProvider.state(
Michael Landoed64b5e2017-06-09 03:19:04 +0300272 States.WORKSPACE_INFORMATION_ARTIFACTS, {
273 url: 'information_artifacts',
274 parent: 'workspace',
275 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
276 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
277 data: {
278 bodyClass: 'information_artifacts'
279 }
280 }
281 );
282
283 $stateProvider.state(
284 States.WORKSPACE_TOSCA_ARTIFACTS, {
285 url: 'tosca_artifacts',
286 parent: 'workspace',
287 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
288 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
289 data: {
290 bodyClass: 'tosca_artifacts'
291 }
292 }
293 );
294
295 $stateProvider.state(
296 States.WORKSPACE_PROPERTIES, {
297 url: 'properties',
298 parent: 'workspace',
299 controller: viewModelsModuleName + '.PropertiesViewModel',
300 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
301 data: {
302 bodyClass: 'properties'
303 }
304 }
305 );
306
307 $stateProvider.state(
308 States.WORKSPACE_SERVICE_INPUTS, {
309 url: 'service_inputs',
310 parent: 'workspace',
311 controller: viewModelsModuleName + '.ServiceInputsViewModel',
312 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
313 data: {
314 bodyClass: 'workspace-inputs'
315 }
316 }
317 );
318
319 $stateProvider.state(
320 States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
321 url: 'properties_assignment',
322 params: {'component': null},
323 template: '<properties-assignment></properties-assignment>',
324 parent: 'workspace',
325 resolve: {
326 componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
327 //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
328 $stateParams.component = injectComponent;
329 return injectComponent;
330 }],
331 },
332 data: {
333 bodyClass: 'properties-assignment'
334 }
335 }
336 );
337
338 $stateProvider.state(
339 States.WORKSPACE_RESOURCE_INPUTS, {
340 url: 'resource_inputs',
341 parent: 'workspace',
342 controller: viewModelsModuleName + '.ResourceInputsViewModel',
343 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
344 data: {
345 bodyClass: 'workspace-inputs'
346 }
347 }
348 );
349
350 $stateProvider.state(
351 States.WORKSPACE_ATTRIBUTES, {
352 url: 'attributes',
353 parent: 'workspace',
354 controller: viewModelsModuleName + '.AttributesViewModel',
355 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
356 data: {
357 bodyClass: 'attributes'
358 }
359 }
360 );
361
362 $stateProvider.state(
363 States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
364 url: 'req_and_capabilities',
365 parent: 'workspace',
366 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
367 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
368 data: {
369 bodyClass: 'attributes'
370 }
371 }
372 );
373
374
375 $stateProvider.state(
376 States.WORKSPACE_MANAGEMENT_WORKFLOW, {
377 parent: 'workspace',
378 url: 'management_workflow',
379 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
380 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
381 }
382 );
383
384 $stateProvider.state(
385 States.WORKSPACE_NETWORK_CALL_FLOW, {
386 parent: 'workspace',
387 url: 'network_call_flow',
388 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
389 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
390 }
391 );
392
393 $stateProvider.state(
394 States.WORKSPACE_DISTRIBUTION, {
395 parent: 'workspace',
396 url: 'distribution',
397 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
398 controller: viewModelsModuleName + '.DistributionViewModel'
399 }
400 );
401
402 $stateProvider.state(
403 States.WORKSPACE_COMPOSITION, {
404 url: 'composition/',
405 parent: 'workspace',
406 controller: viewModelsModuleName + '.CompositionViewModel',
407 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
408 data: {
409 bodyClass: 'composition'
410 }
411 }
412 );
413
414 // $stateProvider.state(
415 // States.WORKSPACE_NG2, {
416 // url: 'ng2/',
417 // component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
418 // templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
419 // }
420 // );
421
422 $stateProvider.state(
423 States.WORKSPACE_DEPLOYMENT, {
424 url: 'deployment/',
425 parent: 'workspace',
426 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
427 controller: viewModelsModuleName + '.DeploymentViewModel',
428 data: {
429 bodyClass: 'composition'
430 }
431 }
432 );
433
434 $stateProvider.state(
435 'workspace.composition.details', {
436 url: 'details',
437 parent: 'workspace.composition',
438 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
439 controller: viewModelsModuleName + '.DetailsViewModel'
440 }
441 );
442
443 $stateProvider.state(
444 'workspace.composition.properties', {
445 url: 'properties',
446 parent: 'workspace.composition',
447 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
448 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
449 }
450 );
451
452 $stateProvider.state(
453 'workspace.composition.artifacts', {
454 url: 'artifacts',
455 parent: 'workspace.composition',
456 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
457 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
458 }
459 );
460
461 $stateProvider.state(
462 'workspace.composition.relations', {
463 url: 'relations',
464 parent: 'workspace.composition',
465 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
466 controller: viewModelsModuleName + '.RelationsViewModel'
467 }
468 );
469
470 $stateProvider.state(
471 'workspace.composition.structure', {
472 url: 'structure',
473 parent: 'workspace.composition',
474 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
475 controller: viewModelsModuleName + '.StructureViewModel'
476 }
477 );
478 $stateProvider.state(
479 'workspace.composition.lifecycle', {
480 url: 'lifecycle',
481 parent: 'workspace.composition',
482 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
483 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
484 }
485 );
486
487 $stateProvider.state(
488 'workspace.composition.api', {
489 url: 'api',
490 parent: 'workspace.composition',
491 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
492 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
493 }
494 );
495 $stateProvider.state(
496 'workspace.composition.deployment', {
497 url: 'deployment',
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 'adminDashboard', {
506 url: '/adminDashboard',
507 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
508 controller: viewModelsModuleName + '.AdminDashboardViewModel',
509 permissions: ['ADMIN']
510 }
511 );
512
513 $stateProvider.state(
514 'onboardVendor', {
515 url: '/onboardVendor',
516 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
517 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
518 }
519 );
520
521 // Build the states for all hosted apps dynamically
522 _.each(hostedApplications, (hostedApp)=> {
523 if (hostedApp.exists) {
524 $stateProvider.state(
525 hostedApp.state.name, {
526 url: hostedApp.state.url,
527 templateUrl: './view-models/dcae-app/dcae-app-view.html',
528 controller: viewModelsModuleName + hostedApp.state.controllerName
529 }
530 );
531 }
532 });
533
534 $stateProvider.state(
535 'catalog', {
536 url: '/catalog',
537 templateUrl: './view-models/catalog/catalog-view.html',
538 controller: viewModelsModuleName + '.CatalogViewModel',
539 resolve: {
540 auth: ["$q", "Sdc.Services.UserResourceService", ($q:any, userResourceService:IUserResourceClass) => {
541 let userInfo:IUserResource = userResourceService.getLoggedinUser();
542 if (userInfo) {
543 return $q.when(userInfo);
544 } else {
545 return $q.reject({authenticated: false});
546 }
547 }]
548 }
549 }
550 );
551
552 $stateProvider.state(
553 'support', {
554 url: '/support',
555 templateUrl: './view-models/support/support-view.html',
556 controller: viewModelsModuleName + '.SupportViewModel'
557 }
558 );
559
560 $stateProvider.state(
561 'error-403', {
562 url: '/error-403',
563 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
564 controller: viewModelsModuleName + '.ErrorViewModel'
565 }
566 );
567
568 tooltipsConfigProvider.options({
569 side: 'bottom',
570 delay: '600',
571 class: 'tooltip-custom',
572 lazy: 0,
573 try: 0
574 });
575
576 }
577]);
578
579ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
580ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
581ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
582ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
Michael Lando75aacbb2017-07-17 21:12:03 +0300583ng1appModule.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 +0300584ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
585ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
Michael Landoed64b5e2017-06-09 03:19:04 +0300586ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
587ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
588ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
589ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
590ng1appModule.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})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
591ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
592ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
593ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
594ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
595ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
596ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
597ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
598ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
599
600ng1appModule.constant('sdcConfig', sdcConfig);
601ng1appModule.constant('sdcMenu', sdcMenu);
602
603ng1appModule.run([
604 '$http',
605 'Sdc.Services.CacheService',
606 'Sdc.Services.CookieService',
607 'Sdc.Services.ConfigurationUiService',
608 'Sdc.Services.UserResourceService',
609 'Sdc.Services.CategoryResourceService',
610 'Sdc.Services.SdcVersionService',
611 '$state',
612 '$rootScope',
613 '$location',
614 'sdcMenu',
615 'ModalsHandler',
616 'Sdc.Services.EcompHeaderService',
617 'LeftPaletteLoaderService',
618 'Sdc.Services.DataTypesService',
619 'AngularJSBridge',
620 ($http:ng.IHttpService,
621 cacheService:CacheService,
622 cookieService:CookieService,
623 ConfigurationUi:ConfigurationUiService,
624 UserResourceClass:IUserResourceClass,
625 categoryResourceService:ICategoryResourceClass,
626 sdcVersionService:SdcVersionService,
627 $state:ng.ui.IStateService,
628 $rootScope:ng.IRootScopeService,
629 $location:ng.ILocationService,
630 sdcMenu:IAppMenu,
631 ModalsHandler:ModalsHandler,
632 ecompHeaderService:EcompHeaderService,
633 LeftPaletteLoaderService:LeftPaletteLoaderService,
634 DataTypesService:DataTypesService,
635 AngularJSBridge):void => {
636
637 //handle cache data - version
638 let initAsdcVersion:Function = ():void => {
639
640 let onFailed = (response) => {
641 console.info('onFailed initAsdcVersion', response);
642 cacheService.set('version', 'N/A');
643 };
644
645 let onSuccess = (version:any) => {
646 let tmpVerArray = version.version.split(".");
647 let ver = tmpVerArray[0] + "." + tmpVerArray[1] + "." + tmpVerArray[2];
648 cacheService.set('version', ver);
649 };
650
651 sdcVersionService.getVersion().then(onSuccess, onFailed);
652
653 };
654
655 let initEcompMenu:Function = (user):void => {
656 ecompHeaderService.getMenuItems(user.userId).then((data)=> {
657 $rootScope['menuItems'] = data;
658 });
659 };
660
661 let initConfigurationUi:Function = ():void => {
662 ConfigurationUi
663 .getConfigurationUi()
664 .then((configurationUi:any) => {
665 cacheService.set('UIConfiguration', configurationUi);
666 });
667 };
668
669 let initCategories:Function = ():void => {
670 let onError = ():void => {
671 console.log('Failed to init categories');
672 };
673
674 categoryResourceService.getAllCategories((categories: Categories):void => {
675 cacheService.set('serviceCategories', categories.serviceCategories);
676 cacheService.set('resourceCategories', categories.resourceCategories);
Michael Landoed64b5e2017-06-09 03:19:04 +0300677 }, onError);
678 };
679
680 // Add hosted applications to sdcConfig
681 sdcConfig.hostedApplications = hostedApplications;
682
683 //handle http config
684 $http.defaults.withCredentials = true;
685 $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
686 $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
687
688 initAsdcVersion();
689 initConfigurationUi();
690 // initLeftPalette();
691 DataTypesService.initDataTypes();
692
693 //handle stateChangeStart
694 let internalDeregisterStateChangeStartWatcher:Function = ():void => {
695 if (deregisterStateChangeStartWatcher) {
696 deregisterStateChangeStartWatcher();
697 deregisterStateChangeStartWatcher = null;
698 }
699 };
700
701 let removeLoader:Function = ():void => {
702 $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
703 $(".sdc-loading-page .caption1").addClass("animated fadeOut");
704 $(".sdc-loading-page .caption2").addClass("animated fadeOut");
705 window.setTimeout(():void=> {
706 $(".sdc-loading-page .main-loader").css("display", "none");
707 $(".sdc-loading-page .caption1").css("display", "none");
708 $(".sdc-loading-page .caption2").css("display", "none");
709 $(".sdc-loading-page").addClass("animated fadeOut");
710 }, 1000);
711 };
712
713 let onNavigateOut:Function = (toState, toParams):void => {
714 let onOk = ():void => {
715 $state.current.data.unsavedChanges = false;
716 $state.go(toState.name, toParams);
717 };
718
719 let data = sdcMenu.alertMessages.exitWithoutSaving;
720 //open notify to user if changes are not saved
721 ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
722 };
723
724 let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
725 console.info((new Date()).getTime());
726 console.info('$stateChangeStart', toState.name);
727 //set body class
728 $rootScope['bodyClass'] = 'default-class';
729 if (toState.data && toState.data.bodyClass) {
730 $rootScope['bodyClass'] = toState.data.bodyClass;
731 }
732
733 // Workaround in case we are entering other state then workspace (user move to catalog)
734 // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
735 if (toState.name.indexOf('workspace') === -1) {
736 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
737 cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
738 }
739 }
740
741 //saving last state to params , for breadcrumbs
742 if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
743 toParams.previousState = fromState.name;
744 } else {
745 toParams.previousState = fromParams.previousState;
746 }
747
748 if (toState.name !== 'error-403' && !UserResourceClass.getLoggedinUser()) {
749 internalDeregisterStateChangeStartWatcher();
750 event.preventDefault();
751
752 UserResourceClass.authorize().$promise.then((user:IUserResource) => {
753 if (!doesUserHasAccess(toState, user)) {
754 $state.go('error-403');
755 console.info('User has no permissions');
756 registerStateChangeStartWatcher();
757 return;
758 }
759 UserResourceClass.setLoggedinUser(user);
760 cacheService.set('user', user);
761 initCategories();
762 // initEcompMenu(user);
763 setTimeout(function () {
764
765 removeLoader();
766
767 // initCategories();
768 if (UserResourceClass.getLoggedinUser().role === 'ADMIN') {
769 // toState.name = "adminDashboard";
770 $state.go("adminDashboard", toParams);
771 registerStateChangeStartWatcher();
772 return;
773 }
774
775 // After user authorized init categories
776 window.setTimeout(():void=> {
777 if ($state.current.name === '') {
778 $state.go(toState.name, toParams);
779 }
780
781 console.log("------$state.current.name=" + $state.current.name);
782 console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
783 registerStateChangeStartWatcher();
784
785 }, 1000);
786
787 }, 0);
788
789 }, () => {
790 $state.go('error-403');
791
792 console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
793 registerStateChangeStartWatcher();
794 });
795 }
796 else if (UserResourceClass.getLoggedinUser()) {
797 internalDeregisterStateChangeStartWatcher();
798 if (!doesUserHasAccess(toState, UserResourceClass.getLoggedinUser())) {
799 event.preventDefault();
800 $state.go('error-403');
801 console.info('User has no permissions');
802 }
803 if (toState.name === "welcome") {
804 $state.go("dashboard");
805 }
806 registerStateChangeStartWatcher();
807 //if form is dirty and not save - notify to user
808 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
809 event.preventDefault();
810 onNavigateOut(toState, toParams);
811 }
812 }
813
814 };
815
816 let doesUserHasAccess:Function = (toState, user):boolean => {
817
818 let isUserHasAccess = true;
819 if (toState.permissions && toState.permissions.length > 0) {
820 isUserHasAccess = _.includes(toState.permissions, user.role);
821 }
822 return isUserHasAccess;
823 };
824 let deregisterStateChangeStartWatcher:Function;
825
826 let registerStateChangeStartWatcher:Function = ():void => {
827 internalDeregisterStateChangeStartWatcher();
828 console.info('registerStateChangeStartWatcher $stateChangeStart');
829 deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
830 onStateChangeStart(event, toState, toParams, fromState, fromParams);
831 });
832 };
833
834 registerStateChangeStartWatcher();
835 }]);
836