list shows for public and own filter
This commit is contained in:
42
src/app/services/user/owner.directive.ts
Normal file
42
src/app/services/user/owner.directive.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
src/app/services/user/owner.module.ts
Normal file
13
src/app/services/user/owner.module.ts
Normal 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 {
|
||||
}
|
||||
Reference in New Issue
Block a user