summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-06-11 14:22:02 +0300
committerMichael Lando <ml636r@att.com>2017-06-11 17:48:32 +0300
commitb3d4898d9e8452ea0b8d848c048e712d43b8d9a3 (patch)
tree0609319203be13f6c29ccbe24cb39c9d64f90095 /catalog-ui/src/app/ng2/services
parentaf9929df75604ce407d0ca542b200630164e0ae6 (diff)
[SDC-29] rebase continue work to align source
Change-Id: I218f1c5ee23fb2c8314f1c70921d3ad8682c10f4 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-ui/src/app/ng2/services')
-rw-r--r--catalog-ui/src/app/ng2/services/component-mode.service.ts29
-rw-r--r--catalog-ui/src/app/ng2/services/component-services/service.service.ts2
-rw-r--r--catalog-ui/src/app/ng2/services/data-type.service.ts12
-rw-r--r--catalog-ui/src/app/ng2/services/hierarchy-nav.service.ts63
-rw-r--r--catalog-ui/src/app/ng2/services/properties.service.ts199
5 files changed, 109 insertions, 196 deletions
diff --git a/catalog-ui/src/app/ng2/services/component-mode.service.ts b/catalog-ui/src/app/ng2/services/component-mode.service.ts
new file mode 100644
index 0000000000..12a581e5f9
--- /dev/null
+++ b/catalog-ui/src/app/ng2/services/component-mode.service.ts
@@ -0,0 +1,29 @@
+/**
+ * Created by rc2122 on 5/23/2017.
+ */
+import { Injectable } from '@angular/core';
+import {WorkspaceMode, ComponentState, Role} from "../../utils/constants";
+import { Component as ComponentData } from "app/models";
+import { CacheService } from "app/services/cache-service"
+
+@Injectable()
+
+export class ComponentModeService {
+
+ constructor(private cacheService:CacheService) {
+ }
+
+ public getComponentMode = (component:ComponentData):WorkspaceMode => {//return if is edit or view for resource or service
+ let mode = WorkspaceMode.VIEW;
+
+ let user = this.cacheService.get("user");
+ if (component.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKOUT &&
+ component.lastUpdaterUserId === user.userId) {
+ if ((component.isService() || component.isResource()) && user.role == Role.DESIGNER) {
+ mode = WorkspaceMode.EDIT;
+ }
+ }
+ return mode;
+ }
+}
+
diff --git a/catalog-ui/src/app/ng2/services/component-services/service.service.ts b/catalog-ui/src/app/ng2/services/component-services/service.service.ts
index b47b64c5c2..d2f7078599 100644
--- a/catalog-ui/src/app/ng2/services/component-services/service.service.ts
+++ b/catalog-ui/src/app/ng2/services/component-services/service.service.ts
@@ -20,7 +20,7 @@ export class ServiceServiceNg2 {
validateConformanceLevel(service: Service): Observable<boolean> {
- return this.http.get(this.baseUrl + service.getTypeUrl() + service.uniqueId + '/conformanceLevelValidation')
+ return this.http.get(this.baseUrl + service.getTypeUrl() + service.uuid + '/conformanceLevelValidation')
.map((res: Response) => {
return res.json();
});
diff --git a/catalog-ui/src/app/ng2/services/data-type.service.ts b/catalog-ui/src/app/ng2/services/data-type.service.ts
index e7ea1a8430..be2388144f 100644
--- a/catalog-ui/src/app/ng2/services/data-type.service.ts
+++ b/catalog-ui/src/app/ng2/services/data-type.service.ts
@@ -49,12 +49,14 @@ export class DataTypeService {
return propertiesArray;
}
*/
-
+
public getDerivedDataTypeProperties(dataTypeObj: DataTypeModel, propertiesArray: Array<DerivedFEProperty>, parentName: string) {
//push all child properties to array
if (dataTypeObj.properties) {
dataTypeObj.properties.forEach((derivedProperty) => {
- propertiesArray.push(new DerivedFEProperty(derivedProperty, parentName));
+ if(dataTypeObj.name !== PROPERTY_DATA.OPENECOMP_ROOT || derivedProperty.name !== PROPERTY_DATA.SUPPLEMENTAL_DATA){//The requirement is to not display the property supplemental_data
+ propertiesArray.push(new DerivedFEProperty(derivedProperty, parentName));
+ }
let derivedDataTypeObj: DataTypeModel = this.getDataTypeByTypeName(derivedProperty.type);
this.getDerivedDataTypeProperties(derivedDataTypeObj, propertiesArray, parentName + "#" + derivedProperty.name);
});
@@ -62,8 +64,8 @@ export class DataTypeService {
//recurse parent (derivedFrom), in case one of parents contains properties
if (PROPERTY_DATA.ROOT_DATA_TYPE !== dataTypeObj.derivedFrom.name) {
this.getDerivedDataTypeProperties(dataTypeObj.derivedFrom, propertiesArray, parentName);
- }
- }
-
+ }
+ }
+
}
diff --git a/catalog-ui/src/app/ng2/services/hierarchy-nav.service.ts b/catalog-ui/src/app/ng2/services/hierarchy-nav.service.ts
new file mode 100644
index 0000000000..512505d7c6
--- /dev/null
+++ b/catalog-ui/src/app/ng2/services/hierarchy-nav.service.ts
@@ -0,0 +1,63 @@
+import { Injectable } from '@angular/core';
+import { SimpleFlatProperty, PropertyFEModel, DerivedFEProperty } from 'app/models';
+
+
+@Injectable()
+export class HierarchyNavService {
+ /**
+ * Build hirarchy structure for the tree when user selects on table row.
+ * First create Array<SimpleFlatProperty> and insert also the parent (PropertyFEModel) to this array.
+ * The Array is flat and contains SimpleFlatProperty that has parentName and uniqueId.
+ * Now we build hirarchy from this Array (that includes childrens) and return it for the tree
+ *
+ * @argument property: PropertyFEModel - property contains flattenedChildren array of DerivedFEProperty
+ * @returns Array<SimpleFlatProperty> - containing childrens Array<SimpleFlatProperty>, augmantin childrens to SimpleFlatProperty.
+ */
+ public getSimplePropertiesTree(property: PropertyFEModel, instanceName: string): Array<SimpleFlatProperty> {
+ // Build Array of SimpleFlatProperty before unflatten function
+ let flattenProperties: Array<SimpleFlatProperty> = [];
+ flattenProperties.push(this.createSimpleFlatProperty(property, instanceName)); // Push the root property
+ _.each(property.flattenedChildren, (child: DerivedFEProperty): void => {
+ if (child.isChildOfListOrMap && child.schema.property.isSimpleType) return; //do not display non-complex children of list or map
+ flattenProperties.push(this.createSimpleFlatProperty(child, instanceName));
+ });
+
+ let tree = this.unflatten(flattenProperties, '', []);
+ return tree[0].childrens; // Return the childrens without the root.
+ }
+
+ public createSimpleFlatProperty = (property: PropertyFEModel | DerivedFEProperty, instanceName:string): SimpleFlatProperty => {
+ if (property instanceof PropertyFEModel) {
+ return new SimpleFlatProperty(property.uniqueId, property.name, property.name, '', instanceName);
+ } else {
+ let propName: string = (property.isChildOfListOrMap) ? property.mapKey : property.name;
+ return new SimpleFlatProperty(property.uniqueId, property.propertiesName, propName, property.parentName, instanceName);
+ }
+
+ }
+
+ /**
+ * Unflatten Array<SimpleFlatProperty> and build hirarchy.
+ * The result will be Array<SimpleFlatProperty> that augmantin with childrens for each SimpleFlatProperty.
+ */
+ private unflatten(array: Array<SimpleFlatProperty>, parent: any, tree?: any): any {
+ tree = typeof tree !== 'undefined' ? tree : [];
+ parent = typeof parent !== 'undefined' && parent !== '' ? parent : { path: '' };
+
+ var childrens = _.filter(array, (child: SimpleFlatProperty): boolean => {
+ return child.parentName == parent.path;
+ });
+
+ if (!_.isEmpty(childrens)) {
+ if (parent.path == '') {
+ tree = childrens;
+ } else {
+ parent['childrens'] = childrens;
+ }
+ _.each(childrens, (child): void => {
+ this.unflatten(array, child);
+ });
+ }
+ return tree;
+ }
+} \ No newline at end of file
diff --git a/catalog-ui/src/app/ng2/services/properties.service.ts b/catalog-ui/src/app/ng2/services/properties.service.ts
index 638e537cd1..a22e2aed20 100644
--- a/catalog-ui/src/app/ng2/services/properties.service.ts
+++ b/catalog-ui/src/app/ng2/services/properties.service.ts
@@ -8,11 +8,11 @@ import { UUID } from "angular2-uuid";
@Injectable()
export class PropertiesService {
- constructor(private dataTypeService:DataTypeService, private contentAfterLastDotPipe:ContentAfterLastDotPipe) {
+ constructor(private dataTypeService: DataTypeService, private contentAfterLastDotPipe: ContentAfterLastDotPipe) {
}
- public getParentPropertyFEModelFromPath = (properties:Array<PropertyFEModel>, path:string) => {
- let parent:PropertyFEModel = _.find(properties, (property:PropertyFEModel):boolean=>{
+ public getParentPropertyFEModelFromPath = (properties: Array<PropertyFEModel>, path: string) => {
+ let parent: PropertyFEModel = _.find(properties, (property: PropertyFEModel): boolean => {
return property.name === path.substring(0, path.indexOf('#'));
});
return parent;
@@ -33,7 +33,7 @@ export class PropertiesService {
}
//disable parents and children of prop
- public disableRelatedProperties = (property:PropertyFEModel, childPath?: string): void => {
+ public disableRelatedProperties = (property: PropertyFEModel, childPath?: string): void => {
if (!childPath) { //selecting the parent property
property.isSelected = true;
property.flattenedChildren && property.flattenedChildren.map(child => { child.isSelected = false; child.isDisabled = true; });
@@ -41,18 +41,18 @@ export class PropertiesService {
property.isSelected = false;
property.isDisabled = true;
property.flattenedChildren.filter((childProp: DerivedFEProperty) => {
- return (childProp.propertiesName.indexOf(childPath + "#") > -1 //is child of prop to disable
- || childPath.indexOf(childProp.propertiesName + "#") > -1); //is parent of prop to disable
+ return (childProp.propertiesName.indexOf(childPath + "#") === 0 //is child of prop to disable
+ || childPath.indexOf(childProp.propertiesName + "#") === 0); //is parent of prop to disable
}).map((child: DerivedFEProperty) => { child.isSelected = false; child.isDisabled = true; });
}
}
- public getCheckedProperties = (properties:Array<PropertyFEModel>): Array<PropertyBEModel> => {
+ public getCheckedProperties = (properties: Array<PropertyFEModel>): Array<PropertyBEModel> => {
let selectedProps: Array<PropertyBEModel> = [];
properties.forEach(prop => {
if (prop.isSelected && !prop.isDeclared && !prop.isDisabled) {
selectedProps.push(new PropertyBEModel(prop));
- } else if(prop.flattenedChildren) {
+ } else if (prop.flattenedChildren) {
prop.flattenedChildren.forEach((child) => {
if (child.isSelected && !child.isDeclared && !child.isDisabled) {
let childProp = new PropertyBEModel(prop, child); //create it from the parent
@@ -64,186 +64,5 @@ export class PropertiesService {
return selectedProps;
}
- /**
- * Build hirarchy structure for the tree when user selects on table row.
- * First create Array<SimpleFlatProperty> and insert also the parent (PropertyFEModel) to this array.
- * The Array is flat and contains SimpleFlatProperty that has parentName and uniqueId.
- * Now we build hirarchy from this Array (that includes childrens) and return it for the tree
- *
- * @argument property: PropertyFEModel - property contains flattenedChildren array of DerivedFEProperty
- * @returns Array<SimpleFlatProperty> - containing childrens Array<SimpleFlatProperty>, augmantin childrens to SimpleFlatProperty.
- */
- public getSimplePropertiesTree(property: PropertyFEModel, instanceName:string):Array<SimpleFlatProperty> {
- // Build Array of SimpleFlatProperty before unflatten function
- let flattenProperties:Array<SimpleFlatProperty> = [];
- flattenProperties.push(new SimpleFlatProperty(property.uniqueId, property.name, property.name, '', instanceName)); // Push the root property
- _.each(property.flattenedChildren, (child:DerivedFEProperty):void => {
- flattenProperties.push(new SimpleFlatProperty(child.uniqueId, child.propertiesName, child.name, child.parentName, instanceName));
- });
-
- let tree = this.unflatten(flattenProperties, '', []);
- return tree[0].childrens; // Return the childrens without the root.
- }
-
- /**
- * Unflatten Array<SimpleFlatProperty> and build hirarchy.
- * The result will be Array<SimpleFlatProperty> that augmantin with childrens for each SimpleFlatProperty.
- */
- private unflatten( array:Array<SimpleFlatProperty>, parent:any, tree?:any ):any {
- tree = typeof tree!=='undefined' ? tree : [];
- parent = typeof parent!=='undefined' && parent!=='' ? parent : { path: '' };
-
- var childrens = _.filter( array, (child:SimpleFlatProperty):boolean => {
- return child.parentName == parent.path;
- });
-
- if( !_.isEmpty( childrens ) ){
- if( parent.path == '' ){
- tree = childrens;
- } else {
- parent['childrens'] = childrens;
- }
- _.each( childrens, ( child ):void => {
- this.unflatten( array, child );
- });
- }
- return tree;
- }
-
- // TODO: To remove
- // public convertPropertiesToFEAndInitialize(properties: Array<PropertyBEModel>): Array<PropertyFEModel> {
- // let props:Array<PropertyFEModel> = [];
- // _.forEach(properties, (property: PropertyFEModel, index: number) => {
- // props[index] = new PropertyFEModel(property);
- // this.initValueObjectRef(props[index]);
- // if (props[index].isDataType ||
- // ((props[index].type === PROPERTY_TYPES.MAP || props[index].type === PROPERTY_TYPES.LIST) && props[index].schema.property.isDataType)) {
- // props[index].valueObjectRef = props[index].valueObjectRef || {};
- // let defaultValueObject:any = props[index].defaultValue ? JSON.parse(props[index].defaultValue): null;
- // this.createPropertiesTreeForProp(props[index], true, defaultValueObject);
- // }
- // });
- // return props;
- // }
-
- /**
- * Converts a property's map values to properties and adds them to property.childrenProperties
- * @param property - property to add children to
- * @param onlyFirstLevel - recursively retrieve properties for each dataType?
- */
- //TODO: To remove
- // public createPropertyNodesForMapOfDataTypes(property: PropertyFEModel, onlyFirstLevel:boolean):void {
- // property.childrenProperties = [];
- // angular.forEach(property.valueObjectRef,function(itemInMap:any, keyInMap:string){
- // let newProperty: PropertyFEModel = new PropertyFEModel(keyInMap,
- // property.schema.property.type,
- // UUID.UUID(),
- // property,
- // property.valueObjectRef[keyInMap]);
- // !onlyFirstLevel && this.createPropertiesTreeForProp(newProperty);
- // property.childrenProperties.push(newProperty);
- // },this);
- // }
-
-
- /**
- * Converts a property's list values to properties and adds them to property.childrenProperties
- * @param property - property to add children to
- * @param onlyFirstLevel - recursively retrieve properties for each dataType?
- */
- //TODO: To remove
- // public createPropertyNodesForListOfDataTypes(property: PropertyFEModel, onlyFirstLevel:boolean):void {
- // property.childrenProperties = [];
- // property.valueObjectRef.forEach((itemInList:any, index:number):void =>{
- // let newProperty: PropertyFEModel = new PropertyFEModel(this.contentAfterLastDotPipe.transform(property.schema.property.type),
- // property.schema.property.type,
- // UUID.UUID(),
- // property,
- // property.valueObjectRef[index]);
- // !onlyFirstLevel && this.createPropertiesTreeForProp(newProperty);
- // property.childrenProperties.push(newProperty);
- // });
- // }
-
- // private checkIfPropertyDerivedFromSimpleAndUpdateProp(property:PropertyFEModel | SchemaProperty): boolean{
- // property.derivedFromSimpleTypeName = this.dataTypeService.getTypeForDataTypeDerivedFromSimple(property.type);
- // if(property.derivedFromSimpleTypeName){
- // property.isSimpleType = true;
- // property.isDataType = false;
- // }
- // return property.isSimpleType;
- // }
-
- // TODO: Remove
- public createPropertiesTreeForProp(property: PropertyFEModel, onlyFirstLevel?: boolean, defaultValueObj?: any): void {
- }
-
- public getPropertyFEModelFromDerivedPropertyUniqueId(properties: Array<PropertyFEModel>, uniqueId: string): PropertyFEModel {
- // _.each(properties, (property):void => {
- // property.flattenedChildren
-
- // });
-
- // let rootProperty = _.find(properties, (property):boolean => { return property.uniqueId === uniqueId; });
- // if
- return null;
- }
-
- /**
- * Utilizes the dataTypeService to retrieve children properties from dataTypes recursively.
- * @param property
- * @param onlyFirstLevel
- */
- // TODO: To remove
- // public createPropertiesTreeForProp(property: PropertyFEModel, onlyFirstLevel?:boolean, defaultValueObj?:any ):void{
- // if (property.isDataType && !this.checkIfPropertyDerivedFromSimpleAndUpdateProp(property)){
- // let dataType: DataTypeModel = this.dataTypeService.getDataTypeByTypeName(property.type);
- // property.childrenProperties = [];
- // let childrenProperties = this.dataTypeService.getDataTypePropertiesRecursively(dataType);
- // childrenProperties.forEach((childProperty: PropertyBEModel):void => {
- // let childDataTypePropertyObj: PropertyFEModel = new PropertyFEModel(childProperty.name, childProperty.type,UUID.UUID(),property, {}, childProperty.schema);
- // //init empty object in valueObjectRef[childProperty.name] because this property's children should has ref to this obj.
- // if(!property.valueObjectRef[childDataTypePropertyObj.name]){
- // if ((childDataTypePropertyObj.isDataType && !this.checkIfPropertyDerivedFromSimpleAndUpdateProp(childDataTypePropertyObj))
- // || childDataTypePropertyObj.type === PROPERTY_TYPES.MAP){
- // property.valueObjectRef[childDataTypePropertyObj.name] = {};
- // }else if(childDataTypePropertyObj.type === PROPERTY_TYPES.LIST){
- // property.valueObjectRef[childDataTypePropertyObj.name] = [];
- // }
- // }
- // childDataTypePropertyObj.valueObjectRef = property.valueObjectRef[childDataTypePropertyObj.name];
- // property.valueObjectRef[childDataTypePropertyObj.name] = property.valueObjectRef[childProperty.name] || childDataTypePropertyObj.defaultValue;
- // if( !childDataTypePropertyObj.isDataType && defaultValueObj ){//init property default value
- // childDataTypePropertyObj.defaultValue = JSON.stringify(defaultValueObj[childDataTypePropertyObj.name]);
- // }
- // property.childrenProperties.push(childDataTypePropertyObj);
- // !onlyFirstLevel && this.createPropertiesTreeForProp(childDataTypePropertyObj, false, (defaultValueObj ? defaultValueObj[childDataTypePropertyObj.name] : null));
- // });
- // } else if (property.type == PROPERTY_TYPES.MAP && property.schema.property.isDataType && !this.checkIfPropertyDerivedFromSimpleAndUpdateProp(property.schema.property)){
- // if( property.valueObjectRef && !_.isEmpty(property.valueObjectRef)){
- // this.createPropertyNodesForMapOfDataTypes(property, onlyFirstLevel);
- // }
- // } else if (property.type == PROPERTY_TYPES.LIST && property.schema.property.isDataType && !this.checkIfPropertyDerivedFromSimpleAndUpdateProp(property.schema.property)){
- // if( property.valueObjectRef && property.valueObjectRef.length){
- // this.createPropertyNodesForListOfDataTypes(property, onlyFirstLevel);
- // }
- // }
- // }
-}
-
-export class SimpleFlatProperty {
- uniqueId:string;
- path:string;
- name:string;
- parentName:string;
- instanceName:string;
-
- constructor(uniqueId?:string, path?:string, name?: string, parentName?:string, instanceName?:string) {
- this.uniqueId = uniqueId;
- this.path = path;
- this.name = name;
- this.parentName = parentName;
- this.instanceName = instanceName;
- }
-}
+} \ No newline at end of file