zgo/src/app/header/header.component.ts

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-10-20 20:51:14 +00:00
import {Component, OnInit, OnDestroy} from '@angular/core';
2021-10-28 20:34:48 +00:00
import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
2021-10-15 19:14:49 +00:00
import {FullnodeService} from '../fullnode.service';
2021-10-20 20:51:14 +00:00
import { UserService } from '../user.service';
2021-10-21 16:22:48 +00:00
import {Subscription, Observable} from 'rxjs';
2021-10-28 20:34:48 +00:00
import { SettingsComponent } from '../settings/settings.component';
2021-10-15 19:14:49 +00:00
2021-10-20 20:51:14 +00:00
import {Owner} from '../owner.model';
2021-10-15 19:14:49 +00:00
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
2021-10-20 20:51:14 +00:00
export class HeaderComponent implements OnInit, OnDestroy {
2021-10-15 19:14:49 +00:00
2021-10-20 20:51:14 +00:00
public height = 0;
private owner: Owner= {_id:'', address: 'none', name:''};
private session: string | null = '';
2021-10-21 16:22:48 +00:00
public heightUpdate: Observable<number>;
public ownerUpdate: Observable<Owner>;
2021-10-21 19:29:04 +00:00
public uZaddrUpdate: Observable<string>;
2021-10-21 16:22:48 +00:00
2021-10-20 20:51:14 +00:00
constructor(
public fullnodeService: FullnodeService,
2021-10-28 20:34:48 +00:00
public userService: UserService,
private dialog: MatDialog
2021-10-20 20:51:14 +00:00
){
2021-10-21 16:22:48 +00:00
this.heightUpdate = fullnodeService.heightUpdate;
2021-10-21 19:29:04 +00:00
this.uZaddrUpdate = userService.uZaddrUpdate;
2021-10-21 16:22:48 +00:00
this.ownerUpdate = userService.ownerUpdate;
2021-10-28 20:34:48 +00:00
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
});
2021-10-15 19:14:49 +00:00
}
ngOnInit(){
2021-10-20 20:51:14 +00:00
}
ngOnDestroy(){
}
2021-10-21 19:29:04 +00:00
shortenZaddr(address:string) {
var addr = address;
2021-10-20 20:51:14 +00:00
var end = addr.length;
var last = end - 5;
return addr.substring(0,5).concat('...').concat(addr.substring(last, end));
2021-10-15 19:14:49 +00:00
}
2021-10-28 20:34:48 +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);
}
});
}
2021-10-15 19:14:49 +00:00
}