Add DOT to property's name permitted chars
[sdc.git] / catalog-ui / src / app / app.ts
index e7e2828..916815e 100644 (file)
 
 'use strict';
 
-import * as _ from "lodash";
-import "reflect-metadata";
+import { AuthenticationService } from 'app/ng2/services/authentication.service';
+import * as _ from 'lodash';
 import 'ng-infinite-scroll';
-import './modules/filters.ts';
-import './modules/utils.ts';
+import { SdcUiCommon, SdcUiComponents, SdcUiServices } from 'onap-ui-angular';
+import 'reflect-metadata';
+import { IAppConfigurtaion, IAppMenu, IHostedApplication, Resource } from './models';
+import { Component } from './models/components/component';
+import { IUserProperties } from './models/user';
 import './modules/directive-module.ts';
+import './modules/filters.ts';
 import './modules/service-module';
+import './modules/utils.ts';
 import './modules/view-model-module.ts';
-import {SdcUiCommon, SdcUiComponents, SdcUiServices} from 'onap-ui-angular';
-import {
-  CookieService,
-  DataTypesService,
-  EcompHeaderService,
-  LeftPaletteLoaderService
-} from "./services";
-import {CacheService, CatalogService, HomeService} from "./services-ng2";
-import {AuthenticationService} from "app/ng2/services/authentication.service";
-import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, PREVIOUS_CSAR_COMPONENT, States} from "./utils";
-import {IAppConfigurtaion, IAppMenu, IHostedApplication, Resource} from "./models";
-import {ComponentFactory} from "./utils/component-factory";
-import {Component} from "./models/components/component";
-import {IUserProperties} from "./models/user";
-import {WorkspaceService} from "./ng2/pages/workspace/workspace.service";
-
-let moduleName: string = 'sdcApp';
-let viewModelsModuleName: string = 'Sdc.ViewModels';
-let directivesModuleName: string = 'Sdc.Directives';
-let servicesModuleName: string = 'Sdc.Services';
-let filtersModuleName: string = 'Sdc.Filters';
-let utilsModuleName: string = 'Sdc.Utils';
+import { WorkspaceService } from './ng2/pages/workspace/workspace.service';
+import { CookieService, DataTypesService, EcompHeaderService, LeftPaletteLoaderService } from './services';
+import { CacheService, CatalogService, HomeService } from './services-ng2';
+import { CHANGE_COMPONENT_CSAR_VERSION_FLAG, PREVIOUS_CSAR_COMPONENT, States } from './utils';
+import { ComponentFactory } from './utils/component-factory';
+
+const moduleName: string = 'sdcApp';
+const viewModelsModuleName: string = 'Sdc.ViewModels';
+const directivesModuleName: string = 'Sdc.Directives';
+const servicesModuleName: string = 'Sdc.Services';
+const filtersModuleName: string = 'Sdc.Filters';
+const utilsModuleName: string = 'Sdc.Utils';
 
 // Load configuration according to environment.
 declare var __ENV__: string;
@@ -62,11 +57,11 @@ if (__ENV__ === 'dev') {
   sdcConfig = require('./../../configurations/prod.js');
   pathPrefix = 'sdc1/';
 } else {
-  console.log("ERROR: Environment configuration not found!");
+  console.log('ERROR: Environment configuration not found!');
 }
 sdcMenu = require('./../../configurations/menu.js');
 
