aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pipes
diff options
context:
space:
mode:
authorys9693 <ys9693@att.com>2020-01-19 13:50:02 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-01-22 12:33:31 +0000
commit16a9fce0e104a38371a9e5a567ec611ae3fc7f33 (patch)
tree03a2aff3060ddb5bc26a90115805a04becbaffc9 /catalog-ui/src/app/ng2/pipes
parentaa83a2da4f911c3ac89318b8e9e8403b072942e1 (diff)
Catalog alignment
Issue-ID: SDC-2724 Signed-off-by: ys9693 <ys9693@att.com> Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe
Diffstat (limited to 'catalog-ui/src/app/ng2/pipes')
-rw-r--r--catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts151
-rw-r--r--catalog-ui/src/app/ng2/pipes/global-pipes.module.ts23
-rw-r--r--catalog-ui/src/app/ng2/pipes/groupBy.pipe.ts3
-rw-r--r--catalog-ui/src/app/ng2/pipes/key-value.pipe.ts41
-rw-r--r--catalog-ui/src/app/ng2/pipes/keys.pipe.ts3
-rw-r--r--catalog-ui/src/app/ng2/pipes/order-by.pipe.ts (renamed from catalog-ui/src/app/ng2/pipes/orderBy.pipe.ts)4
-rw-r--r--catalog-ui/src/app/ng2/pipes/properties-order-by.pipe.ts35
-rw-r--r--catalog-ui/src/app/ng2/pipes/resource-name.pipe.ts13
8 files changed, 265 insertions, 8 deletions
diff --git a/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts b/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts
new file mode 100644
index 0000000000..af107ed006
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pipes/entity-filter.pipe.ts
@@ -0,0 +1,151 @@
+/*-
+ * ============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=========================================================
+ */
+
+import {Pipe, PipeTransform} from "@angular/core";
+import {Component, Resource} from "app/models";
+import {ComponentType} from "app/utils/constants";
+
+export interface ISearchFilter {
+ [key:string]: string;
+}
+
+export interface IEntityFilterObject {
+ // Types
+ selectedComponentTypes?:Array<string>;
+ selectedResourceSubTypes?:Array<string>;
+ // Categories
+ selectedCategoriesModel?:Array<string>;
+ // Statuses
+ selectedStatuses?:Array<string>;
+ // distributed
+ distributed?:Array<string>;
+ // search
+ search?:ISearchFilter;
+
+}
+
+@Pipe({name: 'entity-filter'})
+export class EntityFilterPipe implements PipeTransform{
+ constructor() {
+ }
+
+ public static transform(components:Array<Component>, filter:IEntityFilterObject) {
+ 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 => {
+ let componentCategory = component.categoryNormalizedName +
+ ((component.subCategoryNormalizedName) ? '.' + component.subCategoryNormalizedName : '');
+ if (component.componentType === ComponentType.RESOURCE) {
+ componentCategory = 'resourceNewCategory.' + componentCategory;
+ } else if (component.componentType === ComponentType.SERVICE) {
+ componentCategory = 'serviceNewCategory.' + componentCategory;
+ }
+ if (filter.selectedCategoriesModel.indexOf(componentCategory) !== -1) {
+ filteredCategories.push(component);
+ }
+ });
+ filteredComponents = filteredCategories;
+ }
+
+ // filter by statuses
+ // --------------------------------------------------------------------------
+ if (filter.selectedStatuses && filter.selectedStatuses.length > 0) {
+
+ let filteredStatuses = [];
+ angular.forEach(filteredComponents, (component:Component):void => {
+ if (filter.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 (filter.selectedStatuses.indexOf('DISTRIBUTED') > -1 && !(filter.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;
+ }
+
+ // filter by search
+ // --------------------------------------------------------------------------
+ if (filter.search != undefined) {
+ Object.keys(filter.search).forEach((searchKey) => {
+ let searchVal = filter.search[searchKey];
+ if (searchVal) {
+ searchVal = searchVal.toLowerCase();
+ filteredComponents = filteredComponents.filter((component:Component) =>
+ component[searchKey].toLowerCase().indexOf(searchVal) !== -1);
+ }
+ });
+ }
+
+ return filteredComponents;
+ }
+
+ public transform(components:Array<Component>, filter:IEntityFilterObject) {
+ return EntityFilterPipe.transform(components, filter);
+ }
+}
diff --git a/catalog-ui/src/app/ng2/pipes/global-pipes.module.ts b/catalog-ui/src/app/ng2/pipes/global-pipes.module.ts
index c44d71b30d..66f9518a47 100644
--- a/catalog-ui/src/app/ng2/pipes/global-pipes.module.ts
+++ b/catalog-ui/src/app/ng2/pipes/global-pipes.module.ts
@@ -26,7 +26,10 @@ import {GroupByPipe} from "./groupBy.pipe";
import {ResourceNamePipe} from "./resource-name.pipe";
import {NgModule} from "@angular/core";
import {SafeUrlSanitizerPipe} from "./safeUrlSanitizer.pipe";
-import {OrderByPipe} from "./orderBy.pipe";
+import {EntityFilterPipe} from "./entity-filter.pipe";
+import {KeyValuePipe} from "./key-value.pipe";
+import {PropertiesOrderByPipe} from "./properties-order-by.pipe";
+import {OrderByPipe} from "./order-by.pipe";
@NgModule({
declarations: [
@@ -36,6 +39,9 @@ import {OrderByPipe} from "./orderBy.pipe";
SafeUrlSanitizerPipe,
SearchFilterPipe,
ResourceNamePipe,
+ EntityFilterPipe,
+ KeyValuePipe,
+ PropertiesOrderByPipe,
OrderByPipe
],
exports: [
@@ -45,7 +51,20 @@ import {OrderByPipe} from "./orderBy.pipe";
SafeUrlSanitizerPipe,
SearchFilterPipe,
ResourceNamePipe,
- OrderByPipe
+ EntityFilterPipe,
+ PropertiesOrderByPipe,
+ OrderByPipe,
+ KeyValuePipe
+ ],
+ providers: [
+ ContentAfterLastDotPipe,
+ GroupByPipe,
+ KeysPipe,
+ SafeUrlSanitizerPipe,
+ SearchFilterPipe,
+ ResourceNamePipe,
+ EntityFilterPipe,
+ KeyValuePipe
]
})
diff --git a/catalog-ui/src/app/ng2/pipes/groupBy.pipe.ts b/catalog-ui/src/app/ng2/pipes/groupBy.pipe.ts
index 90dce23352..19811f2f08 100644
--- a/catalog-ui/src/app/ng2/pipes/groupBy.pipe.ts
+++ b/catalog-ui/src/app/ng2/pipes/groupBy.pipe.ts
@@ -26,6 +26,9 @@ import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name: 'groupBy'})
export class GroupByPipe implements PipeTransform {
transform(value: Array<any>, field: string): Array<any> {
+ if(!value) {
+ return null;
+ }
const groupedObj = value.reduce((prev, cur)=> {
if(!prev[cur[field]]) {
prev[cur[field]] = [cur];
diff --git a/catalog-ui/src/app/ng2/pipes/key-value.pipe.ts b/catalog-ui/src/app/ng2/pipes/key-value.pipe.ts
new file mode 100644
index 0000000000..4adb0b12f7
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pipes/key-value.pipe.ts
@@ -0,0 +1,41 @@
+/**
+ * Created by ob0695 on 7/3/2018.
+ */
+/*-
+ * ============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=========================================================
+ */
+
+/**
+ * Created by rc2122 on 5/17/2017.
+ */
+import {Pipe, PipeTransform} from '@angular/core';
+
+@Pipe({name: 'keyValue'})
+export class KeyValuePipe implements PipeTransform {
+ transform(value, field: string): Array<any> {
+ if(!value) {
+ return null;
+ }
+ let keyValueObject = [];
+ for (let key in value) {
+ keyValueObject.push({key:key, value: value[key]});
+ }
+ return keyValueObject;
+ }
+}
diff --git a/catalog-ui/src/app/ng2/pipes/keys.pipe.ts b/catalog-ui/src/app/ng2/pipes/keys.pipe.ts
index 349e9334f7..f8663aca2e 100644
--- a/catalog-ui/src/app/ng2/pipes/keys.pipe.ts
+++ b/catalog-ui/src/app/ng2/pipes/keys.pipe.ts
@@ -23,6 +23,9 @@ import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'keys'})
export class KeysPipe implements PipeTransform {
transform(value, args:string[]) : any {
+ if(!value) {
+ return null;
+ }
let keys = [];
for (let key in value) {
keys.push(key);
diff --git a/catalog-ui/src/app/ng2/pipes/orderBy.pipe.ts b/catalog-ui/src/app/ng2/pipes/order-by.pipe.ts
index 4edbd60f60..6dc5d47863 100644
--- a/catalog-ui/src/app/ng2/pipes/orderBy.pipe.ts
+++ b/catalog-ui/src/app/ng2/pipes/order-by.pipe.ts
@@ -20,10 +20,10 @@
import { Pipe, PipeTransform } from '@angular/core';
-@Pipe({ name: 'orderBy' })
+@Pipe({name: 'orderBy'})
export class OrderByPipe implements PipeTransform {
transform(records: Array<any>, args?: any): any {
- if (!records || !args.path) return records;
+ if (!records || !args.path) { return records; }
let len = args.path.length;
return records.sort((itemIdx1, itemIdx2) => {
var i = 0;
diff --git a/catalog-ui/src/app/ng2/pipes/properties-order-by.pipe.ts b/catalog-ui/src/app/ng2/pipes/properties-order-by.pipe.ts
new file mode 100644
index 0000000000..98debd28d9
--- /dev/null
+++ b/catalog-ui/src/app/ng2/pipes/properties-order-by.pipe.ts
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 Huawei 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=========================================================
+ */
+
+import { Pipe, PipeTransform } from '@angular/core';
+
+@Pipe({ name: 'propertiesOrderBy' })
+export class PropertiesOrderByPipe implements PipeTransform {
+ transform(records: Array<any>, args?: any): any {
+ if (!records || !args.path) return records;
+ let len = args.path.length;
+ return records.sort((itemIdx1, itemIdx2) => {
+ var i = 0;
+ while (i < len) { itemIdx1 = itemIdx1[args.path[i]]; itemIdx2 = itemIdx2[args.path[i]]; i++; }
+ // Order * (-1): We change our order
+ return itemIdx1 + "" > itemIdx2 + "" ? args.direction : args.direction * (- 1);
+ })
+ };
+}
diff --git a/catalog-ui/src/app/ng2/pipes/resource-name.pipe.ts b/catalog-ui/src/app/ng2/pipes/resource-name.pipe.ts
index fdf9526375..0fdbbcaade 100644
--- a/catalog-ui/src/app/ng2/pipes/resource-name.pipe.ts
+++ b/catalog-ui/src/app/ng2/pipes/resource-name.pipe.ts
@@ -20,15 +20,20 @@
import { Pipe, PipeTransform } from '@angular/core';
+import * as _ from 'lodash';
@Pipe({name: 'resourceName'})
export class ResourceNamePipe implements PipeTransform {
+
+ public static getDisplayName (value:string): string {
+ const newName:string =
+ _.last(value.split(/tosca\.nodes\..*network\..*relationships\..*org\.openecomp\..*resource\.nfv\..*nodes\.module\..*cp\..*vl\./));
+ return (newName) ? newName : value;
+ }
+
transform(value) : any {
if (value) {
- //newName = _.last(newName.split('.'));
- const newName:string =
- _.last(value.split(/tosca\.nodes\..*network\..*relationships\..*org\.openecomp\..*resource\.nfv\..*nodes\.module\..*cp\..*vl\./));
- return (newName) ? newName : value;
+ return ResourceNamePipe.getDisplayName(value);
}
}
}