Compare commits
8 Commits
AW-4620
...
4c5b89852b
Author | SHA1 | Date | |
---|---|---|---|
|
4c5b89852b | ||
|
fa90eaf1af | ||
aeded938bd | |||
c61a4fe7f4 | |||
8c3c40cfe6 | |||
e6e10c835e | |||
07a87175b4 | |||
e9ace73ddd |
@@ -146,7 +146,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
|||||||
} else {
|
} else {
|
||||||
evaluatedStyle = styleEntry;
|
evaluatedStyle = styleEntry;
|
||||||
}
|
}
|
||||||
if(evaluatedStyle && evaluatedStyle.geometry_ == null) {
|
if (evaluatedStyle && evaluatedStyle.geometry_ == null && !Array.isArray(evaluatedStyle)) {
|
||||||
evaluatedStyle.setGeometry((feature) => this.geometry(feature));
|
evaluatedStyle.setGeometry((feature) => this.geometry(feature));
|
||||||
}
|
}
|
||||||
return evaluatedStyle;
|
return evaluatedStyle;
|
||||||
@@ -179,7 +179,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
|||||||
this.map.instance.addInteraction(this._hoverSelect);
|
this.map.instance.addInteraction(this._hoverSelect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changes["styles"] && this.instance) {
|
if (changes["styles"]) {
|
||||||
let styles = changes["styles"].currentValue;
|
let styles = changes["styles"].currentValue;
|
||||||
for (const key in styles) {
|
for (const key in styles) {
|
||||||
if (styles.hasOwnProperty(key)) {
|
if (styles.hasOwnProperty(key)) {
|
||||||
|
@@ -13,6 +13,7 @@ import { SchemaService } from './services/schema.service';
|
|||||||
import { FolderService } from './services/folder.service';
|
import { FolderService } from './services/folder.service';
|
||||||
import { TimespanService } from './services/timespan.service';
|
import { TimespanService } from './services/timespan.service';
|
||||||
import { ItemService } from './services/item.service';
|
import { ItemService } from './services/item.service';
|
||||||
|
import { AdminService } from './services/admin.service';
|
||||||
import { EventService } from './services/event.service';
|
import { EventService } from './services/event.service';
|
||||||
import { TypeaheadService } from './services/typeahead.service';
|
import { TypeaheadService } from './services/typeahead.service';
|
||||||
import { UserService } from './services/user.service';
|
import { UserService } from './services/user.service';
|
||||||
@@ -42,6 +43,7 @@ export {
|
|||||||
ItemTypeService,
|
ItemTypeService,
|
||||||
TimespanService,
|
TimespanService,
|
||||||
ItemService,
|
ItemService,
|
||||||
|
AdminService,
|
||||||
EventService,
|
EventService,
|
||||||
TypeaheadService,
|
TypeaheadService,
|
||||||
UserService,
|
UserService,
|
||||||
|
@@ -34,6 +34,7 @@ import { MenuBackgroundComponent } from './components/menu-background/menu-backg
|
|||||||
import { HasPackageDirective} from './components/has-package/has-package.directive';
|
import { HasPackageDirective} from './components/has-package/has-package.directive';
|
||||||
import { PackageExistsDirective} from './components/package-exists/package-exists.directive';
|
import { PackageExistsDirective} from './components/package-exists/package-exists.directive';
|
||||||
import { HasClaimDirective } from './components/has-claim/has-claim.directive';
|
import { HasClaimDirective } from './components/has-claim/has-claim.directive';
|
||||||
|
import { HasRoleDirective } from './components/has-role/has-role.directive';
|
||||||
import { UserMenuComponent} from './components/user-menu/user-menu.component';
|
import { UserMenuComponent} from './components/user-menu/user-menu.component';
|
||||||
import { ThumbnailComponent } from './components/thumbnail/thumbnail.component';
|
import { ThumbnailComponent } from './components/thumbnail/thumbnail.component';
|
||||||
import { Alert } from './enumerations/alert.enum';
|
import { Alert } from './enumerations/alert.enum';
|
||||||
@@ -85,6 +86,7 @@ export {
|
|||||||
HasPackageDirective,
|
HasPackageDirective,
|
||||||
PackageExistsDirective,
|
PackageExistsDirective,
|
||||||
HasClaimDirective,
|
HasClaimDirective,
|
||||||
|
HasRoleDirective,
|
||||||
Alert,
|
Alert,
|
||||||
IEventMessage,
|
IEventMessage,
|
||||||
IItem,
|
IItem,
|
||||||
@@ -148,6 +150,7 @@ export {
|
|||||||
HasPackageDirective,
|
HasPackageDirective,
|
||||||
PackageExistsDirective,
|
PackageExistsDirective,
|
||||||
HasClaimDirective,
|
HasClaimDirective,
|
||||||
|
HasRoleDirective,
|
||||||
UserMenuComponent,
|
UserMenuComponent,
|
||||||
GradientComponent,
|
GradientComponent,
|
||||||
GradientSelectComponent,
|
GradientSelectComponent,
|
||||||
@@ -179,6 +182,7 @@ export {
|
|||||||
HasPackageDirective,
|
HasPackageDirective,
|
||||||
PackageExistsDirective,
|
PackageExistsDirective,
|
||||||
HasClaimDirective,
|
HasClaimDirective,
|
||||||
|
HasRoleDirective,
|
||||||
UserMenuComponent,
|
UserMenuComponent,
|
||||||
GradientComponent,
|
GradientComponent,
|
||||||
GradientSelectComponent,
|
GradientSelectComponent,
|
||||||
|
@@ -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 { Observable, Subscription } from 'rxjs';
|
||||||
|
import { IUser } from '../../models/user';
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[fmHasRole]',
|
||||||
|
})
|
||||||
|
export class HasRoleDirective implements OnInit, OnDestroy{
|
||||||
|
@Input('fmHasRole') role:string;
|
||||||
|
|
||||||
|
constructor(private templateRef$: TemplateRef<any>,private viewContainerRef$: ViewContainerRef,private store$: Store<appCommonReducer.State>) { }
|
||||||
|
private user$:Observable<IUser> = this.store$.select(appCommonReducer.SelectGetUser);
|
||||||
|
private hasView = false;
|
||||||
|
private roleClaim = 'role';
|
||||||
|
private sub: Subscription;
|
||||||
|
ngOnInit() {
|
||||||
|
this.sub = this.user$.subscribe((user) => {
|
||||||
|
if (user && user.claims[this.roleClaim]?.includes(this.role)) {
|
||||||
|
this.viewContainerRef$.createEmbeddedView(this.templateRef$);
|
||||||
|
this.hasView=true;
|
||||||
|
} else if (this.hasView) {
|
||||||
|
this.viewContainerRef$.clear();
|
||||||
|
this.hasView = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ngOnDestroy() {
|
||||||
|
if (this.sub) {this.sub.unsubscribe() };
|
||||||
|
}
|
||||||
|
}
|
@@ -59,10 +59,7 @@ export function reducer(state = initialState, action: appCommonActions.Actions )
|
|||||||
}
|
}
|
||||||
case appCommonActions.INITUSERSUCCESS: {
|
case appCommonActions.INITUSERSUCCESS: {
|
||||||
let a = action as appCommonActions.InitUserSuccess;
|
let a = action as appCommonActions.InitUserSuccess;
|
||||||
let claims = {}
|
let claims = { ...a.userinfo.info };
|
||||||
Object.getOwnPropertyNames(a.userinfo.info).forEach((k) => {
|
|
||||||
claims[k] = a.userinfo[k];
|
|
||||||
});
|
|
||||||
var user:IUser = {
|
var user:IUser = {
|
||||||
code:a.user.code,
|
code:a.user.code,
|
||||||
email:claims["email"]!== undefined ? claims["email"] : a.user.name,
|
email:claims["email"]!== undefined ? claims["email"] : a.user.name,
|
||||||
|
45
projects/common/src/fm/services/admin.service.ts
Normal file
45
projects/common/src/fm/services/admin.service.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { IItem } from '../models/item';
|
||||||
|
import { HttpClient, HttpParams } from "@angular/common/http";
|
||||||
|
import { AppConfig } from "../shared/app.config";
|
||||||
|
import {ItemTypeService} from './itemtype.service';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class AdminService {
|
||||||
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig,private itemTypeService:ItemTypeService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiEndpoint() {
|
||||||
|
return this.appConfig.getConfig("apiEndPoint");
|
||||||
|
}
|
||||||
|
|
||||||
|
getItem(code: string): Observable<IItem> {
|
||||||
|
return this.httpClient.get<IItem>(`${this.ApiEndpoint()}/api/v1/admin/${code}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
getItemList(itemType?: string, dataFilter?: any, level?: number, atItemLocationItemCode?: string, indexed?: boolean, validToday?: boolean): Observable<IItem[]> {
|
||||||
|
var params = new HttpParams();
|
||||||
|
if(itemType) params = params.append("it", itemType);
|
||||||
|
if(dataFilter) params = params.append("df", JSON.stringify(dataFilter));
|
||||||
|
if(atItemLocationItemCode) params = params.append("ail",atItemLocationItemCode);
|
||||||
|
if(indexed) params = params.append("ind",indexed?"true":"false");
|
||||||
|
if (level) params = params.append("lvl", level.toFixed());
|
||||||
|
if (validToday) params = params.append("vt", validToday ? "true" : "false");
|
||||||
|
return this.httpClient.get<IItem[]>(`${this.ApiEndpoint()}/api/v1/admin/`, { params: params });
|
||||||
|
}
|
||||||
|
|
||||||
|
postItem(item:IItem): Observable<IItem> {
|
||||||
|
return this.httpClient.post<IItem>(`${this.ApiEndpoint()}/api/v1/admin`,item);
|
||||||
|
}
|
||||||
|
|
||||||
|
putItem(item:IItem): Observable<IItem> {
|
||||||
|
return this.httpClient.put<IItem>(`${this.ApiEndpoint()}/api/v1/admin/${item.code}`,item);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteItem(code: string): Observable<any> {
|
||||||
|
return this.httpClient.delete<any>(`${this.ApiEndpoint()}/api/v1/admin/${code}`);
|
||||||
|
}
|
||||||
|
}
|
@@ -24,26 +24,33 @@ export class AuthGuard implements CanActivate, CanLoad, CanActivateChild {
|
|||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
||||||
let url: string = state.url;
|
let url: string = state.url;
|
||||||
|
|
||||||
return this.checkLogin(url);
|
return this.checkLogin(url, route);
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
|
||||||
let url: string = state.url;
|
let url: string = state.url;
|
||||||
|
|
||||||
return this.checkLogin(url);
|
return this.checkLogin(url, childRoute);
|
||||||
}
|
}
|
||||||
|
|
||||||
canLoad(route: Route): Promise<boolean> {
|
canLoad(route: Route): Promise<boolean> {
|
||||||
return this.checkLogin(route.path);
|
return this.checkLogin(route.path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkLogin(url: string): Promise<boolean> {
|
checkLogin(url: string, route: ActivatedRouteSnapshot): Promise<boolean> {
|
||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
if (!this.oauthService.hasValidAccessToken()) {
|
if (!this.oauthService.hasValidAccessToken()) {
|
||||||
console.debug("No valid token");
|
console.debug("No valid token");
|
||||||
this.oauthService.initCodeFlow(url);
|
this.oauthService.initCodeFlow(url);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
} else {
|
} else {
|
||||||
|
const requiredRoleClaim = route.data.role;
|
||||||
|
if (!requiredRoleClaim) { resolve(true); }
|
||||||
|
const ownedClaims = this.oauthService.getIdentityClaims();
|
||||||
|
if (!ownedClaims) { resolve(false); }
|
||||||
|
const ownedRoleClaims: string[] = ownedClaims['role'];
|
||||||
|
if (!ownedRoleClaims) { resolve(false); }
|
||||||
|
if (ownedRoleClaims.findIndex(r => r === requiredRoleClaim) <= -1) { resolve(false); }
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
25
src/app/admin/admin-router.module.ts
Normal file
25
src/app/admin/admin-router.module.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
|
import { AuthGuard } from 'dist/common';
|
||||||
|
import { AdminComponent } from './admin.component';
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: AdminComponent,
|
||||||
|
canActivate: [AuthGuard],
|
||||||
|
data: {
|
||||||
|
role: 'admin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
RouterModule.forChild(routes),
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
RouterModule
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AdminRouterModule { }
|
8
src/app/admin/admin.component.ts
Normal file
8
src/app/admin/admin.component.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-test',
|
||||||
|
template: `<h1>Yes! You have access to the admin component.</h1>`
|
||||||
|
})
|
||||||
|
export class AdminComponent {
|
||||||
|
}
|
14
src/app/admin/admin.module.ts
Normal file
14
src/app/admin/admin.module.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { AdminRouterModule} from './admin-router.module';
|
||||||
|
import { AdminComponent } from './admin.component';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
AdminRouterModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
AdminComponent
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
export class AdminModule { }
|
@@ -65,6 +65,7 @@ const routes = [
|
|||||||
},
|
},
|
||||||
{ path: 'map', loadChildren: () => import('../../projects/common-map/src/public-api').then(m => m.AppCommonMapModule), canActivateChild: [AuthGuard],canActivate: [FullScreenGuard], },
|
{ path: 'map', loadChildren: () => import('../../projects/common-map/src/public-api').then(m => m.AppCommonMapModule), canActivateChild: [AuthGuard],canActivate: [FullScreenGuard], },
|
||||||
{ path: 'map3d', loadChildren: () => import('./map3d/map3d.module').then(m => m.Map3DModule), canActivateChild: [AuthGuard], canActivate: [FullScreenGuard] },
|
{ path: 'map3d', loadChildren: () => import('./map3d/map3d.module').then(m => m.Map3DModule), canActivateChild: [AuthGuard], canActivate: [FullScreenGuard] },
|
||||||
|
{ path: 'admin', loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule), canActivateChild: [AuthGuard], canActivate: [FullScreenGuard], data: { role: 'admin' } },
|
||||||
{
|
{
|
||||||
path: 'registerdevice/:deviceToken',
|
path: 'registerdevice/:deviceToken',
|
||||||
canActivate: [FullScreenGuard],
|
canActivate: [FullScreenGuard],
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
<div class="card menu-card">
|
<div class="card menu-card">
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
<li class="nav-item py-0" *fmHasPackage="'vnd.farmmaps.itemtype.package.agrirouter'"><a [routerLinkActive]="['active']" [routerLink]="['/agrirouter']" class="nav-link"><span><i class="fal fa-plug" aria-hidden="true"></i> <span i18n>agrirouter</span></span></a></li>
|
<li class="nav-item py-0" *fmHasPackage="'vnd.farmmaps.itemtype.package.agrirouter'"><a [routerLinkActive]="['active']" [routerLink]="['/agrirouter']" class="nav-link"><span><i class="fal fa-plug" aria-hidden="true"></i> <span i18n>agrirouter</span></span></a></li>
|
||||||
|
<li class="nav-item py-0" *fmHasRole="'admin'"><a [routerLinkActive]="['active']" [routerLink]="['/admin']" class="nav-link"><span><i class="fal fa-plug" aria-hidden="true"></i> <span i18n>Admin role</span></span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user