Commit 8b38df24 authored by Matija Obreza's avatar Matija Obreza

InstituteService regenerated

parent b41f50d4
......@@ -6,6 +6,7 @@ import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECE
import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import FaoInstitute from 'model/genesys/FaoInstitute';
import InstituteService from 'service/genesys/InstituteService';
import InstituteDetails from 'model/genesys/InstituteDetails';
const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: DASHBOARD_RECEIVE_INSTITUTES,
......@@ -17,7 +18,7 @@ const appendInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
payload: { paged, error },
});
const receiveInstitute = (institute: FaoInstitute, error = null) => ({
const receiveInstitute = (institute: InstituteDetails, error = null) => ({
type: DASHBOARD_RECEIVE_INSTITUTE,
payload: { institute, error },
});
......@@ -38,7 +39,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) =
};
export const loadInstitute = (code: string) => (dispatch) => {
return InstituteService.get(code)
return InstituteService.details(code)
.then((institute) => {
dispatch(receiveInstitute(institute));
}).catch((error) => {
......
......@@ -8,6 +8,7 @@ import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import InstituteService from 'service/genesys/InstituteService';
import { showSnackbar } from 'actions/snackbar';
import Page from 'model/Page';
import InstituteDetails from 'model/genesys/InstituteDetails';
const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: RECEIVE_INSTITUTES,
......@@ -19,7 +20,7 @@ const appendInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
payload: { paged, error },
});
const receiveInstitute = (institute: FaoInstitute, error = null) => ({
const receiveInstitute = (institute: InstituteDetails, error = null) => ({
type: RECEIVE_INSTITUTE,
payload: { institute, error },
});
......@@ -63,7 +64,7 @@ export const loadMoreInstitutes = (paged?: FilteredPage<FaoInstitute>) => (dispa
};
export const loadInstitute = (code: string) => (dispatch) => {
return InstituteService.get(code)
return InstituteService.details(code)
.then((institute) => {
dispatch(receiveInstitute(institute));
}).catch((error) => {
......
......@@ -3,76 +3,63 @@ import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import FilteredPage from 'model/FilteredPage';
import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institutes/constants';
import { APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES } from 'institutes/constants';
import FaoInstitute from 'model/genesys/FaoInstitute';
import InstituteDetails from 'model/genesys/InstituteDetails';
const INITIAL_STATE: {
institute: FaoInstitute;
instituteError: any;
paged: FilteredPage<FaoInstitute>;
pagedError: any;
institute: InstituteDetails;
instituteError: any;
paged: FilteredPage<FaoInstitute>;
pagedError: any;
} = {
institute: null,
instituteError: null,
paged: null,
pagedError: null,
institute: null,
instituteError: null,
paged: null,
pagedError: null,
};
function publicInstitutes(state = INITIAL_STATE, action: IReducerAction) {
switch (action.type) {
switch (action.type) {
case RECEIVE_INSTITUTE: {
const { institute, error } = action.payload;
const receivedIndex = state.paged ? state.paged.content.findIndex((item) => item.code === institute.code) : -1;
case RECEIVE_INSTITUTE: {
const { institute, error } = action.payload;
if (receivedIndex !== -1) {
return update(state, {
institute: { $set: institute },
paged: {
content: {
[receivedIndex]: {$set: institute},
},
},
instituteError: {$set: error},
});
} else {
return update(state, {
institute: { $set: institute},
paged: {$set: null},
instituteError: {$set: error},
});
}
}
case RECEIVE_INSTITUTES: {
const { paged, error } = action.payload;
return update(state, {
paged: { $set: paged },
pagedError: { $set: error },
});
}
return update(state, {
institute: { $set: institute },
instituteError: { $set: error },
});
}
case APPEND_INSTITUTES: {
const {paged, error} = action.payload;
case RECEIVE_INSTITUTES: {
const { paged, error } = action.payload;
return update(state, {
paged: { $set: paged },
pagedError: { $set: error },
});
}
return !state.paged ? update(state, {
paged: {$set: paged},
pagedError: {$set: error},
}) :
update(state, {
paged: {
content: {$push: paged.content},
number: {$set: paged.number},
last: {$set: paged.last},
},
pagedError: {$set: error},
});
}
case APPEND_INSTITUTES: {
const { paged, error } = action.payload;
default:
return state;
return !state.paged ? update(state, {
paged: { $set: paged },
pagedError: { $set: error },
}) :
update(state, {
paged: {
content: { $push: paged.content },
number: { $set: paged.number },
last: { $set: paged.last },
},
pagedError: { $set: error },
});
}
default:
return state;
}
}
export default publicInstitutes;
......@@ -9,7 +9,7 @@ import { loadInstitute } from 'institutes/actions/public';
import { applyFilters } from 'accessions/actions/public';
// Models
import FaoInstituteDetails from 'model/genesys/FaoInstituteDetails';
import FaoInstituteDetails from 'model/genesys/InstituteDetails';
// UI
import PageLayout, { MainSection, PageContents, PageSection } from 'ui/layout/PageLayout';
......@@ -42,7 +42,7 @@ const mobile = ['sm', 'xs'] as Breakpoint[];
class DisplayPage extends React.Component<IDisplayPageProps, any> {
protected static needs = [
({ params: { wiewsCode } }) => wiewsCode && loadInstitute(wiewsCode),
({ params: { wiewsCode } }) => loadInstitute(wiewsCode),
];
constructor(props: IDisplayPageProps, context: any) {
......@@ -75,7 +75,8 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
public componentWillMount() {
const { institute, code, loadInstitute } = this.props;
if (code && (! institute || code !== institute.details.code)) {
loadInstitute({ code });
console.log(`Reloading institute data for code=${code}`, institute);
loadInstitute(code);
}
}
......
/*
* Defined in Swagger as '#/definitions/PDCIStatistics'
*/
class PDCIStatistics {
public avg: number;
public count: number;
public elStats: any[];
public histogram: number[];
public histogramJson: string;
public max: number;
public min: number;
}
export default PDCIStatistics;
import FaoInstitute from 'model/genesys/FaoInstitute';
/*
* Defined in Swagger as '#/definitions/FaoInstitute'
*/
class FaoInstituteDetails {
public details: FaoInstitute;
public blurb: any;
public pdciStats: any;
public lastUpdates: any;
public overview: Map<string, any>;
}
export default FaoInstituteDetails;
import Article from 'model/cms/Article';
import FaoInstitute from 'model/genesys/FaoInstitute';
import PDCIStatistics from 'model/accession/PDCIStatistics';
/*
* Defined in Swagger as '#/definitions/InstituteDetails'
*/
class InstituteDetails {
public blurb: Article;
public details: FaoInstitute;
public lastUpdates: any[][];
public overview: any;
public pdciStats: PDCIStatistics;
}
export default InstituteDetails;
......@@ -3,15 +3,16 @@ import * as UrlTemplate from 'url-template';
import * as QueryString from 'query-string';
import { axiosBackend } from 'utilities/requestUtils';
import FilteredPage, { IPageRequest } from 'model/FilteredPage';
import FaoInstitute from 'model/genesys/FaoInstitute';
import FaoInstituteFilter from 'model/genesys/FaoInstituteFilter';
import FilteredPage, { IPageRequest } from 'model/FilteredPage';
import InstituteDetails from 'model/genesys/InstituteDetails';
import InstituteFilter from 'model/genesys/InstituteFilter';
const URL_LIST = `/api/v1/wiews/list`;
const URL_GET = UrlTemplate.parse(`/api/v1/wiews/{code}`);
const URL_DETAILS = UrlTemplate.parse(`/api/v1/wiews/{code}`);
/*
* Defined in OpenAPI as 'wiews'
* Defined in Swagger as 'institute'
*/
class InstituteService {
......@@ -19,17 +20,17 @@ class InstituteService {
* list at /api/v1/wiews/list
*
* @param filter filter
* @param page Pagination request
* @param f f
* @param page undefined
*/
public static async list(filter: string | FaoInstituteFilter, page: IPageRequest): Promise<FilteredPage<FaoInstitute>> {
// console.log('Listing insts', filter, page);
public static list(filter: InstituteFilter | string, page?: IPageRequest): Promise<FilteredPage<FaoInstitute>> {
const qs = QueryString.stringify({
f: typeof filter === 'string' ? filter : undefined,
p: page.page || undefined,
l: page.size || undefined,
d: page && page.direction ? page.direction : FaoInstitute.DEFAULT_SORT.direction,
s: page.properties || FaoInstitute.DEFAULT_SORT.property,
d: page.direction ? page.direction : undefined,
s: page.properties || undefined,
}, {});
const apiUrl = URL_LIST + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
......@@ -38,20 +39,18 @@ class InstituteService {
return axiosBackend.request({
url: apiUrl,
method: 'POST',
headers: {'Content-Type': 'application/json'},
...content,
}).then(({ data }) => data as FilteredPage<FaoInstitute>);
}
/**
* get at /api/v1/wiews/{code}
* details at /api/v1/wiews/{code}
*
* @param code code
*/
public static get(code: string): Promise<FaoInstitute> {
public static details(code: string): Promise<InstituteDetails> {
const apiUrl = URL_GET.expand({ code });
const apiUrl = URL_DETAILS.expand({ code });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -59,9 +58,10 @@ class InstituteService {
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as FaoInstitute);
}).then(({ data }) => data as InstituteDetails);
}
}
export default InstituteService;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment