Implemented hasclaim directive
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
253b3d3c90
commit
f9d0e2aee0
@ -31,6 +31,7 @@ import { TimespanComponent } from './components/timespan/timespan.component';
|
|||||||
import { TagInputComponent } from './components/tag-input/tag-input.component';
|
import { TagInputComponent } from './components/tag-input/tag-input.component';
|
||||||
import { MenuBackgroundComponent } from './components/menu-background/menu-background.component';
|
import { MenuBackgroundComponent } from './components/menu-background/menu-background.component';
|
||||||
import { HasPackageDirective} from './components/has-package/has-package.directive';
|
import { HasPackageDirective} from './components/has-package/has-package.directive';
|
||||||
|
import { HasClaimDirective} from './components/has-claim/has-claim.directive';
|
||||||
import { UserMenuComponent} from './components/user-menu/user-menu.component';
|
import { UserMenuComponent} from './components/user-menu/user-menu.component';
|
||||||
import { Alert } from './enumerations/alert.enum';
|
import { Alert } from './enumerations/alert.enum';
|
||||||
import { IEventMessage } from './models/event.message';
|
import { IEventMessage } from './models/event.message';
|
||||||
@ -63,6 +64,7 @@ export {
|
|||||||
TagInputComponent,
|
TagInputComponent,
|
||||||
UserMenuComponent,
|
UserMenuComponent,
|
||||||
HasPackageDirective,
|
HasPackageDirective,
|
||||||
|
HasClaimDirective,
|
||||||
Alert,
|
Alert,
|
||||||
IEventMessage,
|
IEventMessage,
|
||||||
IItem,
|
IItem,
|
||||||
@ -112,6 +114,7 @@ export {
|
|||||||
SessionClearedComponent,
|
SessionClearedComponent,
|
||||||
MenuBackgroundComponent,
|
MenuBackgroundComponent,
|
||||||
HasPackageDirective,
|
HasPackageDirective,
|
||||||
|
HasClaimDirective,
|
||||||
UserMenuComponent
|
UserMenuComponent
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
@ -131,6 +134,7 @@ export {
|
|||||||
SessionClearedComponent,
|
SessionClearedComponent,
|
||||||
MenuBackgroundComponent,
|
MenuBackgroundComponent,
|
||||||
HasPackageDirective,
|
HasPackageDirective,
|
||||||
|
HasClaimDirective,
|
||||||
UserMenuComponent
|
UserMenuComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
import { Directive, ViewContainerRef,TemplateRef,OnInit,Input,OnDestroy } from '@angular/core';
|
||||||
|
import { Store} from '@ngrx/store';
|
||||||
|
import * as appCommonReducer from '../../reducers/app-common.reducer'
|
||||||
|
import { IPackages } from '../../models/package';
|
||||||
|
import { Observable, Subscription } from 'rxjs';
|
||||||
|
import { skip } from 'rxjs/operators';
|
||||||
|
import {OAuthService } from 'angular-oauth2-oidc';
|
||||||
|
import { IUser } from '../../models/user';
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[fm-hasclaim]',
|
||||||
|
})
|
||||||
|
export class HasClaimDirective implements OnInit{
|
||||||
|
@Input('fm-hasclaim') claim:string;
|
||||||
|
|
||||||
|
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) { }
|
||||||
|
private user$:Observable<IUser> = this.store$.select(appCommonReducer.SelectGetUser).pipe(skip(1));
|
||||||
|
private hasView = false;
|
||||||
|
ngOnInit() {
|
||||||
|
this.user$.subscribe((user) => {
|
||||||
|
if (user.claims[this.claim]) {
|
||||||
|
this.viewContainerRef$.createEmbeddedView(this.templateRef$);
|
||||||
|
this.hasView=true;
|
||||||
|
} else if (this.hasView) {
|
||||||
|
this.viewContainerRef$.clear();
|
||||||
|
this.hasView = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -2,4 +2,5 @@ export interface IUser {
|
|||||||
code?: string;
|
code?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
|
claims: any;
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,15 @@ export function reducer(state = initialState, action: appCommonActions.Actions )
|
|||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case appCommonActions.INITUSERSUCCESS: {
|
case appCommonActions.INITUSERSUCCESS: {
|
||||||
let a = action as appCommonActions.InitUserSuccess;
|
let a = action as appCommonActions.InitUserSuccess;
|
||||||
|
let claims = {}
|
||||||
|
Object.getOwnPropertyNames(a.userinfo).forEach((k) => {
|
||||||
|
claims[k] = a.userinfo[k];
|
||||||
|
});
|
||||||
var user:IUser = {
|
var user:IUser = {
|
||||||
code:a.user.code,
|
code:a.user.code,
|
||||||
email:a.userinfo["email"],
|
email:a.userinfo["email"],
|
||||||
name:a.userinfo["name"]
|
name:a.userinfo["name"],
|
||||||
|
claims:claims
|
||||||
};
|
};
|
||||||
return tassign(state, { user: user,initialized: true });
|
return tassign(state, { user: user,initialized: true });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user