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 {ModalsHandler} from "app/utils";
23 import {PropertyModel, DisplayModule, Component, ComponentInstance, Tab, Module} from "app/models";
24 import {ExpandCollapseListData} from "app/directives/utils/expand-collapse-list-header/expand-collapse-list-header";
26 export interface IHierarchyScope extends ng.IScope {
29 selectedModule:DisplayModule;
32 expandCollapseArtifactsList:ExpandCollapseListData;
33 expandCollapsePropertiesList:ExpandCollapseListData;
34 selectedInstanceId:string;
36 onModuleSelected(moduleId:string, selectedIndex:number):void;
37 onModuleNameChanged(module:DisplayModule):void;
38 updateHeatName():void;
39 loadInstanceModules(instance:ComponentInstance):ng.IPromise<boolean>;
40 openEditPropertyModal(property:PropertyModel, filteredProperties:Array<PropertyModel>):void;
43 export class HierarchyViewModel {
51 constructor(private $scope:IHierarchyScope, private $q:ng.IQService, private ModalsHandler:ModalsHandler) {
52 this.$scope.component = this.$scope.singleTab.data;
53 this.$scope.isLoading = false;
54 this.$scope.expandCollapseArtifactsList = new ExpandCollapseListData();
55 this.$scope.expandCollapsePropertiesList = new ExpandCollapseListData();
56 this.initScopeMethods();
59 private initScopeMethods():void {
61 let collapseModuleData = ():void => {
62 this.$scope.expandCollapseArtifactsList.expandCollapse = false;
63 this.$scope.expandCollapsePropertiesList.expandCollapse = false;
64 this.$scope.expandCollapseArtifactsList.orderByField = "artifactName";
65 this.$scope.expandCollapsePropertiesList.orderByField = "name";
68 this.$scope.onModuleSelected = (moduleId:string, selectedIndex:number, componentInstanceId?:string):void => {
70 let onSuccess = (module:DisplayModule) => {
71 console.log("Module Loaded: ", module);
72 this.$scope.selectedModule = module;
73 this.$scope.isLoading = false;
77 let onFailed = () => {
78 this.$scope.isLoading = false;
81 this.$scope.selectedIndex = selectedIndex;
82 if (!this.$scope.selectedModule || (this.$scope.selectedModule && this.$scope.selectedModule.uniqueId != moduleId)) {
83 this.$scope.isLoading = true;
84 if (this.$scope.component.isService()) {
85 this.$scope.selectedInstanceId = componentInstanceId;
86 this.$scope.component.getModuleInstanceForDisplay(componentInstanceId, moduleId).then(onSuccess, onFailed);
88 this.$scope.component.getModuleForDisplay(moduleId).then(onSuccess, onFailed);
93 this.$scope.updateHeatName = () => {
94 this.$scope.isLoading = true;
96 let originalName:string = this.$scope.selectedModule.name;
98 let onSuccess = (module:Module) => {
99 console.log("Module name updated:", module.name);
100 this.$scope.selectedModule.name = module.name;
101 this.$scope.isLoading = false;
104 let onFailed = () => {
105 this.$scope.isLoading = false;
106 this.$scope.selectedModule.name = originalName;
109 this.$scope.selectedModule.updateName();
110 this.$scope.component.updateGroupMetadata(new DisplayModule(this.$scope.selectedModule)).then(onSuccess, onFailed);
113 this.$scope.openEditPropertyModal = (property:PropertyModel, filteredProperties:Array<PropertyModel>):void => {
114 this.ModalsHandler.openEditModulePropertyModal(property, this.$scope.component, this.$scope.selectedModule, filteredProperties).then(() => {