2018-06-13 18:34:10 +02:00
|
|
|
import { Component, OnInit } 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-06-28 17:11:04 +02:00
|
|
|
import { WebsocketService } from 'app/core/services/websocket.service';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { tap } from 'rxjs/operators';
|
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-03 11:52:16 +02:00
|
|
|
//into own service
|
|
|
|
import { DS } from 'app/core/services/DS.service';
|
|
|
|
import { User } from 'app/core/models/user';
|
|
|
|
import { Group } from 'app/core/models/group';
|
|
|
|
import { BaseModel } from '../core/models/baseModel';
|
|
|
|
|
2018-06-13 18:34:10 +02:00
|
|
|
@Component({
|
2018-06-16 18:05:46 +02:00
|
|
|
selector: 'app-site',
|
|
|
|
templateUrl: './site.component.html',
|
|
|
|
styleUrls: ['./site.component.css']
|
2018-06-13 18:34:10 +02:00
|
|
|
})
|
|
|
|
export class SiteComponent implements OnInit {
|
2018-06-25 17:03:52 +02:00
|
|
|
isMobile = false;
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2018-06-25 17:03:52 +02:00
|
|
|
constructor(
|
|
|
|
private authService: AuthService,
|
2018-06-28 17:11:04 +02:00
|
|
|
private websocketService: WebsocketService,
|
2018-06-25 17:03:52 +02:00
|
|
|
private router: Router,
|
2018-06-29 17:24:44 +02:00
|
|
|
private breakpointObserver: BreakpointObserver,
|
2018-07-03 11:52:16 +02:00
|
|
|
private translate: TranslateService,
|
|
|
|
private dS: DS
|
2018-06-25 17:03:52 +02:00
|
|
|
) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.breakpointObserver
|
|
|
|
.observe([Breakpoints.Small, Breakpoints.HandsetPortrait])
|
|
|
|
.subscribe((state: BreakpointState) => {
|
|
|
|
if (state.matches) {
|
|
|
|
this.isMobile = true;
|
|
|
|
} else {
|
|
|
|
this.isMobile = false;
|
|
|
|
}
|
|
|
|
});
|
2018-06-28 17:11:04 +02:00
|
|
|
|
|
|
|
// connect to a the websocket
|
|
|
|
const socket = this.websocketService.connect();
|
|
|
|
|
|
|
|
// subscribe to the socket
|
|
|
|
socket.subscribe(response => {
|
|
|
|
console.log('log : ', response); // will contain all the config variables
|
2018-07-03 11:52:16 +02:00
|
|
|
this.storeResponse(response);
|
2018-06-28 17:11:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// basically everything needed for AutoUpdate
|
|
|
|
socket.next(val => {
|
|
|
|
console.log('socket.next: ', val);
|
|
|
|
});
|
2018-06-29 17:24:44 +02:00
|
|
|
|
|
|
|
//get a translation via code: use the translation service
|
|
|
|
this.translate.get('Motions').subscribe((res: string) => {
|
|
|
|
console.log(res);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-03 11:52:16 +02:00
|
|
|
//test. will move to an own service later
|
|
|
|
//create models out of socket answer
|
|
|
|
storeResponse(socketResponse): void {
|
|
|
|
socketResponse.forEach(model => {
|
|
|
|
switch (model.collection) {
|
|
|
|
case 'users/group': {
|
|
|
|
this.dS.inject(BaseModel.fromJSON(model.data, Group));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'users/user': {
|
|
|
|
this.dS.inject(BaseModel.fromJSON(model.data, User));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log('collection: "' + model.collection + '" is not yet parsed');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-29 17:24:44 +02:00
|
|
|
selectLang(lang: string): void {
|
|
|
|
console.log('selected langauge: ', lang);
|
|
|
|
console.log('get Langs : ', this.translate.getLangs());
|
|
|
|
|
|
|
|
this.translate.use(lang).subscribe(res => {
|
|
|
|
console.log('language changed : ', res);
|
|
|
|
});
|
2018-06-25 17:03:52 +02:00
|
|
|
}
|
2018-06-13 18:34:10 +02:00
|
|
|
|
2018-06-19 16:55:50 +02:00
|
|
|
logOutButton() {
|
|
|
|
console.log('logout');
|
|
|
|
this.authService.logout().subscribe();
|
|
|
|
this.router.navigate(['/login']);
|
|
|
|
}
|
2018-06-13 18:34:10 +02:00
|
|
|
}
|