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 import * as _ from "lodash";
23 import {MenuItemGroup, MenuItem} from "app/utils";
24 import {BreadcrumbsPath, BreadcrumbsMenu} from "../onboard-vendor/onboard-vendor-view-model";
25 import {CacheService} from "app/services";
26 import {IUserProperties} from "app/models";
28 export class TestData {
29 breadcrumbs:BreadcrumbsPath;
32 export interface IDcaeAppViewModelScope extends ng.IScope {
35 topNavMenuModel:Array<MenuItemGroup>;
36 topNavRootMenu:MenuItemGroup;
41 export class DcaeAppViewModel {
45 'Sdc.Services.CacheService'
48 private firstControlledTopNavMenu:MenuItemGroup;
50 constructor(private $scope:IDcaeAppViewModelScope,
51 private $q:ng.IQService,
52 private cacheService:CacheService) {
54 this.$scope.testData = {
60 this.$scope.version = this.cacheService.get('version');
62 this.$scope.onTestEvent = (eventName:string, data:any):void => {
64 case 'breadcrumbsupdated':
65 this.handleBreadcrumbsUpdate(data);
70 this.$scope.topNavMenuModel = [];
72 this.$scope.user = this.cacheService.get('user');
75 updateBreadcrumbsPath = (selectedKeys:Array<string>):ng.IPromise<boolean> => {
76 let topNavMenuModel = this.$scope.topNavMenuModel;
77 let startIndex = topNavMenuModel.indexOf(this.firstControlledTopNavMenu);
78 if (startIndex === -1) {
79 startIndex = topNavMenuModel.length;
81 topNavMenuModel.splice(startIndex + selectedKeys.length);
82 this.$scope.testData = {
83 breadcrumbs: {selectedKeys: selectedKeys}
86 return this.$q.when(true);
89 handleBreadcrumbsUpdate(breadcrumbsMenus:Array<BreadcrumbsMenu>):void {
90 let selectedKeys = [];
91 let topNavMenus = breadcrumbsMenus.map((breadcrumbMenu, breadcrumbIndex) => {
92 let topNavMenu = new MenuItemGroup();
93 topNavMenu.menuItems = breadcrumbMenu.menuItems.map(menuItem =>
96 this.updateBreadcrumbsPath,
99 [selectedKeys.concat([menuItem.key])]
102 topNavMenu.selectedIndex = _.findIndex(
103 breadcrumbMenu.menuItems,
104 menuItem => menuItem.key === breadcrumbMenu.selectedKey
106 selectedKeys.push(breadcrumbMenu.selectedKey);
110 let topNavMenuModel = this.$scope.topNavMenuModel;
111 let len = topNavMenuModel.length;
112 let startIndex = topNavMenuModel.indexOf(this.firstControlledTopNavMenu);
113 if (startIndex === -1) {
116 topNavMenuModel.splice(startIndex, len - startIndex);
117 topNavMenuModel.push.apply(topNavMenuModel, topNavMenus);
118 this.firstControlledTopNavMenu = topNavMenus[0];
120 if (startIndex === 1 && this.$scope.topNavRootMenu == null) {
121 let topNavRootMenu = topNavMenuModel[0];
122 let onboardItem = topNavRootMenu.menuItems[topNavRootMenu.selectedIndex];
123 let originalCallback = onboardItem.callback;
124 onboardItem.callback = (...args) => {
125 let ret = this.updateBreadcrumbsPath([]);
126 return originalCallback && originalCallback.apply(undefined, args) || ret;
128 this.$scope.topNavRootMenu = topNavRootMenu;
131 this.updateBreadcrumbsPath(selectedKeys);