2018-08-23 16:49:51 +02:00
|
|
|
import { Component, OnInit, HostBinding, ViewChild } from '@angular/core';
|
2018-06-19 16:55:50 +02:00
|
|
|
import { Router } from '@angular/router';
|
2018-06-25 17:03:52 +02:00
|
|
|
import { BreakpointObserver, Breakpoints, BreakpointState } from '@angular/cdk/layout';
|
2018-06-19 16:55:50 +02:00
|
|
|
|
|
|
|
import { AuthService } from 'app/core/services/auth.service';
|
2018-07-06 09:38:25 +02:00
|
|
|
import { AutoupdateService } from 'app/core/services/autoupdate.service';
|
|
|
|
import { OperatorService } from 'app/core/services/operator.service';
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2018-06-29 17:24:44 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core'; //showcase
|
2018-07-04 17:51:31 +02:00
|
|
|
import { BaseComponent } from 'app/base.component';
|
2018-07-31 15:46:55 +02:00
|
|
|
import { pageTransition, navItemAnim } from 'app/shared/animations';
|
2018-08-23 16:49:51 +02:00
|
|
|
import { MatDialog, MatSidenav } from '@angular/material';
|
|
|
|
import { ViewportService } from '../core/services/viewport.service';
|
2018-07-03 11:52:16 +02:00
|
|
|
|
2018-06-13 18:34:10 +02:00
|
|
|
@Component({
|
2018-06-16 18:05:46 +02:00
|
|
|
selector: 'app-site',
|
2018-07-31 15:46:55 +02:00
|
|
|
animations: [pageTransition, navItemAnim],
|
2018-06-16 18:05:46 +02:00
|
|
|
templateUrl: './site.component.html',
|
2018-07-26 16:40:34 +02:00
|
|
|
styleUrls: ['./site.component.scss']
|
2018-06-13 18:34:10 +02:00
|
|
|
})
|
2018-07-04 17:51:31 +02:00
|
|
|
export class SiteComponent extends BaseComponent implements OnInit {
|
2018-08-02 16:39:08 +02:00
|
|
|
/**
|
2018-08-23 16:49:51 +02:00
|
|
|
* HTML element of the side panel
|
2018-08-02 16:39:08 +02:00
|
|
|
*/
|
2018-08-23 16:49:51 +02:00
|
|
|
@ViewChild('sideNav') sideNav: MatSidenav;
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2018-08-02 16:39:08 +02:00
|
|
|
/**
|
2018-08-23 16:49:51 +02:00
|
|
|
* Get the username from the operator (should be known already)
|
2018-08-02 16:39:08 +02:00
|
|
|
*/
|
2018-08-23 16:49:51 +02:00
|
|
|
username = this.operator.username;
|
2018-08-07 12:30:21 +02:00
|
|
|
|
2018-08-02 16:39:08 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param authService
|
|
|
|
* @param autoupdateService
|
|
|
|
* @param operator
|
|
|
|
* @param router
|
|
|
|
* @param breakpointObserver
|
|
|
|
* @param translate
|
|
|
|
* @param dialog
|
|
|
|
*/
|
2018-06-25 17:03:52 +02:00
|
|
|
constructor(
|
|
|
|
private authService: AuthService,
|
2018-07-06 09:38:25 +02:00
|
|
|
private autoupdateService: AutoupdateService,
|
|
|
|
private operator: OperatorService,
|
2018-06-25 17:03:52 +02:00
|
|
|
private router: Router,
|
2018-08-23 16:49:51 +02:00
|
|
|
public vp: ViewportService,
|
2018-08-07 12:30:21 +02:00
|
|
|
public translate: TranslateService,
|
2018-08-02 16:39:08 +02:00
|
|
|
public dialog: MatDialog
|
2018-07-04 17:51:31 +02:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
2018-06-25 17:03:52 +02:00
|
|
|
|
2018-08-02 16:39:08 +02:00
|
|
|
/**
|
|
|
|
* Initialize the site component
|
|
|
|
*/
|
2018-06-25 17:03:52 +02:00
|
|
|
ngOnInit() {
|
2018-08-23 16:49:51 +02:00
|
|
|
this.vp.checkForChange();
|
2018-06-28 17:11:04 +02:00
|
|
|
|
2018-08-22 16:03:49 +02:00
|
|
|
// get a translation via code: use the translation service
|
2018-08-16 17:03:39 +02:00
|
|
|
// this.translate.get('Motions').subscribe((res: string) => {
|
2018-08-22 16:03:49 +02:00
|
|
|
// console.log('translation of motions in the target language: ' + res);
|
|
|
|
// });
|
2018-07-06 09:38:25 +02:00
|
|
|
|
2018-08-22 16:03:49 +02:00
|
|
|
// start autoupdate if the user is logged in:
|
2018-07-06 09:38:25 +02:00
|
|
|
this.operator.whoAmI().subscribe(resp => {
|
|
|
|
if (resp.user) {
|
|
|
|
this.autoupdateService.startAutoupdate();
|
|
|
|
} else {
|
|
|
|
//if whoami is not sucsessfull, forward to login again
|
|
|
|
this.operator.clear();
|
|
|
|
this.router.navigate(['/login']);
|
|
|
|
}
|
2018-06-29 17:24:44 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-23 16:49:51 +02:00
|
|
|
/**
|
|
|
|
* Closes the sidenav in mobile view
|
|
|
|
*/
|
|
|
|
toggleSideNav() {
|
|
|
|
if (this.vp.isMobile) {
|
|
|
|
this.sideNav.toggle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 16:39:08 +02:00
|
|
|
/**
|
|
|
|
* Let the user change the language
|
|
|
|
* @param lang the desired language (en, de, fr, ...)
|
|
|
|
*/
|
2018-08-07 12:30:21 +02:00
|
|
|
selectLang(selection: string): void {
|
|
|
|
this.translate.use(selection).subscribe();
|
|
|
|
}
|
2018-06-29 17:24:44 +02:00
|
|
|
|
2018-08-07 12:30:21 +02:00
|
|
|
/**
|
|
|
|
* Get the name of a Language by abbreviation.
|
|
|
|
*/
|
|
|
|
getLangName(abbreviation: string): string {
|
|
|
|
if (abbreviation === 'en') {
|
|
|
|
return this.translate.instant('English');
|
|
|
|
} else if (abbreviation === 'de') {
|
|
|
|
return this.translate.instant('German');
|
|
|
|
} else if (abbreviation === 'fr') {
|
|
|
|
return this.translate.instant('French');
|
|
|
|
}
|
2018-06-25 17:03:52 +02:00
|
|
|
}
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2018-08-02 16:39:08 +02:00
|
|
|
/**
|
|
|
|
* Function to log out the current user
|
|
|
|
*/
|
2018-06-19 16:55:50 +02:00
|
|
|
logOutButton() {
|
|
|
|
this.authService.logout().subscribe();
|
|
|
|
this.router.navigate(['/login']);
|
|
|
|
}
|
2018-06-13 18:34:10 +02:00
|
|
|
}
|