"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