aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models/components/product.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/models/components/product.ts')
-rw-r--r--catalog-ui/src/app/models/components/product.ts105
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";
+ }
+}
+
+