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/models/components/product.ts | |
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/models/components/product.ts')
-rw-r--r-- | catalog-ui/src/app/models/components/product.ts | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/catalog-ui/src/app/models/components/product.ts b/catalog-ui/src/app/models/components/product.ts new file mode 100644 index 0000000000..0f2c00e822 --- /dev/null +++ b/catalog-ui/src/app/models/components/product.ts @@ -0,0 +1,105 @@ +/** + * Created by obarda on 2/4/2016. + */ +'use strict'; +import {Component} from "./component"; +import {IProductService} from "../../services/components/product-service"; +import {IGroup, ISubCategory, IMainCategory, ICategoryBase} from "../category"; +import {ComponentMetadata} from "../component-metadata"; + +export class Product extends Component { + + public contacts:Array<string>; + public componentService:IProductService; + public fullName:string; + + constructor(componentService:IProductService, $q:ng.IQService, component?:Product) { + super(componentService, $q, component); + + if (component) { + this.fullName = component.fullName; + this.filterTerm = this.name + ' ' + this.description + ' ' + (this.tags ? this.tags.toString() : '') + ' ' + this.version; + this.contacts = component.contacts; + } + this.componentService = componentService; + this.iconSprite = "sprite-product-icons"; + } + + public deleteGroup = (uniqueId:string):void => { + _.forEach(this.categories, (category:IMainCategory) => { + _.forEach(category.subcategories, (subcategory:ISubCategory) => { + subcategory.groupings = _.reject(subcategory.groupings, (group:IGroup) => { + return group.uniqueId === uniqueId; + }); + if (subcategory.groupings.length == 0) { // if there is no groups, delete the subcategory + category.subcategories = _.reject(category.subcategories, (subcategoryObj:ISubCategory) => { + return subcategoryObj.uniqueId === subcategory.uniqueId; + }); + if (category.subcategories.length == 0) { // if there is no subcategory, delete the category + this.categories = _.reject(this.categories, (categoryObj:IMainCategory) => { + return categoryObj.uniqueId === category.uniqueId; + }); + } + } + }); + }); + }; + + private getCategoryObjectById = (categoriesArray:Array<ICategoryBase>, categoryUniqueId:string):ICategoryBase => { + let categorySelected = _.find(categoriesArray, (category) => { + return category.uniqueId === categoryUniqueId; + }); + return categorySelected; + }; + + public addGroup = (category:IMainCategory, subcategory:ISubCategory, group:IGroup):void => { + if (!this.categories) { + this.categories = new Array<IMainCategory>(); + } + let existingCategory:IMainCategory = <IMainCategory>this.getCategoryObjectById(this.categories, category.uniqueId); + let newGroup = angular.copy(group); + newGroup.filterTerms = undefined; + newGroup.isDisabled = undefined; + if (!existingCategory) { + let newCategory:IMainCategory = angular.copy(category); + newCategory.filteredGroup = undefined; + newCategory.subcategories = []; + let newSubcategory:ISubCategory = angular.copy(subcategory); + newSubcategory.groupings = []; + newSubcategory.groupings.push(newGroup); + newCategory.subcategories.push(newSubcategory); + this.categories.push(newCategory); + } + else { + let existingSubcategory:ISubCategory = <ISubCategory> this.getCategoryObjectById(existingCategory.subcategories, subcategory.uniqueId); + if (!existingSubcategory) { + let newSubcategory:ISubCategory = angular.copy(subcategory); + newSubcategory.groupings = []; + newSubcategory.groupings.push(newGroup); + existingCategory.subcategories.push(newSubcategory); + + } else { + let existingGroup:IGroup = <IGroup> this.getCategoryObjectById(existingSubcategory.groupings, group.uniqueId); + if (!existingGroup) { + existingSubcategory.groupings.push(newGroup); + } + } + } + }; + + getTypeUrl():string { + return 'products/'; + } + + public setComponentMetadata(componentMetadata:ComponentMetadata) { + super.setComponentMetadata(componentMetadata); + this.setComponentDisplayData(); + }; + + setComponentDisplayData():void { + this.filterTerm = this.name + ' ' + this.description + ' ' + (this.tags ? this.tags.toString() : '') + ' ' + this.version; + this.iconSprite = "sprite-product-icons"; + } +} + + |