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 {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
26 import {ModalsHandler} from "app/utils";
27 import {Capability, PropertyModel, Requirement} from "app/models";
28 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
29 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
31 export class SortTableDefined {
36 interface IReqAndCapabilitiesViewModelScope extends IWorkspaceViewModelScope {
37 requirementsTableHeadersList:Array<any>;
38 capabilitiesTableHeadersList:Array<any>;
39 capabilityPropertiesTableHeadersList:Array<any>;
40 requirementsSortTableDefined:SortTableDefined;
41 capabilitiesSortTableDefined:SortTableDefined;
42 propertiesSortTableDefined:SortTableDefined;
43 requirements:Array<Requirement>;
44 capabilities:Array<Capability>;
46 filteredProperties:Array<Array<PropertyModel>>;
49 sort(sortBy:string, sortByTableDefined:SortTableDefined):void;
50 updateProperty(property:PropertyModel, indexInFilteredProperties:number):void;
51 allCapabilitiesSelected(selected:boolean):void;
54 export class ReqAndCapabilitiesViewModel {
64 constructor(private $scope:IReqAndCapabilitiesViewModelScope,
65 private $filter:ng.IFilterService,
66 private ModalsHandler:ModalsHandler,
67 private ComponentServiceNg2: ComponentServiceNg2) {
69 this.initCapabilitiesAndRequirements();
72 private initCapabilitiesAndRequirements = (): void => {
74 if(!this.$scope.component.capabilities || !this.$scope.component.requirements) {
75 this.$scope.isLoading = true;
76 this.ComponentServiceNg2.getCapabilitiesAndRequirements(this.$scope.component.componentType, this.$scope.component.uniqueId).subscribe((response:ComponentGenericResponse) => {
77 this.$scope.component.capabilities = response.capabilities;
78 this.$scope.component.requirements = response.requirements;
80 this.$scope.isLoading = false;
82 this.$scope.isLoading = false;
90 private openEditPropertyModal = (property:PropertyModel, indexInFilteredProperties:number):void => {
91 //...because there is not be api
92 _.forEach(this.$scope.filteredProperties[indexInFilteredProperties], (prop:PropertyModel)=> {
95 this.ModalsHandler.openEditPropertyModal(property, this.$scope.component, this.$scope.filteredProperties[indexInFilteredProperties], false).then(() => {
100 private initScope = ():void => {
102 this.$scope.requirementsSortTableDefined = {
106 this.$scope.capabilitiesSortTableDefined = {
110 this.$scope.propertiesSortTableDefined = {
115 this.$scope.setValidState(true);
116 this.$scope.requirementsTableHeadersList = [
117 {title: 'Name', property: 'name'},
118 {title: 'Capability', property: 'capability'},
119 {title: 'Node', property: 'node'},
120 {title: 'Relationship', property: 'relationship'},
121 {title: 'Connected To', property: ''},
122 {title: 'Occurrences', property: ''}
124 this.$scope.capabilitiesTableHeadersList = [
125 {title: 'Name', property: 'name'},
126 {title: 'Type', property: 'type'},
127 {title: 'Description', property: ''},
128 {title: 'Valid Source', property: ''},
129 {title: 'Occurrences', property: ''}
131 this.$scope.capabilityPropertiesTableHeadersList = [
132 {title: 'Name', property: 'name'},
133 {title: 'Type', property: 'type'},
134 {title: 'Schema', property: 'schema.property.type'},
135 {title: 'Description', property: 'description'},
137 this.$scope.filteredProperties = [];
139 this.$scope.mode = 'requirements';
140 this.$scope.requirements = [];
141 _.forEach(this.$scope.component.requirements, (req:Array<Requirement>, capName)=> {
142 this.$scope.requirements = this.$scope.requirements.concat(req);
145 this.$scope.capabilities = [];
146 _.forEach(this.$scope.component.capabilities, (cap:Array<Capability>, capName)=> {
147 this.$scope.capabilities = this.$scope.capabilities.concat(cap);
150 this.$scope.sort = (sortBy:string, sortByTableDefined:SortTableDefined):void => {
151 sortByTableDefined.reverse = (sortByTableDefined.sortByField === sortBy) ? !sortByTableDefined.reverse : false;
152 sortByTableDefined.sortByField = sortBy;
155 this.$scope.updateProperty = (property:PropertyModel, indexInFilteredProperties:number):void => {
156 this.openEditPropertyModal(property, indexInFilteredProperties);
159 this.$scope.allCapabilitiesSelected = (selected:boolean):void => {
160 _.forEach(this.$scope.capabilities, (cap:Capability)=> {
161 cap.selected = selected;