Commit 83aa6264 authored by Matija Obreza's avatar Matija Obreza
Browse files

Refactored code to get rid of wrappers to access_token

parent e45b5a45
...@@ -18,6 +18,7 @@ import getDir from '../server/middleware/detectDirection'; ...@@ -18,6 +18,7 @@ import getDir from '../server/middleware/detectDirection';
// JSS & MUI // JSS & MUI
import { MuiThemeProvider } from '@material-ui/core/styles'; import { MuiThemeProvider } from '@material-ui/core/styles';
import theme from 'ui/theme'; import theme from 'ui/theme';
import { configureBackendApi } from 'utilities/requestUtils';
declare const __PRELOADED_STATE__: any; declare const __PRELOADED_STATE__: any;
...@@ -33,6 +34,9 @@ const detectedLang = initialLanguage ? initialLanguage : detectLocaleFromPath(vi ...@@ -33,6 +34,9 @@ const detectedLang = initialLanguage ? initialLanguage : detectLocaleFromPath(vi
const historyOptions = { basename: detectedLang !== 'en' ? `${virtualPath}/${detectedLang}` : `${virtualPath}` }; const historyOptions = { basename: detectedLang !== 'en' ? `${virtualPath}/${detectedLang}` : `${virtualPath}` };
const history = createHistory(historyOptions); const history = createHistory(historyOptions);
// Configure axios for client
configureBackendApi({ apiUrl: `${virtualPath}/proxy` });
const initialState = __PRELOADED_STATE__ === undefined ? {} : __PRELOADED_STATE__; const initialState = __PRELOADED_STATE__ === undefined ? {} : __PRELOADED_STATE__;
const store = composeEnhancers(applyMiddleware(thunk, routerMiddleware(history)))(createStore)(rootReducer, initialState); const store = composeEnhancers(applyMiddleware(thunk, routerMiddleware(history)))(createStore)(rootReducer, initialState);
......
import { configureBackendApi } from 'utilities/requestUtils';
/** /**
* Start the frontend server * Start the frontend server
*/ */
let server = require('./server').default; const server = require('./server').default;
const PORT = process.env.PORT || 3000; const PORT = process.env.PORT || 3000;
// Configure axios for server
configureBackendApi({ apiUrl: `http://localhost:${PORT}/proxy` });
// start server on PORT // start server on PORT
server.listen(PORT, () => { server.listen(PORT, () => {
console.log('HTTP server listening on: ' + PORT); console.log('HTTP server listening on: ' + PORT);
......
...@@ -26,7 +26,7 @@ import detectLocaleFromPath from './detectLocaleFromPath'; ...@@ -26,7 +26,7 @@ import detectLocaleFromPath from './detectLocaleFromPath';
import getDir from './detectDirection'; import getDir from './detectDirection';
import config from '../config'; import config from '../config';
import checkAuthToken from './checkAuthToken'; import checkAuthToken from './checkAuthToken';
import {configure} from 'actions/applicationConfig'; import { configure } from 'actions/applicationConfig';
const prerenderer = (html, errHtml) => (req, res) => { const prerenderer = (html, errHtml) => (req, res) => {
console.log('Init prerenderer, request url:', req.url); console.log('Init prerenderer, request url:', req.url);
...@@ -36,6 +36,7 @@ const prerenderer = (html, errHtml) => (req, res) => { ...@@ -36,6 +36,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
const store = createStore(rootReducer, {} as any, applyMiddleware(thunk, routerMiddleware(createMemoryHistory))); const store = createStore(rootReducer, {} as any, applyMiddleware(thunk, routerMiddleware(createMemoryHistory)));
// Only send public data to client // Only send public data to client
store.dispatch(configure({ frontendPath: config.frontendPath, apiUrl: config.apiUrl, googleClientId: config.googleClientId })); store.dispatch(configure({ frontendPath: config.frontendPath, apiUrl: config.apiUrl, googleClientId: config.googleClientId }));
console.log(`Processing request`, req._parsedOriginalUrl); console.log(`Processing request`, req._parsedOriginalUrl);
const pathname = req._parsedOriginalUrl.pathname; const pathname = req._parsedOriginalUrl.pathname;
const search = req._parsedOriginalUrl.search; const search = req._parsedOriginalUrl.search;
......
...@@ -8,8 +8,9 @@ import AccessionFilter from 'model/AccessionFilter'; ...@@ -8,8 +8,9 @@ import AccessionFilter from 'model/AccessionFilter';
import AccessionDetails from 'model/AccessionDetails'; import AccessionDetails from 'model/AccessionDetails';
import AccessionMapInfo from 'model/AccessionMapInfo'; import AccessionMapInfo from 'model/AccessionMapInfo';
import {list as listAccessions, getDetailsByUuid, getDetailsByDoi, listOverview as listAccessionOverview, toUUID, mapInfo} from 'service/genesys/actions/accessionService';
import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO} from 'accessions/constants'; import {RECEIVE_ACCESSIONS, RECEIVE_ACCESSION, RECEIVE_ACCESSION_OVERVIEW, APPEND_ACCESSIONS, RECEIVE_ACCESSION_MAPINFO} from 'accessions/constants';
import AccessionService from 'service/genesys/AccessionService';
import { AccessionIdentifier } from 'model/dataset.model';
const receiveAccessions = (paged: FilteredPage<Accession>, error = null) => ({ const receiveAccessions = (paged: FilteredPage<Accession>, error = null) => ({
type: RECEIVE_ACCESSIONS, type: RECEIVE_ACCESSIONS,
...@@ -36,7 +37,14 @@ const receiveAccession = (accession: AccessionDetails, error = null) => ({ ...@@ -36,7 +37,14 @@ const receiveAccession = (accession: AccessionDetails, error = null) => ({
payload: { accession, error }, payload: { accession, error },
}); });
export { listAccessions as listAccessionsPromise, toUUID as toUUIDPromise }; export const toUUIDPromise = (identifiers: AccessionIdentifier[]) => (dispatch, getState): Promise<Map<string, AccessionIdentifier>> => {
return AccessionService.toUUID(identifiers);
};
export const listAccessionsPromise = (filter: string | AccessionFilter, page: IPageRequest) => (dispatch, getState): Promise<FilteredPage<Accession>> => {
return AccessionService.list(filter, page);
};
export const updateRoute = (paged: FilteredPage<Accession>, path: string = '/a') => (dispatch) => { export const updateRoute = (paged: FilteredPage<Accession>, path: string = '/a') => (dispatch) => {
const qs = { const qs = {
...@@ -53,7 +61,7 @@ export const updateRoute2 = (filterCode: string, path: string = '/a', qs?: any) ...@@ -53,7 +61,7 @@ export const updateRoute2 = (filterCode: string, path: string = '/a', qs?: any)
export const applyFilters = (filters: string | AccessionFilter, page: IPageRequest = { page: 0 }) => (dispatch) => { export const applyFilters = (filters: string | AccessionFilter, page: IPageRequest = { page: 0 }) => (dispatch) => {
console.log('Applying new filter', filters); console.log('Applying new filter', filters);
return dispatch(listAccessions(filters, page)) return AccessionService.list(filters, page)
.then((paged) => { .then((paged) => {
dispatch(receiveAccessions(paged)); dispatch(receiveAccessions(paged));
dispatch(updateRoute(paged)); dispatch(updateRoute(paged));
...@@ -65,7 +73,7 @@ export const applyFilters = (filters: string | AccessionFilter, page: IPageReque ...@@ -65,7 +73,7 @@ export const applyFilters = (filters: string | AccessionFilter, page: IPageReque
export const applyOverviewFilters = (filters: string | AccessionFilter, page: IPageRequest = { page: 0 }) => (dispatch) => { export const applyOverviewFilters = (filters: string | AccessionFilter, page: IPageRequest = { page: 0 }) => (dispatch) => {
console.log('Applying new filter', filters); console.log('Applying new filter', filters);
return dispatch(listAccessionOverview(filters)) return AccessionService.listOverview(filters)
.then((overview) => { .then((overview) => {
dispatch(receiveAccessionOverview(overview)); dispatch(receiveAccessionOverview(overview));
dispatch(updateRoute2(overview.filterCode, '/a/overview')); dispatch(updateRoute2(overview.filterCode, '/a/overview'));
...@@ -76,7 +84,7 @@ export const applyOverviewFilters = (filters: string | AccessionFilter, page: IP ...@@ -76,7 +84,7 @@ export const applyOverviewFilters = (filters: string | AccessionFilter, page: IP
}; };
export const loadAccessionsOverviewPage = (filterCode: string) => (dispatch) => { export const loadAccessionsOverviewPage = (filterCode: string) => (dispatch) => {
return dispatch(listAccessionOverview(filterCode)) return AccessionService.listOverview(filterCode)
.then((paged) => { .then((paged) => {
dispatch(receiveAccessionOverview(paged)); dispatch(receiveAccessionOverview(paged));
}).catch((error) => { }).catch((error) => {
...@@ -86,7 +94,7 @@ export const loadAccessionsOverviewPage = (filterCode: string) => (dispatch) => ...@@ -86,7 +94,7 @@ export const loadAccessionsOverviewPage = (filterCode: string) => (dispatch) =>
}; };
export const loadAccessionsMapInfo = (filters: string | AccessionFilter) => (dispatch) => { export const loadAccessionsMapInfo = (filters: string | AccessionFilter) => (dispatch) => {
return dispatch(mapInfo(filters)) return AccessionService.mapInfo(filters)
.then((mapInfo: AccessionMapInfo) => { .then((mapInfo: AccessionMapInfo) => {
dispatch(receiveAccessionMapInfo(mapInfo)); dispatch(receiveAccessionMapInfo(mapInfo));
dispatch(updateRoute2(mapInfo.filterCode, '/a/map')); dispatch(updateRoute2(mapInfo.filterCode, '/a/map'));
...@@ -98,7 +106,7 @@ export const loadAccessionsMapInfo = (filters: string | AccessionFilter) => (dis ...@@ -98,7 +106,7 @@ export const loadAccessionsMapInfo = (filters: string | AccessionFilter) => (dis
export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) => { export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) => {
const filterCode = getState().accessions.public.paged.filterCode; const filterCode = getState().accessions.public.paged.filterCode;
return dispatch(listAccessions(filterCode, page)) return AccessionService.list(filterCode, page)
.then((paged) => { .then((paged) => {
if (paged.number === 0) { if (paged.number === 0) {
dispatch(receiveAccessions(paged)); dispatch(receiveAccessions(paged));
...@@ -113,10 +121,10 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) = ...@@ -113,10 +121,10 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) =
}; };
export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) => (dispatch) => { export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) => (dispatch) => {
const loader = doi ? getDetailsByDoi : getDetailsByUuid; const loader = doi ? AccessionService.getDetailsByDoi : AccessionService.getDetailsByUuid;
const lookup = doi ? doi : uuid; const lookup = doi ? doi : uuid;
return dispatch(loader(lookup)) return loader(lookup)
.then((accession) => { .then((accession) => {
dispatch(receiveAccession(accession)); dispatch(receiveAccession(accession));
}).catch((error) => { }).catch((error) => {
...@@ -126,7 +134,7 @@ export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) => ...@@ -126,7 +134,7 @@ export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) =>
}; };
export const overviewAccessions = (filterCode: string) => (dispatch) => { export const overviewAccessions = (filterCode: string) => (dispatch) => {
return dispatch(listAccessionOverview(filterCode)) return AccessionService.listOverview(filterCode)
.then((overview) => { .then((overview) => {
dispatch(receiveAccessionOverview(overview)); dispatch(receiveAccessionOverview(overview));
}).catch((error) => { }).catch((error) => {
......
...@@ -5,6 +5,7 @@ import { clearCookies, saveCookies } from 'utilities'; ...@@ -5,6 +5,7 @@ import { clearCookies, saveCookies } from 'utilities';
import { ROLE_CLIENT } from 'constants/userRoles'; import { ROLE_CLIENT } from 'constants/userRoles';
import {log} from 'utilities/debug'; import {log} from 'utilities/debug';
import {loginUser} from 'user/actions/public'; import {loginUser} from 'user/actions/public';
import { configureBackendApi } from 'utilities/requestUtils';
export function checkAccessTokens(dispatch) { export function checkAccessTokens(dispatch) {
const cookieToken: string = typeof window !== 'undefined' && cookies.get('access_token'); const cookieToken: string = typeof window !== 'undefined' && cookies.get('access_token');
...@@ -45,6 +46,8 @@ function loginAppRequest() { ...@@ -45,6 +46,8 @@ function loginAppRequest() {
} }
function loginApp(d) { function loginApp(d) {
// console.log('Login app', d);
configureBackendApi({ accessToken: d.access_token });
return { return {
type: Constants.LOGIN_APP, type: Constants.LOGIN_APP,
authorities: [ROLE_CLIENT], authorities: [ROLE_CLIENT],
......
...@@ -4,7 +4,7 @@ import {SidPermissions} from 'model/acl.model'; ...@@ -4,7 +4,7 @@ import {SidPermissions} from 'model/acl.model';
export const permissions = (clazz: string, id: number) => (dispatch, getState) => { export const permissions = (clazz: string, id: number) => (dispatch, getState) => {
return PermissionService.permissions(getState().login.access_token, clazz, id) return PermissionService.permissions(clazz, id)
.catch((error) => { .catch((error) => {
log('Error', error); log('Error', error);
}); });
...@@ -12,7 +12,7 @@ export const permissions = (clazz: string, id: number) => (dispatch, getState) = ...@@ -12,7 +12,7 @@ export const permissions = (clazz: string, id: number) => (dispatch, getState) =
export const addPermission = (clazz: string, id: number, sidPermissions: SidPermissions) => (dispatch, getState) => { export const addPermission = (clazz: string, id: number, sidPermissions: SidPermissions) => (dispatch, getState) => {
return PermissionService.addPermission(getState().login.access_token, clazz, id, sidPermissions) return PermissionService.addPermission(clazz, id, sidPermissions)
.catch((error) => { .catch((error) => {
log('Error', error); log('Error', error);
}); });
...@@ -20,7 +20,7 @@ export const addPermission = (clazz: string, id: number, sidPermissions: SidPerm ...@@ -20,7 +20,7 @@ export const addPermission = (clazz: string, id: number, sidPermissions: SidPerm
export const autocomplete = (term: string) => (dispatch, getState) => { export const autocomplete = (term: string) => (dispatch, getState) => {
return PermissionService.autocomplete(getState().login.access_token, term) return PermissionService.autocomplete(term)
.catch((error) => { .catch((error) => {
log('Error', error); log('Error', error);
}); });
......
...@@ -4,9 +4,7 @@ import {InfoService} from 'service/InfoService'; ...@@ -4,9 +4,7 @@ import {InfoService} from 'service/InfoService';
import ServerInfo from 'model/serverinfo.model'; import ServerInfo from 'model/serverinfo.model';
export const serverInfoRequest = () => (dispatch, getState): Promise<ServerInfo> => { export const serverInfoRequest = () => (dispatch, getState): Promise<ServerInfo> => {
const token = getState().login.access_token; return InfoService.getServerInfo()
return InfoService.getServerInfo(token)
.then((data) => dispatch(getServerInfo(data))) .then((data) => dispatch(getServerInfo(data)))
.catch((error) => log('Error', error)); .catch((error) => log('Error', error));
}; };
......
const origin = typeof window !== 'undefined' ? export const API_ROOT = '';
// if we're on the client
window.document.baseURI.replace(window.location.origin, '').replace(/\/$/, '')
// or on the server
: 'http://localhost:3000';
export const API_ROOT = `${origin}/proxy`;
export const API_BASE_URL = `${API_ROOT}/api/v0`; export const API_BASE_URL = `${API_ROOT}/api/v0`;
export const APIv1_BASE_URL = `${API_ROOT}/api/v1`; export const APIv1_BASE_URL = `${API_ROOT}/api/v1`;
export const SERVER_INFO_URL = `${API_ROOT}/api/v1/info/version`;
export const LOGIN_URL = `${API_ROOT}/oauth/token`;
export const LOGOUT_URL = `${API_BASE_URL}/me/logout`;
export const GET_USER_PROFILE_URL = `${API_BASE_URL}/me/profile`;
export const CHANGE_USER_PASSWORD_URL = `${API_BASE_URL}/me/password`;
export const CHECK_TOKEN_URL = `${API_ROOT}/oauth/check_token`;
export const VERIFY_GOOGLE_TOKEN_URL = `${API_ROOT}/google/verify-token`;
...@@ -17,7 +17,7 @@ export const loadCrops = (forceReload: boolean = false) => (dispatch, getState) ...@@ -17,7 +17,7 @@ export const loadCrops = (forceReload: boolean = false) => (dispatch, getState)
const isDataStale = Date.now() - timeSinceLastFetch > LOAD_CROPS_CACHE_IDLE; const isDataStale = Date.now() - timeSinceLastFetch > LOAD_CROPS_CACHE_IDLE;
if (isDataStale || forceReload) { if (isDataStale || forceReload) {
return CropService.listCrops(getState().login.access_token) return CropService.listCrops()
.then((list) => { .then((list) => {
dispatch(receiveCrops(list)); dispatch(receiveCrops(list));
}) })
...@@ -29,7 +29,7 @@ export const loadCrops = (forceReload: boolean = false) => (dispatch, getState) ...@@ -29,7 +29,7 @@ export const loadCrops = (forceReload: boolean = false) => (dispatch, getState)
export const saveCrop = (crop: Crop) => (dispatch, getState) => { export const saveCrop = (crop: Crop) => (dispatch, getState) => {
return CropService.saveCrop(getState().login.access_token, crop) return CropService.saveCrop(crop)
.then(() => { .then(() => {
dispatch(loadCrops(true)); dispatch(loadCrops(true));
}).catch((error) => { }).catch((error) => {
...@@ -38,7 +38,7 @@ export const saveCrop = (crop: Crop) => (dispatch, getState) => { ...@@ -38,7 +38,7 @@ export const saveCrop = (crop: Crop) => (dispatch, getState) => {
}; };
export const deleteCrop = (crop: Crop) => (dispatch, getState) => { export const deleteCrop = (crop: Crop) => (dispatch, getState) => {
return CropService.deleteCrop(getState().login.access_token, crop.shortName) return CropService.deleteCrop(crop.shortName)
.then(() => { .then(() => {
dispatch(loadCrops(true)); dispatch(loadCrops(true));
}) })
......
// Actions
import {get, list as listInstitutes} from 'service/genesys/actions/instituteService';
// Constants // Constants
import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECEIVE_INSTITUTES} from 'institutes/constants'; import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECEIVE_INSTITUTES} from 'institutes/constants';
...@@ -7,6 +5,7 @@ import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECE ...@@ -7,6 +5,7 @@ import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECE
// Model // Model
import FilteredPage, {IPageRequest} from 'model/FilteredPage'; import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import FaoInstitute from 'model/FaoInstitute'; import FaoInstitute from 'model/FaoInstitute';
import InstituteService from 'service/genesys/InstituteService';
const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({ const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: DASHBOARD_RECEIVE_INSTITUTES, type: DASHBOARD_RECEIVE_INSTITUTES,
...@@ -25,7 +24,7 @@ const receiveInstitute = (institute: FaoInstitute, error = null) => ({ ...@@ -25,7 +24,7 @@ const receiveInstitute = (institute: FaoInstitute, error = null) => ({
export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) => { export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) => {
const filterCode = getState().institutes.paged.filterCode; const filterCode = getState().institutes.paged.filterCode;
return dispatch(listInstitutes(filterCode, page)) return InstituteService.list(filterCode, page)
.then((paged) => { .then((paged) => {
if (paged.number === 0) { if (paged.number === 0) {
dispatch(receiveInstitutes(paged)); dispatch(receiveInstitutes(paged));
...@@ -39,7 +38,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) = ...@@ -39,7 +38,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) =
}; };
export const loadInstitute = (code: string) => (dispatch) => { export const loadInstitute = (code: string) => (dispatch) => {
return dispatch(get(code)) return InstituteService.get(code)
.then((institute) => { .then((institute) => {
dispatch(receiveInstitute(institute)); dispatch(receiveInstitute(institute));
}).catch((error) => { }).catch((error) => {
......
import { list as listInstitutes, get } from 'service/genesys/actions/instituteService';
import navigateTo from 'actions/navigation'; import navigateTo from 'actions/navigation';
import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institutes/constants'; import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institutes/constants';
...@@ -6,6 +5,7 @@ import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institut ...@@ -6,6 +5,7 @@ import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institut
import FaoInstitute from 'model/FaoInstitute'; import FaoInstitute from 'model/FaoInstitute';
import FaoInstituteFilter from 'model/FaoInstituteFilter'; import FaoInstituteFilter from 'model/FaoInstituteFilter';
import FilteredPage, {IPageRequest} from 'model/FilteredPage'; import FilteredPage, {IPageRequest} from 'model/FilteredPage';
import InstituteService from 'service/genesys/InstituteService';
const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({ const receiveInstitutes = (paged: FilteredPage<FaoInstitute>, error = null) => ({
type: RECEIVE_INSTITUTES, type: RECEIVE_INSTITUTES,
...@@ -30,12 +30,13 @@ export const updateRoute = (paged: FilteredPage<FaoInstitute>) => (dispatch) => ...@@ -30,12 +30,13 @@ export const updateRoute = (paged: FilteredPage<FaoInstitute>) => (dispatch) =>
dispatch(navigateTo(paged.filterCode ? `/wiews/${paged.filterCode}` : '/wiews', qs)); dispatch(navigateTo(paged.filterCode ? `/wiews/${paged.filterCode}` : '/wiews', qs));
}; };
export const listInstitutesPromise = (filter: string | FaoInstituteFilter, page: IPageRequest) => (dispatch, getState): Promise<FilteredPage<FaoInstitute>> => {
export { listInstitutes as listInstitutesPromise }; return InstituteService.list(filter, page);
};
export const applyFilters = (filters: string | FaoInstituteFilter, page: IPageRequest = { page: 0 }) => (dispatch) => { export const applyFilters = (filters: string | FaoInstituteFilter, page: IPageRequest = { page: 0 }) => (dispatch) => {
console.log('Applying new filter', filters); console.log('Applying new filter', filters);
return dispatch(listInstitutes(filters, page)) return InstituteService.list(filters, page)
.then((paged) => { .then((paged) => {
dispatch(receiveInstitutes(paged)); dispatch(receiveInstitutes(paged));
dispatch(updateRoute(paged)); dispatch(updateRoute(paged));
...@@ -47,7 +48,7 @@ export const applyFilters = (filters: string | FaoInstituteFilter, page: IPageRe ...@@ -47,7 +48,7 @@ export const applyFilters = (filters: string | FaoInstituteFilter, page: IPageRe
export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) => { export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) => {
const filterCode = getState().institutes.paged.filterCode; const filterCode = getState().institutes.paged.filterCode;
return dispatch(listInstitutes(filterCode, page)) return InstituteService.list(filterCode, page)
.then((paged) => { .then((paged) => {
if (paged.number === 0) { if (paged.number === 0) {
dispatch(receiveInstitutes(paged)); dispatch(receiveInstitutes(paged));
...@@ -62,7 +63,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) = ...@@ -62,7 +63,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) =
}; };
export const loadInstitute = (code: string) => (dispatch) => { export const loadInstitute = (code: string) => (dispatch) => {
return dispatch(get(code)) return InstituteService.get(code)
.then((institute) => { .then((institute) => {
dispatch(receiveInstitute(institute)); dispatch(receiveInstitute(institute));
}).catch((error) => { }).catch((error) => {
......
...@@ -29,7 +29,7 @@ const receiveGallery = (gallery: ImageGallery, error = null) => ({ ...@@ -29,7 +29,7 @@ const receiveGallery = (gallery: ImageGallery, error = null) => ({
// Get folder details // Get folder details
export const getFolder = (path: string = '/') => (dispatch, getState) => { export const getFolder = (path: string = '/') => (dispatch, getState) => {
return RepositoryService.getFolder(getState().login.access_token, normalize(path)) return RepositoryService.getFolder(normalize(path))
.then((folder: FolderDetails) => { .then((folder: FolderDetails) => {
dispatch(receiveFolder(folder)); dispatch(receiveFolder(folder));
}) })
...@@ -41,7 +41,7 @@ export const getFolder = (path: string = '/') => (dispatch, getState) => { ...@@ -41,7 +41,7 @@ export const getFolder = (path: string = '/') => (dispatch, getState) => {
// Get folder details // Get folder details
export const deleteFolder = (path: string) => (dispatch, getState) => { export const deleteFolder = (path: string) => (dispatch, getState) => {
return RepositoryService.deleteFolder(getState().login.access_token, normalize(path)) return RepositoryService.deleteFolder(normalize(path))
.then((folder: RepositoryFolder) => { .then((folder: RepositoryFolder) => {
console.log(`Folder deleted ${path}`, folder); console.log(`Folder deleted ${path}`, folder);
return true; return true;
...@@ -55,7 +55,7 @@ export const deleteFolder = (path: string) => (dispatch, getState) => { ...@@ -55,7 +55,7 @@ export const deleteFolder = (path: string) => (dispatch, getState) => {
// Upload file // Upload file
export const uploadFile = (path: string, file: File) => (dispatch, getState) => { export const uploadFile = (path: string, file: File) => (dispatch, getState) => {
return RepositoryService.uploadFile(getState().login.access_token, normalize(path), file) return RepositoryService.uploadFile(normalize(path), file)
.then((file: RepositoryFile) => { .then((file: RepositoryFile) => {
dispatch(getFolder(file.folder.path)); dispatch(getFolder(file.folder.path));
}) })
...@@ -67,7 +67,7 @@ export const uploadFile = (path: string, file: File) => (dispatch, getState) => ...@@ -67,7 +67,7 @@ export const uploadFile = (path: string, file: File) => (dispatch, getState) =>
// Image gallery // Image gallery
export const getGallery = (path: string) => (dispatch, getState) => { export const getGallery = (path: string) => (dispatch, getState) => {
return RepositoryService.getGallery(getState().login.access_token, normalize(path)) return RepositoryService.getGallery(normalize(path))
.then((gallery: ImageGallery) => { .then((gallery: ImageGallery) => {
dispatch(receiveGallery(gallery)); dispatch(receiveGallery(gallery));
}) })
...@@ -81,7 +81,7 @@ export const createGallery = (path: string, title: string, description?: string) ...@@ -81,7 +81,7 @@ export const createGallery = (path: string, title: string, description?: string)
const gallery: ImageGallery = new ImageGallery(); const gallery: ImageGallery = new ImageGallery();
gallery.title = title; gallery.title = title;
gallery.description = description; gallery.description = description;
return RepositoryService.createGallery(getState().login.access_token, normalize(path), gallery) return RepositoryService.createGallery(normalize(path), gallery)
.then((gallery: ImageGallery) => { .then((gallery: ImageGallery) => {
console.log(`Gallery created at ${path}`, gallery); console.log(`Gallery created at ${path}`, gallery);
dispatch(receiveGallery(null)); dispatch(receiveGallery(null));
...@@ -95,7 +95,7 @@ export const createGallery = (path: string, title: string, description?: string) ...@@ -95,7 +95,7 @@ export const createGallery = (path: string, title: string, description?: string)
// Get folder details // Get folder details
export const removeGallery = (path: string) => (dispatch, getState) => { export const removeGallery = (path: string) => (dispatch, getState) => {
return RepositoryService.removeGallery(getState().login.access_token, normalize(path)) return RepositoryService.removeGallery(normalize(path))
.then((gallery: ImageGallery) => { .then((gallery: ImageGallery) => {
console.log(`Gallery deleted ${path}`, gallery); console.log(`Gallery deleted ${path}`, gallery);
dispatch(receiveGallery(null)); dispatch(receiveGallery(null));
......
import * as _ from 'lodash'; import * as _ from 'lodash';
import {getRequest, listRequests, sendValidationEmail, recheckPid, validateRequest} from 'service/genesys/actions/requestService';
// constants // constants
import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RECEIVE_MATERIAL_REQUESTS} from 'requests/constants'; import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RECEIVE_MATERIAL_REQUESTS} from 'requests/constants';
...@@ -7,6 +6,8 @@ import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RE ...@@ -7,6 +6,8 @@ import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RE
// models // models
import MaterialRequest from 'model/MaterialRequest'; import MaterialRequest from 'model/MaterialRequest';
import FilteredPage, {IPageRequest} from 'model/FilteredPage';