Refactor itemtype loading
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
parent
52170590e3
commit
b83aca7969
@ -65,10 +65,11 @@ export class AppCommonServiceModule {
|
|||||||
ngModule: AppCommonServiceModule,
|
ngModule: AppCommonServiceModule,
|
||||||
providers: [
|
providers: [
|
||||||
AppConfig,
|
AppConfig,
|
||||||
|
ItemTypeService,
|
||||||
{
|
{
|
||||||
provide: APP_INITIALIZER,
|
provide: APP_INITIALIZER,
|
||||||
useFactory: appConfigFactory,
|
useFactory: appConfigFactory,
|
||||||
deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage],
|
deps: [Injector, AppConfig, OAuthService, AuthConfigFactory, OAuthStorage,ItemTypeService],
|
||||||
multi: true
|
multi: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -4,4 +4,5 @@ export interface IItemType {
|
|||||||
editor?: string;
|
editor?: string;
|
||||||
isFolder?: boolean;
|
isFolder?: boolean;
|
||||||
iconColor?: string;
|
iconColor?: string;
|
||||||
|
extraAttributes?: string;
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,13 @@ import { IItem } from '../models/item';
|
|||||||
import { IItemTask } from '../models/itemTask';
|
import { IItemTask } from '../models/itemTask';
|
||||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
import { HttpClient, HttpParams } from "@angular/common/http";
|
||||||
import { AppConfig } from "../shared/app.config";
|
import { AppConfig } from "../shared/app.config";
|
||||||
|
import {ItemTypeService} from './itemtype.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class ItemService {
|
export class ItemService {
|
||||||
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
constructor(public httpClient: HttpClient, public appConfig: AppConfig,private itemTypeService:ItemTypeService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiEndpoint() {
|
ApiEndpoint() {
|
||||||
@ -37,7 +38,13 @@ export class ItemService {
|
|||||||
if (searchTags) params = params.append("t", searchTags);
|
if (searchTags) params = params.append("t", searchTags);
|
||||||
if (startDate) params = params.append("sd", startDate.toISOString());
|
if (startDate) params = params.append("sd", startDate.toISOString());
|
||||||
if (endDate) params = params.append("ed", endDate.toISOString());
|
if (endDate) params = params.append("ed", endDate.toISOString());
|
||||||
if (itemType) params = params.append("it", itemType);
|
if (itemType) {
|
||||||
|
params = params.append("it", itemType);
|
||||||
|
let extraAttributes = this.itemTypeService.getExtraAttributes(itemType);
|
||||||
|
if(extraAttributes) {
|
||||||
|
params = params.append("da", extraAttributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (parentCode) params = params.append("pc", parentCode);
|
if (parentCode) params = params.append("pc", parentCode);
|
||||||
if (dataFilter) params = params.append("df", dataFilter);
|
if (dataFilter) params = params.append("df", dataFilter);
|
||||||
if (level) params = params.append("lvl", dataFilter);
|
if (level) params = params.append("lvl", dataFilter);
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {IItemTypes} from '../models/item.types'
|
import {IItemTypes} from '../models/item.types'
|
||||||
import {IItem} from '../models/item'
|
import {IItem} from '../models/item'
|
||||||
import {ItemService} from '../services/item.service';
|
import {AppConfig} from '../shared/app.config';
|
||||||
|
import {HttpClient, HttpXhrBackend} from '@angular/common/http';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class ItemTypeService {
|
export class ItemTypeService {
|
||||||
public itemTypes: IItemTypes;
|
public itemTypes: IItemTypes;
|
||||||
|
private httpClient: HttpClient;
|
||||||
|
|
||||||
constructor(itemService:ItemService) {
|
constructor(xhrBackend: HttpXhrBackend) {
|
||||||
itemService.getItemTypes().subscribe((itemTypes) => {
|
this.httpClient = new HttpClient(xhrBackend);
|
||||||
this.itemTypes = itemTypes;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// itemService.getItemTypes().subscribe((itemTypes) => {
|
||||||
|
// this.itemTypes = itemTypes;
|
||||||
|
// });
|
||||||
|
|
||||||
getIcon(itemType: string) {
|
getIcon(itemType: string) {
|
||||||
var icon = "fa fa-file-o";
|
var icon = "fa fa-file-o";
|
||||||
if (this.itemTypes[itemType]) icon = this.itemTypes[itemType].icon;
|
if (this.itemTypes[itemType]) icon = this.itemTypes[itemType].icon;
|
||||||
@ -27,6 +31,12 @@ export class ItemTypeService {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getExtraAttributes(itemType: string) {
|
||||||
|
var extraAttributes = null;
|
||||||
|
if (this.itemTypes[itemType]) extraAttributes = this.itemTypes[itemType].extraAttributes;
|
||||||
|
return extraAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
hasViewer(item: IItem) {
|
hasViewer(item: IItem) {
|
||||||
let itemType: string = item.itemType;
|
let itemType: string = item.itemType;
|
||||||
if (this.itemTypes[itemType]) return this.itemTypes[itemType].viewer !== undefined;
|
if (this.itemTypes[itemType]) return this.itemTypes[itemType].viewer !== undefined;
|
||||||
@ -43,4 +53,16 @@ export class ItemTypeService {
|
|||||||
let itemType: string = item.itemType;
|
let itemType: string = item.itemType;
|
||||||
return itemType == "vnd.farmmaps.itemtype.geotiff.processed" || itemType == "vnd.farmmaps.itemtype.layer" || itemType == "vnd.farmmaps.itemtype.shape.processed";
|
return itemType == "vnd.farmmaps.itemtype.geotiff.processed" || itemType == "vnd.farmmaps.itemtype.layer" || itemType == "vnd.farmmaps.itemtype.shape.processed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public load(config:AppConfig): Promise<any> {
|
||||||
|
|
||||||
|
var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/`
|
||||||
|
return this.httpClient.get(url)
|
||||||
|
.toPromise()
|
||||||
|
.then((itemTypes:IItemTypes) => {
|
||||||
|
this.itemTypes = itemTypes;
|
||||||
|
//return data;
|
||||||
|
})
|
||||||
|
.catch(error => this.itemTypes = null);
|
||||||
|
};
|
||||||
}
|
}
|
@ -3,44 +3,49 @@ import { Location} from '@angular/common';
|
|||||||
import { Router,UrlSerializer } from '@angular/router';
|
import { Router,UrlSerializer } from '@angular/router';
|
||||||
import { AuthConfig, OAuthService, JwksValidationHandler, OAuthErrorEvent, OAuthStorage } from 'angular-oauth2-oidc';
|
import { AuthConfig, OAuthService, JwksValidationHandler, OAuthErrorEvent, OAuthStorage } from 'angular-oauth2-oidc';
|
||||||
import { AppConfig } from "./app.config";
|
import { AppConfig } from "./app.config";
|
||||||
|
import {ItemTypeService} from '../services/itemtype.service';
|
||||||
import { IAuthconfigFactory } from './authconfigFactory';
|
import { IAuthconfigFactory } from './authconfigFactory';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthService: OAuthService, authconfigFactory:IAuthconfigFactory,authStorage:OAuthStorage): () => Promise<any> {
|
export function appConfigFactory(injector:Injector, appConfig: AppConfig, oauthService: OAuthService, authconfigFactory:IAuthconfigFactory,authStorage:OAuthStorage,itemtypeService:ItemTypeService): () => Promise<any> {
|
||||||
return (): Promise<any> => {
|
return (): Promise<any> => {
|
||||||
return appConfig.load().then(() => {
|
return new Promise((resolve,reject) => {
|
||||||
oauthService.events.subscribe((event) => {
|
appConfig.load().then(() => {
|
||||||
console.debug(event.type);
|
oauthService.events.subscribe((event) => {
|
||||||
if (event.type == 'token_error' || event.type == 'silent_refresh_timeout') {
|
console.debug(event.type);
|
||||||
let e = event as OAuthErrorEvent;
|
if (event.type == 'token_error' || event.type == 'silent_refresh_timeout') {
|
||||||
let p = e.params as any;
|
let e = event as OAuthErrorEvent;
|
||||||
if (event.type == 'silent_refresh_timeout' || (p.error && p.error == 'login_required')) {
|
let p = e.params as any;
|
||||||
let router = injector.get(Router);
|
if (event.type == 'silent_refresh_timeout' || (p.error && p.error == 'login_required')) {
|
||||||
console.debug("Session expired");
|
let router = injector.get(Router);
|
||||||
router.navigate(['loggedout'], { queryParams: { redirectTo: router.url } });
|
console.debug("Session expired");
|
||||||
|
router.navigate(['loggedout'], { queryParams: { redirectTo: router.url } });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
oauthService.configure(authconfigFactory.getAuthConfig(appConfig));
|
|
||||||
oauthService.setStorage(authStorage);
|
|
||||||
oauthService.tokenValidationHandler = new JwksValidationHandler();
|
|
||||||
oauthService.tokenValidationHandler.validateAtHash = function () {
|
|
||||||
return new Promise<boolean>((res) => { res(true); })
|
|
||||||
};
|
|
||||||
oauthService.setupAutomaticSilentRefresh();
|
|
||||||
let location = injector.get(Location);
|
|
||||||
let router = injector.get(Router);
|
|
||||||
let urlPath = location.path();
|
|
||||||
oauthService.loadDiscoveryDocument().then(() => {
|
|
||||||
oauthService.tryLogin({
|
|
||||||
onTokenReceived: (info) => {
|
|
||||||
urlPath = info.state;
|
|
||||||
}
|
|
||||||
}).then(() => {
|
|
||||||
router.navigateByUrl(urlPath);
|
|
||||||
});
|
});
|
||||||
})
|
oauthService.configure(authconfigFactory.getAuthConfig(appConfig));
|
||||||
|
oauthService.setStorage(authStorage);
|
||||||
|
oauthService.tokenValidationHandler = new JwksValidationHandler();
|
||||||
|
oauthService.tokenValidationHandler.validateAtHash = function () {
|
||||||
|
return new Promise<boolean>((res) => { res(true); })
|
||||||
|
};
|
||||||
|
oauthService.setupAutomaticSilentRefresh();
|
||||||
|
let location = injector.get(Location);
|
||||||
|
let router = injector.get(Router);
|
||||||
|
let urlPath = location.path();
|
||||||
|
oauthService.loadDiscoveryDocument().then(() => {
|
||||||
|
oauthService.tryLogin({
|
||||||
|
onTokenReceived: (info) => {
|
||||||
|
urlPath = info.state;
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
router.navigateByUrl(urlPath);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}).then(() => {
|
||||||
|
itemtypeService.load(appConfig).then(() => resolve()).catch(() => reject());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user