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 {Distribution, DistributionComponent, Service} from "app/models";
24 import {ModalsHandler, Dictionary} from "app/utils";
25 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
27 interface IDistributionViewModel extends IWorkspaceViewModelScope {
28 modalDistribution:ng.ui.bootstrap.IModalServiceInstance;
30 distributions:Array<Distribution>;
31 showComponents(distribution:Distribution):void;
32 markAsDeployed(distribution:Distribution):void;
33 getStatusCount(distributionComponent:Array<DistributionComponent>):any;
34 initDistributions():void;
35 getUrlName(url:string):string;
37 openDisributionStatusModal:Function;
40 export class DistributionViewModel {
48 constructor(private $scope:IDistributionViewModel,
49 private ModalsHandler:ModalsHandler) {
51 this.$scope.setValidState(true);
54 private initScope = ():void => {
55 this.$scope.service = <Service>this.$scope.component;
58 // Open Distribution status modal
59 this.$scope.openDisributionStatusModal = (distribution:Distribution, status:string):void => {
60 this.ModalsHandler.openDistributionStatusModal(distribution, status, this.$scope.component).then(()=> {
68 this.$scope.showComponents = (distribution:Distribution):void => {
69 let onError = (response) => {
70 console.info('onError showComponents', response);
72 let onSuccess = (distributionComponents:Array<DistributionComponent>) => {
73 distribution.distributionComponents = distributionComponents;
74 distribution.statusCount = this.$scope.getStatusCount(distribution.distributionComponents);
75 // distribution.components = this.aggregateDistributionComponent(distributionComponents);;
77 this.$scope.service.getDistributionsComponent(distribution.distributionID).then(onSuccess, onError);
80 this.$scope.getStatusCount = (distributionComponent:Array<DistributionComponent>):any => {
81 return _.countBy(distributionComponent, 'status')
84 this.$scope.getUrlName = (url:string):string => {
85 let urlName:string = _.last(url.split('/'));
89 this.$scope.markAsDeployed = (distribution:Distribution):void => {
90 let onError = (response) => {
91 console.info('onError markAsDeployed', response);
93 let onSuccess = (result:any) => {
94 distribution.deployementStatus = 'Deployed';
96 this.$scope.service.markAsDeployed(distribution.distributionID).then(onSuccess, onError);
100 this.$scope.initDistributions = ():void => {
101 let onError = (response) => {
102 console.info('onError initDistributions', response);
104 let onSuccess = (distributions:Array<Distribution>) => {
105 this.$scope.distributions = distributions;
107 this.$scope.service.getDistributionsList().then(onSuccess, onError);
110 this.$scope.initDistributions();
115 private aggregateDistributionComponent = (distributionComponents:Array<DistributionComponent>):any => {
116 let aggregateDistributions:Dictionary<string,Dictionary<string,Array<DistributionComponent>>> = new Dictionary<string,Dictionary<string,Array<DistributionComponent>>>();
117 let tempAggregateDistributions:any = _.groupBy(distributionComponents, 'omfComponentID');
118 let aa = new Dictionary<string,Array<DistributionComponent>>();
120 let tempAggregate:any;
121 _.forEach(tempAggregateDistributions, (distributionComponents:Array<DistributionComponent>, omfComponentID:string)=> {
123 let urls:any = _.groupBy(distributionComponents, 'url');
124 aggregateDistributions.setValue(omfComponentID, urls);
125 // aggregateDistributions[omfComponentID] = ;
128 console.log(aggregateDistributions);
129 return aggregateDistributions;