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

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