1 import { Component, OnInit, Input, AfterViewInit } from '@angular/core';
2 import { SecurityService } from './security.service';
5 selector: 'app-security',
6 templateUrl: './security.component.html',
7 styleUrls: ['./security.component.css']
9 export class SecurityComponent implements OnInit {
11 @Input("reportId") reportId1 : string;
12 @Input("reportType") reportType : string;
14 reportOwnerList : {}[];
15 reportRoleList : {}[];
16 reportSecurityInfo : {};
17 reportUserList : any[];
18 reportSecurityRoles : any[];
19 showSpinner : boolean;
22 reportOwnerId : string;
23 publicReport : string;
25 showUserListSpinner : boolean;
26 userEditAccessArr : boolean[];
27 userEditAccess : string;
28 showRoleListSpinner : boolean;
30 addRoleEditAccessArr : boolean[];
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;
42 this.reportOwner = "";
43 this.publicReport = "";
44 this.showUserListSpinner = false;
45 this.userEditAccessArr = new Array();
46 this.showRoleListSpinner = false;
47 this.addRoleEditAccessArr = new Array();
53 this.showSpinner = true;
55 if(this.reportType === "Dashboard")
64 this._securityService.getReportOwnerList()
65 .subscribe((responseOwnerList) => {
66 this.reportOwnerList = responseOwnerList;
68 // console.log(this.reportOwnerList);
70 this._securityService.getReportSecurityInfo()
71 .subscribe((responseSecurityInfo) => {
72 this.reportSecurityInfo = responseSecurityInfo;
74 console.log(this.reportSecurityInfo);
76 this.reportOwnerId = this.reportSecurityInfo["ownerId"];
78 this.publicReport = this.reportSecurityInfo["isPublic"] == "true" ? "YES" : "NO";
80 for(let k=0; k<this.reportOwnerList.length; k++)
82 if(this.reportOwnerId === this.reportOwnerList[k]["id"])
84 this.reportOwner = this.reportOwnerList[k]["name"];
89 if(this.fetchCnt == 5)
91 this.showSpinner = false;
97 if(this.fetchCnt == 5)
99 this.showSpinner = false;
106 this._securityService.getReportUserList()
107 .subscribe((responseUserList) => {
108 this.reportUserList = responseUserList;
110 console.log(this.reportUserList);
112 for(let ru=0; ru<this.reportUserList.length; ru++)
114 if(this.reportUserList[ru]["readOnly"] === true)
116 this.userEditAccessArr[ru] = false;
120 this.userEditAccessArr[ru] = true;
125 if(this.fetchCnt == 5)
127 this.showSpinner = false;
131 this._securityService.getReportSecurityRoles()
132 .subscribe((responseSecurityRoles) => {
133 this.reportSecurityRoles = responseSecurityRoles;
135 console.log(this.reportSecurityRoles);
137 for(let sr=0; sr<this.reportSecurityRoles.length; sr++)
139 if(this.reportSecurityRoles[sr]["readOnly"] === true)
141 this.addRoleEditAccessArr[sr] = false;
145 this.addRoleEditAccessArr[sr] = true;
148 console.log(this.reportSecurityRoles);
150 this._securityService.getReportRoleList()
151 .subscribe((responseRoleList) => {
152 this.reportRoleList = responseRoleList;
154 console.log(this.reportRoleList);
156 for(let m=0; m<this.reportSecurityRoles.length; m++)
158 for(let n=0; n<this.reportRoleList.length; n++)
160 if(this.reportSecurityRoles[m] === this.reportRoleList[n])
162 this.reportRoleList.splice(n, 1);
168 if(this.fetchCnt == 5)
170 this.showSpinner = false;
175 if(this.fetchCnt == 5)
177 this.showSpinner = false;
187 this.showUserListSpinner = true;
188 let reportUserId = "";
189 for(let p=0; p<this.reportOwnerList.length; p++)
191 if(this.reportOwnerList[p]["name"] === this.reportUser)
193 reportUserId = this.reportOwnerList[p]["id"];
197 console.log(reportUserId);
199 this._securityService.addReportUser(reportUserId)
200 .subscribe((responseAddUser) => {
203 this._securityService.getReportUserList()
204 .subscribe((responseUserList) => {
205 this.reportUserList = responseUserList;
207 console.log(this.reportUserList);
209 this.showUserListSpinner = false;
217 removeReportUser(reportUserName : string)
219 this.showUserListSpinner = true;
220 let reportUserId = "";
221 for(let p=0; p<this.reportOwnerList.length; p++)
223 if(this.reportOwnerList[p]["name"] === reportUserName)
225 reportUserId = this.reportOwnerList[p]["id"];
226 this.userEditAccessArr[p] = false;
230 console.log(reportUserId);
232 this._securityService.removeReportUser(reportUserId)
233 .subscribe((responseRemoveUser) => {
236 this._securityService.getReportUserList()
237 .subscribe((responseUserList) => {
238 this.reportUserList = responseUserList;
240 console.log(this.reportUserList);
242 this.showUserListSpinner = false;
249 addUserEditAccess(reportUserId : string, reportUserIndex : number)
251 console.log(reportUserId, reportUserIndex);
252 console.log(this.userEditAccessArr);
255 if(this.userEditAccessArr[reportUserIndex] === true)
264 this._securityService.addUserEditAccess(reportUserId, readOnly)
265 .subscribe((responseAddUserAccess) => {
274 this.showRoleListSpinner = true;
276 console.log(this.reportRoleList);
278 for(let ro=0; ro<this.reportRoleList.length; ro++)
280 if(this.reportRoleList[ro]["name"] === this.reportRole)
282 roleId = this.reportRoleList[ro]["id"];
288 this._securityService.addReportRole(roleId)
289 .subscribe((addRoleResponse) => {
291 this._securityService.getReportSecurityRoles()
292 .subscribe((responseSecurityRoles) => {
293 this.reportSecurityRoles = responseSecurityRoles;
295 console.log(this.reportSecurityRoles);
297 this._securityService.getReportRoleList()
298 .subscribe((responseRoleList) => {
299 this.reportRoleList = responseRoleList;
301 console.log(this.reportRoleList);
303 for(let m=0; m<this.reportSecurityRoles.length; m++)
305 for(let n=0; n<this.reportRoleList.length; n++)
307 if(this.reportSecurityRoles[m] === this.reportRoleList[n])
309 this.reportRoleList.splice(n, 1);
314 this.showRoleListSpinner = false;
322 removeReportRole(roleId : string)
324 this.showRoleListSpinner = true;
326 for(let rl=0; rl<this.reportSecurityRoles.length; rl++)
328 if(this.reportSecurityRoles[rl]["id"] === roleId)
330 this.addRoleEditAccessArr[rl] = false;
335 this._securityService.removeReportRole(roleId)
336 .subscribe((removeRoleResponse) => {
337 this._securityService.getReportSecurityRoles()
338 .subscribe((responseSecurityRoles) => {
339 this.reportSecurityRoles = responseSecurityRoles;
341 console.log(this.reportSecurityRoles);
343 this._securityService.getReportRoleList()
344 .subscribe((responseRoleList) => {
345 this.reportRoleList = responseRoleList;
347 console.log(this.reportRoleList);
349 for(let m=0; m<this.reportSecurityRoles.length; m++)
351 for(let n=0; n<this.reportRoleList.length; n++)
353 if(this.reportSecurityRoles[m] === this.reportRoleList[n])
355 this.reportRoleList.splice(n, 1);
360 this.showRoleListSpinner = false;
367 addRoleEditAccess(roleId : string, roleIndex : number)
369 console.log(this.addRoleEditAccessArr);
372 if(this.addRoleEditAccessArr[roleIndex] === true)
382 this._securityService.addRoleEditAccess(roleId, readOnly)
383 .subscribe((responseEditRoleAccess) => {
389 saveSecurityTabData()
392 let finalPostObj = new Object();
394 // console.log(this.reportOwnerList);
395 for(let kl=0; kl<this.reportOwnerList.length; kl++)
397 if(this.reportOwnerList[kl]["name"] == this.reportOwner)
399 finalPostObj["userId"] = this.reportOwnerList[kl]["id"];
403 if(this.publicReport === "YES")
405 finalPostObj["isPublic"] = "true";
409 finalPostObj["isPublic"] = "false";
411 // console.log(finalPostObj);
413 this._securityService.saveSecurityTabInfo(finalPostObj)
414 .subscribe((responseFinalPost) => {
417 this.showSpinner = true;
419 this._securityService.getReportOwnerList()
420 .subscribe((responseOwnerList) => {
421 this.reportOwnerList = responseOwnerList;
423 console.log(this.reportOwnerList);
425 this._securityService.getReportSecurityInfo()
426 .subscribe((responseSecurityInfo) => {
427 this.reportSecurityInfo = responseSecurityInfo;
429 console.log(this.reportSecurityInfo);
431 this.reportOwnerId = this.reportSecurityInfo["ownerId"];
433 this.publicReport = this.reportSecurityInfo["isPublic"] == "true" ? "YES" : "NO";
435 for(let k=0; k<this.reportOwnerList.length; k++)
437 if(this.reportOwnerId === this.reportOwnerList[k]["id"])
439 this.reportOwner = this.reportOwnerList[k]["name"];
444 if(this.fetchCnt == 5)
446 this.showSpinner = false;
452 if(this.fetchCnt == 5)
454 this.showSpinner = false;
461 this._securityService.getReportUserList()
462 .subscribe((responseUserList) => {
463 this.reportUserList = responseUserList;
465 console.log(this.reportUserList);
467 for(let ru=0; ru<this.reportUserList.length; ru++)
469 if(this.reportUserList[ru]["readOnly"] === true)
471 this.userEditAccessArr[ru] = false;
475 this.userEditAccessArr[ru] = true;
480 if(this.fetchCnt == 5)
482 this.showSpinner = false;
486 this._securityService.getReportSecurityRoles()
487 .subscribe((responseSecurityRoles) => {
488 this.reportSecurityRoles = responseSecurityRoles;
490 console.log(this.reportSecurityRoles);
492 for(let sr=0; sr<this.reportSecurityRoles.length; sr++)
494 if(this.reportSecurityRoles[sr]["readOnly"] === true)
496 this.addRoleEditAccessArr[sr] = false;
500 this.addRoleEditAccessArr[sr] = true;
503 console.log(this.reportSecurityRoles);
505 this._securityService.getReportRoleList()
506 .subscribe((responseRoleList) => {
507 this.reportRoleList = responseRoleList;
509 console.log(this.reportRoleList);
511 for(let m=0; m<this.reportSecurityRoles.length; m++)
513 for(let n=0; n<this.reportRoleList.length; n++)
515 if(this.reportSecurityRoles[m] === this.reportRoleList[n])
517 this.reportRoleList.splice(n, 1);
523 if(this.fetchCnt == 5)
525 this.showSpinner = false;
530 if(this.fetchCnt == 5)
532 this.showSpinner = false;