consumerportal
Version:
mydna Custimised for you
136 lines (109 loc) • 3.86 kB
text/typescript
/// <reference path="../includes.ts" />
module app {
import IUser = services.IUser;
import CartItem = services.CartItem;
import ReportNavigationCard = services.ReportNavigationCard;
import IPatientCase = services.IPatientCase;
class SiteNavController {
public static $inject = [
'$scope',
'$location',
'userService',
'patientService',
'cartService',
'authenSrvc'
];
public $onInit: Function;
public siteOptions: boolean = false;
public user: IUser;
public reports: services.ReportNavigationCard[];
public cartItems: CartItem[] = [];
public hasMarketplace: boolean = false;
private random: number = Math.random();
constructor(
private $scope: any,
private $location: angular.ILocationService,
private userService: services.IUserService,
private patientService: services.IPatientService,
private cartService: services.ICartService,
private authenSrvc: authenSrvc.IAuthenService
) {
this.$onInit = () => {
/*
if (this.userService.isLoggedIn()) {
this.getUser();
}
*/
$scope.$on('changeUser', (ev: any, user: IUser) => {
if (user) {
this.getUser();
}
else {
this.user = null;
}
});
$scope.$on('cartUpdated', (ev: any, cartItems: CartItem[]) => {
this.cartItems = cartItems;
});
this.$scope.$on('patientCasesUpdated', (ev: any, pcs: IPatientCase[]) => {
if (pcs.length > 0) {
this.getReports();
}
});
}
}
logOut() {
this.user = null;
this.authenSrvc.logOut();
}
private removeListeners() {
$(document).off('click.toggle' + this.random);
$(window).off('scroll.popup' + this.random);
}
public $onDestroy() {
this.removeListeners();
}
private close = () => {
this.siteOptions = false;
this.removeListeners();
this.$scope.$apply();
};
public toggleSiteOptions() {
if (!this.siteOptions) {
this.siteOptions = true;
setTimeout(() => {
$(document).on('click.toggle' + this.random, this.close);
$(window).on('scroll.popup' + this.random, this.close)
});
}
}
open(hash:string) {
this.siteOptions = false;
window.location.hash = hash;
}
openUrl(url: string, newWindow: boolean = false) {
window.open(url, newWindow ? "_blank" : "_self");
}
private getReports() {
this.patientService.getReportNavigation().then((values: ReportNavigationCard[]) => {
this.reports = values;
});
}
private getUser() {
this.userService.user().then((user: IUser) => {
this.user = user;
});
}
}
class Header {
public bindings: any;
public templateUrl: string = 'views/header.html';
public controller: any = SiteNavController;
public controllerAs: string = 'vm';
constructor() {
}
}
angular
.module('app')
.component('mydnaHeader', new Header());
}