Add basic package managing plumbing
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
750a743a50
commit
2ea51d94ef
@ -3,10 +3,14 @@ import { Action } from '@ngrx/store';
|
|||||||
import { IItemTypes } from '../models/item.types';
|
import { IItemTypes } from '../models/item.types';
|
||||||
import { IListItem } from '../models/list.item';
|
import { IListItem } from '../models/list.item';
|
||||||
import { IUser } from '../models/user';
|
import { IUser } from '../models/user';
|
||||||
|
import { IItem } from '../models/item';
|
||||||
|
|
||||||
export const INITUSER = '[AppCommon] InitUser';
|
export const INITUSER = '[AppCommon] InitUser';
|
||||||
export const INITUSERSUCCESS = '[AppCommon] InitUserSuccess';
|
export const INITUSERSUCCESS = '[AppCommon] InitUserSuccess';
|
||||||
|
|
||||||
|
export const INITUSERPACKAGES = '[AppCommon] InitUserPackages';
|
||||||
|
export const INITUSERPACKAGESSUCCESS = '[AppCommon] InitUserPackagesSuccess';
|
||||||
|
|
||||||
export const INITROOT = '[Explorer] InitRoot';
|
export const INITROOT = '[Explorer] InitRoot';
|
||||||
export const INITROOTSUCCESS = '[Explorer] InitRootSuccess';
|
export const INITROOTSUCCESS = '[Explorer] InitRootSuccess';
|
||||||
|
|
||||||
@ -61,6 +65,12 @@ export class InitUserSuccess implements Action {
|
|||||||
constructor(public user:IUser ) { }
|
constructor(public user:IUser ) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class InitUserPackagesSuccess implements Action {
|
||||||
|
readonly type = INITUSERPACKAGESSUCCESS;
|
||||||
|
|
||||||
|
constructor(public items:IItem[] ) { }
|
||||||
|
}
|
||||||
|
|
||||||
export class InitRoot implements Action {
|
export class InitRoot implements Action {
|
||||||
readonly type = INITROOT;
|
readonly type = INITROOT;
|
||||||
|
|
||||||
@ -250,4 +260,6 @@ export type Actions = OpenModal
|
|||||||
| TaskErrorEvent
|
| TaskErrorEvent
|
||||||
| DeviceUpdateEvent
|
| DeviceUpdateEvent
|
||||||
| ToggleMenu
|
| ToggleMenu
|
||||||
| SetMenuVisible;
|
| SetMenuVisible
|
||||||
|
| InitUserPackagesSuccess;
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ import { SidePanelComponent } from './components/side-panel/side-panel.component
|
|||||||
import { TimespanComponent } from './components/timespan/timespan.component';
|
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 { Alert } from './enumerations/alert.enum';
|
import { Alert } from './enumerations/alert.enum';
|
||||||
import { IEventMessage } from './models/event.message';
|
import { IEventMessage } from './models/event.message';
|
||||||
import { IItem, Item } from './models/item';
|
import { IItem, Item } from './models/item';
|
||||||
@ -39,6 +40,7 @@ import { IItemTypes } from './models/item.types';
|
|||||||
import { IItemTask, ItemTask } from './models/itemTask';
|
import { IItemTask, ItemTask } from './models/itemTask';
|
||||||
import { IListItem } from './models/list.item';
|
import { IListItem } from './models/list.item';
|
||||||
import { ITypeaheadItem } from './models/typeahead.item';
|
import { ITypeaheadItem } from './models/typeahead.item';
|
||||||
|
import { IPackage,IPackages } from './models/package';
|
||||||
import { IUser } from './models/user';
|
import { IUser } from './models/user';
|
||||||
import { IQueryState } from './models/query.state';
|
import { IQueryState } from './models/query.state';
|
||||||
import { ICodeListItem } from './models/code.list.item';
|
import { ICodeListItem } from './models/code.list.item';
|
||||||
@ -58,6 +60,7 @@ export {
|
|||||||
SidePanelComponent,
|
SidePanelComponent,
|
||||||
TimespanComponent,
|
TimespanComponent,
|
||||||
TagInputComponent,
|
TagInputComponent,
|
||||||
|
HasPackageDirective,
|
||||||
Alert,
|
Alert,
|
||||||
IEventMessage,
|
IEventMessage,
|
||||||
IItem,
|
IItem,
|
||||||
@ -71,6 +74,8 @@ export {
|
|||||||
IUser,
|
IUser,
|
||||||
ICodeListItem,
|
ICodeListItem,
|
||||||
IQueryState,
|
IQueryState,
|
||||||
|
IPackage,
|
||||||
|
IPackages,
|
||||||
commonActions,
|
commonActions,
|
||||||
commonReducers,
|
commonReducers,
|
||||||
IAuthconfigFactory,
|
IAuthconfigFactory,
|
||||||
@ -103,7 +108,8 @@ export {
|
|||||||
TimespanComponent,
|
TimespanComponent,
|
||||||
TagInputComponent,
|
TagInputComponent,
|
||||||
SessionClearedComponent,
|
SessionClearedComponent,
|
||||||
MenuBackgroundComponent
|
MenuBackgroundComponent,
|
||||||
|
HasPackageDirective
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
NgbModule,
|
NgbModule,
|
||||||
@ -120,7 +126,8 @@ export {
|
|||||||
TimespanComponent,
|
TimespanComponent,
|
||||||
TagInputComponent,
|
TagInputComponent,
|
||||||
SessionClearedComponent,
|
SessionClearedComponent,
|
||||||
MenuBackgroundComponent
|
MenuBackgroundComponent,
|
||||||
|
HasPackageDirective
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AppCommonModule {
|
export class AppCommonModule {
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[fm-haspackage]',
|
||||||
|
})
|
||||||
|
export class HasPackageDirective implements OnInit,OnDestroy{
|
||||||
|
@Input('fm-haspackage') package:string;
|
||||||
|
|
||||||
|
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) { }
|
||||||
|
private packages$:Observable<IPackages> = this.store$.select(appCommonReducer.SelectGetUserPackages);
|
||||||
|
private hasView = false;
|
||||||
|
private packSub:Subscription;
|
||||||
|
ngOnInit() {
|
||||||
|
this.packages$.subscribe((packages) => {
|
||||||
|
if (packages[this.package] && packages[this.package].enabled) {
|
||||||
|
this.viewContainerRef$.createEmbeddedView(this.templateRef$);
|
||||||
|
this.hasView=true;
|
||||||
|
} else if (this.hasView) {
|
||||||
|
this.viewContainerRef$.clear();
|
||||||
|
this.hasView = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
if(this.packSub) this.packSub.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,18 @@ export class AppCommonEffects {
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@Effect()
|
||||||
|
initUserPackages$:Observable<Action> = this.actions$.pipe(
|
||||||
|
ofType(appCommonActions.INITUSERSUCCESS),
|
||||||
|
switchMap((action) => {
|
||||||
|
let a = action as appCommonActions.InitUserSuccess;
|
||||||
|
return this.itemService$.getChildItemList(a.user.code+":USER_PACKAGES","vnd.farmmaps.itemtype.package").pipe(
|
||||||
|
switchMap((items) => of(new appCommonActions.InitUserPackagesSuccess(items))),
|
||||||
|
catchError(error => of(new appCommonActions.Fail(error)))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
@Effect()
|
@Effect()
|
||||||
initUserSuccess$: Observable<Action> = this.actions$.pipe(
|
initUserSuccess$: Observable<Action> = this.actions$.pipe(
|
||||||
ofType(appCommonActions.INITUSERSUCCESS),
|
ofType(appCommonActions.INITUSERSUCCESS),
|
||||||
|
9
projects/common/src/fm/models/package.ts
Normal file
9
projects/common/src/fm/models/package.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export interface IPackage {
|
||||||
|
id:string
|
||||||
|
name:string;
|
||||||
|
enabled?:boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPackages {
|
||||||
|
[id: string]: IPackage;
|
||||||
|
}
|
@ -2,6 +2,7 @@ import { tassign } from 'tassign';
|
|||||||
import { IItemTypes} from '../models/item.types';
|
import { IItemTypes} from '../models/item.types';
|
||||||
import { IListItem } from '../models/list.item';
|
import { IListItem } from '../models/list.item';
|
||||||
import { IUser } from '../models/user';
|
import { IUser } from '../models/user';
|
||||||
|
import { IPackage,IPackages} from '../models/package';
|
||||||
import * as appCommonActions from '../actions/app-common.actions';
|
import * as appCommonActions from '../actions/app-common.actions';
|
||||||
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
|
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ export interface State {
|
|||||||
fullScreen: boolean,
|
fullScreen: boolean,
|
||||||
routeLoading:boolean,
|
routeLoading:boolean,
|
||||||
menuVisible: boolean,
|
menuVisible: boolean,
|
||||||
|
userPackages: IPackages
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: State = {
|
export const initialState: State = {
|
||||||
@ -26,7 +28,8 @@ export const initialState: State = {
|
|||||||
user:null,
|
user:null,
|
||||||
fullScreen: true,
|
fullScreen: true,
|
||||||
routeLoading: false,
|
routeLoading: false,
|
||||||
menuVisible: false
|
menuVisible: false,
|
||||||
|
userPackages: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reducer(state = initialState, action: appCommonActions.Actions ): State {
|
export function reducer(state = initialState, action: appCommonActions.Actions ): State {
|
||||||
@ -79,6 +82,15 @@ export function reducer(state = initialState, action: appCommonActions.Actions )
|
|||||||
let a = action as appCommonActions.SetMenuVisible;
|
let a = action as appCommonActions.SetMenuVisible;
|
||||||
return tassign(state, { menuVisible: a.visible });
|
return tassign(state, { menuVisible: a.visible });
|
||||||
}
|
}
|
||||||
|
case appCommonActions.INITUSERPACKAGESSUCCESS:{
|
||||||
|
let a = action as appCommonActions.InitUserPackagesSuccess;
|
||||||
|
let packages = {}
|
||||||
|
a.items.forEach((item) => {
|
||||||
|
packages[item.data.id]=item.data;
|
||||||
|
});
|
||||||
|
|
||||||
|
return tassign(state,{userPackages:packages});
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -93,7 +105,7 @@ export const getFullScreen = (state: State) => state.fullScreen;
|
|||||||
export const getRouteLoading = (state: State) => state.routeLoading;
|
export const getRouteLoading = (state: State) => state.routeLoading;
|
||||||
export const getMenuVisible = (state: State) => state.menuVisible;
|
export const getMenuVisible = (state: State) => state.menuVisible;
|
||||||
export const getUser = (state: State) => state.user;
|
export const getUser = (state: State) => state.user;
|
||||||
|
export const getUserPackages = (state: State) => state.userPackages;
|
||||||
|
|
||||||
export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME);
|
export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME);
|
||||||
|
|
||||||
@ -105,4 +117,5 @@ export const selectGetFullScreen = createSelector(selectAppCommonState, getFullS
|
|||||||
export const selectGetRouteLoading = createSelector(selectAppCommonState, getRouteLoading);
|
export const selectGetRouteLoading = createSelector(selectAppCommonState, getRouteLoading);
|
||||||
export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuVisible);
|
export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuVisible);
|
||||||
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
||||||
|
export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages);
|
||||||
|
|
||||||
|
24
projects/common/src/fm/services/package.service.ts
Normal file
24
projects/common/src/fm/services/package.service.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Store} from '@ngrx/store';
|
||||||
|
import * as appCommonReducer from '../reducers/app-common.reducer'
|
||||||
|
import { IPackages } from '../models/package';
|
||||||
|
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
|
||||||
|
export class PackageService {
|
||||||
|
private packages$:IPackages = {};
|
||||||
|
|
||||||
|
constructor(private store$: Store<appCommonReducer.State>) {
|
||||||
|
store$.select(appCommonReducer.SelectGetUserPackages).subscribe((packages) => {
|
||||||
|
this.packages$ = packages;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
hasPackage(id:string):boolean {
|
||||||
|
if(!this.packages$[id]) return false;
|
||||||
|
return this.packages$[id].enabled == true;
|
||||||
|
}
|
||||||
|
}
|
@ -11,4 +11,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card menu-card">
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
<li class="nav-item py-0" *fm-haspackage="'vnd.farmmaps.package.agriroute'"><a [routerLinkActive]="['active']" [routerLink]="['/agrirouter']" class="nav-link"><span i18n><i class="fa fa-plug" aria-hidden="true"></i> agrirouter</span></a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user