Implement then else for haspackage
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
00346a963e
commit
997ebb24a7
@ -5,29 +5,56 @@ import { IPackages } from '../../models/package';
|
|||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[fm-haspackage]',
|
selector: '[fmHasPackage]',
|
||||||
})
|
})
|
||||||
export class HasPackageDirective implements OnInit,OnDestroy{
|
export class HasPackageDirective implements OnDestroy{
|
||||||
@Input('fm-haspackage') package:string;
|
@Input()
|
||||||
|
set fmHasPackage(packageIdentifier:string) {
|
||||||
|
this.packageIdentifier$ = packageIdentifier;
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
|
||||||
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) { }
|
@Input()
|
||||||
private packages$:Observable<IPackages> = this.store$.select(appCommonReducer.SelectGetUserPackages);
|
set fmHasPackageThen(thenTemplate:TemplateRef<any>) {
|
||||||
private hasView = false;
|
this.thenTemplate$ = thenTemplate;
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
set fmHasPackageElse(thenTemplate:TemplateRef<any>) {
|
||||||
|
this.elseTemplate$ = thenTemplate;
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private packageIdentifier$:string;
|
||||||
|
private thenTemplate$:TemplateRef<any>;
|
||||||
|
private elseTemplate$:TemplateRef<any>;
|
||||||
|
private packages$:any = {};
|
||||||
|
private packagesObservable$:Observable<IPackages> = this.store$.select(appCommonReducer.SelectGetUserPackages);
|
||||||
private packSub:Subscription;
|
private packSub:Subscription;
|
||||||
ngOnInit() {
|
|
||||||
this.packages$.subscribe((packages) => {
|
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) {
|
||||||
const today = new Date(new Date(Date.now()).toUTCString()).setHours(0,0,0,0);
|
this.thenTemplate$=templateRef$;
|
||||||
if (packages[this.package] &&
|
this.packSub = this.store$.select(appCommonReducer.SelectGetUserPackages).subscribe((packages) => {
|
||||||
packages[this.package].enabled &&
|
this.packages$ = packages;
|
||||||
(packages[this.package].dataDate && new Date(packages[this.package].dataDate).setHours(0, 0, 0, 0) <= today) &&
|
this.updateView();
|
||||||
(packages[this.package].dataEndDate == null || new Date(packages[this.package].dataEndDate).setHours(0, 0, 0, 0) >= today)) {
|
|
||||||
this.viewContainerRef$.createEmbeddedView(this.templateRef$);
|
|
||||||
this.hasView=true;
|
|
||||||
} else if (this.hasView) {
|
|
||||||
this.viewContainerRef$.clear();
|
|
||||||
this.hasView = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
updateView() {
|
||||||
|
const today = new Date(new Date(Date.now()).toUTCString()).setHours(0, 0, 0, 0);
|
||||||
|
if (this.packages$[this.packageIdentifier$] &&
|
||||||
|
this.packages$[this.packageIdentifier$].enabled &&
|
||||||
|
(this.packages$[this.packageIdentifier$].dataDate && new Date(this.packages$[this.packageIdentifier$].dataDate).setHours(0, 0, 0, 0) <= today) &&
|
||||||
|
(this.packages$[this.packageIdentifier$].dataEndDate == null || new Date(this.packages$[this.packageIdentifier$].dataEndDate).setHours(0, 0, 0, 0) >= today)) {
|
||||||
|
this.viewContainerRef$.createEmbeddedView(this.thenTemplate$);
|
||||||
|
} else if (this.elseTemplate$) {
|
||||||
|
this.viewContainerRef$.createEmbeddedView(this.elseTemplate$);
|
||||||
|
} else {
|
||||||
|
this.viewContainerRef$.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
Loading…
Reference in New Issue
Block a user