added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / dashboard / dashboard.component.ts
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 import { Component, OnInit, ViewChild, HostListener, EventEmitter, OnDestroy } from '@angular/core';\r
18 import { routerTransition } from '../../router.animations';\r
19 import { MatPaginator, MatDialog } from '@angular/material';\r
20 import { ListService } from 'app/shared/services/list.service';\r
21 import { TestExecutionService } from 'app/shared/services/test-execution.service';\r
22 import { TestDefinitionService } from 'app/shared/services/test-definition.service';\r
23 import { SchedulingService } from 'app/shared/services/scheduling.service';\r
24 import { Subject, Observable, Subscription } from 'rxjs';\r
25 import { UserService } from 'app/shared/services/user.service';\r
26 import { FeathersService } from 'app/shared/services/feathers.service';\r
27 import { GroupService } from 'app/shared/services/group.service';\r
28 import { FilterModalComponent } from '../components/stats/filter-modal/filter-modal.component';\r
29 import { StatsService } from '../components/stats/stats.service';\r
30 \r
31 @Component({\r
32   selector: 'app-dashboard',\r
33   templateUrl: './dashboard.component.pug',\r
34   styleUrls: ['./dashboard.component.scss'],\r
35   animations: [routerTransition()]\r
36 })\r
37 \r
38 export class DashboardComponent implements OnInit, OnDestroy {\r
39 \r
40   private toDestroy: Array<Subscription> = [];\r
41 \r
42   // Top of the page stats\r
43   public topStats = {\r
44     COMPLETED: 0,\r
45     UNKNOWN: 0,\r
46     FAILURE: 0,\r
47     STOPPED: 0,\r
48     UNAUTHORIZED: 0,\r
49     FAILED: 0\r
50   };\r
51 \r
52   public testDefinitionList = null;\r
53   public testExecutions;\r
54   public displayedColumns = ['name', 'result', 'startTime'];\r
55   public displayedScheduleColumns = ['name', 'nextRun'];\r
56   public weekExecutions = 0;\r
57   public weekSchedules = 0;\r
58   public filter = { testResult: '' }; // for dropdown in html\r
59   public group;\r
60 \r
61   public eventsSubject: Subject<void>;\r
62 \r
63   public TD_selectedTDs = "All";\r
64   public TI_selectedTDs = "All";\r
65   public TI_selectedTIs = "Top 5";\r
66   public sched_selectedTIs = "All";\r
67 \r
68   public viewers = [];\r
69 \r
70   @ViewChild(MatPaginator) executionsPaginator: MatPaginator;\r
71   @ViewChild(MatPaginator) scheduledPaginator: MatPaginator;\r
72 \r
73   constructor(\r
74     private _groups: GroupService,\r
75     private filterModal: MatDialog, \r
76     private stats: StatsService\r
77   ) { }\r
78 \r
79   async ngOnInit() {\r
80 \r
81     this.stats.getDefaultData(this._groups.getGroup());\r
82     this.toDestroy.push(this._groups.groupChange().subscribe(group => {\r
83       this.stats.getDefaultData(group);\r
84     }));\r
85 \r
86     //this.resetData();\r
87 \r
88   //   this.stats.onTDExecutionChangeFinished().subscribe(res => {\r
89   //     this.TD_selectedTDs = "";\r
90   //     this.stats.getTDFilters().selected.forEach(item => {\r
91   //       this.TD_selectedTDs += (item.viewValue + ", ");\r
92   //     })\r
93   //     let charLimit = 200;\r
94   //     if (this.TD_selectedTDs.length > charLimit) {\r
95   //       this.TD_selectedTDs = this.TD_selectedTDs.slice(0, charLimit) + "...";\r
96   //     } else this.TD_selectedTDs = this.TD_selectedTDs.slice(0, this.TD_selectedTDs.length - 2);\r
97   //   })\r
98 \r
99   //   this.stats.onTIExecutionChangeFinished().subscribe(res => {\r
100   //     let selectedTIs = this.stats.getTIFilters().selectedTIs;\r
101   //     let selectedTDs = this.stats.getTIFilters().selectedTDs;\r
102 \r
103   //     if (selectedTIs.length == 0) this.TI_selectedTIs = "All";\r
104   //     else {\r
105   //       this.TI_selectedTIs = "";\r
106   //       this.stats.getTIFilters().selectedTIs.forEach(item => {\r
107   //         this.TI_selectedTIs += (item + ", ");\r
108   //       })\r
109   //       let charLimit = 200;\r
110   //       if (this.TI_selectedTIs.length > charLimit) {\r
111   //         this.TI_selectedTIs = this.TI_selectedTIs.slice(0, charLimit) + "...";\r
112   //       } else this.TI_selectedTIs = this.TI_selectedTIs.slice(0, this.TI_selectedTIs.length - 2);\r
113   //     }\r
114 \r
115   //     if (selectedTDs.length == 0) this.TI_selectedTDs = "All";\r
116   //     else {\r
117   //       this.TI_selectedTDs = "";\r
118   //       this.stats.getTIFilters().selectedTDs.forEach(item => {\r
119   //         this.TI_selectedTDs += (item + ", ");\r
120   //       })\r
121   //       let charLimit = 200;\r
122   //       if (this.TI_selectedTDs.length > charLimit) {\r
123   //         this.TI_selectedTDs = this.TI_selectedTDs.slice(0, charLimit) + "...";\r
124   //       } else this.TI_selectedTDs = this.TI_selectedTDs.slice(0, this.TI_selectedTDs.length - 2);\r
125   //     }\r
126   //   })\r
127 \r
128   //   this.stats.onScheduleChangeFinished().subscribe(res => {\r
129   //     let selectedTIs = this.stats.scheduledTests.map(el => el.name);\r
130   //     //console.log(selectedTIs);\r
131   //     if (selectedTIs.length == 0) this.sched_selectedTIs = "All";\r
132   //     else {\r
133   //       this.sched_selectedTIs = "";\r
134   //       this.stats.scheduledTests.map(el => el.name).forEach(item => {\r
135   //         this.sched_selectedTIs += (item + ", ");\r
136   //       })\r
137   //       let charLimit = 200;\r
138   //       if (this.sched_selectedTIs.length > charLimit) {\r
139   //         this.sched_selectedTIs = this.sched_selectedTIs.slice(0, charLimit) + "...";\r
140   //       } else this.sched_selectedTIs = this.sched_selectedTIs.slice(0, this.sched_selectedTIs.length - 2);\r
141   //     }\r
142   //   })\r
143   }\r
144 \r
145   ngOnDestroy(){\r
146     this.toDestroy.forEach(elem => {\r
147       elem.unsubscribe();\r
148     });\r
149   }\r
150 \r
151   openFilterModal() {\r
152     let open = this.filterModal.open(FilterModalComponent, {\r
153       width: '50%',\r
154       height: '60%',\r
155       disableClose: true\r
156     })\r
157 \r
158     open.afterClosed().subscribe(res => {\r
159       this.ngOnInit();\r
160     })\r
161   }\r
162 \r
163   resetData() {\r
164     //console.log("resetting");\r
165     this.TD_selectedTDs = "All";\r
166     this.TI_selectedTDs = "All";\r
167     this.TI_selectedTIs = "Top 5";\r
168     this.sched_selectedTIs = "All";\r
169     this.stats.getDefaultData(this._groups.getGroup());\r
170   }\r
171 \r
172 }\r
173 \r