import { Component, Injector, OnInit, ViewChild } from '@angular/core'; import { AppConsts } from '@shared/AppConsts'; import { UrlHelper } from '@shared/helpers/UrlHelper'; import { CustomerServiceProxy, SubscriptionStartType } from '@shared/service-proxies/service-proxies'; import { ChatSignalrService } from 'app/shared/layout/chat/chat-signalr.service'; import * as moment from 'moment'; import { AppComponentBase } from 'shared/common/app-component-base'; import { SignalRHelper } from 'shared/helpers/SignalRHelper'; import { LinkedAccountsModalComponent } from '@app/shared/layout/linked-accounts-modal.component'; import { LoginAttemptsModalComponent } from '@app/shared/layout/login-attempts-modal.component'; import { ChangePasswordModalComponent } from '@app/shared/layout/profile/change-password-modal.component'; import { ChangeProfilePictureModalComponent } from '@app/shared/layout/profile/change-profile-picture-modal.component'; import { MySettingsModalComponent } from '@app/shared/layout/profile/my-settings-modal.component'; import { NotificationSettingsModalComponent } from '@app/shared/layout/notifications/notification-settings-modal.component'; import { UserNotificationHelper } from '@app/shared/layout/notifications/UserNotificationHelper'; import { filter } from 'rxjs/operators'; import * as signalR from '@aspnet/signalr'; import { Router, NavigationEnd } from '@angular/router'; import { EmergencyNotifModalComponent } from './shared/layout/notifications/emegency-notifications.component'; import { UrlService } from '@app/shared/url.service'; @Component({ templateUrl: './app.component.html', styleUrls: ['./app.component.less'] }) export class AppComponent extends AppComponentBase implements OnInit { subscriptionStartType = SubscriptionStartType; theme: string; installationMode = true; @ViewChild('loginAttemptsModal', { static: true }) loginAttemptsModal: LoginAttemptsModalComponent; @ViewChild('linkedAccountsModal', { static: false }) linkedAccountsModal: LinkedAccountsModalComponent; @ViewChild('changePasswordModal', { static: true }) changePasswordModal: ChangePasswordModalComponent; @ViewChild('changeProfilePictureModal', { static: true }) changeProfilePictureModal: ChangeProfilePictureModalComponent; @ViewChild('mySettingsModal', { static: true }) mySettingsModal: MySettingsModalComponent; @ViewChild('notificationSettingsModal', { static: true }) notificationSettingsModal: NotificationSettingsModalComponent; @ViewChild('emergencyNotifModalComponent', { static: true }) emergencyNotifModalComponent: EmergencyNotifModalComponent; @ViewChild('chatBarComponent', { static: false }) chatBarComponent; isQuickThemeSelectEnabled: boolean = this.setting.getBoolean('App.UserManagement.IsQuickThemeSelectEnabled'); IsSessionTimeOutEnabled: boolean = this.setting.getBoolean('App.UserManagement.SessionTimeOut.IsEnabled') && this.appSession.userId != null; previousUrl: string = null; currentUrl: string = null; public constructor( injector: Injector, private _chatSignalrService: ChatSignalrService, private _userNotificationHelper: UserNotificationHelper, private _customerService : CustomerServiceProxy, private _router: Router, private urlService: UrlService ) { super(injector); } ngOnInit(): void { this._userNotificationHelper.settingsModal = this.notificationSettingsModal; this._userNotificationHelper.emergencyModal = this.emergencyNotifModalComponent; this.theme = abp.setting.get('App.UiManagement.Theme').toLocaleLowerCase(); this.installationMode = UrlHelper.isInstallUrl(location.href); this.registerModalOpenEvents(); if (this.appSession.application) { SignalRHelper.initSignalR(() => { this._chatSignalrService.init(); }); } // const connection = new signalR.HubConnectionBuilder() // .configureLogging(signalR.LogLevel.Information) // .withUrl("http://localhost:65302/location") // .build(); // connection.start().then(function () { // console.log('Connected!'); // }).catch(function (err) { // return console.error(err.toString()); // }); // connection.on("GetLocation", (latitude: string,longitude: string) => { // console.log('test'); // this.messageService.add({ severity: 'success', summary: 'Success Notification', detail: 'Yey' }); // }); // Setting the previous and current URL. this._router.events.pipe( filter((event) => event instanceof NavigationEnd) ).subscribe((event: NavigationEnd) => { this.previousUrl = this.currentUrl; this.currentUrl = event.url; this.urlService.setPreviousUrl(this.previousUrl); }); } checkIfUser(){ this._customerService.checkIfCustomer(this.appSession.userId).subscribe(result =>{ if(result){ this._router.navigate(['/app/sprintship/customer-dashboard']); } }); } ngAfterViewInit(): void{ if(this.appSession.tenant!=null && this.appSession.tenant.tenancyName == 'fbx' && this.appSession.user.hasBackgroundImage) { this.backgroundChanger(); $("body").attr("id", "sprinthub2"); } } backgroundChanger() :void { let totalCount = 8; let num = Math.ceil(Math.random() * totalCount); document.body.style.background = "rgba(0, 0, 0, 10) url(/assets/images/backgrounds/" + num + ".jpg)"; document.body.style.backgroundRepeat = "repeat"; // console.log('background no.: ' + num); } subscriptionStatusBarVisible(): boolean { return this.appSession.tenantId > 0 && (this.appSession.tenant.isInTrialPeriod || this.subscriptionIsExpiringSoon()); } subscriptionIsExpiringSoon(): boolean { if (this.appSession.tenant.subscriptionEndDateUtc) { return moment().utc().add(AppConsts.subscriptionExpireNootifyDayCount, 'days') >= moment(this.appSession.tenant.subscriptionEndDateUtc); } return false; } registerModalOpenEvents(): void { abp.event.on('app.show.loginAttemptsModal', () => { this.loginAttemptsModal.show(); }); abp.event.on('app.show.linkedAccountsModal', () => { this.linkedAccountsModal.show(); }); abp.event.on('app.show.changePasswordModal', () => { this.changePasswordModal.show(); }); abp.event.on('app.show.changeProfilePictureModal', () => { this.changeProfilePictureModal.show(); }); abp.event.on('app.show.mySettingsModal', () => { this.mySettingsModal.show(); }); } getRecentlyLinkedUsers(): void { abp.event.trigger('app.getRecentlyLinkedUsers'); } onMySettingsModalSaved(): void { abp.event.trigger('app.onMySettingsModalSaved'); } }