show user in show
restrict show actions
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user