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 rcohen on 9/22/2016.
25 import * as _ from "lodash";
26 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
27 import {ModalsHandler} from "app/utils";
28 import {Capability, PropertyModel, Requirement} from "app/models";
29 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
30 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
32 export class SortTableDefined {
37 interface IReqAndCapabilitiesViewModelScope extends IWorkspaceViewModelScope {
38 requirementsTableHeadersList:Array<any>;
39 capabilitiesTableHeadersList:Array<any>;
40 capabilityPropertiesTableHeadersList:Array<any>;
41 requirementsSortTableDefined:SortTableDefined;
42 capabilitiesSortTableDefined:SortTableDefined;
43 propertiesSortTableDefined:SortTableDefined;
44 requirements:Array<Requirement>;
45 capabilities:Array<Capability>;
47 filteredProperties:Array<Array<PropertyModel>>;
50 sort(sortBy:string, sortByTableDefined:SortTableDefined):void;
51 updateProperty(property:PropertyModel, indexInFilteredProperties:number):void;
52 allCapabilitiesSelected(selected:boolean):void;
55 export class ReqAndCapabilitiesViewModel {
65 constructor(private $scope:IReqAndCapabilitiesViewModelScope,
66 private $filter:ng.IFilterService,
67 private ModalsHandler:ModalsHandler,
68 private ComponentServiceNg2: ComponentServiceNg2) {
70 this.initCapabilitiesAndRequirements();
73 private initCapabilitiesAndRequirements = (): void => {
75 if(!this.$scope.component.capabilities || !this.$scope.component.requirements) {
76 this.$scope.isLoading = true;
77 this.ComponentServiceNg2.getCapabilitiesAndRequirements(this.$scope.component.componentType, this.$scope.component.uniqueId).subscribe((response:ComponentGenericResponse) => {
78 this.$scope.component.capabilities = response.capabilities;
79 this.$scope.component.requirements = response.requirements;
81 this.$scope.isLoading = false;
83 this.$scope.isLoading = false;
91 private openEditPropertyModal = (property:PropertyModel, indexInFilteredProperties:number):void => {
92 //...because there is not be api
93 _.forEach(this.$scope.filteredProperties[indexInFilteredProperties], (prop:PropertyModel)=> {
96 this.ModalsHandler.openEditPropertyModal(property, this.$scope.component, this.$scope.filteredProperties[indexInFilteredProperties], false, "component", this.$scope.component.uniqueId).then(() => {
101 private initScope = ():void => {
103 this.$scope.requirementsSortTableDefined = {
107 this.$scope.capabilitiesSortTableDefined = {
111 this.$scope.propertiesSortTableDefined = {
116 this.$scope.setValidState(true);
117 this.$scope.requirementsTableHeadersList = [
118 {title: 'Name', property: 'name'},
119 {title: 'Capability', property: 'capability'},
120 {title: 'Node', property: 'node'},
121 {title: 'Relationship', property: 'relationship'},
122 {title: 'Connected To', property: ''},
123 {title: 'Occurrences', property: ''}
125 this.$scope.capabilitiesTableHeadersList = [
126 {title: 'Name', property: 'name'},
127 {title: 'Type', property: 'type'},
128 {title: 'Description', property: ''},
129 {title: 'Valid Source', property: ''},
130 {title: 'Occurrences', property: ''}
132 this.$scope.capabilityPropertiesTableHeadersList = [
133 {title: 'Name', property: 'name'},
134 {title: 'Type', property: 'type'},
135 {title: 'Schema', property: 'schema.property.type'},
136 {title: 'Description', property: 'description'},
138 this.$scope.filteredProperties = [];
140 this.$scope.mode = 'requirements';
141 this.$scope.requirements = [];
142 _.forEach(this.$scope.component.requirements, (req:Array<Requirement>, capName)=> {
143 this.$scope.requirements = this.$scope.requirements.concat(req);
146 this.$scope.capabilities = [];
147 _.forEach(this.$scope.component.capabilities, (cap:Array<Capability>, capName)=> {
148 this.$scope.capabilities = this.$scope.capabilities.concat(cap);
151 this.$scope.sort = (sortBy:string, sortByTableDefined:SortTableDefined):void => {
152 sortByTableDefined.reverse = (sortByTableDefined.sortByField === sortBy) ? !sortByTableDefined.reverse : false;
153 sortByTableDefined.sortByField = sortBy;
156 this.$scope.updateProperty = (property:PropertyModel, indexInFilteredProperties:number):void => {
157 this.openEditPropertyModal(property, indexInFilteredProperties);
160 this.$scope.allCapabilitiesSelected = (selected:boolean):void => {
161 _.forEach(this.$scope.capabilities, (cap:Capability)=> {
162 cap.selected = selected;