import { AppStorageService } from './service/common/app-storage.service'; import { WindowRefService } from './service/common/window.ref.service'; import { CommonService } from './service/common/common.service'; import { SharedService } from './service/common/shared.service'; import { Component, OnInit } from '@angular/core'; import { Http } from '@angular/http'; import { Location } from '@angular/common'; import { TranslateService } from '@ngx-translate/core'; import * as _ from 'lodash'; import { AppConstants } from './common/AppConstants'; import { SessionStorageService } from './service/common/session-storage.service'; import { Router, ActivatedRoute } from '@angular/router'; import { AuthService } from './service/common/auth.service'; import { UserService } from './service/common/user.service'; import { environment } from './environments/environment'; import { Subscription } from 'rxjs/Subscription'; import { ToasterConfig, IToasterConfig } from 'angular2-toaster'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/skip'; import { NavService, INavItem } from './service/common/nav.service'; import { CrowdinService } from './service/common/crowdin.service'; @Component({ selector: 'app-root', templateUrl: 'dbm.data.store.component.html', styleUrls: ['dbm.data.store.component.scss'] }) export class AppComponent implements OnInit { private language: string; private langOptions: any[] = []; public version: string; private envName: string; public notifyOptions: any; public showLoader: boolean = false; public toasterConfig: ToasterConfig; private navToggle = false; public showPrivacyDialog = false; public showLegalNotices = false; public eulaReadOnly = false; public navItems: INavItem[] = []; public currentDate: Date = new Date(); constructor(public translate: TranslateService, public user: UserService, public auth: AuthService, public location: Location, public router: Router, public http: Http, public route: ActivatedRoute, public sessionStorageService: SessionStorageService, public appStorageService: AppStorageService, public sharedService: SharedService, public commonService: CommonService, public windowRef: WindowRefService, public activatedRoute: ActivatedRoute, public navService: NavService, public crowdinService: CrowdinService) { this.appStorageService.set(AppConstants.LOCALE, window.navigator.language); this.language = window.navigator.language; // Two character language like 'en' const options = this.sessionStorageService.get(AppConstants.optionListStorageKey); this.langOptions = options ? options['languages'] : []; this.envName = environment.envName; this.version = environment.versionNumber; console.log('In App Component. Env Name = ', this.envName); this.sharedService.$loader.subscribe(visible => { this.showLoader = visible; }); this.navService.$navItemsChanged.subscribe(navItems => { this.navItems = navItems; }); this.toasterConfig = new ToasterConfig({ limit: 3, tapToDismiss: true, showCloseButton: true, newestOnTop: true, timeout: 3000, animation: 'flyLeft' }); } isSearchRoute() { if (this.router.url === '/projects') { return true; } } goToSettings() { this.router.navigate(['/settings']); } goToPrivacyPolicy() { this.showPrivacyDialog = true; } goToEndUserAgreement() { this.eulaReadOnly = true; } goToLegalNotices() { this.showLegalNotices = true; } goToRoute(navItem: INavItem) { if (navItem.routeUrl) { this.router.navigateByUrl(navItem.routeUrl); } } cancelLegal() { this.showLegalNotices = false; } cancelPrivacy() { this.showPrivacyDialog = false; } cancelEula() { if (this.eulaReadOnly) { this.eulaReadOnly = false; return; } if (this.user && this.user.authentication) { this.user.authentication.eulaAcceptance = null; this.appStorageService.set(AppConstants.ISB_EULA, this.user.authentication.eulaAcceptance); } this.router.navigate(['./logout']); } logout() { this.auth.logout(); if (environment.envName === 'test') { this.router.navigate(['/logout']); } } ngOnInit() { this.eulaReadOnly = false; if (location.pathname === '/logout') { return; } if (location.search.includes("translate=true")) { this.crowdinService.UseCrowdin() } if (location.hash === "#/stats" || location.pathname === '/stats') { this.appStorageService.set(AppConstants.ShowStats, true); } if (!_.includes(location.href, AppConstants.OauthCallBack)) { if (location.hash && location.hash != '#/' && location.hash != '#') { const url = location.href; this.appStorageService.set(AppConstants.ReturnUrl, url); console.log('Setting Return URL to ', url); } } console.log('Language = ', this.language); this.user.authenticatedFromStorage(); // if(!_.includes(location.href, AppConstants.OauthCallBack)) { // this.router.navigate(['/oauth_callback']); // } this.language = 'en'; this.translate.setDefaultLang(this.language); console.log('Language = ', this.language); } toggleNav(onlyClose: boolean = false): void { if (onlyClose) { this.navToggle = false; } else { this.navToggle = !this.navToggle; } } navClass(): string { if (this.navToggle) { return ''; } else { return 'collapse'; } } }