6c994723e59f567eb44daa8ec8a9c6daea59d6f9
[portal/sdk.git] /
1 import { Component, OnInit, Input, AfterViewInit } from '@angular/core';
2 import { SecurityService } from './security.service';
3
4 @Component({
5   selector: 'app-security',
6   templateUrl: './security.component.html',
7   styleUrls: ['./security.component.css']
8 })
9 export class SecurityComponent implements OnInit {
10
11   @Input("reportId") reportId1 : string;
12   @Input("reportType") reportType : string;
13
14   reportOwnerList : {}[];
15   reportRoleList : {}[];
16   reportSecurityInfo : {};
17   reportUserList : any[];
18   reportSecurityRoles : any[];
19   showSpinner : boolean;
20   fetchCnt : number;
21   reportOwner : string;
22   reportOwnerId : string;
23   publicReport : string;
24   reportUser : string;
25   showUserListSpinner : boolean;
26   userEditAccessArr : boolean[];
27   userEditAccess : string;
28   showRoleListSpinner : boolean;
29   reportRole : string;
30   addRoleEditAccessArr : boolean[];
31   stepNo : string;
32
33   
34   constructor(private _securityService : SecurityService) {
35     this.reportOwnerList = new Array();
36     this.reportRoleList = new Array();
37     this.reportSecurityInfo = new Object();
38     this.reportUserList = new Array();
39     this.reportSecurityRoles = new Array();
40     this.showSpinner = true;
41     this.fetchCnt = 0;
42     this.reportOwner = "";
43     this.publicReport = "";
44     this.showUserListSpinner = false;
45     this.userEditAccessArr = new Array();
46     this.showRoleListSpinner = false;
47     this.addRoleEditAccessArr = new Array();
48
49     
50    }
51
52   ngOnInit() {
53     this.showSpinner = true;
54
55     if(this.reportType === "Dashboard")
56     {
57       this.stepNo = "2";
58     }
59     else
60     {
61       this.stepNo = "6";
62     }
63
64     this._securityService.getReportOwnerList()
65     .subscribe((responseOwnerList) => {
66       this.reportOwnerList = responseOwnerList;
67
68       // console.log(this.reportOwnerList);
69
70       this._securityService.getReportSecurityInfo()
71     .subscribe((responseSecurityInfo) => {
72       this.reportSecurityInfo = responseSecurityInfo;
73
74       //console.log(this.reportSecurityInfo);
75
76       this.reportOwnerId = this.reportSecurityInfo["ownerId"];
77
78       this.publicReport = this.reportSecurityInfo["isPublic"] == "true" ? "YES" : "NO";
79
80       for(let k=0; k<this.reportOwnerList.length; k++)
81       {
82         if(this.reportOwnerId === this.reportOwnerList[k]["id"])
83         {
84           this.reportOwner = this.reportOwnerList[k]["name"];
85         }
86       }
87
88       this.fetchCnt++;
89       if(this.fetchCnt == 5)
90       {
91         this.showSpinner = false;
92       }
93     });
94
95
96       this.fetchCnt++;
97       if(this.fetchCnt == 5)
98       {
99         this.showSpinner = false;
100       }
101     });
102
103     
104
105
106     this._securityService.getReportUserList()
107     .subscribe((responseUserList) => {
108       this.reportUserList = responseUserList;
109
110       //console.log(this.reportUserList);
111
112       for(let ru=0; ru<this.reportUserList.length; ru++)
113       {
114         if(this.reportUserList[ru]["readOnly"] === true)
115         {
116           this.userEditAccessArr[ru] = false;
117         }
118         else
119         {
120           this.userEditAccessArr[ru] = true;
121         }
122       }
123
124       this.fetchCnt++;
125       if(this.fetchCnt == 5)
126       {
127         this.showSpinner = false;
128       }
129     });
130
131     this._securityService.getReportSecurityRoles()
132     .subscribe((responseSecurityRoles) => {
133       this.reportSecurityRoles = responseSecurityRoles;
134
135       //console.log(this.reportSecurityRoles);
136
137       for(let sr=0; sr<this.reportSecurityRoles.length; sr++)
138       {
139         if(this.reportSecurityRoles[sr]["readOnly"] === true)
140         {
141           this.addRoleEditAccessArr[sr] = false;
142         }
143         else
144         {
145           this.addRoleEditAccessArr[sr] = true;
146         }
147       }
148       //console.log(this.reportSecurityRoles);
149
150       this._securityService.getReportRoleList()
151     .subscribe((responseRoleList) => {
152       this.reportRoleList = responseRoleList;
153
154       //console.log(this.reportRoleList);
155
156       for(let m=0; m<this.reportSecurityRoles.length; m++)
157       {
158         for(let n=0; n<this.reportRoleList.length; n++)
159         {
160           if(this.reportSecurityRoles[m] === this.reportRoleList[n])
161           {
162             this.reportRoleList.splice(n, 1);
163           }
164         }
165       }
166
167       this.fetchCnt++;
168       if(this.fetchCnt == 5)
169       {
170         this.showSpinner = false;
171       }
172     });
173
174       this.fetchCnt++;
175       if(this.fetchCnt == 5)
176       {
177         this.showSpinner = false;
178       }
179     });
180
181     
182   }
183
184   addReportUser()
185   {
186
187     this.showUserListSpinner = true;
188     let reportUserId = "";
189     for(let p=0; p<this.reportOwnerList.length; p++)
190     {
191       if(this.reportOwnerList[p]["name"] === this.reportUser)
192       {
193         reportUserId = this.reportOwnerList[p]["id"];
194       }
195     }
196
197     //console.log(reportUserId);
198
199     this._securityService.addReportUser(reportUserId)
200     .subscribe((responseAddUser) => {
201       
202
203       this._securityService.getReportUserList()
204     .subscribe((responseUserList) => {
205       this.reportUserList = responseUserList;
206
207       //console.log(this.reportUserList);
208
209       this.showUserListSpinner = false;
210       });
211
212
213     });
214     
215   }
216
217   removeReportUser(reportUserName : string)
218   {
219     this.showUserListSpinner = true;
220     let reportUserId = "";
221     for(let p=0; p<this.reportOwnerList.length; p++)
222     {
223       if(this.reportOwnerList[p]["name"] === reportUserName)
224       {
225         reportUserId = this.reportOwnerList[p]["id"];
226         this.userEditAccessArr[p] = false;
227       }
228     }
229
230     //console.log(reportUserId);
231
232     this._securityService.removeReportUser(reportUserId)
233     .subscribe((responseRemoveUser) => {
234       
235
236       this._securityService.getReportUserList()
237     .subscribe((responseUserList) => {
238       this.reportUserList = responseUserList;
239
240       //console.log(this.reportUserList);
241
242       this.showUserListSpinner = false;
243       });
244
245
246     });
247   }
248
249   addUserEditAccess(reportUserId : string, reportUserIndex : number)
250   {
251     //console.log(reportUserId, reportUserIndex);
252     //console.log(this.userEditAccessArr);
253     let readOnly="";
254
255    if(this.userEditAccessArr[reportUserIndex] === true)
256    {
257      readOnly = "N";
258    }
259    else
260    {
261      readOnly = "Y";
262    }
263
264     this._securityService.addUserEditAccess(reportUserId, readOnly)
265     .subscribe((responseAddUserAccess) => {
266       
267     });
268   }
269
270
271   addReportRole()
272   {
273     let roleId;
274     this.showRoleListSpinner = true;
275
276     //console.log(this.reportRoleList);
277
278     for(let ro=0; ro<this.reportRoleList.length; ro++)
279     {
280       if(this.reportRoleList[ro]["name"] === this.reportRole)
281       {
282         roleId = this.reportRoleList[ro]["id"];
283       }
284     }
285
286     //console.log(roleId);
287
288     this._securityService.addReportRole(roleId)
289     .subscribe((addRoleResponse) => {
290
291       this._securityService.getReportSecurityRoles()
292     .subscribe((responseSecurityRoles) => {
293       this.reportSecurityRoles = responseSecurityRoles;
294
295       //console.log(this.reportSecurityRoles);
296
297       this._securityService.getReportRoleList()
298     .subscribe((responseRoleList) => {
299       this.reportRoleList = responseRoleList;
300
301       //console.log(this.reportRoleList);
302
303       for(let m=0; m<this.reportSecurityRoles.length; m++)
304       {
305         for(let n=0; n<this.reportRoleList.length; n++)
306         {
307           if(this.reportSecurityRoles[m] === this.reportRoleList[n])
308           {
309             this.reportRoleList.splice(n, 1);
310           }
311         }
312       }
313
314       this.showRoleListSpinner = false;
315     });
316
317     });
318
319     });
320   }
321
322   removeReportRole(roleId : string)
323   {
324     this.showRoleListSpinner = true;
325
326     for(let rl=0; rl<this.reportSecurityRoles.length; rl++)
327     {
328       if(this.reportSecurityRoles[rl]["id"] === roleId)
329       {
330         this.addRoleEditAccessArr[rl] = false;
331       }
332     }
333     
334
335     this._securityService.removeReportRole(roleId)
336     .subscribe((removeRoleResponse) => {
337       this._securityService.getReportSecurityRoles()
338     .subscribe((responseSecurityRoles) => {
339       this.reportSecurityRoles = responseSecurityRoles;
340
341       //console.log(this.reportSecurityRoles);
342
343       this._securityService.getReportRoleList()
344     .subscribe((responseRoleList) => {
345       this.reportRoleList = responseRoleList;
346
347       //console.log(this.reportRoleList);
348
349       for(let m=0; m<this.reportSecurityRoles.length; m++)
350       {
351         for(let n=0; n<this.reportRoleList.length; n++)
352         {
353           if(this.reportSecurityRoles[m] === this.reportRoleList[n])
354           {
355             this.reportRoleList.splice(n, 1);
356           }
357         }
358       }
359
360       this.showRoleListSpinner = false;
361     });
362
363     });
364     });
365   }
366
367   addRoleEditAccess(roleId : string, roleIndex : number)
368   {
369     //console.log(this.addRoleEditAccessArr);
370     let readOnly = "";
371
372     if(this.addRoleEditAccessArr[roleIndex] === true)
373     {
374       readOnly = "N";
375     }
376     else
377     {
378       readOnly = "Y";
379     }
380
381
382     this._securityService.addRoleEditAccess(roleId, readOnly)
383     .subscribe((responseEditRoleAccess) => {
384
385     });
386   }
387
388
389   saveSecurityTabData()
390   {
391     this.fetchCnt = 0;
392     let finalPostObj = new Object();
393
394     // //console.log(this.reportOwnerList);
395     for(let kl=0; kl<this.reportOwnerList.length; kl++)
396     {
397       if(this.reportOwnerList[kl]["name"] == this.reportOwner)
398       {
399         finalPostObj["userId"] = this.reportOwnerList[kl]["id"];
400       }
401     }
402
403     if(this.publicReport === "YES")
404     {
405       finalPostObj["isPublic"] = "true";
406     }
407     else
408     {
409       finalPostObj["isPublic"] = "false";
410     }
411      //console.log(finalPostObj);
412
413     this._securityService.saveSecurityTabInfo(finalPostObj)
414     .subscribe((responseFinalPost) => {
415
416       
417     this.showSpinner = true;
418
419     this._securityService.getReportOwnerList()
420     .subscribe((responseOwnerList) => {
421       this.reportOwnerList = responseOwnerList;
422
423       //console.log(this.reportOwnerList);
424
425       this._securityService.getReportSecurityInfo()
426     .subscribe((responseSecurityInfo) => {
427       this.reportSecurityInfo = responseSecurityInfo;
428
429       //console.log(this.reportSecurityInfo);
430
431       this.reportOwnerId = this.reportSecurityInfo["ownerId"];
432
433       this.publicReport = this.reportSecurityInfo["isPublic"] == "true" ? "YES" : "NO";
434
435       for(let k=0; k<this.reportOwnerList.length; k++)
436       {
437         if(this.reportOwnerId === this.reportOwnerList[k]["id"])
438         {
439           this.reportOwner = this.reportOwnerList[k]["name"];
440         }
441       }
442
443       this.fetchCnt++;
444       if(this.fetchCnt == 5)
445       {
446         this.showSpinner = false;
447       }
448     });
449
450
451       this.fetchCnt++;
452       if(this.fetchCnt == 5)
453       {
454         this.showSpinner = false;
455       }
456     });
457
458     
459
460
461     this._securityService.getReportUserList()
462     .subscribe((responseUserList) => {
463       this.reportUserList = responseUserList;
464
465       //console.log(this.reportUserList);
466
467       for(let ru=0; ru<this.reportUserList.length; ru++)
468       {
469         if(this.reportUserList[ru]["readOnly"] === true)
470         {
471           this.userEditAccessArr[ru] = false;
472         }
473         else
474         {
475           this.userEditAccessArr[ru] = true;
476         }
477       }
478
479       this.fetchCnt++;
480       if(this.fetchCnt == 5)
481       {
482         this.showSpinner = false;
483       }
484     });
485
486     this._securityService.getReportSecurityRoles()
487     .subscribe((responseSecurityRoles) => {
488       this.reportSecurityRoles = responseSecurityRoles;
489
490       //console.log(this.reportSecurityRoles);
491
492       for(let sr=0; sr<this.reportSecurityRoles.length; sr++)
493       {
494         if(this.reportSecurityRoles[sr]["readOnly"] === true)
495         {
496           this.addRoleEditAccessArr[sr] = false;
497         }
498         else
499         {
500           this.addRoleEditAccessArr[sr] = true;
501         }
502       }
503       //console.log(this.reportSecurityRoles);
504
505       this._securityService.getReportRoleList()
506     .subscribe((responseRoleList) => {
507       this.reportRoleList = responseRoleList;
508
509       //console.log(this.reportRoleList);
510
511       for(let m=0; m<this.reportSecurityRoles.length; m++)
512       {
513         for(let n=0; n<this.reportRoleList.length; n++)
514         {
515           if(this.reportSecurityRoles[m] === this.reportRoleList[n])
516           {
517             this.reportRoleList.splice(n, 1);
518           }
519         }
520       }
521
522       this.fetchCnt++;
523       if(this.fetchCnt == 5)
524       {
525         this.showSpinner = false;
526       }
527     });
528
529       this.fetchCnt++;
530       if(this.fetchCnt == 5)
531       {
532         this.showSpinner = false;
533       }
534     });
535
536     });
537   }
538
539 }