Commit 766d34ed authored by Matija Obreza's avatar Matija Obreza

Auto-update ISO3166 vocabulary

parent 264cf708
Pipeline #7118 passed with stages
in 6 minutes and 55 seconds
......@@ -11,6 +11,7 @@ import VocabularyTerm from 'model/vocabulary/VocabularyTerm';
const URL_AUTOCOMPLETE_LANGUAGE_TERM = `/api/v0/lang/autocomplete`;
const URL_UPDATE_LANGUAGE_VOCABULARY = `/api/v0/lang/update`;
const URL_UPDATE_ISO3166_VOCABULARY = `/api/v0/geo/update`;
const URL_GET_LANGUAGE_TERM = UrlTemplate.parse(`/api/v0/lang/{code}`);
const URL_CREATE = `/api/v0/vocabulary/create`;
const URL_LIST = `/api/v0/vocabulary/list`;
......@@ -50,6 +51,25 @@ class VocabularyService {
}).then(({ data }) => data as VocabularyTerm[]);
}
/**
* updateLanguageVocabulary at /api/v0/lang/update
*
*/
public static updateISO3166Vocabulary(): Promise<string> {
const apiUrl = URL_UPDATE_ISO3166_VOCABULARY;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as string);
}
/**
* updateLanguageVocabulary at /api/v0/lang/update
*
......
......@@ -45,3 +45,8 @@ export const saveVocabulary = (vocabulary: Vocabulary) => (dispatch, getState) =
throw new SubmissionError({ name: 'Name already used', _error: error.error });
});
};
export const autoUpdateVocabularies = () => (dispatch, getState) => {
return Promise.all([ VocabularyService.updateLanguageVocabulary(), VocabularyService.updateISO3166Vocabulary(), VocabularyService.updateWiewsVocabulary() ]);
};
......@@ -84,7 +84,7 @@ export const editVocabulary = (uuid: string) => (dispatch, getState) => {
]);
};
const showVocabulary = (uuid: string) => (dispatch) => {
export const showVocabulary = (uuid: string) => (dispatch) => {
log('Navigating to Vocabulary details');
dispatch(push(`/admin/vocabulary/${uuid}`));
};
......@@ -100,7 +100,7 @@ export const promiseListVocabularies = (page: number = 0, results: number = 50,
};
// Load them
const listVocabularies = (page: number = 0, results: number = 50, sortBy?: string[], filter?: VocabularyFilter, order?: string) => (dispatch, getState) => {
export const listVocabularies = (page: number = 0, results: number = 50, sortBy?: string[], filter?: VocabularyFilter, order?: string) => (dispatch, getState) => {
return VocabularyService.list(filter, { page, size: results, properties: sortBy, direction: order })
.then((paged) => {
......@@ -110,13 +110,3 @@ const listVocabularies = (page: number = 0, results: number = 50, sortBy?: strin
log('Error', error);
});
};
const autoUpdate = () => (dispatch, getState) => {
return Promise.all([ VocabularyService.updateLanguageVocabulary(), VocabularyService.updateWiewsVocabulary() ]);
};
export {
listVocabularies, showVocabulary, autoUpdate,
};
......@@ -4,7 +4,8 @@ import { bindActionCreators } from 'redux';
import { withStyles } from '@material-ui/core/styles';
import { parse } from 'query-string';
import { listVocabularies, promiseListVocabularies, createVocabulary, autoUpdate } from 'vocabulary/actions/public';
import { listVocabularies, promiseListVocabularies, createVocabulary } from 'vocabulary/actions/public';
import { autoUpdateVocabularies } from 'vocabulary/actions/admin';
import { Page, Pagination } from 'model/common.model';
import PagedLoader from 'ui/common/PagedLoader';
......@@ -83,9 +84,9 @@ class BrowsePage extends React.Component<IBrowsePageProps & any, any> {
history.push(location);
}
protected autoUpdate = () => {
const {autoUpdate, pagination} = this.props;
autoUpdate()
protected autoUpdateVocabularies = () => {
const {autoUpdateVocabularies, pagination} = this.props;
autoUpdateVocabularies()
.then(() => {
console.log('Vocabularies are updated');
listVocabularies(pagination.page, pagination.size, pagination.sort, pagination.filter, pagination.dir);
......@@ -112,7 +113,7 @@ class BrowsePage extends React.Component<IBrowsePageProps & any, any> {
title="What do you want to do?"
buttons={
<div>
<Button className={ classes.updateButton } variant="raised" onClick={ this.autoUpdate }>
<Button className={ classes.updateButton } variant="raised" onClick={ this.autoUpdateVocabularies }>
Update vocabularies
</Button>
<Button variant="raised" onClick={ createVocabulary }>
......@@ -158,7 +159,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
listVocabularies,
promiseListVocabularies,
createVocabulary,
autoUpdate,
autoUpdateVocabularies,
}, dispatch);
const styled = withStyles(styles)(BrowsePage);
......
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