mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
add share to c/dt/t/sp, refactor share input, ifOwner directive
This commit is contained in:
42
src-ui/src/app/directives/if-owner.directive.ts
Normal file
42
src-ui/src/app/directives/if-owner.directive.ts
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user