mirror of https://github.com/abpframework/abp.git
committed by
GitHub
18 changed files with 190 additions and 62 deletions
@ -1,31 +1,68 @@ |
|||
import { Directive, ElementRef, Input, OnDestroy, OnInit, Optional, Renderer2 } from '@angular/core'; |
|||
import { |
|||
Directive, |
|||
ElementRef, |
|||
Input, |
|||
OnDestroy, |
|||
OnInit, |
|||
Renderer2, |
|||
ViewContainerRef, |
|||
TemplateRef, |
|||
Optional, |
|||
SimpleChanges, |
|||
OnChanges, |
|||
} from '@angular/core'; |
|||
import { Store } from '@ngxs/store'; |
|||
import { ConfigState } from '../states'; |
|||
import { takeUntilDestroy } from '../utils'; |
|||
import { Subscription } from 'rxjs'; |
|||
|
|||
@Directive({ |
|||
selector: '[abpPermission]', |
|||
}) |
|||
export class PermissionDirective implements OnInit, OnDestroy { |
|||
export class PermissionDirective implements OnInit, OnDestroy, OnChanges { |
|||
@Input('abpPermission') condition: string; |
|||
|
|||
constructor(@Optional() private elRef: ElementRef, private renderer: Renderer2, private store: Store) {} |
|||
subscription: Subscription; |
|||
|
|||
constructor( |
|||
private elRef: ElementRef, |
|||
private renderer: Renderer2, |
|||
private store: Store, |
|||
@Optional() private templateRef: TemplateRef<any>, |
|||
private vcRef: ViewContainerRef, |
|||
) {} |
|||
|
|||
private check() { |
|||
if (this.subscription) { |
|||
this.subscription.unsubscribe(); |
|||
} |
|||
|
|||
this.subscription = this.store |
|||
.select(ConfigState.getGrantedPolicy(this.condition)) |
|||
.pipe(takeUntilDestroy(this)) |
|||
.subscribe(isGranted => { |
|||
if (this.templateRef && isGranted) { |
|||
this.vcRef.clear(); |
|||
this.vcRef.createEmbeddedView(this.templateRef); |
|||
} else if (this.templateRef && !isGranted) { |
|||
this.vcRef.clear(); |
|||
} else if (!isGranted && !this.templateRef) { |
|||
this.renderer.removeChild((this.elRef.nativeElement as HTMLElement).parentElement, this.elRef.nativeElement); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
ngOnInit() { |
|||
if (this.condition) { |
|||
this.store |
|||
.select(ConfigState.getGrantedPolicy(this.condition)) |
|||
.pipe(takeUntilDestroy(this)) |
|||
.subscribe(isGranted => { |
|||
if (!isGranted) { |
|||
this.renderer.removeChild( |
|||
(this.elRef.nativeElement as HTMLElement).parentElement, |
|||
this.elRef.nativeElement, |
|||
); |
|||
} |
|||
}); |
|||
if (this.templateRef && !this.condition) { |
|||
this.vcRef.createEmbeddedView(this.templateRef); |
|||
} |
|||
} |
|||
|
|||
ngOnDestroy(): void {} |
|||
|
|||
ngOnChanges({ condition }: SimpleChanges) { |
|||
if ((condition || { currentValue: null }).currentValue) { |
|||
this.check(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,13 @@ |
|||
export {}; |
|||
|
|||
declare global { |
|||
interface Date { |
|||
toLocalISOString(): string; |
|||
} |
|||
} |
|||
|
|||
Date.prototype.toLocalISOString = function(this: Date): string { |
|||
const timezoneOffset = this.getTimezoneOffset(); |
|||
|
|||
return new Date(this.getTime() - timezoneOffset * 60000).toISOString(); |
|||
}; |
|||
@ -1,4 +1,4 @@ |
|||
<div #container id="abp-error" class="error"> |
|||
<div #container id="abp-http-error-container" class="error" [style.backgroundColor]="backgroundColor"> |
|||
<button *ngIf="!hideCloseIcon" id="abp-close-button" type="button" class="close mr-2" (click)="destroy()"> |
|||
<span aria-hidden="true">×</span> |
|||
</button> |
|||
@ -1,7 +1,6 @@ |
|||
.error { |
|||
position: fixed; |
|||
top: 0; |
|||
background-color: #fff; |
|||
width: 100vw; |
|||
height: 100vh; |
|||
z-index: 999999; |
|||
Loading…
Reference in new issue