application.service.js
9.16 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
213
214
215
216
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var http_1 = require("@angular/http");
var router_1 = require("@angular/router");
var Observable_1 = require("rxjs/Observable");
require("rxjs/add/operator/map");
require("rxjs/add/operator/catch");
var ApplicationService = /** @class */ (function () {
function ApplicationService(http, router) {
this.http = http;
this.router = router;
if (this.currentUser == null) {
var user = localStorage.getItem("currentUser");
if (user != null) {
this.currentUser = JSON.parse(user);
this.loggedIn = true;
}
}
this.userId = 0;
this.firstName = "";
this.lastName = "";
this.emailId = "";
}
ApplicationService.prototype.getAppSettings = function (applicationName) {
var headers = new http_1.Headers();
headers.append('Content-Type', 'application/json');
var params = new http_1.URLSearchParams();
params.set("applicationName", applicationName);
params.set("userId", this.currentUser._id);
return this.http.get('DentalDecks.Server/api/AppSettings', { headers: headers, search: params })
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.getMenuItemsWithNoChildren = function (menuItems) {
if (this.appSettingsLoaded) {
var menuItemsSubset = new Array();
for (var i = 0; i < menuItems.length; i++) {
if (menuItems[i].menuItems == null) {
for (var j = 0; j < menuItems[i].roles.length; j++) {
if (menuItems[i].roles[j] == this.currentUser.role) {
menuItemsSubset.push(menuItems[i]);
break;
}
}
}
}
return menuItemsSubset;
}
};
ApplicationService.prototype.getMenuItemsWithChildren = function (menuItems) {
if (this.appSettingsLoaded) {
var menuItemsSubset = new Array();
for (var i = 0; i < menuItems.length; i++) {
if (menuItems[i].menuItems != null) {
for (var j = 0; j < menuItems[i].roles.length; j++) {
if (menuItems[i].roles[j] == this.currentUser.role) {
menuItemsSubset.push(menuItems[i]);
break;
}
}
}
}
return menuItemsSubset;
}
};
ApplicationService.prototype.login = function (applicationName, username, password) {
var headers = new http_1.Headers();
headers.append('Content-Type', 'application/json');
var params = new http_1.URLSearchParams();
params.set("applicationName", applicationName);
params.set("username", username);
params.set("password", password);
return this.http.get('DentalDecks.Server/api/Authenticate', { headers: headers, search: params })
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.logout = function () {
this.currentUser = null;
localStorage.removeItem("currentUser");
this.router.navigate(['/login']);
};
ApplicationService.prototype.resetPassword = function (username) {
var headers = new http_1.Headers();
headers.append('Content-Type', 'application/json');
var user = new Object();
user.emailAddress = username;
return this.http.post('DentalDecks.Server/api/Password', JSON.stringify(user), { headers: headers })
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.updatePassword = function (userId, password) {
var headers = new http_1.Headers();
headers.append('Content-Type', 'application/json');
var user = new Object();
user.userId = userId;
user.password = password;
return this.http.post('DentalDecks.Server/api/UpdatePassword', JSON.stringify(user), { headers: headers })
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.isResetPasswordExpired = function (userId) {
var headers = new http_1.Headers();
headers.append('Content-Type', 'application/json');
var params = new http_1.URLSearchParams();
params.set("userId", userId);
return this.http.get('DentalDecks.Server/api/Password', { headers: headers, search: params })
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.getLongDate = function (date) {
var returnValue = new Date(date);
return returnValue.toLocaleDateString();
};
ApplicationService.prototype.getDateTime = function (date) {
var orderDate = "";
if (date != null && date != "")
orderDate = new Date(date).toLocaleDateString() + " " + new Date(date).toLocaleTimeString();
return orderDate;
};
ApplicationService.prototype.getRelativeDate = function (date) {
if (date != null) {
date = new Date(date);
var delta = Math.round((+new Date - date) / 1000);
var minute = 60, hour = minute * 60, day = hour * 24, week = day * 7;
var fuzzy;
if (delta < 30) {
fuzzy = 'just now.';
}
else if (delta < minute) {
fuzzy = delta + ' seconds ago.';
}
else if (delta < 2 * minute) {
fuzzy = 'a minute ago.';
}
else if (delta < hour) {
fuzzy = Math.floor(delta / minute) + ' minutes ago.';
}
else if (Math.floor(delta / hour) == 1) {
fuzzy = '1 hour ago.';
}
else if (delta < day) {
fuzzy = Math.floor(delta / hour) + ' hours ago.';
}
else if (delta < day * 2 && delta > day) {
fuzzy = 'yesterday';
}
else {
fuzzy = Math.floor(delta / (60 * 60 * 24)) + ' days ago';
}
return fuzzy;
}
else {
return "";
}
};
ApplicationService.prototype.extractData = function (res) {
var body = res.json();
return body || {};
};
ApplicationService.prototype.handleError = function (error) {
// In a real world app, we might use a remote logging infrastructure
var errMsg;
if (error instanceof http_1.Response) {
var body = error.json() || '';
var err = body.error || JSON.stringify(body);
errMsg = error.status + " - " + (error.statusText || '') + " " + err;
}
else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable_1.Observable.throw(errMsg);
};
ApplicationService.prototype.getAccountTypes = function () {
return this.http.get('http://localhost:85/AIAHTML5.Server/api/accounttype')
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.getStates = function () {
return this.http.get('http://localhost:85/AIAHTML5.Server/api/state')
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.getCountries = function () {
return this.http.get('http://localhost:85/AIAHTML5.Server/api/country')
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.getSecurityQuestions = function () {
return this.http.get('http://localhost:85/AIAHTML5.Server/api/securityquestionlist')
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService.prototype.getLicenseTypes = function () {
return this.http.get('http://localhost:85/AIAHTML5.Server/api/licensetype')
.map(this.extractData)
.catch(this.handleError);
};
ApplicationService = __decorate([
core_1.Injectable(),
__metadata("design:paramtypes", [http_1.Http, router_1.Router])
], ApplicationService);
return ApplicationService;
}());
exports.ApplicationService = ApplicationService;
//# sourceMappingURL=application.service.js.map