Move query state to common
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
3baf0b15c7
commit
17af34ff94
@ -39,6 +39,7 @@ 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 { IUser } from './models/user';
|
import { IUser } from './models/user';
|
||||||
|
import { IQueryState } from './models/query.state';
|
||||||
import { ICodeListItem } from './models/code.list.item';
|
import { ICodeListItem } from './models/code.list.item';
|
||||||
import * as commonActions from './actions/app-common.actions';
|
import * as commonActions from './actions/app-common.actions';
|
||||||
import * as commonReducers from './reducers/app-common.reducer';
|
import * as commonReducers from './reducers/app-common.reducer';
|
||||||
@ -67,6 +68,7 @@ export {
|
|||||||
ITypeaheadItem,
|
ITypeaheadItem,
|
||||||
IUser,
|
IUser,
|
||||||
ICodeListItem,
|
ICodeListItem,
|
||||||
|
IQueryState,
|
||||||
commonActions,
|
commonActions,
|
||||||
commonReducers,
|
commonReducers,
|
||||||
IAuthconfigFactory,
|
IAuthconfigFactory,
|
||||||
|
12
projects/common/src/fm/models/query.state.ts
Normal file
12
projects/common/src/fm/models/query.state.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export interface IQueryState {
|
||||||
|
itemCode: string;
|
||||||
|
parentCode: string;
|
||||||
|
level: number;
|
||||||
|
itemType: string;
|
||||||
|
query: string;
|
||||||
|
tags: string;
|
||||||
|
bboxFilter: boolean;
|
||||||
|
startDate: Date;
|
||||||
|
endDate: Date;
|
||||||
|
bbox: number[];
|
||||||
|
}
|
53
projects/common/src/fm/services/state-serializer.service.ts
Normal file
53
projects/common/src/fm/services/state-serializer.service.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { Injectable, Query } from '@angular/core';
|
||||||
|
import { IQueryState } from '../models/query.state';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class StateSerializerService {
|
||||||
|
|
||||||
|
serialize(queryState: IQueryState): string {
|
||||||
|
|
||||||
|
var state = "";
|
||||||
|
state += (queryState.itemCode) ? queryState.itemCode : "";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.parentCode) ? queryState.parentCode + ";" + queryState.level.toString() : ";";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.itemType) ? queryState.itemType : "";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.query) ? encodeURIComponent( queryState.query ) : "";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.tags) ? encodeURIComponent( queryState.tags ) : "";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.bboxFilter) ? "1" : "0";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.startDate) ? JSON.stringify(queryState.startDate) : "";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.endDate) ? JSON.stringify(queryState.endDate) : "";
|
||||||
|
state += ";";
|
||||||
|
state += (queryState.bboxFilter && queryState.bbox && queryState.bbox.length>0) ? JSON.stringify(queryState.bbox) : "";
|
||||||
|
|
||||||
|
return btoa(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
deserialize(queryState: string): IQueryState {
|
||||||
|
var state: IQueryState = { itemCode: null, parentCode: null, level: 1, itemType: null, query: null, tags: null, bboxFilter: false, startDate: null, endDate: null,bbox:[] };
|
||||||
|
var stateParts = atob(queryState).split(";");
|
||||||
|
if (stateParts.length == 10) {
|
||||||
|
if (stateParts[0] != "") state.itemCode = stateParts[0];
|
||||||
|
if (stateParts[1] != "") {
|
||||||
|
state.parentCode = stateParts[1];
|
||||||
|
state.level = parseInt(stateParts[2]);
|
||||||
|
}
|
||||||
|
if (stateParts[3] != "") state.itemType = stateParts[3];
|
||||||
|
if (stateParts[4] != "") state.query = decodeURIComponent(stateParts[4]);
|
||||||
|
if (stateParts[5] != "") state.tags = decodeURIComponent( stateParts[5]);
|
||||||
|
if (stateParts[6] != "") state.bboxFilter = parseInt(stateParts[6]) == 1;
|
||||||
|
if (stateParts[7] != "") state.startDate = new Date(Date.parse(JSON.parse(stateParts[7])));
|
||||||
|
if (stateParts[8] != "") state.endDate = new Date(Date.parse(JSON.parse(stateParts[8])));
|
||||||
|
if (stateParts[9] != "") state.bbox = JSON.parse(stateParts[9]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user