Commit 6c84e64b authored by Maksym Tishchenko's avatar Maksym Tishchenko
Browse files

Viability: Environments

parent d518d465
......@@ -100,7 +100,9 @@
"InventoryViabilityRule": "Inventory viability rule",
"InventoryViabilityRule_plural": "Inventory viability rules",
"InventoryViabilityData": "Inventory viability data",
"InventoryViabilityData_plural": "Inventory viability datas"
"InventoryViabilityData_plural": "Inventory viability datas",
"InventoryViabilityEnvironment": "Inventory viability environment",
"InventoryViabilityEnvironment_plural": "Inventory viability environments"
},
"Cooperator": {
"id": "Cooperator ID",
......@@ -777,6 +779,17 @@
"site": "Maintenance site",
"cooperator": "Cooperator"
},
"InventoryViabilityEnvironment": {
"lightHours": "Light hours",
"nmWaveLenght": "NM wave length",
"lightPotency": "Light potency",
"lightGrades": "Light grades",
"lightPotencyUnitCode": "Light potency",
"gradesUnitCode": "Grades",
"darkGrades": "Dark grades",
"equipmentCode": "Equipment",
"note": "Note"
},
"AggregatedInventoryQuantity": {
"inventoryMaintenancePolicyCount": "Inventory Maintenance Policy Count",
"quantityOnHand": "Quantity On Hand",
......
import DateFilter from '@gringlobal-ce/client/model/gringlobal/DateFilter';
import NumberFilter from '../common/NumberFilter';
/**
* InventoryViabilityEnvFilter
*
* GRIN-Global CE API
*/
class InventoryViabilityEnvFilter {
public NOT: InventoryViabilityEnvFilter;
public NULL: string[];
public NOTNULL: string[];
public id: number[];
public createdBy: number[];
public createdDate: DateFilter;
public modifiedBy: number[];
public modifiedDate: DateFilter;
public ownedBy: number[];
public ownedDate: DateFilter;
public lightHours: NumberFilter;
public nmWaveLenght: NumberFilter;
public lightPotency: NumberFilter;
public lightGrades: NumberFilter;
public darkGrades: NumberFilter;
public lightPotencyUnitCode: string[];
public gradesUnitCode: string[];
public equipmentCode: string[];
}
export default InventoryViabilityEnvFilter;
......@@ -22,7 +22,11 @@ class InventoryViabilityEnvironment {
public equipmentCode: string;
public note: string;
public static CodeGroup = {
lightPotencyUnitCode: 'UNIT_OF_LIGHTPOTENCY',
gradesUnitCode: 'UNIT_OF_TEMPERATURE',
equipmentCode: 'VIABILITY_EQUIPMENT',
}
}
export default InventoryViabilityEnvironment;
......@@ -76,6 +76,8 @@ import InventoryViabilityAction from './InventoryViabilityAction';
import InventoryViabilityRule from './InventoryViabilityRule';
import InventoryViabilityRuleFilter from './InventoryViabilityRuleFilter';
import AuditLogFilter from './AuditLogFilter';
import InventoryViabilityEnvironment from './InventoryViabilityEnvironment';
import InventoryViabilityEnvFilter from './InventoryViabilityEnvFilter';
export {
AuditLog,
......@@ -121,6 +123,8 @@ export {
InventoryViabilityActionFilter, InventoryViabilityAction,
InventoryViabilityRule,
InventoryViabilityRuleFilter,
InventoryViabilityEnvironment,
InventoryViabilityEnvFilter,
};
......@@ -159,6 +163,7 @@ type OrderRequestActionFilteredPage = FilteredPage<OrderRequestAction, OrderRequ
type InventoryViabilityFilteredPage = FilteredPage<InventoryViability, InventoryViabilityFilter>;
type InventoryViabilityActionFilteredPage = FilteredPage<InventoryViabilityAction, InventoryViabilityActionFilter>;
type InventoryViabilityRuleFilteredPage = FilteredPage<InventoryViabilityRule, InventoryViabilityRuleFilter>;
type InventoryViabilityEnvFilteredPage = FilteredPage<InventoryViabilityEnvironment, InventoryViabilityEnvFilter>;
// Crop Trait Observation
interface IObservationData {
......@@ -211,5 +216,6 @@ export {
IWithObservationsData,
InventoryViabilityFilteredPage,
InventoryViabilityActionFilteredPage,
InventoryViabilityRuleFilteredPage
InventoryViabilityRuleFilteredPage,
InventoryViabilityEnvFilteredPage
};
......@@ -86,7 +86,9 @@
"InventoryViabilityRule": "Inventory viability rule",
"InventoryViabilityRule_plural": "Inventory viability rules",
"InventoryViabilityData": "Inventory viability data",
"InventoryViabilityData_plural": "Inventory viability datas"
"InventoryViabilityData_plural": "Inventory viability datas",
"InventoryViabilityEnvironment": "Inventory viability environment",
"InventoryViabilityEnvironment_plural": "Inventory viability environments"
},
"Cooperator": {
"id": "Cooperator ID",
......@@ -765,6 +767,17 @@
"site": "Maintenance site",
"cooperator": "Cooperator"
},
"InventoryViabilityEnvironment": {
"lightHours": "Light hours",
"nmWaveLenght": "NM wave length",
"lightPotency": "Light potency",
"lightGrades": "Light grades",
"lightPotencyUnitCode": "Light potency",
"gradesUnitCode": "Grades",
"darkGrades": "Dark grades",
"equipmentCode": "Equipment",
"note": "Note"
},
"AggregatedInventoryQuantity": {
"inventoryMaintenancePolicyCount": "Inventory Maintenance Policy Count",
"quantityOnHand": "Quantity On Hand",
......
......@@ -4,7 +4,7 @@ import * as QueryString from 'query-string';
import { AxiosInstance, AxiosRequestConfig } from 'axios';
import OrderRequest from '@gringlobal-ce/client/model/gringlobal/OrderRequest';
import { InventoryAction, InventoryActionFilteredPage, InventoryFilter, InventoryViabilityFilteredPage } from '@gringlobal-ce/client/model/gringlobal';
import { InventoryAction, InventoryActionFilteredPage, InventoryFilter, InventoryViabilityEnvFilteredPage, InventoryViabilityFilteredPage } from '@gringlobal-ce/client/model/gringlobal';
import InventoryViability, { InventoryViabilityDetails } from '@gringlobal-ce/client/model/gringlobal/InventoryViability';
import InventoryViabilityEnvironment from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityEnvironment';
import InventoryViabilityAction from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityAction';
......@@ -16,6 +16,7 @@ import InventoryViabilityActionRequest from '@gringlobal-ce/client/model/gringlo
import InventoryViabilityActionFilter from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityActionFilter';
import InventoryViabilityDataEnvironmentMap from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityDataEnvironmentMap';
import { dereferenceReferences3, stripObjectsToId } from '../utilities';
import InventoryViabilityEnvFilter from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityEnvFilter';
const URL_UPDATE_DATA = `/api/v1/i/viability/data`;
const URL_CREATE_DATA = `/api/v1/i/viability/data`;
......@@ -29,6 +30,8 @@ const URL_LIST_SCHEDULED_INVENTORIES = `/api/v1/i/viability/scheduled`;
const URL_ORDER_VIABILITY_TEST = `/api/v1/i/viability/order`;
const URL_LIST = `/api/v1/i/viability/list`;
const URL_FILTER = `/api/v1/i/viability/filter`;
const URL_LIST_ENV = `/api/v1/i/viability-env/list`;
const URL_FILTER_ENV = `/api/v1/i/viability-env/filter`;
const URL_START_ACTIONS = `/api/v1/i/viability/action/start`;
const URL_SCHEDULE_ACTIONS = `/api/v1/i/viability/action/schedule`;
const URL_REOPEN_ACTIONS = `/api/v1/i/viability/action/reopen`;
......@@ -322,6 +325,61 @@ class InventoryViabilityService {
});
}
/**
* listEnv at /api/v1/i/viability-env/list
*
* @param data Request body
* @param page
* @param xhrConfig additional xhr config
*/
public listEnv = (data: Partial<InventoryViabilityFilter>, page: IPageRequest = {}, xhrConfig?: AxiosRequestConfig): Promise<InventoryViabilityEnvFilteredPage> => {
const qs = QueryString.stringify({
p: page.page || undefined,
l: page.size || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST_ENV + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { data };
return this._axios.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as InventoryViabilityEnvFilteredPage);
}
/**
* filterEnv at /api/v1/i/viability-env/filter
*
* @param filter
* @param page
* @param xhrConfig additional xhr config
*/
public filterEnv = (filter: InventoryViabilityEnvFilter | string, page?: IPageRequest, xhrConfig?: AxiosRequestConfig): Promise<InventoryViabilityEnvFilteredPage> => {
const qs = QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_FILTER_ENV + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { data: typeof filter === 'string' ? null : { ...filter } };
return this._axios.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as InventoryViabilityEnvFilteredPage);
}
/**
* startActions at /api/v1/i/viability/action/start
*
......
......@@ -1117,7 +1117,8 @@
"rules": "Viability rules",
"prepareOrder": "Prepare order",
"observation": "Record new observation",
"start": "Begin testing"
"start": "Begin testing",
"environments": "Viability environments"
},
"public": {
"c": {
......@@ -1164,6 +1165,11 @@
"species": "Species"
}
},
"environment": {
"browse": {
"title": "Browse inventory viability environments"
}
},
"order": {
"browse": {
"title": "Select from one scheduled inventory",
......
......@@ -60,6 +60,11 @@ function ViabilityMenu({ currentPath }: { currentPath: string }): JSX.Element {
<ListItemText primary={ t('viability.navigation.actions') } />
</ListItem>
</Link>
<Link to="/viability/environment">
<ListItem button className={ currentPath?.match('^/viability/environment(/[0-9]+$|$)') && classes.selectedRoute }>
<ListItemText primary={ t('viability.navigation.environments') } />
</ListItem>
</Link>
<Link to="/viability/rule">
<ListItem button className={ currentPath?.match('^/viability/rule(/[0-9]+$|$)') && classes.selectedRoute }>
<ListItemText primary={ t('viability.navigation.rules') } />
......
......@@ -30,11 +30,22 @@ export const SAGA_REMOVE_VIABILITY_RULE = 'saga/viability/public/REMOVE_VIABILIT
export const SAGA_REMOVE_VIABILITY_RULES = 'saga/viability/public/REMOVE_VIABILITY_RULES'
export const SAGA_REMOVE_VIABILITY_RULE_MAPS = 'saga/viability/public/REMOVE_VIABILITY_RULE_MAPS'
export const SAGA_RECEIVE_VIABILITY_RULE_MAP_SUCCESS = 'saga/VIABILITY_GROUP/public/RECEIVE_VIABILITY_RULE_MAP_SUCCESS';
export const RECEIVE_VIABILITY_ENV_LIST = 'success/viability/public/RECEIVE_VIABILITY_ENV_LIST';
export const RECEIVE_VIABILITY_ENV = 'success/viability/public/RECEIVE_VIABILITY_ENV';
export const RECEIVE_VIABILITY_ENV_ITEM = 'success/viability/public/RECEIVE_VIABILITY_ENV_ITEM';
export const REMOVE_VIABILITY_ENV = 'success/viability/public/REMOVE_VIABILITY_ENV';
export const SAGA_LIST_VIABILITY_ENV = 'saga/viability/public/SAGA_LIST_VIABILITY_ENV';
export const SAGA_RECEIVE_VIABILITY_ENV = 'saga/viability/public/RECEIVE_VIABILITY_ENV';
export const SAGA_RECEIVE_VIABILITY_ENV_SUCCESS = 'saga/VIABILITY_GROUP/public/RECEIVE_VIABILITY_ENV_SUCCESS';
export const SAGA_REMOVE_VIABILITY_ENV = 'saga/viability/public/REMOVE_VIABILITY_ENV'
export const SAGA_REMOVE_VIABILITY_ENVS = 'saga/viability/public/REMOVE_VIABILITY_ENVS'
// Model
import {
InventoryViability,
InventoryViabilityActionFilter,
InventoryViabilityActionFilteredPage,
InventoryViabilityActionFilteredPage, InventoryViabilityEnvFilteredPage,
InventoryViabilityFilter,
InventoryViabilityFilteredPage, InventoryViabilityRule,
InventoryViabilityRuleFilter,
......@@ -46,6 +57,8 @@ import { sagaNavigate } from '@gringlobal-ce/client/action/navigation';
import { ApiCall } from '@gringlobal-ce/client/model/common';
import { InventoryViabilityService, InventoryViabilityRuleService } from '@gringlobal-ce/client/service';
import InventoryViabilityRuleMap from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityRuleMap';
import InventoryViabilityEnvFilter from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityEnvFilter';
import InventoryViabilityEnvironment from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityEnvironment';
......@@ -63,6 +76,12 @@ export const inventoryViabilityPublicSagas = [
takeEvery(SAGA_REMOVE_VIABILITY_RULES, removeViabilityRulesSaga),
takeEvery(SAGA_RECEIVE_VIABILITY_RULE_SUCCESS, receiveViabilityRuleSaga),
takeEvery(SAGA_LIST_VIABILITY_ENV, listViabilityEnvSaga),
takeEvery(SAGA_RECEIVE_VIABILITY_ENV, getViabilityEnvSaga),
takeEvery(SAGA_REMOVE_VIABILITY_ENV, removeViabilityEnvSaga),
takeEvery(SAGA_REMOVE_VIABILITY_ENVS, removeViabilityEnvsSaga),
takeEvery(SAGA_RECEIVE_VIABILITY_ENV_SUCCESS, receiveViabilityEnvSaga),
takeEvery(SAGA_LIST_VIABILITY_SPECIES, listViabilitySpeciesSaga),
takeEvery(SAGA_RECEIVE_VIABILITY_RULE_MAP_SUCCESS, receiveViabilityRuleMapSaga),
takeEvery(SAGA_REMOVE_VIABILITY_RULE_MAPS, removeViabilityRuleMapsSaga)
......@@ -310,3 +329,97 @@ function* removeViabilityRuleMapsSaga(action) {
}
}
// Viability Environment
export const getViabilityEnvAction = (id: number | string) => ({
type: SAGA_RECEIVE_VIABILITY_ENV,
payload: { id },
});
export const listViabilityEnvAction = (filter: Partial<InventoryViabilityEnvFilter> = {}, pageR: IPageRequest = { page: 0, size: 100 }) => ({
type: SAGA_LIST_VIABILITY_ENV,
payload: {
filter,
pageR,
},
});
export const loadMoreViabilityEnvAction = (viabilityEnv: InventoryViabilityEnvFilteredPage) => {
return {
type: SAGA_LIST_VIABILITY_ENV,
payload: {
filter: viabilityEnv.filter,
pageR: Page.nextPage(viabilityEnv),
},
};
};
function* getViabilityEnvSaga(action) {
yield put({
type: 'API',
target: RECEIVE_VIABILITY_ENV,
method: InventoryViabilityService.getEnv,
params: [ action.payload.id ],
});
}
function * listViabilityEnvSaga(action) {
yield put({
type: 'API',
target: RECEIVE_VIABILITY_ENV_LIST,
method: InventoryViabilityService.filterEnv,
params: [ action.payload.filter, action.payload.pageR ],
});
}
function* removeViabilityEnvSaga(action) {
yield put({
type: 'API',
target: REMOVE_VIABILITY_ENV,
method: InventoryViabilityService.removeEnv,
params: [ action.payload.id ],
onSuccess: (viabilityEnv: InventoryViabilityEnvironment) => {
return (function* () {
yield call(sagaNavigate, '/viability/environment');
return viabilityEnv;
})();
},
});
}
function* receiveViabilityEnvSaga(action) {
yield put({
type: RECEIVE_VIABILITY_ENV_ITEM,
payload: { apiCall: ApiCall.success(action.payload.viabilityEnv) },
});
}
export const removeViabilityEnvAction = (id: number) => ({
type: SAGA_REMOVE_VIABILITY_ENV,
payload: { id },
});
export const receiveViabilityEnvSuccessAction = (viabilityEnv: InventoryViabilityEnvironment) => ({
type: SAGA_RECEIVE_VIABILITY_ENV_SUCCESS,
payload: { viabilityEnv },
});
export const removeViabilityEnvsAction = (ids: number[]) => ({
type: SAGA_REMOVE_VIABILITY_ENVS,
payload: { ids },
});
function* removeViabilityEnvsSaga(action) {
for (const id of action.payload.ids) {
yield put({
type: 'API',
target: REMOVE_VIABILITY_ENV,
method: InventoryViabilityService.removeEnv,
params: [ id ],
});
yield take(REMOVE_VIABILITY_ENV);
yield take(REMOVE_VIABILITY_ENV);
}
}
......@@ -5,10 +5,19 @@ import {
RECEIVE_VIABILITY,
RECEIVE_VIABILITY_ACTIONS_LIST,
REMOVE_VIABILITY,
RECEIVE_VIABILITY_ITEM, RECEIVE_VIABILITY_RULE, RECEIVE_VIABILITY_RULE_LIST, RECEIVE_VIABILITY_RULE_ITEM, REMOVE_VIABILITY_RULE, RECEIVE_VIABILITY_SPECIES_LIST, RECEIVE_VIABILITY_RULE_MAP_ITEM, REMOVE_VIABILITY_RULE_MAP,
RECEIVE_VIABILITY_ITEM,
RECEIVE_VIABILITY_RULE,
RECEIVE_VIABILITY_RULE_LIST,
RECEIVE_VIABILITY_RULE_ITEM,
REMOVE_VIABILITY_RULE,
RECEIVE_VIABILITY_SPECIES_LIST,
RECEIVE_VIABILITY_RULE_MAP_ITEM,
REMOVE_VIABILITY_RULE_MAP,
RECEIVE_VIABILITY_ENV,
RECEIVE_VIABILITY_ENV_ITEM, RECEIVE_VIABILITY_ENV_LIST, REMOVE_VIABILITY_ENV,
} from 'viability/action/public';
// Model
import { InventoryViability, InventoryViabilityActionFilteredPage, InventoryViabilityFilteredPage, InventoryViabilityRule, InventoryViabilityRuleFilteredPage } from '@gringlobal-ce/client/model/gringlobal';
import { InventoryViability, InventoryViabilityActionFilteredPage, InventoryViabilityEnvFilteredPage, InventoryViabilityFilteredPage, InventoryViabilityRule, InventoryViabilityRuleFilteredPage } from '@gringlobal-ce/client/model/gringlobal';
import { FilteredPage, Page } from '@gringlobal-ce/client/model/page';
import { ApiCall } from '@gringlobal-ce/client/model/common';
import InventoryViabilityRuleMap from '@gringlobal-ce/client/model/gringlobal/InventoryViabilityRuleMap';
......@@ -20,6 +29,7 @@ const initialState: {
viabilityRule: ApiCall<InventoryViabilityRule>,
viabilityRuleList: ApiCall<InventoryViabilityRuleFilteredPage>,
viabilityRuleMapList: ApiCall<Page<InventoryViabilityRuleMap>>
viabilityEnvList: ApiCall<InventoryViabilityEnvFilteredPage>,
} = {
viability: null,
viabilityList: null,
......@@ -27,6 +37,7 @@ const initialState: {
viabilityRule: null,
viabilityRuleList: null,
viabilityRuleMapList: null,
viabilityEnvList: null,
};
const viabilityPublicReducer = (state = initialState, action) => {
......@@ -335,6 +346,104 @@ const viabilityPublicReducer = (state = initialState, action) => {
}
return state;
}
case RECEIVE_VIABILITY_ENV: {
const { apiCall } = action.payload;
if (apiCall.data && state.viabilityEnvList) {
const { data: viabilityEnvList } = state.viabilityEnvList;
const viabilityEnv = apiCall.data;
const updatedIndex = viabilityEnvList && viabilityEnvList.content && viabilityEnvList.content.findIndex((stateEnv) => +stateEnv.id === +viabilityEnv.id);
if (updatedIndex !== undefined && updatedIndex !== -1) {
return update(state, {
viabilityEnvList: {
data: {
content: {
[updatedIndex]: { $set: viabilityEnv },
},
},
},
});
} else {
return update(state, {
viabilityEnvList: {
data: {
content: {
$set: [ ...viabilityEnvList.content, viabilityEnv ],
},
},
},
});
}
}
return state
}
case RECEIVE_VIABILITY_ENV_ITEM: {
const { apiCall } = action.payload;
if (apiCall.data && state.viabilityEnvList) {
const { data: viabilityEnvList } = state.viabilityEnvList;
const viabilityEnv = apiCall.data;
const updatedIndex = viabilityEnvList && viabilityEnvList.content && viabilityEnvList.content.findIndex((stateEnv) => +stateEnv.id === +viabilityEnv.id);
if (updatedIndex !== undefined && updatedIndex !== -1) {
return update(state, {
viabilityEnvList: {
data: {
content: {
[updatedIndex]: { $set: viabilityEnv },
},
},
},
});
} else {
return update(state, {
viabilityEnvList: {
data: {
content: {
$set: [ ...viabilityEnvList.content, viabilityEnv ],
},
},
},
});
}
}
return state
}
case RECEIVE_VIABILITY_ENV_LIST: {
const { apiCall: { loading, error, timestamp, data } } = action.payload;
return update(state, {
viabilityEnvList: {
$set: {
loading,
error,
timestamp,
data: FilteredPage.merge(state.viabilityEnvList && state.viabilityEnvList.data, data),
},
},
});
}
case REMOVE_VIABILITY_ENV: {
const { apiCall: { data } } = action.payload;
if (data) {
if (state.viabilityEnvList && state.viabilityEnvList.data && state.viabilityEnvList.data.content) {
const updatedViabilityEnvList = state.viabilityEnvList.data.content.filter((env) => env.id !== data.id);
return update(state, {
viabilityEnvList: {
data: {
content: {
$set: updatedViabilityEnvList,
},
totalElements: {
$apply: (total) => total - 1,
},
},
},
});
}
}
return state;
}
default:
return state;
}
......
......@@ -60,6 +60,13 @@ const viabilityRoutes: IRoute[] = [
}),
path: '/observation',
},
{
exact: true,
component: Loadable({
loader: () => import(/* webpackMode:"lazy", webpackChunkName: "viability" */'viability/ui/EnvBrowsePage'),
}),
path: '/environment',
},
];
export { viabilityRoutes };
......@@ -5,7 +5,8 @@
"rules": "Viability rules",
"prepareOrder": "Prepare order",
"observation": "Record new observation",
"start": "Begin testing"
"start": "Begin testing",
"environments": "Viability environments"
},
"public": {
"c": {
......@@ -52,6 +53,11 @@
"species": "Species"
}
},
"environment": {
"browse": {
"title": "Browse inventory viability environments"
}
},
"order": {
"browse": {
"title": "Select from one scheduled inventory",
......
import * as React from 'react';
import { connect } from 'react-redux';