+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
'use strict';
//import 'restangular';
//import 'angular-ui-router';
+import * as _ from "lodash";
import "reflect-metadata";
import 'ng-infinite-scroll';
import './modules/filters.ts';
import './modules/directive-module.ts';
import './modules/service-module';
import './modules/view-model-module.ts';
+import {SdcUiComponentsNg1Module} from 'sdc-ui/lib/angular';
import {
- IUserResourceClass,
DataTypesService,
LeftPaletteLoaderService,
EcompHeaderService,
CookieService,
ConfigurationUiService,
CacheService,
- IUserResource,
SdcVersionService,
ICategoryResourceClass,
EntityService
} from "./services";
+import { UserService } from "./ng2/services/user.service";
import {forwardRef} from '@angular/core';
import {UpgradeAdapter} from '@angular/upgrade';
-import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States} from "./utils";
+import {CHANGE_COMPONENT_CSAR_VERSION_FLAG, States, PREVIOUS_CSAR_COMPONENT} from "./utils";
import {IAppConfigurtaion, IAppMenu, IMainCategory, Resource, IHostedApplication} from "./models";
import {ComponentFactory} from "./utils/component-factory";
import {ModalsHandler} from "./utils/modals-handler";
import {downgradeComponent} from "@angular/upgrade/static";
import {AppModule} from './ng2/app.module';
-import {PropertiesAssignmentComponent} from "./ng2/pages/properties-assignment/properties-assignment.page.component";
import {Component} from "./models/components/component";
import {ComponentServiceNg2} from "./ng2/services/component-services/component.service";
import {ComponentMetadata} from "./models/component-metadata";
import {Categories} from "./models/categories";
-
+import {IUserProperties} from "./models/user";
let moduleName:string = 'sdcApp';
let viewModelsModuleName:string = 'Sdc.ViewModels';
'angular-clipboard',
'angularResizable',
'infinite-scroll',
+ SdcUiComponentsNg1Module.name,
viewModelsModuleName,
directivesModuleName,
servicesModuleName,
// ===================== Hosted applications section ====================
export const ng1appModule:ng.IModule = angular.module(moduleName, dependentModules);
-angular.module('sdcApp').directive('propertiesAssignment', downgradeComponent({component: PropertiesAssignmentComponent}) as angular.IDirectiveFactory);
ng1appModule.config([
'$stateProvider',
NotificationProvider:any):void => {
NotificationProvider.setOptions({
- delay: 10000,
+ delay: 5000,
startTop: 10,
startRight: 10,
closeOnClick: true,
positionX: 'right',
positionY: 'top'
});
+ NotificationProvider.options.templateUrl = 'notification-custom-template.html';
$translateProvider.useStaticFilesLoader({
prefix: pathPrefix + 'assets/languages/',
$stateProvider.state(
'dashboard', {
- url: '/dashboard?show&folder',
+ url: '/dashboard?show&folder&filter.term&filter.status&filter.distributed',
templateUrl: "./view-models/dashboard/dashboard-view.html",
controller: viewModelsModuleName + '.DashboardViewModel',
}
);
let componentsParam:Array<any> = ['$stateParams', 'Sdc.Services.EntityService', 'Sdc.Services.CacheService', ($stateParams:any, EntityService:EntityService, cacheService:CacheService) => {
- if (cacheService.get('breadcrumbsComponents')) {
- return cacheService.get('breadcrumbsComponents');
+ if (cacheService.get('breadcrumbsComponentsState') === $stateParams.previousState) {
+ const breadcrumbsComponents = cacheService.get('breadcrumbsComponents');
+ if (breadcrumbsComponents) {
+ return breadcrumbsComponents;
+ }
} else {
- return EntityService.getCatalog();
+ let breadcrumbsComponentsPromise;
+ if ($stateParams.previousState === 'dashboard') {
+ breadcrumbsComponentsPromise = EntityService.getAllComponents(true);
+ } else if ($stateParams.previousState === 'catalog') {
+ breadcrumbsComponentsPromise = EntityService.getCatalog();
+ } else {
+ cacheService.remove('breadcrumbsComponentsState');
+ cacheService.remove('breadcrumbsComponents');
+ return [];
+ }
+ breadcrumbsComponentsPromise.then((components) => {
+ cacheService.set('breadcrumbsComponentsState', $stateParams.previousState);
+ cacheService.set('breadcrumbsComponents', components);
+ });
+ return breadcrumbsComponentsPromise;
}
}];
+ const oldWorkspaceController:Array<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);
+ $location.url(newUrl);
+ }];
+
+ $stateProvider.state(
+ 'workspace-old', {
+ url: '/workspace/:id/:type/*workspaceInnerPath',
+ controller: oldWorkspaceController
+ }
+ );
+
$stateProvider.state(
'workspace', {
- url: '/workspace/:id/:type/',
+ url: '/:previousState/workspace/:id/:type/',
params: {'importedFile': null, 'componentCsar': null, 'resourceType': null, 'disableButtons': null},
templateUrl: './view-models/workspace/workspace-view.html',
controller: viewModelsModuleName + '.WorkspaceViewModel',
resolve: {
- injectComponent: ['$stateParams', 'ComponentFactory', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, ComponentServiceNg2:ComponentServiceNg2) {
- if ($stateParams.id) {
- return ComponentFactory.getComponentWithMetadataFromServer($stateParams.type.toUpperCase(), $stateParams.id);
+ injectComponent: ['$stateParams', 'ComponentFactory', 'Sdc.Services.CacheService', 'ComponentServiceNg2', function ($stateParams, ComponentFactory:ComponentFactory, cacheService:CacheService, ComponentServiceNg2:ComponentServiceNg2) {
+
+ 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) {
+ cacheService.set(PREVIOUS_CSAR_COMPONENT, angular.copy(component));
+ }
+ component = ComponentFactory.updateComponentFromCsar($stateParams.componentCsar, <Resource>component);
+ }
+ return component;
+ });
} else if ($stateParams.componentCsar && $stateParams.componentCsar.csarUUID) {
return $stateParams.componentCsar;
} else {
data: {unsavedChanges: false, bodyClass: 'general'}
}
);
- //
- $stateProvider.state(
- States.WORKSPACE_ICONS, {
- url: 'icons',
- parent: 'workspace',
- controller: viewModelsModuleName + '.IconsViewModel',
- templateUrl: './view-models/workspace/tabs/icons/icons-view.html',
- data: {unsavedChanges: false, bodyClass: 'icons'}
-
- }
- );
$stateProvider.state(
States.WORKSPACE_ACTIVITY_LOG, {
parent: 'workspace',
controller: viewModelsModuleName + '.ActivityLogViewModel',
templateUrl: './view-models/workspace/tabs/activity-log/activity-log.html',
- data: {unsavedChanges: false}
}
);
}
);
- $stateProvider.state(
- States.WORKSPACE_HIERARCHY, {
- url: 'hierarchy',
- parent: 'workspace',
- controller: viewModelsModuleName + '.ProductHierarchyViewModel',
- templateUrl: './view-models/workspace/tabs/product-hierarchy/product-hierarchy-view.html',
- data: {unsavedChanges: false}
-
- }
- );
-
$stateProvider.state(
States.WORKSPACE_INFORMATION_ARTIFACTS, {
url: 'information_artifacts',
}
);
- $stateProvider.state(
- States.WORKSPACE_SERVICE_INPUTS, {
- url: 'service_inputs',
- parent: 'workspace',
- controller: viewModelsModuleName + '.ServiceInputsViewModel',
- templateUrl: './view-models/workspace/tabs/inputs/service-input/service-inputs-view.html',
- data: {
- bodyClass: 'workspace-inputs'
- }
- }
- );
-
$stateProvider.state(
States.WORKSPACE_PROPERTIES_ASSIGNMENT, {
url: 'properties_assignment',
}
);
- $stateProvider.state(
- States.WORKSPACE_RESOURCE_INPUTS, {
- url: 'resource_inputs',
- parent: 'workspace',
- controller: viewModelsModuleName + '.ResourceInputsViewModel',
- templateUrl: './view-models/workspace/tabs/inputs/resource-input/resource-inputs-view.html',
- data: {
- bodyClass: 'workspace-inputs'
- }
- }
- );
-
$stateProvider.state(
States.WORKSPACE_ATTRIBUTES, {
url: 'attributes',
}
);
+ $stateProvider.state(
+ States.WORKSPACE_REQUIREMENTS_AND_CAPABILITIES_EDITABLE, {
+ url: 'req_and_capabilities_editable',
+ parent: 'workspace',
+ controller: viewModelsModuleName + '.ReqAndCapabilitiesViewModel',
+ templateUrl: './view-models/workspace/tabs/req-and-capabilities/req-and-capabilities-editable-view.html',
+ data: {
+ bodyClass: 'attributes'
+ }
+ }
+ );
+
$stateProvider.state(
States.WORKSPACE_MANAGEMENT_WORKFLOW, {
controller: viewModelsModuleName + '.ResourceArtifactsViewModel'
}
);
+ $stateProvider.state(
+ 'workspace.composition.consumption', {
+ url: 'consumption',
+ parent: 'workspace.composition',
+ templateUrl: './view-models/workspace/tabs/composition/tabs/service-consumption/service-consumption-view.html',
+ controller: viewModelsModuleName + '.ServiceConsumptionViewModel'
+ }
+ );
+ $stateProvider.state(
+ 'workspace.composition.dependencies', {
+ url: 'dependencies',
+ parent: 'workspace.composition',
+ templateUrl: './view-models/workspace/tabs/composition/tabs/service-dependencies/service-dependencies-view.html',
+ controller: viewModelsModuleName + '.ServiceDependenciesViewModel'
+ }
+ );
+
+ $stateProvider.state(
+ States.WORKSPACE_INTERFACE_OPERATION, {
+ url: 'interface_operation',
+ parent: 'workspace',
+ controller: viewModelsModuleName + '.InterfaceOperationViewModel',
+ templateUrl: './view-models/workspace/tabs/interface-operation/interface-operation-view.html',
+ data: {
+ bodyClass: 'interface_operation'
+ }
+ }
+ );
+
+ $stateProvider.state(
+ 'workspace.plugins', {
+ url: 'plugins/*path',
+ parent: 'workspace',
+ params: {'queryParams': null},
+ templateUrl: './view-models/workspace/tabs/plugins/plugins-context-view.html',
+ controller: viewModelsModuleName + '.PluginsContextViewModel'
+ }
+ );
$stateProvider.state(
'adminDashboard', {
}
);
+ $stateProvider.state(
+ 'plugins', {
+ url: '/plugins/*path',
+ templateUrl: './view-models/plugins/plugins-tab-view.html',
+ controller: viewModelsModuleName + '.PluginsTabViewModel'
+ }
+ );
+
// Build the states for all hosted apps dynamically
_.each(hostedApplications, (hostedApp)=> {
if (hostedApp.exists) {
$stateProvider.state(
'catalog', {
- url: '/catalog',
+ url: '/catalog?filter.components&filter.resourceSubTypes&filter.categories&filter.statuses&filter.order&filter.term&filter.active',
templateUrl: './view-models/catalog/catalog-view.html',
controller: viewModelsModuleName + '.CatalogViewModel',
resolve: {
- auth: ["$q", "Sdc.Services.UserResourceService", ($q:any, userResourceService:IUserResourceClass) => {
- let userInfo:IUserResource = userResourceService.getLoggedinUser();
+ auth: ["$q", "UserServiceNg2", ($q:any, userService:UserService) => {
+ let userInfo:IUserProperties = userService.getLoggedinUser();
if (userInfo) {
return $q.when(userInfo);
} else {
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('TagValidationPattern', /^[\s\w_.-]{1,50}$/);
-ng1appModule.value('VendorValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,25}$/);
+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}$/);
ng1appModule.value('VendorModelNumberValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,65}$/);
+ng1appModule.value('ServiceTypeAndRoleValidationPattern', /^[\x20-\x21\x23-\x29\x2B-\x2E\x30-\x39\x3B\x3D\x40-\x5B\x5D-\x7B\x7D-\xFF]{1,256}$/);
ng1appModule.value('ContactIdValidationPattern', /^[\s\w-]{1,50}$/);
ng1appModule.value('UserIdValidationPattern', /^[\s\w-]{1,50}$/);
ng1appModule.value('ProjectCodeValidationPattern', /^[\s\w-]{5,50}$/);
'Sdc.Services.CacheService',
'Sdc.Services.CookieService',
'Sdc.Services.ConfigurationUiService',
- 'Sdc.Services.UserResourceService',
+ 'UserServiceNg2',
'Sdc.Services.CategoryResourceService',
'Sdc.Services.SdcVersionService',
'$state',
'LeftPaletteLoaderService',
'Sdc.Services.DataTypesService',
'AngularJSBridge',
+ '$templateCache',
($http:ng.IHttpService,
cacheService:CacheService,
cookieService:CookieService,
ConfigurationUi:ConfigurationUiService,
- UserResourceClass:IUserResourceClass,
+ userService:UserService,
categoryResourceService:ICategoryResourceClass,
sdcVersionService:SdcVersionService,
$state:ng.ui.IStateService,
ecompHeaderService:EcompHeaderService,
LeftPaletteLoaderService:LeftPaletteLoaderService,
DataTypesService:DataTypesService,
- AngularJSBridge):void => {
-
+ AngularJSBridge,
+ $templateCache:ng.ITemplateCacheService):void => {
+ $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
+ $templateCache.put('notification-custom-template.html', require('./view-models/shared/notification-custom-template.html'));
//handle cache data - version
let initAsdcVersion:Function = ():void => {
categoryResourceService.getAllCategories((categories: Categories):void => {
cacheService.set('serviceCategories', categories.serviceCategories);
cacheService.set('resourceCategories', categories.resourceCategories);
- cacheService.set('productCategories', categories.productCategories);
}, onError);
};
deregisterStateChangeStartWatcher();
deregisterStateChangeStartWatcher = null;
}
+ if (deregisterStateChangeSuccessWatcher) {
+ deregisterStateChangeSuccessWatcher();
+ deregisterStateChangeSuccessWatcher = null;
+ }
};
let removeLoader:Function = ():void => {
let onStateChangeStart:Function = (event, toState, toParams, fromState, fromParams):void => {
console.info((new Date()).getTime());
console.info('$stateChangeStart', toState.name);
- //set body class
- $rootScope['bodyClass'] = 'default-class';
- if (toState.data && toState.data.bodyClass) {
- $rootScope['bodyClass'] = toState.data.bodyClass;
- }
- // 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.
- if (toState.name.indexOf('workspace') === -1) {
- if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
- cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
+ if (toState.name !== 'error-403' && !userService.getLoggedinUser()) {
+ if (toState.name !== 'welcome') {
+ event.preventDefault();
}
- }
- //saving last state to params , for breadcrumbs
- if (['dashboard', 'catalog', 'onboardVendor'].indexOf(fromState.name) > -1) {
- toParams.previousState = fromState.name;
- } else {
- toParams.previousState = fromParams.previousState;
- }
-
- if (toState.name !== 'error-403' && !UserResourceClass.getLoggedinUser()) {
- internalDeregisterStateChangeStartWatcher();
- event.preventDefault();
-
- UserResourceClass.authorize().$promise.then((user:IUserResource) => {
- if (!doesUserHasAccess(toState, user)) {
+ userService.authorize().subscribe((userInfo:IUserProperties) => {
+ if (!doesUserHasAccess(toState, userInfo)) {
$state.go('error-403');
console.info('User has no permissions');
- registerStateChangeStartWatcher();
return;
}
- UserResourceClass.setLoggedinUser(user);
- cacheService.set('user', user);
+ userService.setLoggedinUser(userInfo);
+ cacheService.set('user', userInfo);
initCategories();
- // initEcompMenu(user);
+ // initEcompMenu(userInfo);
setTimeout(function () {
removeLoader();
// initCategories();
- if (UserResourceClass.getLoggedinUser().role === 'ADMIN') {
+ if (userService.getLoggedinUser().role === 'ADMIN') {
// toState.name = "adminDashboard";
$state.go("adminDashboard", toParams);
- registerStateChangeStartWatcher();
return;
}
}
console.log("------$state.current.name=" + $state.current.name);
- console.info('-----registerStateChangeStartWatcher authorize $stateChangeStart');
- registerStateChangeStartWatcher();
}, 1000);
}, () => {
$state.go('error-403');
-
- console.info('registerStateChangeStartWatcher error-403 $stateChangeStart');
- registerStateChangeStartWatcher();
});
}
- else if (UserResourceClass.getLoggedinUser()) {
- internalDeregisterStateChangeStartWatcher();
- if (!doesUserHasAccess(toState, UserResourceClass.getLoggedinUser())) {
+ else if (userService.getLoggedinUser()) {
+ if (!doesUserHasAccess(toState, userService.getLoggedinUser())) {
event.preventDefault();
$state.go('error-403');
console.info('User has no permissions');
if (toState.name === "welcome") {
$state.go("dashboard");
}
- registerStateChangeStartWatcher();
+
//if form is dirty and not save - notify to user
if (fromState.data && fromState.data.unsavedChanges && fromParams.id != toParams.id) {
event.preventDefault();
}
}
+ // if enetering workspace, set the previousState param
+ if (toState.name.indexOf('workspace') !== -1) {
+ if (!toParams.previousState) {
+ const tmpPreviousState1 = fromParams && fromParams.previousState;
+ const tmpPreviousState2 = (['dashboard', 'catalog'].indexOf(fromState.name) !== -1) ? fromState.name : 'catalog';
+ toParams.previousState = tmpPreviousState1 || tmpPreviousState2;
+ }
+ }
+
+ };
+
+ let onStateChangeSuccess:Function = (event, toState, toParams, fromState, fromParams):void => {
+ console.info('$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.
+ if (toState.name.indexOf('workspace') === -1) {
+ if (cacheService.contains(CHANGE_COMPONENT_CSAR_VERSION_FLAG)) {
+ cacheService.remove(CHANGE_COMPONENT_CSAR_VERSION_FLAG);
+ }
+ if (cacheService.contains(PREVIOUS_CSAR_COMPONENT)){
+ cacheService.remove(PREVIOUS_CSAR_COMPONENT);
+ }
+ }
+
+ //set body class
+ $rootScope['bodyClass'] = 'default-class';
+ if (toState.data && toState.data.bodyClass) {
+ $rootScope['bodyClass'] = toState.data.bodyClass;
+ }
};
let doesUserHasAccess:Function = (toState, user):boolean => {
return isUserHasAccess;
};
let deregisterStateChangeStartWatcher:Function;
+ let deregisterStateChangeSuccessWatcher:Function;
let registerStateChangeStartWatcher:Function = ():void => {
internalDeregisterStateChangeStartWatcher();
deregisterStateChangeStartWatcher = $rootScope.$on('$stateChangeStart', (event, toState, toParams, fromState, fromParams):void => {
onStateChangeStart(event, toState, toParams, fromState, fromParams);
});
+ deregisterStateChangeSuccessWatcher = $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState, fromParams):void => {
+ onStateChangeSuccess(event, toState, toParams, fromState, fromParams);
+ });
};
registerStateChangeStartWatcher();