zgo/src/app/viewer/viewer.component.ts

105 lines
2.7 KiB
TypeScript
Raw Normal View History

2021-10-20 20:51:14 +00:00
import { Component, OnInit, OnDestroy } from '@angular/core';
2021-10-15 19:14:49 +00:00
import { CanActivate, Router, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
2021-10-20 20:51:14 +00:00
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
2021-10-15 19:14:49 +00:00
import { UserService } from '../user.service';
import { FullnodeService } from '../fullnode.service';
2021-10-21 21:23:33 +00:00
import { ItemService } from '../items/items.service';
import { Subscription, Observable } from 'rxjs';
2021-11-11 15:18:38 +00:00
import { SettingsComponent } from '../settings/settings.component';
2021-10-20 20:51:14 +00:00
import {Owner} from '../owner.model';
2021-11-11 15:18:38 +00:00
import {User} from '../user.model';
2021-10-15 19:14:49 +00:00
@Component({
selector: 'app-viewer',
templateUrl: './viewer.component.html',
styleUrls: ['./viewer.component.css']
})
export class ViewerComponent implements OnInit {
2021-11-11 15:18:38 +00:00
intervalHolder: any;
2021-10-20 20:51:14 +00:00
public message: string = "Welcome to the inside!";
2021-11-11 15:18:38 +00:00
public user: User = {
address: '',
session: '',
blocktime: 0,
expiration: 0,
pin: '',
validated: false
};
private owner: Owner= {_id:'', address: 'none', name:''};
public addrUpdate: Observable<string>;
2021-10-21 19:29:04 +00:00
public ownerUpdate: Observable<Owner>;
2021-11-11 15:18:38 +00:00
public userUpdate: Observable<User>;
2021-11-18 15:57:22 +00:00
orientation: boolean = false;
2021-10-20 20:51:14 +00:00
2021-10-15 19:14:49 +00:00
constructor(
public fullnodeService: FullnodeService,
private router: Router,
2021-10-20 20:51:14 +00:00
public userService: UserService,
private dialog: MatDialog
2021-10-15 19:14:49 +00:00
){
this.addrUpdate = fullnodeService.addrUpdate;
2021-10-21 19:29:04 +00:00
this.ownerUpdate = userService.ownerUpdate;
2021-11-11 15:18:38 +00:00
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
});
this.userUpdate = userService.userUpdate;
this.userUpdate.subscribe((user) => {
this.user = user;
});
2021-10-15 19:14:49 +00:00
}
ngOnInit(){
2021-11-18 15:57:22 +00:00
this.orientation = (window.innerWidth <= 500);
2021-10-21 19:29:04 +00:00
this.ownerUpdate.subscribe((owner) => {
this.message = owner.name;
});
2021-11-11 15:18:38 +00:00
this.loginCheck();
this.intervalHolder = setInterval(() => {
this.loginCheck();
}, 60000);
2021-10-15 19:14:49 +00:00
}
ngOnDestroy(){
}
2021-10-20 20:51:14 +00:00
2021-11-18 15:57:22 +00:00
onResize(event: any){
this.orientation = (event.target.innerWidth <= 500);
}
2021-11-11 15:18:38 +00:00
shortenZaddr(address:string) {
var addr = address;
var end = addr.length;
var last = end - 5;
return addr.substring(0,5).concat('...').concat(addr.substring(last, end));
}
2021-11-18 15:57:22 +00:00
2021-11-11 15:18:38 +00:00
openSettings() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.data = this.owner;
const dialogRef = this.dialog.open(SettingsComponent, dialogConfig);
dialogRef.afterClosed().subscribe((val) => {
if (val != null) {
console.log('Saving settings');
this.userService.updateOwner(val);
}
});
}
loginCheck(){
var today = new Date().getTime() / 1000;
2021-11-18 15:57:22 +00:00
//console.log('User check', this.user.validated);
2021-11-11 15:18:38 +00:00
if (this.user.expiration < today || !this.user.validated) {
console.log('Log in expired!');
this.router.navigate(['/login']);
}
}
2021-10-15 19:14:49 +00:00
}