diff options
author | Michael Lando <ml636r@att.com> | 2017-06-09 03:19:04 +0300 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-06-09 03:19:04 +0300 |
commit | ed64b5edff15e702493df21aa3230b81593e6133 (patch) | |
tree | a4cb01fdaccc34930a8db403a3097c0d1e40914b /catalog-ui/src/app/filters | |
parent | 280f8015d06af1f41a3ef12e8300801c7a5e0d54 (diff) |
[SDC-29] catalog 1707 rebase commit.
Change-Id: I43c3dc5cf44abf5da817649bc738938a3e8388c1
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-ui/src/app/filters')
-rw-r--r-- | catalog-ui/src/app/filters/catalog-status-filter.ts | 18 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/category-type-filter.ts | 28 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/clear-whitespaces-filter.ts | 16 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/entity-filter.ts | 94 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/graph-resource-name-filter.ts | 22 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/resource-name-filter.ts | 21 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/resource-type-filter.ts | 17 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/string-to-date-filter.ts | 12 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/tests-id-filter.ts | 11 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/trim-filter.ts | 15 | ||||
-rw-r--r-- | catalog-ui/src/app/filters/truncate-filter.ts | 26 |
11 files changed, 280 insertions, 0 deletions
diff --git a/catalog-ui/src/app/filters/catalog-status-filter.ts b/catalog-ui/src/app/filters/catalog-status-filter.ts new file mode 100644 index 0000000000..c28ec1d1e5 --- /dev/null +++ b/catalog-ui/src/app/filters/catalog-status-filter.ts @@ -0,0 +1,18 @@ +/** + * Created by obarda on 19/08/2015. + */ +export class CatalogStatusFilter { + + constructor() { + let filter = <CatalogStatusFilter>( (statuses:any) => { + let filtered = []; + angular.forEach(statuses, function (status) { + filtered.push(status); + }); + return filtered; + }); + + return filter; + } +} + diff --git a/catalog-ui/src/app/filters/category-type-filter.ts b/catalog-ui/src/app/filters/category-type-filter.ts new file mode 100644 index 0000000000..66663263c3 --- /dev/null +++ b/catalog-ui/src/app/filters/category-type-filter.ts @@ -0,0 +1,28 @@ +import {ComponentType} from "../utils/constants"; +import {CacheService} from "../services/cache-service"; +export class CategoryTypeFilter { + + static $inject = ['Sdc.Services.CacheService']; + + constructor(cacheService:CacheService) { + let filter = <CategoryTypeFilter>(categories:any, selectedType:Array<string>, selectedSubResourceTypes:Array<string>) => { + + if (selectedType.indexOf(ComponentType.RESOURCE) === -1 && selectedSubResourceTypes.length > 0) { + selectedType = selectedType.concat([ComponentType.RESOURCE]); + } + + if (!selectedType.length) + return categories; + + let filteredCategories:any = []; + selectedType.forEach((type:string) => { + filteredCategories = filteredCategories.concat(cacheService.get(type.toLowerCase() + 'Categories')); + }); + + return _.filter(categories, function (category:any) { + return filteredCategories.indexOf(category) != -1; + }); + }; + return filter; + } +} diff --git a/catalog-ui/src/app/filters/clear-whitespaces-filter.ts b/catalog-ui/src/app/filters/clear-whitespaces-filter.ts new file mode 100644 index 0000000000..ea6129e22b --- /dev/null +++ b/catalog-ui/src/app/filters/clear-whitespaces-filter.ts @@ -0,0 +1,16 @@ +export class ClearWhiteSpacesFilter { + + constructor() { + let filter = <ClearWhiteSpacesFilter>( (text:string) => { + if (!angular.isString(text)) { + return text; + } + + return text.replace(/ /g, ''); // remove also whitespaces inside + }); + + return filter; + } +} + + diff --git a/catalog-ui/src/app/filters/entity-filter.ts b/catalog-ui/src/app/filters/entity-filter.ts new file mode 100644 index 0000000000..97d9b85f9b --- /dev/null +++ b/catalog-ui/src/app/filters/entity-filter.ts @@ -0,0 +1,94 @@ +import {Component, Resource} from "../models"; +export class EntityFilter { + + constructor() { + + let filter = <EntityFilter>( (components:Array<Component>, filter:any) => { + + let filteredComponents:Array<Component> = components; + + // filter by type + // -------------------------------------------------------------------------- + if ((filter.selectedComponentTypes && filter.selectedComponentTypes.length > 0) || (filter.selectedResourceSubTypes && filter.selectedResourceSubTypes.length > 0)) { + let filteredTypes = []; + angular.forEach(components, (component:Component):void => { + // Filter by component type + let typeLower:string = component.componentType.toLowerCase(); + let typeFirstCapital:string = typeLower.charAt(0).toUpperCase() + typeLower.slice(1); + if (filter.selectedComponentTypes.indexOf(typeFirstCapital) !== -1) { + filteredTypes.push(component); + } + + // Filter by resource sub type, only in case the resource checkbox was not selected (because in this case we already added all the components in above section). + if (component.isResource() && filter.selectedComponentTypes.indexOf("Resource") === -1 && filter.selectedResourceSubTypes.length > 0) { + //filteredComponents.pop(); // Remove the last inserted component. + let resource:Resource = <Resource>component; + if (filter.selectedResourceSubTypes.indexOf(resource.getComponentSubType()) !== -1) { + filteredTypes.push(component); + } + } + }); + filteredComponents = filteredTypes; + } + + // filter by categories & subcategories & groupings + // -------------------------------------------------------------------------- + if (filter.selectedCategoriesModel && filter.selectedCategoriesModel.length > 0) { + let filteredCategories = []; + angular.forEach(filteredComponents, (component:Component):void => { + if (component.categories && filter.selectedCategoriesModel.indexOf(component.categories[0].uniqueId) !== -1) { + filteredCategories.push(component); + } else if (component.categories && component.categories[0].subcategories && filter.selectedCategoriesModel.indexOf(component.categories[0].subcategories[0].uniqueId) !== -1) { + filteredCategories.push(component); + } else if (component.categories && component.categories[0].subcategories && component.categories[0].subcategories[0].groupings && filter.selectedCategoriesModel.indexOf(component.categories[0].subcategories[0].groupings[0].uniqueId) !== -1) { + filteredCategories.push(component); + } + }); + filteredComponents = filteredCategories; + } + + // filter by statuses + // -------------------------------------------------------------------------- + if (filter.selectedStatuses && filter.selectedStatuses.length > 0) { + //convert array of array to string array + let selectedStatuses:Array<string> = [].concat.apply([], filter.selectedStatuses); + + let filteredStatuses = []; + angular.forEach(filteredComponents, (component:Component):void => { + if (selectedStatuses.indexOf(component.lifecycleState) > -1) { + filteredStatuses.push(component); + } + //if status DISTRIBUTED && CERTIFIED are selected the component will added in CERTIFIED status , not need to add twice + if (selectedStatuses.indexOf('DISTRIBUTED') > -1 && !(selectedStatuses.indexOf('CERTIFIED') > -1)) { + if (component.distributionStatus && component.distributionStatus.indexOf('DISTRIBUTED') > -1 && component.lifecycleState.indexOf('CERTIFIED') > -1) { + filteredStatuses.push(component); + } + } + }); + filteredComponents = filteredStatuses; + } + + // filter by statuses and distributed + // -------------------------------------------------------------------------- + if (filter.distributed != undefined && filter.distributed.length > 0) { + let filterDistributed:Array<any> = filter.distributed; + let filteredDistributed = []; + angular.forEach(filteredComponents, (entity) => { + filterDistributed.forEach((distribute) => { + let distributeItem = distribute.split(','); + distributeItem.forEach((item) => { + if (item !== undefined && entity.distributionStatus === item) { + filteredDistributed.push(entity); + } + }) + }); + }); + filteredComponents = filteredDistributed; + } + + return filteredComponents; + }); + + return filter; + } +} diff --git a/catalog-ui/src/app/filters/graph-resource-name-filter.ts b/catalog-ui/src/app/filters/graph-resource-name-filter.ts new file mode 100644 index 0000000000..a4698612f6 --- /dev/null +++ b/catalog-ui/src/app/filters/graph-resource-name-filter.ts @@ -0,0 +1,22 @@ +export class GraphResourceNameFilter { + + constructor() { + let filter = <GraphResourceNameFilter>( (name:string) => { + let context = document.createElement("canvas").getContext("2d"); + context.font = "13px Arial"; + + if (67 < context.measureText(name).width) { + let newLen = name.length - 3; + let newName = name.substring(0, newLen); + + while (59 < (context.measureText(newName).width)) { + newName = newName.substring(0, (--newLen)); + } + return newName + '...'; + } + + return name; + }); + return filter; + } +} diff --git a/catalog-ui/src/app/filters/resource-name-filter.ts b/catalog-ui/src/app/filters/resource-name-filter.ts new file mode 100644 index 0000000000..cd0189dc9a --- /dev/null +++ b/catalog-ui/src/app/filters/resource-name-filter.ts @@ -0,0 +1,21 @@ +export class ResourceNameFilter { + + + constructor() { + let filter = <ResourceNameFilter>( (name:string) => { + if (name) { + //let newName:string = _.last(name.split('.')); + let newName = + _.last(_.last(_.last(_.last(_.last(_.last(_.last(_.last(name.split('tosca.nodes.')) + .split('network.')).split('relationships.')).split('org.openecomp.')).split('resource.nfv.')) + .split('nodes.module.')).split('cp.')).split('vl.')); + if (newName) { + return newName; + } + return name; + } + }); + + return filter; + } +} diff --git a/catalog-ui/src/app/filters/resource-type-filter.ts b/catalog-ui/src/app/filters/resource-type-filter.ts new file mode 100644 index 0000000000..f2d06f0edd --- /dev/null +++ b/catalog-ui/src/app/filters/resource-type-filter.ts @@ -0,0 +1,17 @@ +import {CacheService} from "../services/cache-service"; + +export class ResourceTypeFilter { + static '$inject' = ['Sdc.Services.CacheService']; + + constructor(cacheService:CacheService) { + let filter = <ResourceTypeFilter>(resourceType:string) => { + let uiConfiguration:any = cacheService.get('UIConfiguration'); + + if (uiConfiguration.resourceTypes && uiConfiguration.resourceTypes[resourceType]) { + return uiConfiguration.resourceTypes[resourceType]; + } + return resourceType; + } + return filter; + } +} diff --git a/catalog-ui/src/app/filters/string-to-date-filter.ts b/catalog-ui/src/app/filters/string-to-date-filter.ts new file mode 100644 index 0000000000..846180a2cc --- /dev/null +++ b/catalog-ui/src/app/filters/string-to-date-filter.ts @@ -0,0 +1,12 @@ +export class StringToDateFilter { + + constructor() { + let filter = <StringToDateFilter>( (date:string) => { + if (date) { + return new Date(date.replace(" UTC", '').replace(" ", 'T') + '+00:00'); + } + }); + return filter; + } +} + diff --git a/catalog-ui/src/app/filters/tests-id-filter.ts b/catalog-ui/src/app/filters/tests-id-filter.ts new file mode 100644 index 0000000000..0e5af31169 --- /dev/null +++ b/catalog-ui/src/app/filters/tests-id-filter.ts @@ -0,0 +1,11 @@ +export class TestsIdFilter { + + constructor() { + let filter = <TestsIdFilter>( (testId:string) => { + return testId.replace(/\s/g, '_').toLowerCase(); + }); + + return filter; + } +} + diff --git a/catalog-ui/src/app/filters/trim-filter.ts b/catalog-ui/src/app/filters/trim-filter.ts new file mode 100644 index 0000000000..f174034748 --- /dev/null +++ b/catalog-ui/src/app/filters/trim-filter.ts @@ -0,0 +1,15 @@ +export class TrimFilter { + + constructor() { + let filter = <TrimFilter>( (text:string) => { + if (!angular.isString(text)) { + return text; + } + + return text.replace(/^\s+|\s+$/g, ''); // you could use .trim, but it's not going to work in IE<9 + }); + + return filter; + } +} + diff --git a/catalog-ui/src/app/filters/truncate-filter.ts b/catalog-ui/src/app/filters/truncate-filter.ts new file mode 100644 index 0000000000..e660871e3b --- /dev/null +++ b/catalog-ui/src/app/filters/truncate-filter.ts @@ -0,0 +1,26 @@ +export class TruncateFilter { + constructor() { + let filter = <TruncateFilter>(str:string, length:number) => { + if (str.length <= length) { + return str; + } + + //if(str[length - 1] === ' '){ + // return str.substring(0, length - 1) + '...'; + //} + + let char; + let index = length; + while (char !== ' ' && index !== 0) { + index--; + char = str[index]; + } + if (index === 0) { + return (index === 0) ? str : str.substring(0, length - 3) + '...'; + } + return (index === 0) ? str : str.substring(0, index) + '...'; + }; + return filter; + } + +} |