ngx-admin/src/app/@theme/components/header/header.component.ts

94 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-06-21 17:09:29 +03:00
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { NbMenuService, NbSidebarService } from '@nebular/theme';
import { UserData } from '../../../@core/data/users';
2018-06-21 17:09:29 +03:00
import { AnalyticsService } from '../../../@core/utils/analytics.service';
import { takeWhile } from 'rxjs/operators/takeWhile';
import { fromEvent as observableFromEvent } from 'rxjs/observable/fromEvent';
import { AbService } from '../../../@core/utils/ab.service';
import { LayoutService } from '../../../@core/utils';
@Component({
selector: 'ngx-header',
2017-04-28 15:14:05 +03:00
styleUrls: ['./header.component.scss'],
templateUrl: './header.component.html',
})
2018-06-21 17:09:29 +03:00
export class HeaderComponent implements OnInit , OnDestroy {
@Input() position = 'normal';
user: any;
2018-06-21 17:09:29 +03:00
hireTextVariant: string = 'solution-hire';
userMenu = [{ title: 'Profile' }, { title: 'Log out' }];
2018-06-21 17:09:29 +03:00
private alive = true;
constructor(private sidebarService: NbSidebarService,
private menuService: NbMenuService,
private userService: UserData,
2018-06-21 17:09:29 +03:00
private analytics: AnalyticsService,
private abService: AbService,
private layoutService: LayoutService) {
2018-06-21 17:09:29 +03:00
observableFromEvent(document, 'mouseup')
.pipe(takeWhile(() => this.alive))
.subscribe(() => {
let selection: any;
if (window.getSelection) {
selection = window.getSelection();
} else if ((<any> document).selection) {
selection = (<any> document).selection.createRange();
}
if (selection && selection.toString() === 'contact@akveo.com') {
this.analytics.trackEvent('contactEmail', 'select');
}
});
}
ngOnInit() {
this.userService.getUsers()
.subscribe((users: any) => this.user = users.nick);
2018-06-21 17:09:29 +03:00
this.listenForVariants();
}
2017-06-21 17:34:10 +03:00
toggleSidebar(): boolean {
this.sidebarService.toggle(true, 'menu-sidebar');
this.layoutService.changeLayoutSize();
return false;
}
goToHome() {
this.menuService.navigateHome();
}
startSearch() {
2018-06-21 17:09:29 +03:00
this.analytics.trackEvent('startSearch');
}
trackEmailClick() {
this.analytics.trackEvent('contactEmail', 'click');
}
ngOnDestroy() {
this.alive = false;
}
listenForVariants() {
const variants = [
AbService.VARIANT_DEVELOPERS_HIRE,
AbService.VARIANT_HIGHLIGHT_HIRE,
AbService.VARIANT_SOLUTION_HIRE,
];
this.abService.onAbEvent()
.subscribe((e: { name: string }) => {
if (variants.includes(e.name)) {
this.hireTextVariant = e.name;
}
});
}
}