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 rc2122 on 7/4/2017.
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";
29 import {Component} from "app/models";
30 import {ResourceType} from "app/utils/constants";
32 interface IIconsModalViewModelScope {
33 modalIcons:ng.ui.bootstrap.IModalServiceInstance;
37 changeIcon(icon:string):void,
42 export class IconsModalViewModel {
45 'Sdc.Services.AvailableIconsService',
52 constructor(private $scope:IIconsModalViewModelScope,
53 private availableIconsService:AvailableIconsService,
54 private ComponentFactory:ComponentFactory,
55 private $state:ng.ui.IStateService,
56 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
57 private component: Component) {
60 this.$scope.iconSprite = this.component.iconSprite;
61 this.$scope.selectedIcon = this.component.icon;
63 if (this.component.isResource()) {
69 private _initIcons = ():void => {
71 // For subcategories that where created by admin, there is no icons
72 this.$scope.icons = new Array<string>();
73 if (this.component.categories && this.component.categories.length > 0) {
75 _.forEach(this.component.categories, (category:IMainCategory):void => {
77 this.$scope.icons = this.$scope.icons.concat(category.icons);
79 if (category.subcategories) {
80 _.forEach(category.subcategories, (subcategory:ISubCategory):void => {
81 if (subcategory.icons) {
82 this.$scope.icons = this.$scope.icons.concat(subcategory.icons);
89 if (this.component.isResource()) {
90 let resourceType:string = this.component.getComponentSubType();
91 if (resourceType === ResourceType.VL) {
92 this.$scope.icons = ['vl'];
94 if (resourceType === ResourceType.CP) {
95 this.$scope.icons = ['cp'];
99 if (this.$scope.icons.length === 0) {
100 this.$scope.icons = this.availableIconsService.getIcons(this.component.componentType);
102 //we always add the defual icon to the list
103 this.$scope.icons.push('defaulticon');
106 private initVendor = ():void => {
107 let vendors:Array<string> = this.availableIconsService.getIcons(this.component.componentType).slice(5, 19);
108 let vendorName = this.component.vendorName.toLowerCase();
109 if ('at&t' === vendorName) {
112 if ('nokia' === vendorName) {
113 vendorName = 'nokiasiemens';
115 let vendor:string = _.find(vendors, (vendor:string)=> {
116 return vendor.replace(/[_]/g, '').toLowerCase() === vendorName;
119 if (vendor && this.$scope.icons.indexOf(vendor) === -1) {
120 this.$scope.icons.push(vendor);
124 private initScope():void {
125 this.$scope.modalIcons = this.$uibModalInstance;
126 this.$scope.icons = [];
127 this.$scope.changeIcon = (icon:string):void => {
128 this.$scope.selectedIcon = icon;
130 this.$scope.cancel = ():void => {
131 this.$uibModalInstance.dismiss();
133 this.$scope.updateIcon = ():void => {
134 let isDirty:boolean = this.component.icon != this.$scope.selectedIcon;
135 this.component.icon = this.$scope.selectedIcon;
136 this.$uibModalInstance.close(isDirty);