list shows for public and own filter

This commit is contained in:
2020-05-03 16:43:45 +02:00
committed by smuddy
parent 38c32adf6a
commit 8619027fdb
8 changed files with 93 additions and 17 deletions

View File

@@ -0,0 +1,42 @@
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;
constructor(
private element: ElementRef,
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private userService: UserService
) {
}
public ngOnInit(): void {
this.userService.user$.subscribe(user => {
this.currentUser = user;
this.updateView();
});
this.userService.loggedIn$().subscribe(_ => {
this.loggedIn = !!_;
this.updateView();
});
this.updateView();
}
private updateView() {
this.viewContainer.clear();
if (this.loggedIn && this.currentUser.id === this.appOwner) {
this.viewContainer.createEmbeddedView(this.templateRef);
}
}
}

View File

@@ -0,0 +1,13 @@
import {NgModule} from '@angular/core';
import {OwnerDirective} from './owner.directive';
import {CommonModule} from '@angular/common';
@NgModule({
declarations: [OwnerDirective],
exports: [OwnerDirective],
imports: [
CommonModule
]
})
export class OwnerModule {
}