app.component.ts
7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import { Component, OnInit } from '@angular/core';
import { UserService } from './components/userentity/user.service';
import { ManageDiscountCodeService } from './components/managediscountcode/managediscountcode.service';
import { SubscriptionPriceService } from './components/subscriptionprice/subscriptionprice.service';
import { LicenseService } from './components/licenseentity/license.service';
import { ReportService } from './components/reports/report.service';
import { UserManageRightsModel } from './components/userentity/datamodel';
//import { MyAuthService } from './shared/my-auth.service';
import { GlobalService } from './shared/global';
import { Router, NavigationEnd } from '@angular/router';
import { LoadingService } from './shared/loading.service';
import {Idle, DEFAULT_INTERRUPTSOURCES} from '@ng-idle/core';
import {Keepalive} from '@ng-idle/keepalive';
import { Title } from '@angular/platform-browser';
import { ConfirmService } from './shared/confirm/confirm.service';
import { timeout } from 'rxjs/operator/timeout';
//import { HttpClient } from '@angular/common/http';
//import { HttpErrorResponse } from '@angular/common/http';
//import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-component',
templateUrl: '../app/app.component.html',
providers: [UserService, ManageDiscountCodeService, SubscriptionPriceService, LicenseService, ReportService]
})
export class AppComponent implements OnInit {
public obj: any;
public objMenu: Array<any>=[];
public objMenuGernal: any;
public menustaus: string;
public submenustaus: string;
public UpdateProfileVisible: boolean;
public UserManageRightsList: Array<UserManageRightsModel>;
public LicenseTypeId:any;
constructor(private idle: Idle, private keepalive: Keepalive,private titleService: Title,private _confirmService: ConfirmService,private userservice: UserService,private _loadingService: LoadingService, public global: GlobalService, private router: Router,) {
const projectTitle= this.titleService.getTitle();
//console.log("idleTime: "+this.global.aiaIdleTime+" aiaIdleTimeOut: "+this.global.aiaIdleTimeOut+" Interval: "+this.global.aiaPingInterval);
// sets an idle timeout of 20 minutes.
this.idle.setIdle(this.global.aiaIdleTime);
// sets a timeout period of 30 seconds. after 30 seconds of inactivity, the user will be considered timed out.
this.idle.setTimeout(this.global.aiaIdleTimeOut);
// sets the ping interval to 10 seconds
this.keepalive.interval(this.global.aiaPingInterval);
// sets the default interrupts, in this case, things like clicks, scrolls,mousemove touches to the document
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
this.idle.onInterrupt.subscribe(() => {
this.titleService.setTitle(projectTitle);
})
this.idle.onTimeout.subscribe(() => {
//console.log("Timed out!");
this.titleService.setTitle('Your session has expired!');
this._loadingService.ShowLoading("global-loading");
this.loginManageStatus('logout');
});
this.idle.onTimeoutWarning.subscribe((countdown) => {
// console.log("You will time out in "+countdown);
var minute=Math.floor(countdown/60);
var remaining = minute+':'+(("00" + (countdown - minute * 60)).slice(-2) );
this.titleService.setTitle(remaining+' until your session times out!');
});
this.keepalive.onPing.subscribe(() =>{
// this.lastPing = new Date();
// console.log("last ping: "+this.lastPing);
this.loginManageStatus('update');
});
// this.idle.onIdleEnd.subscribe(() => {
// console.log("No longer idle. ");
// });
// this.idle.onIdleStart.subscribe(() =>{
// console.log("You\'ve gone idle!");
// });
if(window.location.host=="localhost:4200")
{
// for 'ng serve --open' command
//**** for localhost:4200 *****//
//insert new session
this.loginManageStatus('insert');
}
this.idle.watch();
}
ngOnInit(): void {
this.menustaus = "True";
this.global.getJSON().subscribe(data => {
this.obj = data["AdminSections"] ;
this.LicenseTypeId=this.global.LicenseTypeId;
if(this.LicenseTypeId !=undefined && this.LicenseTypeId!=0 && this.global.UserTypeName=="Client Admin")
{
if(this.obj[2].UserType=="Client Admin")
{
var mainsection=this.obj[2];
var clientadminSection=mainsection.HeaderMenu[4];
var siteUageReportSection=clientadminSection.SubMenu[6];
var concurrentLicenseId=siteUageReportSection.LicenseTypeId;
//do not show this report for concurrent license of client admin
if(concurrentLicenseId ==this.LicenseTypeId)
{
siteUageReportSection.SubMenuStatus="False";
}
}
}
for (let i = 0; i < 7; i++) {
if (this.obj[i].Id == this.global.UserType) {
if (this.global.UserTypeName == "General Admin") {
this.userservice.GetGeneralAdminMenu({
UserId: this.global.UserId,
UserType: this.global.UserTypeName
}).subscribe(x => {
this.UserManageRightsList = x;
this.objMenuGernal = this.obj[i].HeaderMenu;
//this.objMenuGernal = this.objMenu;
//this.objMenu='';
for (var imenu = 0; imenu < this.objMenuGernal.length; imenu++) {
for (var k = 0; k < this.UserManageRightsList.length; k++) {
if (this.objMenuGernal[imenu].HeaderMenuName == this.UserManageRightsList[k].Title) {
// this.global.objMenu.push(this.objMenuGernal[imenu]);
this.objMenu.push(this.objMenuGernal[imenu]);
break;
}
}
}
this.router.navigate(['/updateuserprofile']);
}, error => {
});
}
else {
this.objMenu = this.obj[i].HeaderMenu;
this.router.navigate(['/updateuserprofile']);
}
}
}
}, error => console.log(error));
}
logout() {
this._loadingService.ShowLoading("global-loading");
this.loginManageStatus('logout');
}
loginManageStatus(tagname:string) {
this.userservice.ManageUserLoginStatus({
userId: this.global.UserId,
tagName: tagname,
SessionId:this.global.SessionId,
isSiteUser:this.global.isSiteUser,
isAdmin:this.global.isAdmin
}).subscribe(status => {
//console.log(status);
if(status=='False')
{
if(tagname=='logout')
{
this._loadingService.HideLoading("global-loading");
}
if(window.location.host!="localhost:4200")
{
localStorage.removeItem('loggedInUserDetails');
window.location.href = window.location.origin;
}
}
},error =>{
console.log(error);
this.idle.stop();
this._confirmService.activate(error, "alertMsg");
this._loadingService.HideLoading("global-loading");
setTimeout(function(){
window.location.href = window.location.origin;
},5000);
})
}
Product() {
//window.location.href = this.global.LiveURL;
window.location.href = window.location.origin;
//this.router.navigate([this.global.LiveURL]);
}
changeOfRoutes()
{
//used to hide nevigation on ipad device while nevigate to page
$('#navbar').removeClass('navbar-collapse collapse in');
$('#navbar').addClass('navbar-collapse collapse');
}
}