2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 * Created by obarda on 2/4/2016.
25 import {Component} from "./component";
26 import {IProductService} from "../../services/components/product-service";
27 import {IGroup, ISubCategory, IMainCategory, ICategoryBase} from "../category";
28 import {ComponentMetadata} from "../component-metadata";
30 export class Product extends Component {
32 public contacts:Array<string>;
33 public componentService:IProductService;
34 public fullName:string;
36 constructor(componentService:IProductService, $q:ng.IQService, component?:Product) {
37 super(componentService, $q, component);
40 this.fullName = component.fullName;
41 this.filterTerm = this.name + ' ' + this.description + ' ' + (this.tags ? this.tags.toString() : '') + ' ' + this.version;
42 this.contacts = component.contacts;
44 this.componentService = componentService;
45 this.iconSprite = "sprite-product-icons";
48 public deleteGroup = (uniqueId:string):void => {
49 _.forEach(this.categories, (category:IMainCategory) => {
50 _.forEach(category.subcategories, (subcategory:ISubCategory) => {
51 subcategory.groupings = _.reject(subcategory.groupings, (group:IGroup) => {
52 return group.uniqueId === uniqueId;
54 if (subcategory.groupings.length == 0) { // if there is no groups, delete the subcategory
55 category.subcategories = _.reject(category.subcategories, (subcategoryObj:ISubCategory) => {
56 return subcategoryObj.uniqueId === subcategory.uniqueId;
58 if (category.subcategories.length == 0) { // if there is no subcategory, delete the category
59 this.categories = _.reject(this.categories, (categoryObj:IMainCategory) => {
60 return categoryObj.uniqueId === category.uniqueId;
68 private getCategoryObjectById = (categoriesArray:Array<ICategoryBase>, categoryUniqueId:string):ICategoryBase => {
69 let categorySelected = _.find(categoriesArray, (category) => {
70 return category.uniqueId === categoryUniqueId;
72 return categorySelected;
75 public addGroup = (category:IMainCategory, subcategory:ISubCategory, group:IGroup):void => {
76 if (!this.categories) {
77 this.categories = new Array<IMainCategory>();
79 let existingCategory:IMainCategory = <IMainCategory>this.getCategoryObjectById(this.categories, category.uniqueId);
80 let newGroup = angular.copy(group);
81 newGroup.filterTerms = undefined;
82 newGroup.isDisabled = undefined;
83 if (!existingCategory) {
84 let newCategory:IMainCategory = angular.copy(category);
85 newCategory.filteredGroup = undefined;
86 newCategory.subcategories = [];
87 let newSubcategory:ISubCategory = angular.copy(subcategory);
88 newSubcategory.groupings = [];
89 newSubcategory.groupings.push(newGroup);
90 newCategory.subcategories.push(newSubcategory);
91 this.categories.push(newCategory);
94 let existingSubcategory:ISubCategory = <ISubCategory> this.getCategoryObjectById(existingCategory.subcategories, subcategory.uniqueId);
95 if (!existingSubcategory) {
96 let newSubcategory:ISubCategory = angular.copy(subcategory);
97 newSubcategory.groupings = [];
98 newSubcategory.groupings.push(newGroup);
99 existingCategory.subcategories.push(newSubcategory);
102 let existingGroup:IGroup = <IGroup> this.getCategoryObjectById(existingSubcategory.groupings, group.uniqueId);
103 if (!existingGroup) {
104 existingSubcategory.groupings.push(newGroup);
110 getTypeUrl():string {
114 public setComponentMetadata(componentMetadata:ComponentMetadata) {
115 super.setComponentMetadata(componentMetadata);
116 this.setComponentDisplayData();
119 setComponentDisplayData():void {
120 this.filterTerm = this.name + ' ' + this.description + ' ' + (this.tags ? this.tags.toString() : '') + ' ' + this.version;
121 this.iconSprite = "sprite-product-icons";