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 4/4/2016.
25 import {ComponentFactory} from "app/utils";
26 import {AvailableIconsService} from "app/services";
27 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
28 import {IMainCategory, ISubCategory} from "app/models";
30 export interface IIconsScope extends IWorkspaceViewModelScope {
33 setComponentIcon(iconSrc:string):void;
36 export class IconsViewModel {
40 'Sdc.Services.AvailableIconsService',
45 constructor(private $scope:IIconsScope,
46 private availableIconsService:AvailableIconsService,
47 private ComponentFactory:ComponentFactory,
48 private $state:ng.ui.IStateService) {
53 this.$scope.updateSelectedMenuItem();
54 this.$scope.iconSprite = this.$scope.component.iconSprite;
56 if (this.$scope.component.isResource()) {
61 private initialIcon:string = this.$scope.component.icon;
62 private initIcons = ():void => {
64 // For subcategories that where created by admin, there is no icons
65 this.$scope.icons = new Array<string>();
66 if (this.$scope.component.categories && this.$scope.component.categories.length > 0) {
68 _.forEach(this.$scope.component.categories, (category:IMainCategory):void => {
70 this.$scope.icons = this.$scope.icons.concat(category.icons);
72 if (category.subcategories) {
73 _.forEach(category.subcategories, (subcategory:ISubCategory):void => {
74 if (subcategory.icons) {
75 this.$scope.icons = this.$scope.icons.concat(subcategory.icons);
82 if (this.$scope.component.isResource()) {
83 let resourceType:string = this.$scope.component.getComponentSubType();
84 if (resourceType === 'VL') {
85 this.$scope.icons = ['vl'];
87 if (resourceType === 'CP') {
88 this.$scope.icons = ['cp'];
92 if (this.$scope.icons.length === 0) {
93 this.$scope.icons = this.availableIconsService.getIcons(this.$scope.component.componentType);
95 //we always add the defual icon to the list
96 this.$scope.icons.push('defaulticon');
99 private initVendor = ():void => {
100 let vendors:Array<string> = this.availableIconsService.getIcons(this.$scope.component.componentType).slice(5, 19);
101 let vendorName = this.$scope.component.vendorName.toLowerCase();
102 if ('at&t' === vendorName) {
105 if ('nokia' === vendorName) {
106 vendorName = 'nokiasiemens';
108 let vendor:string = _.find(vendors, (vendor:string)=> {
109 return vendor.replace(/[_]/g, '').toLowerCase() === vendorName;
112 if (vendor && this.$scope.icons.indexOf(vendor) === -1) {
113 this.$scope.icons.push(vendor);
117 private initScope():void {
118 this.$scope.icons = [];
119 this.$scope.setValidState(true);
120 //if(this.$scope.component.icon === DEFAULT_ICON){
121 // //this.$scope.setValidState(false);
124 this.$scope.setComponentIcon = (iconSrc:string):void => {
125 this.$state.current.data.unsavedChanges = !this.$scope.isViewMode() && (iconSrc != this.initialIcon);
126 this.$scope.component.icon = iconSrc;
127 // this.$scope.setValidState(true);