add share to c/dt/t/sp, refactor share input, ifOwner directive

This commit is contained in:
Michael Shamoon
2022-12-07 14:55:40 -08:00
parent 5dc14449f9
commit 43b9909a09
18 changed files with 192 additions and 18 deletions

View File

@@ -0,0 +1,42 @@
import {
Directive,
Input,
OnChanges,
OnInit,
TemplateRef,
ViewContainerRef,
} from '@angular/core'
import { PaperlessUser } from '../data/paperless-user'
import { SettingsService } from '../services/settings.service'
@Directive({
selector: '[ifOwner]',
})
export class IfOwnerDirective implements OnInit, OnChanges {
// The role the user must have
@Input()
ifOwner: PaperlessUser
/**
* @param {ViewContainerRef} viewContainerRef -- The location where we need to render the templateRef
* @param {TemplateRef<any>} templateRef -- The templateRef to be potentially rendered
* @param {PermissionsService} permissionsService -- Will give us access to the permissions a user has
*/
constructor(
private viewContainerRef: ViewContainerRef,
private templateRef: TemplateRef<any>,
private settings: SettingsService
) {}
public ngOnInit(): void {
if (!this.ifOwner || this.ifOwner?.id === this.settings.currentUser.id) {
this.viewContainerRef.createEmbeddedView(this.templateRef)
} else {
this.viewContainerRef.clear()
}
}
public ngOnChanges(): void {
this.ngOnInit()
}
}