fixed log4j issue
[eliot.git] / blueprints / common / eliot-ui / frontend-src / src / app / history / history.component.ts
1 import { Component, OnInit, ViewChild, Output } from '@angular/core';
2 import {MatTableDataSource} from '@angular/material/table';
3 import {SelectionModel} from '@angular/cdk/collections';
4
5 import { historyInformation, historyDetails, historyPostInfo, fileDownload, currentDeployInfo, currentDeployDetails } from '../datainterface';
6
7 import { EliotserviceService } from '../eliotservice.service';
8
9 import { MatPaginator } from '@angular/material/paginator';
10
11 @Component({
12   selector: 'app-history',
13   templateUrl: './history.component.html',
14   styleUrls: ['./history.component.scss']
15 })
16 export class HistoryComponent implements OnInit {
17
18   months: string[];
19   tempArray: string[];
20   date: Date = new Date();
21   selectedId: string[];
22   description: string;
23   temp: number;
24   downloadObj = {
25     fileupload: []
26   }
27   constzero = 0;
28   var : number;
29   unoccupied = 12;
30   yamlfiles : string[] = ["yaml1","yaml2","yaml3","yaml4","yaml5","yaml6"];
31
32   historyColumns: string [] = ['select','date','csarPackage','yamlFile','status'];
33
34   historyJanColumns: string [] = ['select','date','yamlFile','status','download'];
35
36   historyDataSource = new MatTableDataSource<historyInformation>(HISTORY_INFO_LIST);
37
38   historyInfo = {} as historyDetails;
39   historyPostInfo = {} as historyPostInfo;
40   currentDeployDetail = {} as currentDeployDetails
41
42   historyId = [];
43   historyIdInfo = {};
44
45   postIdInfo = {} as fileDownload;
46   sessionArr = [];
47   sessionObjj = {};
48
49   january = [];
50
51   monthBool: boolean = false;
52   janBool: boolean = false;
53
54   monthDetails = [];
55   currentStatus: boolean;
56
57   currentDeployColumns: string [] = ['appName','yamlName','nodeIp','runningStatus'];
58   currentDeployDataSource = new MatTableDataSource<currentDeployInfo>(CURRENT_DEPLOY_INFO_LIST);
59   currentDeployArrayList = [];
60
61   statusHistoryArray: string[] = ['Current History','Past History'];
62   statusSelected: string;
63
64   @Output()
65
66   @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
67
68   constructor(private serviceObj:EliotserviceService) { }
69
70   ngOnInit() {
71     this.description = "Application Package (.csar) / Deployment Yaml History.....!"
72     this.var = 0;
73     this.months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
74     this.tempArray = Object.assign([], this.months);
75     this.getHistoryData();
76     this.currentHistoryData();
77     debugger;
78     this.init();
79     this.statusSelected = "Past History";
80     // this.currentStatus = true;
81   }
82
83   selectedStatus(event) {
84     // if(event.target)
85     debugger;
86     if(event.value=="Current History"){
87       this.currentStatus = true;
88       this.getCurrentHistoryData()
89     }
90     if(event.value=="Past History"){
91       this.currentStatus = false;
92     }
93   }
94
95   selectedMonth(m: string){
96     this.sessionArr = JSON.parse(sessionStorage.getItem('datakey'));
97     this.january = [];
98     this.historyDataSource = new MatTableDataSource<historyInformation>(HISTORY_INFO_LIST);
99     this.sessionArr.forEach(data => {
100       if (data.month == m) {
101         this.january.push(data);
102         this.historyDataSource = new MatTableDataSource(this.january);
103       }
104     })
105   }
106
107   clearMonth(m: string){
108     console.log("Inside clearMonth");
109     this.selectedMonth(m);
110     this.historyDataSource = new MatTableDataSource<historyInformation>(HISTORY_INFO_LIST);
111     this.january = [];
112   }
113
114   downloadYaml(){
115     this.monthBool == true;
116     if(this.monthBool == true){
117       console.log("Month bool is true...");
118       console.log(this.historyDataSource.data);
119       debugger;
120       this.selection.selected.forEach( data => {
121           this.postIdInfo.id =  data.id;
122           this.postIdInfo.fileName = data.yamlFile;
123           this.historyId.push(this.postIdInfo);
124           debugger;
125         }, error => {
126           console.log(error);
127         }
128       );
129       this.historyPostInfo.fileDownload = this.historyId;
130       debugger;
131       
132         this.serviceObj.postHistoryId(this.historyId).subscribe(
133           data => {
134             console.log(data);
135             debugger;
136           },
137           error => {
138             console.log(error);
139           }
140         );
141     }
142   }
143
144   init() {
145     
146     this.monthDetails = [
147       {
148         monthName: 'Jan - Monthwise Deployment Historical Data',
149         iconName: 'archive',
150         displayName: 'download',
151         value: 'jan'
152       },
153       {
154         monthName: 'Feb - Monthwise Deployment Historical Data',
155         iconName: 'archive',
156         displayName: 'download',
157         value: 'feb'
158       },
159       {
160         monthName: 'Mar - Monthwise Deployment Historical Data',
161         iconName: 'archive',
162         displayName: 'download',
163         value: 'mar'
164       },
165       {
166         monthName: 'Apr - Monthwise Deployment Historical Data',
167         iconName: 'archive',
168         displayName: 'download',
169         value: 'apr'
170       },
171       {
172         monthName: 'May - Monthwise Deployment Historical Data',
173         iconName: 'archive',
174         displayName: 'download',
175         value: 'may'
176       },
177       {
178         monthName: 'Jun - Monthwise Deployment Historical Data',
179         iconName: 'archive',
180         displayName: 'download',
181         value: 'jun'
182       },
183       {
184         monthName: 'Jul - Monthwise Deployment Historical Data',
185         iconName: 'archive',
186         displayName: 'download',
187         value: 'jul'
188       },
189       {
190         monthName: 'Aug - Monthwise Deployment Historical Data',
191         iconName: 'archive',
192         displayName: 'download',
193         value: 'aug'
194       },
195       {
196         monthName: 'Sep - Monthwise Deployment Historical Data',
197         iconName: 'archive',
198         displayName: 'download',
199         value: 'sep'
200       },
201       {
202         monthName: 'Oct - Monthwise Deployment Historical Data',
203         iconName: 'archive',
204         displayName: 'download',
205         value: 'oct'
206       },
207       {
208         monthName: 'Nov - Monthwise Deployment Historical Data',
209         iconName: 'archive',
210         displayName: 'download',
211         value: 'nov'
212       },
213       {
214         monthName: 'Dec - Monthwise Deployment Historical Data',
215         iconName: 'archive',
216         displayName: 'download',
217         value: 'dec'
218       }
219     ]
220   }
221
222   getHistoryData() {
223
224     this.serviceObj.getHistoryInfo().subscribe(
225       data => {
226         this.historyInfo = data;
227         sessionStorage.setItem('datakey',JSON.stringify(this.historyInfo.eliotHistory));
228         debugger;
229         this.sessionArr = JSON.parse(sessionStorage.getItem('datakey'));
230       },
231       error => {
232         console.log(error);
233       }
234     );
235   }
236
237   getCurrentHistoryData() {
238     this.serviceObj.getCurrentDeployInfo()
239        .subscribe(data => {
240         debugger;
241         this.currentDeployDetail = data;
242         this.currentDeployArrayList = this.currentDeployDetail.currentDeployArray;
243         this.currentDeployDataSource = new MatTableDataSource(this.currentDeployArrayList);
244         this.currentDeployDataSource.paginator = this.paginator;
245        },
246        error => console.log(error));
247   }
248
249   currentHistoryData() {
250     if(this.statusSelected=="Current History"){
251       this.currentStatus = true;
252       
253     }
254     else {
255       this.currentStatus = false;
256     }
257   }
258
259   selection = new SelectionModel<historyInformation>(true, []);
260
261   isAllSelectedJan() {
262     const numSelected = this.selection.selected.length;
263     const numRows = this.historyDataSource.data.length;
264     this.monthBool = true;
265     return numSelected === numRows;
266   }
267
268   masterToggleJan() {
269     this.isAllSelectedJan() ?
270       this.selection.clear() :
271       this.historyDataSource.data.forEach(row => this.selection.select(row));
272   }
273
274   checkboxLabelJan(row?: historyInformation): string {
275     if (!row) {
276       return `${this.isAllSelectedJan() ? 'select' : 'deselect'} all`;
277     }
278     return `${this.selection.isSelected(row) ? 'deselect' : 'select'} row ${row.id + 1}`;
279   }
280
281 }
282 const HISTORY_INFO_LIST: historyInformation[] = [
283   { id:'', date:'',csarPackage:'',yamlFile:'', month:'', status:''}
284 ];
285
286 const CURRENT_DEPLOY_INFO_LIST: currentDeployInfo[] = [
287   { deployId:'',appName: '', yamlName: '', nodeIp: '', runningStatus: ''}
288 ];