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 * as _ from "lodash";
26 import {ComponentFactory} from "app/utils";
27 import {AvailableIconsService} from "app/services";
28 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
29 import {IMainCategory, ISubCategory} from "app/models";
30 import {Component} from "app/models";
31 import {ResourceType} from "app/utils/constants";
33 interface IIconsModalViewModelScope {
34 modalIcons:ng.ui.bootstrap.IModalServiceInstance;
38 changeIcon(icon:string):void,
43 export class IconsModalViewModel {
46 'Sdc.Services.AvailableIconsService',
53 constructor(private $scope:IIconsModalViewModelScope,
54 private availableIconsService:AvailableIconsService,
55 private ComponentFactory:ComponentFactory,
56 private $state:ng.ui.IStateService,
57 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
58 private component: Component) {
61 this.$scope.iconSprite = this.component.iconSprite;
62 this.$scope.selectedIcon = this.component.icon;
64 if (this.component.isResource()) {
70 private _initIcons = ():void => {
72 // For subcategories that where created by admin, there is no icons
73 this.$scope.icons = new Array<string>();
74 if (this.component.categories && this.component.categories.length > 0) {
76 _.forEach(this.component.categories, (category:IMainCategory):void => {
78 this.$scope.icons = this.$scope.icons.concat(category.icons);
80 if (category.subcategories) {
81 _.forEach(category.subcategories, (subcategory:ISubCategory):void => {
82 if (subcategory.icons) {
83 this.$scope.icons = this.$scope.icons.concat(subcategory.icons);
90 if (this.component.isResource()) {
91 let resourceType:string = this.component.getComponentSubType();
92 if (resourceType === ResourceType.VL) {
93 this.$scope.icons = ['vl'];
95 if (resourceType === ResourceType.CP) {
96 this.$scope.icons = ['cp'];
100 if (this.$scope.icons.length === 0) {
101 this.$scope.icons = this.availableIconsService.getIcons(this.component.componentType);
103 //we always add the defual icon to the list
104 this.$scope.icons.push('defaulticon');
107 private initVendor = ():void => {
108 let vendors:Array<string> = this.availableIconsService.getIcons(this.component.componentType).slice(5, 19);
109 let vendorName = this.component.vendorName.toLowerCase();
110 if ('at&t' === vendorName) {
113 if ('nokia' === vendorName) {
114 vendorName = 'nokiasiemens';
116 let vendor:string = _.find(vendors, (vendor:string)=> {
117 return vendor.replace(/[_]/g, '').toLowerCase() === vendorName;
120 if (vendor && this.$scope.icons.indexOf(vendor) === -1) {
121 this.$scope.icons.push(vendor);
125 private initScope():void {
126 this.$scope.modalIcons = this.$uibModalInstance;
127 this.$scope.icons = [];
128 this.$scope.changeIcon = (icon:string):void => {
129 this.$scope.selectedIcon = icon;
131 this.$scope.cancel = ():void => {
132 this.$uibModalInstance.dismiss();
134 this.$scope.updateIcon = ():void => {
135 let isDirty:boolean = this.component.icon != this.$scope.selectedIcon;
136 this.component.icon = this.$scope.selectedIcon;
137 this.$uibModalInstance.close(isDirty);