-let dependentModules: Array<string> = [
+const dependentModules: string[] = [
   'ui.router',
   'ui.bootstrap',
   'ui.bootstrap.tpls',
@@ -94,22 +89,22 @@ let dependentModules: Array<string> = [
 
 // ===================== Hosted applications section ====================
 // Define here new hosted apps
-let hostedApplications: Array<IHostedApplication> = [
+const hostedApplications: IHostedApplication[] = [
   {
-    "moduleName": "dcaeApp",
-    "navTitle": "DCAE",
-    "defaultState": 'dcae.app.home',
-    "state": {
-      "name": "dcae",
-      "url": "/dcae",
-      "relativeHtmlPath": 'dcae-app/dcae-app-view.html',
-      "controllerName": '.DcaeAppViewModel'
+    moduleName: 'dcaeApp',
+    navTitle: 'DCAE',
+    defaultState: 'dcae.app.home',
+    state: {
+      name: 'dcae',
+      url: '/dcae',
+      relativeHtmlPath: 'dcae-app/dcae-app-view.html',
+      controllerName: '.DcaeAppViewModel'
     }
   }
 ];
 
 // Check if module exists (in case the javascript was not loaded).
-let isModuleExists = (moduleName: string): boolean => {
+const isModuleExists = (moduleName: string): boolean => {
   try {
     angular.module(moduleName);
     dependentModules.push(moduleName);
@@ -123,7 +118,7 @@ let isModuleExists = (moduleName: string): boolean => {
 // Check which hosted applications exists
 _.each(hostedApplications, (hostedApp) => {
   if (isModuleExists(hostedApp.moduleName)) {
-    hostedApp['exists'] = true;
+    hostedApp.exists = true;
   }
 });
 // ===================== Hosted applications section ====================
@@ -175,8 +170,7 @@ ng1appModule.config([
         },
     );
 
-
-    let componentsParam: Array<any> = ['$stateParams', 'HomeService', 'CatalogService', 'Sdc.Services.CacheService', ($stateParams: any, HomeService: HomeService, CatalogService: CatalogService, cacheService: CacheService) => {
+    const componentsParam: any[] = ['$stateParams', 'HomeService', 'CatalogService', 'Sdc.Services.CacheService', ($stateParams: any, HomeService: HomeService, CatalogService: CatalogService, cacheService: CacheService) => {
       if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
         const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
         if (breadcrumbsComponents) {
@@ -201,7 +195,7 @@ ng1appModule.config([
       }
     }];
 
-    const oldWorkspaceController: Array<any> = ['$location', ($location: ng.ILocationService) => {
+    const oldWorkspaceController: any[] = ['$location', ($location: ng.ILocationService) => {
       // redirect old /workspace/* urls to /catalog/workspace/* url
       const newUrl = '/catalog' + $location.url();
       console.log('old workspace path - redirecting to:', newUrl);
@@ -216,27 +210,36 @@ ng1appModule.config([
     );
 
     $stateProvider.state(
-        'workspace', {
+        States.TYPE_WORKSPACE, {
+          url: '/:previousState/type-workspace/:type/:id/:subPage',
+          params: {
+              importedFile: null
+          },
+          template: '<app-type-workspace></app-type-workspace>'
+        }
+    );
+
+    $stateProvider.state(
+        States.WORKSPACE, {
           url: '/:previousState/workspace/:id/:type/',
           params: {
-            'importedFile': null,
-            'componentCsar': null,
-            'resourceType': null,
-            'disableButtons': null
+            importedFile: null,
+            componentCsar: null,
+            resourceType: null,
+            disableButtons: null
           },
           templateUrl: './view-models/workspace/workspace-view.html',
           controller: viewModelsModuleName + '.WorkspaceViewModel',
           resolve: {
-            injectComponent: ['$stateParams', 'ComponentFactory', 'workspaceService', 'Sdc.Services.CacheService', function ($stateParams, ComponentFactory: ComponentFactory, workspaceService: WorkspaceService, cacheService: CacheService) {
-
-              if ($stateParams.id && $stateParams.id.length) { //need to check length in case ID is an empty string
+            injectComponent: ['$stateParams', 'ComponentFactory', 'workspaceService', 'Sdc.Services.CacheService', function($stateParams, ComponentFactory: ComponentFactory, workspaceService: WorkspaceService, cacheService: CacheService) {
+              if ($stateParams.id && $stateParams.id.length) { // need to check length in case ID is an empty string
                 return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id).then(
                     (component: Component) => {
                       if ($stateParams.componentCsar && component.isResource()) {
-                        if ((<Resource>component).csarVersion != $stateParams.componentCsar.csarVersion) {
+                        if ((component as Resource).csarVersion != $stateParams.componentCsar.csarVersion) {
                           cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
                         }
-                        component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
+                        component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, component as Resource);
                       }
                       workspaceService.setComponentMetadata(component.componentMetadata);
                       return component;
@@ -244,13 +247,13 @@ ng1appModule.config([
               } else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
                 return $stateParams.componentCsar;
               } else {
-                let emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
+                const emptyComponent = ComponentFactory.createEmptyComponent($stateParams.type.toUpperCase());
                 if (emptyComponent.isResource() && $stateParams.resourceType) {
                   // Set the resource type
-                  (<Resource>emptyComponent).resourceType = $stateParams.resourceType;
+                  (emptyComponent as Resource).resourceType = $stateParams.resourceType;
                 }
                 if ($stateParams.importedFile) {
-                  (<Resource>emptyComponent).importedFile = $stateParams.importedFile;
+                  (emptyComponent as Resource).importedFile = $stateParams.importedFile;
                 }
                 return emptyComponent;
               }
@@ -270,7 +273,6 @@ ng1appModule.config([
         }
     );
 
-
     $stateProvider.state(
         States.WORKSPACE_INFORMATION_ARTIFACTS, {
           url: 'information_artifacts',
@@ -287,7 +289,6 @@ ng1appModule.config([
         }
     );
 
-
     $stateProvider.state(
         States.WORKSPACE_DEPLOYMENT_ARTIFACTS, {
           url: 'deployment_artifacts',
@@ -311,12 +312,11 @@ ng1appModule.config([
     $stateProvider.state(
         States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
           url: 'properties_assignment',
-          params: {'component': null},
+          params: {component: null},
           template: '<properties-assignment></properties-assignment>',
           parent: 'workspace',
           resolve: {
-            componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
-              //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
+            componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
               $stateParams.component = injectComponent;
               return injectComponent;
             }],
@@ -341,7 +341,7 @@ ng1appModule.config([
           parent: 'workspace',
           template: '<attributes-outputs></attributes-outputs>',
           resolve: {
-            componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
+            componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
               $stateParams.component = injectComponent;
               return injectComponent;
             }],
@@ -373,7 +373,6 @@ ng1appModule.config([
         }
     );
 
-
     $stateProvider.state(
         States.WORKSPACE_MANAGEMENT_WORKFLOW, {
           parent: 'workspace',
@@ -392,16 +391,14 @@ ng1appModule.config([
         }
     );
 
-
     $stateProvider.state(
         States.WORKSPACE_COMPOSITION, {
           url: 'composition/',
-          params: {'component': null},
+          params: {component: null},
           parent: 'workspace',
           template: '<composition-page></composition-page>',
           resolve: {
-            componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
-              //injectComponent.componentService = null; // this is for not passing the service so no one will use old api and start using new api
+            componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
               $stateParams.component = injectComponent;
               return injectComponent;
             }],
@@ -442,7 +439,7 @@ ng1appModule.config([
           url: 'details',
           parent: 'workspace.composition',
           resolve: {
-            componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
+            componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
               $stateParams.component = injectComponent;
               return injectComponent;
             }],
@@ -529,7 +526,7 @@ ng1appModule.config([
           parent: 'workspace',
           template: '<plugin-context-view></plugin-context-view>',
           resolve: {
-            componentData: ['injectComponent', '$stateParams', function (injectComponent: Component, $stateParams) {
+            componentData: ['injectComponent', '$stateParams', function(injectComponent: Component, $stateParams) {
               $stateParams.component = injectComponent;
               return injectComponent;
             }],
@@ -580,8 +577,8 @@ ng1appModule.config([
           url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
           template: '<catalog-page></catalog-page>',
           resolve: {
-            auth: ["$q", "AuthenticationServiceNg2", ($q: any, authService: AuthenticationService) => {
-              let userInfo: IUserProperties = authService.getLoggedinUser();
+            auth: ['$q', 'AuthenticationServiceNg2', ($q: any, authService: AuthenticationService) => {
+              const userInfo: IUserProperties = authService.getLoggedinUser();
               if (userInfo) {
                 return $q.when(userInfo);
               } else {
@@ -595,7 +592,7 @@ ng1appModule.config([
     $stateProvider.state(
         'error-403', {
           url: '/error-403',
-          templateUrl: "./view-models/modals/error-modal/error-403-view.html",
+          templateUrl: './view-models/modals/error-modal/error-403-view.html',
           controller: viewModelsModuleName + '.ErrorViewModel'
         }
     );
@@ -612,8 +609,8 @@ ng1appModule.config([
 ]);
 
 ng1appModule.value('ValidationPattern', /^[\s\w\&_.:-]{1,1024}$/);
-ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); //DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
-ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9_:-]{1,50}$/);// DE210977
+ng1appModule.value('ComponentNameValidationPattern', /^(?=.*[^. ])[\s\w\&_.:-]{1,1024}$/); // DE250513 - same as ValidationPattern above, plus requirement that name not consist of dots and/or spaces alone.
+ng1appModule.value('PropertyNameValidationPattern', /^[a-zA-Z0-9._:\-@]{1,100}$/); // DE210977
 ng1appModule.value('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
 ng1appModule.value('VendorReleaseValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
 ng1appModule.value('VendorNameValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,60}$/);
@@ -670,15 +667,14 @@ ng1appModule.run([
     // Add hosted applications to sdcConfig
     sdcConfig.hostedApplications = hostedApplications;
 
-    //handle http config
+    // handle http config
     $http.defaults.withCredentials = true;
-    // $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
     $http.defaults.headers.common[cookieService.getUserIdSuffix()] = cookieService.getUserId();
 
     DataTypesService.loadDataTypesCache(null);
 
-    //handle stateChangeStart
-    let internalDeregisterStateChangeStartWatcher: Function = (): void => {
+    // handle stateChangeStart
+    const internalDeregisterStateChangeStartWatcher: Function = (): void => {
       if (deregisterStateChangeStartWatcher) {
         deregisterStateChangeStartWatcher();
         deregisterStateChangeStartWatcher = null;
@@ -689,59 +685,57 @@ ng1appModule.run([
       }
     };
 
-    let removeLoader: Function = (): void => {
-      $(".sdc-loading-page .main-loader").addClass("animated fadeOut");
-      $(".sdc-loading-page .caption1").addClass("animated fadeOut");
-      $(".sdc-loading-page .caption2").addClass("animated fadeOut");
+    const removeLoader: Function = (): void => {
+      $('.sdc-loading-page .main-loader').addClass('animated fadeOut');
+      $('.sdc-loading-page .caption1').addClass('animated fadeOut');
+      $('.sdc-loading-page .caption2').addClass('animated fadeOut');
       window.setTimeout((): void => {
-        $(".sdc-loading-page .main-loader").css("display", "none");
-        $(".sdc-loading-page .caption1").css("display", "none");
-        $(".sdc-loading-page .caption2").css("display", "none");
-        $(".sdc-loading-page").addClass("animated fadeOut");
+        $('.sdc-loading-page .main-loader').css('display', 'none');
+        $('.sdc-loading-page .caption1').css('display', 'none');
+        $('.sdc-loading-page .caption2').css('display', 'none');
+        $('.sdc-loading-page').addClass('animated fadeOut');
       }, 1000);
     };
 
-    let onNavigateOut: Function = (toState, toParams): void => {
-      let onOk: Function = (): void => {
+    const onNavigateOut: Function = (toState, toParams): void => {
+      const onOk: Function = (): void => {
         $state.current.data.unsavedChanges = false;
         $state.go(toState.name, toParams);
       };
 
-      let data = sdcMenu.alertMessages.exitWithoutSaving;
+      const data = sdcMenu.alertMessages.exitWithoutSaving;
       const okButton = {
-        testId: "OK",
+        testId: 'OK',
         text: sdcMenu.alertMessages.okButton,
         type: SdcUiCommon.ButtonType.warning,
         callback: onOk,
         closeModal: true
       } as SdcUiComponents.ModalButtonComponent;
-      //open notify to user if changes are not saved
+      // open notify to user if changes are not saved
       ModalServiceSdcUI.openWarningModal(data.title,
           data.message,
           'navigate-modal',
           [okButton]);
     };
 
-    let onStateChangeStart: Function = (event, toState, toParams, fromState, fromParams): void => {
-      console.info((new Date()).getTime());
-      console.info('$stateChangeStart', toState.name);
+    const onStateChangeStart: Function = (event, toState, toParams, fromState, fromParams): void => {
+      console.debug((new Date()).getTime());
+      console.debug('$stateChangeStart', toState.name);
       if (toState.name !== 'error-403' && !authService.getLoggedinUser()) {
 
-
         authService.authenticate().subscribe((userInfo: IUserProperties) => {
           if (!doesUserHasAccess(toState, userInfo)) {
             $state.go('error-403');
-            console.info('User has no permissions');
+            console.debug('User has no permissions');
             return;
           }
           authService.setLoggedinUser(userInfo);
-          setTimeout(function () {
+          setTimeout(function() {
 
             removeLoader();
 
             if (authService.getLoggedinUser().role === 'ADMIN') {
-              // toState.name = "adminDashboard";
-              $state.go("adminDashboard", toParams);
+              $state.go('adminDashboard', toParams);
               return;
             }
 
@@ -751,7 +745,7 @@ ng1appModule.run([
                 $state.go(toState.name, toParams);
               }
 
-              console.log("------$state.current.name=" + $state.current.name);
+              console.log('------$state.current.name=' + $state.current.name);
 
             }, 1000);
 
@@ -761,7 +755,7 @@ ng1appModule.run([
           $state.go('error-403');
         });
       } else if (authService.getLoggedinUser()) {
-        let user: IUserProperties = authService.getLoggedinUser();
+        const user: IUserProperties = authService.getLoggedinUser();
         if (!cacheService.contains('user')) {
           cacheService.set('user', user);
         }
@@ -769,17 +763,15 @@ ng1appModule.run([
         if (!doesUserHasAccess(toState, authService.getLoggedinUser())) {
           event.preventDefault();
           $state.go('error-403');
-          console.info('User has no permissions');
+          console.debug('User has no permissions');
         }
 
         if (authService.getLoggedinUser().role === 'ADMIN') {
-          // toState.name = "adminDashboard";
-          $state.go("adminDashboard", toParams);
+          $state.go('adminDashboard', toParams);
           return;
         }
 
-
-        //if form is dirty and not save  - notify to user
+        // if form is dirty and not save  - notify to user
         if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
           event.preventDefault();
           onNavigateOut(toState, toParams);
@@ -797,8 +789,8 @@ ng1appModule.run([
 
     };
 
-    let onStateChangeSuccess: Function = (event, toState, toParams, fromState, fromParams): void => {
-      console.info('$stateChangeSuccess', toState.name);
+    const onStateChangeSuccess: Function = (event, toState, toParams, fromState, fromParams): void => {
+      console.debug('$stateChangeSuccess', toState.name);
 
       // Workaround in case we are entering other state then workspace (user move to catalog)
       // remove the changeComponentCsarVersion, user should open again the VSP list and select one for update.
@@ -811,14 +803,14 @@ ng1appModule.run([
         }
       }
 
-      //set body class
-      $rootScope['bodyClass'] = 'default-class';
+      // set body class
+      $rootScope.bodyClass = 'default-class';
       if (toState.data && toState.data.bodyClass) {
-        $rootScope['bodyClass'] = toState.data.bodyClass;
+        $rootScope.bodyClass = toState.data.bodyClass;
       }
     };
 
-    let doesUserHasAccess: Function = (toState, user): boolean => {
+    const doesUserHasAccess: Function = (toState, user): boolean => {
 
       let isUserHasAccess = true;
       if (toState.permissions && toState.permissions.length > 0) {
@@ -829,9 +821,9 @@ ng1appModule.run([
     let deregisterStateChangeStartWatcher: Function;
     let deregisterStateChangeSuccessWatcher: Function;
 
-    let registerStateChangeStartWatcher: Function = (): void => {
+    const registerStateChangeStartWatcher: Function = (): void => {
       internalDeregisterStateChangeStartWatcher();
-      console.info('registerStateChangeStartWatcher $stateChangeStart');
+      console.debug('registerStateChangeStartWatcher $stateChangeStart');
       deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams): void => {
         onStateChangeStart(event, toState, toParams, fromState, fromParams);
       });
@@ -841,4 +833,3 @@ ng1appModule.run([
     };
     registerStateChangeStartWatcher();
   }]);
-