show user in show

restrict show actions
This commit is contained in:
2020-05-03 17:18:23 +02:00
committed by smuddy
parent 8619027fdb
commit 8b6ff52054
13 changed files with 114 additions and 34 deletions

View File

@@ -1,14 +1,18 @@
import {Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef} from '@angular/core';
import {User} from './user';
import {UserService} from './user.service';
@Directive({
selector: '[appOwner]'
})
export class OwnerDirective implements OnInit {
@Input() appOwner: string;
private currentUser: User;
private loggedIn: boolean;
private currentUserId: string;
private _appOwner: string;
@Input() set appOwner(value: string) {
this._appOwner = value;
this.updateView();
}
constructor(
private element: ElementRef,
@@ -20,12 +24,8 @@ export class OwnerDirective implements OnInit {
}
public ngOnInit(): void {
this.userService.user$.subscribe(user => {
this.currentUser = user;
this.updateView();
});
this.userService.loggedIn$().subscribe(_ => {
this.loggedIn = !!_;
this.userService.userId$.subscribe(user => {
this.currentUserId = user;
this.updateView();
});
this.updateView();
@@ -33,10 +33,9 @@ export class OwnerDirective implements OnInit {
private updateView() {
this.viewContainer.clear();
if (this.loggedIn && this.currentUser.id === this.appOwner) {
if (this.currentUserId === this._appOwner) {
this.viewContainer.createEmbeddedView(this.templateRef);
}
}
}