[SDC-29] catalog 1707 rebase commit.
[sdc.git] / catalog-ui / src / app / app.ts
1 'use strict';
2
3 //import 'restangular';
4 //import 'angular-ui-router';
5 import "reflect-metadata";
6 import 'ng-infinite-scroll';
7 import './modules/filters.ts';
8 import './modules/utils.ts';
9 import './modules/directive-module.ts';
10 import './modules/service-module';
11 import './modules/view-model-module.ts';
12
13 import {
14     IUserResourceClass,
15     DataTypesService,
16     LeftPaletteLoaderService,
17     EcompHeaderService,
18     CookieService,
19     ConfigurationUiService,
20     CacheService,
21     IUserResource,
22     SdcVersionService,
23     ICategoryResourceClass,
24     EntityService
25 } from "./services";
26 import {forwardRef} from '@angular/core';
27 import {UpgradeAdapter} from '@angular/upgrade';
28 import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States} from "./utils";
29 import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
30 import {ComponentFactory} from "./utils/component-factory";
31 import {ModalsHandler} from "./utils/modals-handler";
32 import {downgradeComponent} from "@angular/upgrade/static";
33
34 import {AppModule} from './ng2/app.module';
35 import {PropertiesAssignmentComponent} from "./ng2/pages/properties-assignment/properties-assignment.page.component";
36 import {Component} from "./models/components/component";
37 import {ComponentServiceNg2} from "./ng2/services/component-services/component.service";
38 import {ComponentMetadata} from "./models/component-metadata";
39 import {Categories} from "./models/categories";
40
41
42 let moduleName:string = 'sdcApp';
43 let viewModelsModuleName:string = 'Sdc.ViewModels';
44 let directivesModuleName:string = 'Sdc.Directives';
45 let servicesModuleName:string = 'Sdc.Services';
46 let filtersModuleName:string = 'Sdc.Filters';
47 let utilsModuleName:string = 'Sdc.Utils';
48
49 // Load configuration according to environment.
50 declare var __ENV__:string;
51 let sdcConfig:IAppConfigurtaion;
52 let sdcMenu:IAppMenu;
53 let pathPrefix:string = '';
54 if (__ENV__ === 'dev') {
55     sdcConfig = require('./../../configurations/dev.js');
56 } else if (__ENV__ === 'prod') {
57     sdcConfig = require('./../../configurations/prod.js');
58     pathPrefix = 'sdc1/';
59 } else {
60     console.log("ERROR: Environment configuration not found!");
61 }
62 sdcMenu = require('./../../configurations/menu.js');
63
64 let dependentModules:Array<string> = [
65     'ui.router',
66     'ui.bootstrap',
67     'ui.bootstrap.tpls',
68     'ngDragDrop',
69     'ui-notification',
70     'ngResource',
71     'ngSanitize',
72     'naif.base64',
73     'base64',
74     'uuid4',
75     'checklist-model',
76     'angular.filter',
77     'pascalprecht.translate',
78     '720kb.tooltips',
79     'restangular',
80     'angular-clipboard',
81     'angularResizable',
82     'infinite-scroll',
83     viewModelsModuleName,
84     directivesModuleName,
85     servicesModuleName,
86     filtersModuleName,
87     utilsModuleName
88 ];
89
90 // ===================== Hosted applications section ====================
91 // Define here new hosted apps
92 let hostedApplications:Array<IHostedApplication> = [
93     {
94         "moduleName": "dcaeApp",
95         "navTitle": "DCAE",
96         "defaultState": 'dcae.app.home',
97         "state": {
98             "name": "dcae",
99             "url": "/dcae",
100             "relativeHtmlPath": 'dcae-app/dcae-app-view.html',
101             "controllerName": '.DcaeAppViewModel'
102         }
103     }
104 ];
105
106 // Check if module exists (in case the javascript was not loaded).
107 let isModuleExists = (moduleName:string):boolean => {
108     try {
109         angular.module(moduleName);
110         dependentModules.push(moduleName);
111         return true;
112     } catch (e) {
113         console.log('Module ' + moduleName + ' does not exists');
114         return false;
115     }
116 };
117
118 // Check which hosted applications exists
119 _.each(hostedApplications, (hostedApp)=> {
120     if (isModuleExists(hostedApp.moduleName)) {
121         hostedApp['exists'] = true;
122     }
123 });
124 // ===================== Hosted applications section ====================
125
126 export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
127 angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory);
128
129 ng1appModule.config([
130     '$stateProvider',
131     '$translateProvider',
132     '$urlRouterProvider',
133     '$httpProvider',
134     'tooltipsConfigProvider',
135     'NotificationProvider',
136     ($stateProvider:any,
137      $translateProvider:any,
138      $urlRouterProvider:ng.ui.IUrlRouterProvider,
139      $httpProvider:ng.IHttpProvider,
140      tooltipsConfigProvider:any,
141      NotificationProvider:any):void => {
142
143         NotificationProvider.setOptions({
144             delay: 10000,
145             startTop: 10,
146             startRight: 10,
147             closeOnClick: true,
148             verticalSpacing: 20,
149             horizontalSpacing: 20,
150             positionX: 'right',
151             positionY: 'top'
152         });
153
154         $translateProvider.useStaticFilesLoader({
155             prefix: pathPrefix + 'assets/languages/',
156             langKey: '',
157             suffix: '.json?d=' + (new Date()).getTime()
158         });
159         $translateProvider.useSanitizeValueStrategy('escaped');
160         $translateProvider.preferredLanguage('en_US');
161
162         $httpProvider.interceptors.push('Sdc.Services.HeaderInterceptor');
163         $httpProvider.interceptors.push('Sdc.Services.HttpErrorInterceptor');
164         $urlRouterProvider.otherwise('welcome');
165
166         $stateProvider.state(
167             'dashboard', {
168                 url: '/dashboard?show&folder',
169                 templateUrl: "./view-models/dashboard/dashboard-view.html",
170                 controller: viewModelsModuleName + '.DashboardViewModel',
171             }
172         );
173
174         $stateProvider.state(
175             'welcome', {
176                 url: '/welcome',
177                 templateUrl: "./view-models/welcome/welcome-view.html",
178                 controller: viewModelsModuleName + '.WelcomeViewModel'
179             }
180         );
181
182         let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => {
183             if (cacheService.get('breadcrumbsComponents')) {
184                 return cacheService.get('breadcrumbsComponents');
185             } else {
186                 return EntityService.getCatalog();
187             }
188         }];
189
190         $stateProvider.state(
191             'workspace', {
192                 url: '/workspace/:id/:type/',
193                 params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
194                 templateUrl: './view-models/workspace/workspace-view.html',
195                 controller: viewModelsModuleName + '.WorkspaceViewModel',
196                 resolve: {
197                     injectComponent: ['$stateParams', 'ComponentFactory', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, ComponentServiceNg2:ComponentServiceNg2) {
198                         if ($stateParams.id) {
199                             return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id);
200                         } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
201                             return $stateParams.componentCsar;
202                         } else {
203                             let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
204                             if (emptyComponent.isResource() && $stateParams.resourceType) {
205                                 // Set the resource type
206                                 (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
207                             }
208                             if ($stateParams.importedFile) {
209                                 (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
210                             }
211                             return emptyComponent;
212                         }
213                     }],
214                     components: componentsParam
215                 }
216             }
217         );
218
219         $stateProvider.state(
220             States.WORKSPACE_GENERAL, {
221                 url: 'general',
222                 parent: 'workspace',
223                 controller: viewModelsModuleName + '.GeneralViewModel',
224                 templateUrl: './view-models/workspace/tabs/general/general-view.html',
225                 data: {unsavedChanges: false, bodyClass: 'general'}
226             }
227         );
228         //
229         $stateProvider.state(
230             States.WORKSPACE_ICONS, {
231                 url: 'icons',
232                 parent: 'workspace',
233                 controller: viewModelsModuleName + '.IconsViewModel',
234                 templateUrl: './view-models/workspace/tabs/icons/icons-view.html',
235                 data: {unsavedChanges: false, bodyClass: 'icons'}
236
237             }
238         );
239
240         $stateProvider.state(
241             States.WORKSPACE_ACTIVITY_LOG, {
242                 url: 'activity_log',
243                 parent: 'workspace',
244                 controller: viewModelsModuleName + '.ActivityLogViewModel',
245                 templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
246                 data: {unsavedChanges: false}
247             }
248         );
249
250         $stateProvider.state(
251             States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
252                 url: 'deployment_artifacts',
253                 parent: 'workspace',
254                 controller: viewModelsModuleName + '.DeploymentArtifactsViewModel',
255                 templateUrl: './view-models/workspace/tabs/deployment-artifacts/deployment-artifacts-view.html',
256                 data: {
257                     bodyClass: 'deployment_artifacts'
258                 }
259             }
260         );
261
262         $stateProvider.state(
263             States.WORKSPACE_HIERARCHY, {
264                 url: 'hierarchy',
265                 parent: 'workspace',
266                 controller: viewModelsModuleName + '.ProductHierarchyViewModel',
267                 templateUrl: './view-models/workspace/tabs/product-hierarchy/product-hierarchy-view.html',
268                 data: {unsavedChanges: false}
269
270             }
271         );
272
273         $stateProvider.state(
274             States.WORKSPACE_INFORMATION_ARTIFACTS, {
275                 url: 'information_artifacts',
276                 parent: 'workspace',
277                 controller: viewModelsModuleName + '.InformationArtifactsViewModel',
278                 templateUrl: './view-models/workspace/tabs/information-artifacts/information-artifacts-view.html',
279                 data: {
280                     bodyClass: 'information_artifacts'
281                 }
282             }
283         );
284
285         $stateProvider.state(
286             States.WORKSPACE_TOSCA_ARTIFACTS, {
287                 url: 'tosca_artifacts',
288                 parent: 'workspace',
289                 controller: viewModelsModuleName + '.ToscaArtifactsViewModel',
290                 templateUrl: './view-models/workspace/tabs/tosca-artifacts/tosca-artifacts-view.html',
291                 data: {
292                     bodyClass: 'tosca_artifacts'
293                 }
294             }
295         );
296
297         $stateProvider.state(
298             States.WORKSPACE_PROPERTIES, {
299                 url: 'properties',
300                 parent: 'workspace',
301                 controller: viewModelsModuleName + '.PropertiesViewModel',
302                 templateUrl: './view-models/workspace/tabs/properties/properties-view.html',
303                 data: {
304                     bodyClass: 'properties'
305                 }
306             }
307         );
308
309         $stateProvider.state(
310             States.WORKSPACE_SERVICE_INPUTS, {
311                 url: 'service_inputs',
312                 parent: 'workspace',
313                 controller: viewModelsModuleName + '.ServiceInputsViewModel',
314                 templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
315                 data: {
316                     bodyClass: 'workspace-inputs'
317                 }
318             }
319         );
320
321         $stateProvider.state(
322             States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
323                 url: 'properties_assignment',
324                 params: {'component': null},
325                 template: '<properties-assignment></properties-assignment>',
326                 parent: 'workspace',
327                 resolve: {
328                     componentData: ['injectComponent', '$stateParams', function (injectComponent:Component, $stateParams) {
329                         //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
330                         $stateParams.component = injectComponent;
331                         return injectComponent;
332                     }],
333                 },
334                 data: {
335                     bodyClass: 'properties-assignment'
336                 }
337             }
338         );
339
340         $stateProvider.state(
341             States.WORKSPACE_RESOURCE_INPUTS, {
342                 url: 'resource_inputs',
343                 parent: 'workspace',
344                 controller: viewModelsModuleName + '.ResourceInputsViewModel',
345                 templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
346                 data: {
347                     bodyClass: 'workspace-inputs'
348                 }
349             }
350         );
351
352         $stateProvider.state(
353             States.WORKSPACE_ATTRIBUTES, {
354                 url: 'attributes',
355                 parent: 'workspace',
356                 controller: viewModelsModuleName + '.AttributesViewModel',
357                 templateUrl: './view-models/workspace/tabs/attributes/attributes-view.html',
358                 data: {
359                     bodyClass: 'attributes'
360                 }
361             }
362         );
363
364         $stateProvider.state(
365             States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES, {
366                 url: 'req_and_capabilities',
367                 parent: 'workspace',
368                 controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
369                 templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-view.html',
370                 data: {
371                     bodyClass: 'attributes'
372                 }
373             }
374         );
375
376
377         $stateProvider.state(
378             States.WORKSPACE_MANAGEMENT_WORKFLOW, {
379                 parent: 'workspace',
380                 url: 'management_workflow',
381                 templateUrl: './view-models/workspace/tabs/management-workflow/management-workflow-view.html',
382                 controller: viewModelsModuleName + '.ManagementWorkflowViewModel'
383             }
384         );
385
386         $stateProvider.state(
387             States.WORKSPACE_NETWORK_CALL_FLOW, {
388                 parent: 'workspace',
389                 url: 'network_call_flow',
390                 templateUrl: './view-models/workspace/tabs/network-call-flow/network-call-flow-view.html',
391                 controller: viewModelsModuleName + '.NetworkCallFlowViewModel'
392             }
393         );
394
395         $stateProvider.state(
396             States.WORKSPACE_DISTRIBUTION, {
397                 parent: 'workspace',
398                 url: 'distribution',
399                 templateUrl: './view-models/workspace/tabs/distribution/distribution-view.html',
400                 controller: viewModelsModuleName + '.DistributionViewModel'
401             }
402         );
403
404         $stateProvider.state(
405             States.WORKSPACE_COMPOSITION, {
406                 url: 'composition/',
407                 parent: 'workspace',
408                 controller: viewModelsModuleName + '.CompositionViewModel',
409                 templateUrl: './view-models/workspace/tabs/composition/composition-view.html',
410                 data: {
411                     bodyClass: 'composition'
412                 }
413             }
414         );
415
416         // $stateProvider.state(
417         //     States.WORKSPACE_NG2, {
418         //         url: 'ng2/',
419         //        component: downgradeComponent({component: NG2Example2Component}), //viewModelsModuleName + '.NG2Example',
420         //        templateUrl: './ng2/view-ng2/ng2.example2/ng2.example2.component.html'
421         //     }
422         // );
423
424         $stateProvider.state(
425             States.WORKSPACE_DEPLOYMENT, {
426                 url: 'deployment/',
427                 parent: 'workspace',
428                 templateUrl: './view-models/workspace/tabs/deployment/deployment-view.html',
429                 controller: viewModelsModuleName + '.DeploymentViewModel',
430                 data: {
431                     bodyClass: 'composition'
432                 }
433             }
434         );
435
436         $stateProvider.state(
437             'workspace.composition.details', {
438                 url: 'details',
439                 parent: 'workspace.composition',
440                 templateUrl: './view-models/workspace/tabs/composition/tabs/details/details-view.html',
441                 controller: viewModelsModuleName + '.DetailsViewModel'
442             }
443         );
444
445         $stateProvider.state(
446             'workspace.composition.properties', {
447                 url: 'properties',
448                 parent: 'workspace.composition',
449                 templateUrl: './view-models/workspace/tabs/composition/tabs/properties-and-attributes/properties-view.html',
450                 controller: viewModelsModuleName + '.ResourcePropertiesViewModel'
451             }
452         );
453
454         $stateProvider.state(
455             'workspace.composition.artifacts', {
456                 url: 'artifacts',
457                 parent: 'workspace.composition',
458                 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
459                 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
460             }
461         );
462
463         $stateProvider.state(
464             'workspace.composition.relations', {
465                 url: 'relations',
466                 parent: 'workspace.composition',
467                 templateUrl: './view-models/workspace/tabs/composition/tabs/relations/relations-view.html',
468                 controller: viewModelsModuleName + '.RelationsViewModel'
469             }
470         );
471
472         $stateProvider.state(
473             'workspace.composition.structure', {
474                 url: 'structure',
475                 parent: 'workspace.composition',
476                 templateUrl: './view-models/workspace/tabs/composition/tabs/structure/structure-view.html',
477                 controller: viewModelsModuleName + '.StructureViewModel'
478             }
479         );
480         $stateProvider.state(
481             'workspace.composition.lifecycle', {
482                 url: 'lifecycle',
483                 parent: 'workspace.composition',
484                 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
485                 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
486             }
487         );
488
489         $stateProvider.state(
490             'workspace.composition.api', {
491                 url: 'api',
492                 parent: 'workspace.composition',
493                 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
494                 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
495             }
496         );
497         $stateProvider.state(
498             'workspace.composition.deployment', {
499                 url: 'deployment',
500                 parent: 'workspace.composition',
501                 templateUrl: './view-models/workspace/tabs/composition/tabs/artifacts/artifacts-view.html',
502                 controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
503             }
504         );
505
506         $stateProvider.state(
507             'adminDashboard', {
508                 url: '/adminDashboard',
509                 templateUrl: './view-models/admin-dashboard/admin-dashboard-view.html',
510                 controller: viewModelsModuleName + '.AdminDashboardViewModel',
511                 permissions: ['ADMIN']
512             }
513         );
514
515         $stateProvider.state(
516             'onboardVendor', {
517                 url: '/onboardVendor',
518                 templateUrl: './view-models/onboard-vendor/onboard-vendor-view.html',
519                 controller: viewModelsModuleName + '.OnboardVendorViewModel'//,
520             }
521         );
522
523         // Build the states for all hosted apps dynamically
524         _.each(hostedApplications, (hostedApp)=> {
525             if (hostedApp.exists) {
526                 $stateProvider.state(
527                     hostedApp.state.name, {
528                         url: hostedApp.state.url,
529                         templateUrl: './view-models/dcae-app/dcae-app-view.html',
530                         controller: viewModelsModuleName + hostedApp.state.controllerName
531                     }
532                 );
533             }
534         });
535
536         $stateProvider.state(
537             'catalog', {
538                 url: '/catalog',
539                 templateUrl: './view-models/catalog/catalog-view.html',
540                 controller: viewModelsModuleName + '.CatalogViewModel',
541                 resolve: {
542                     auth: ["$q", "Sdc.Services.UserResourceService", ($q:any, userResourceService:IUserResourceClass) => {
543                         let userInfo:IUserResource = userResourceService.getLoggedinUser();
544                         if (userInfo) {
545                             return $q.when(userInfo);
546                         } else {
547                             return $q.reject({authenticated: false});
548                         }
549                     }]
550                 }
551             }
552         );
553
554         $stateProvider.state(
555             'support', {
556                 url: '/support',
557                 templateUrl: './view-models/support/support-view.html',
558                 controller: viewModelsModuleName + '.SupportViewModel'
559             }
560         );
561
562         $stateProvider.state(
563             'error-403', {
564                 url: '/error-403',
565                 templateUrl: "./view-models/modals/error-modal/error-403-view.html",
566                 controller: viewModelsModuleName + '.ErrorViewModel'
567             }
568         );
569
570         tooltipsConfigProvider.options({
571             side: 'bottom',
572             delay: '600',
573             class: 'tooltip-custom',
574             lazy: 0,
575             try: 0
576         });
577
578     }
579 ]);
580
581 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
582 ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
583 ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
584 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
585 ng1appModule.value('VendorValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
586 ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
587 ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
588 ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
589 ng1appModule.value('LabelValidationPattern', /^[\sa-zA-Z0-9+-]{1,25}$/);
590 ng1appModule.value('UrlValidationPattern', /^(https?|ftp):\/\/(((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([A-Za-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([A-Za-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([A-Za-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([A-Za-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/);
591 ng1appModule.value('IntegerValidationPattern', /^(([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))$/);
592 ng1appModule.value('IntegerNoLeadingZeroValidationPattern', /^(0|[-+]?[1-9][0-9]*|[-+]?0x[0-9a-fA-F]+|[-+]?0o[0-7]+)$/);
593 ng1appModule.value('FloatValidationPattern', /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f?$/);
594 ng1appModule.value('NumberValidationPattern', /^((([-+]?\d+)|([-+]?0x[0-9a-fA-F]+))|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?))$/);
595 ng1appModule.value('KeyValidationPattern', /^[\s\w-]{1,50}$/);
596 ng1appModule.value('CommentValidationPattern', /^[\u0000-\u00BF]*$/);
597 ng1appModule.value('BooleanValidationPattern', /^([Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee])$/);
598 ng1appModule.value('MapKeyValidationPattern', /^[\w]{1,50}$/);
599
600 ng1appModule.constant('sdcConfig', sdcConfig);
601 ng1appModule.constant('sdcMenu', sdcMenu);
602
603 ng1appModule.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);
677                 cacheService.set('productCategories', categories.productCategories);
678             }, onError);
679         };
680
681         // Add hosted applications to sdcConfig
682         sdcConfig.hostedApplications = hostedApplications;
683
684         //handle http config
685         $http.defaults.withCredentials = true;
686         $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
687         $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
688
689         initAsdcVersion();
690         initConfigurationUi();
691        // initLeftPalette();
692         DataTypesService.initDataTypes();
693
694         //handle stateChangeStart
695         let internalDeregisterStateChangeStartWatcher:Function = ():void => {
696             if (deregisterStateChangeStartWatcher) {
697                 deregisterStateChangeStartWatcher();
698                 deregisterStateChangeStartWatcher = null;
699             }
700         };
701
702         let removeLoader:Function = ():void => {
703             $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
704             $(".sdc-loading-page .caption1").addClass("animated fadeOut");
705             $(".sdc-loading-page .caption2").addClass("animated fadeOut");
706             window.setTimeout(():void=> {
707                 $(".sdc-loading-page .main-loader").css("display", "none");
708                 $(".sdc-loading-page .caption1").css("display", "none");
709                 $(".sdc-loading-page .caption2").css("display", "none");
710                 $(".sdc-loading-page").addClass("animated fadeOut");
711             }, 1000);
712         };
713
714         let onNavigateOut:Function = (toState, toParams):void => {
715             let onOk = ():void => {
716                 $state.current.data.unsavedChanges = false;
717                 $state.go(toState.name, toParams);
718             };
719
720             let data = sdcMenu.alertMessages.exitWithoutSaving;
721             //open notify to user if changes are not saved
722             ModalsHandler.openAlertModal(data.title, data.message).then(onOk);
723         };
724
725         let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
726             console.info((new Date()).getTime());
727             console.info('$stateChangeStart', toState.name);
728             //set body class
729             $rootScope['bodyClass'] = 'default-class';
730             if (toState.data && toState.data.bodyClass) {
731                 $rootScope['bodyClass'] = toState.data.bodyClass;
732             }
733
734             // Workaround in case we are entering other state then workspace (user move to catalog)
735             // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
736             if (toState.name.indexOf('workspace') === -1) {
737                 if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
738                     cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
739                 }
740             }
741
742             //saving last state to params , for breadcrumbs
743             if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
744                 toParams.previousState = fromState.name;
745             } else {
746                 toParams.previousState = fromParams.previousState;
747             }
748
749             if (toState.name !== 'error-403' && !UserResourceClass.getLoggedinUser()) {
750                 internalDeregisterStateChangeStartWatcher();
751                 event.preventDefault();
752
753                 UserResourceClass.authorize().$promise.then((user:IUserResource) => {
754                     if (!doesUserHasAccess(toState, user)) {
755                         $state.go('error-403');
756                         console.info('User has no permissions');
757                         registerStateChangeStartWatcher();
758                         return;
759                     }
760                     UserResourceClass.setLoggedinUser(user);
761                     cacheService.set('user', user);
762                     initCategories();
763                     //   initEcompMenu(user);
764                     setTimeout(function () {
765
766                         removeLoader();
767
768                         // initCategories();
769                         if (UserResourceClass.getLoggedinUser().role === 'ADMIN') {
770                             // toState.name = "adminDashboard";
771                             $state.go("adminDashboard", toParams);
772                             registerStateChangeStartWatcher();
773                             return;
774                         }
775
776                         // After user authorized init categories
777                         window.setTimeout(():void=> {
778                             if ($state.current.name === '') {
779                                 $state.go(toState.name, toParams);
780                             }
781
782                             console.log("------$state.current.name=" + $state.current.name);
783                             console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
784                             registerStateChangeStartWatcher();
785
786                         }, 1000);
787
788                     }, 0);
789
790                 }, () => {
791                     $state.go('error-403');
792
793                     console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
794                     registerStateChangeStartWatcher();
795                 });
796             }
797             else if (UserResourceClass.getLoggedinUser()) {
798                 internalDeregisterStateChangeStartWatcher();
799                 if (!doesUserHasAccess(toState, UserResourceClass.getLoggedinUser())) {
800                     event.preventDefault();
801                     $state.go('error-403');
802                     console.info('User has no permissions');
803                 }
804                 if (toState.name === "welcome") {
805                     $state.go("dashboard");
806                 }
807                 registerStateChangeStartWatcher();
808                 //if form is dirty and not save  - notify to user
809                 if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
810                     event.preventDefault();
811                     onNavigateOut(toState, toParams);
812                 }
813             }
814
815         };
816
817         let doesUserHasAccess:Function = (toState, user):boolean => {
818
819             let isUserHasAccess = true;
820             if (toState.permissions && toState.permissions.length > 0) {
821                 isUserHasAccess = _.includes(toState.permissions, user.role);
822             }
823             return isUserHasAccess;
824         };
825         let deregisterStateChangeStartWatcher:Function;
826
827         let registerStateChangeStartWatcher:Function = ():void => {
828             internalDeregisterStateChangeStartWatcher();
829             console.info('registerStateChangeStartWatcher $stateChangeStart');
830             deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
831                 onStateChangeStart(event, toState, toParams, fromState, fromParams);
832             });
833         };
834
835         registerStateChangeStartWatcher();
836     }]);
837