Begins implementation of Background process store module. Begins implementation of 'last updated at...' info on Item Edition Page. Fixes disabled metadata not being listed at metadata edition page. Fixes error on creating filter. Get's rid of vuex warning when switching metadata and filter enabled state.

This commit is contained in:
Mateus Machado Luna 2018-06-25 13:01:07 -03:00
parent 48a4828ad9
commit 7ea185248c
18 changed files with 211 additions and 18 deletions

View File

@ -229,7 +229,6 @@
<script>
import { mapActions, mapGetters } from 'vuex';
import MetadatumEditionForm from './../edition/metadatum-edition-form.vue';
import { tainacan as axios } from '../../../js/axios/axios.js';
export default {
name: 'ImporterEditionForm',
@ -288,6 +287,9 @@ export default {
...mapActions('collection', [
'fetchCollectionsForParent'
]),
...mapActions('bgprocess', [
'fetchProcess'
]),
...mapActions('metadata', [
'fetchMetadata',
'fetchMetadatumTypes',
@ -296,6 +298,9 @@ export default {
...mapGetters('metadata', [
'getMetadatumTypes'
]),
...mapGetters('bgprocess', [
'getProcess'
]),
createImporter() {
// Puts loading on Draft Importer creation
this.isLoading = true;
@ -390,7 +395,7 @@ export default {
}
},
onCheckBackgroundProcessStatus() {
axios.get('/bg-processes/' + this.backgroundProcess.bg_process_id)
this.fetchProcess(this.backgroundProcess.bg_process_id)
.then((backgroundProcess) => {
this.$console.log(JSON.stringify(backgroundProcess));
})

View File

@ -13,6 +13,9 @@
<div class="columns">
<div class="column is-5-5">
<!-- Last Updated Info -->
<p>{{ $i18n.get('info_updated_at') + ' ' + lastUpdated }}</p>
<!-- Status -------------------------------- -->
<div class="section-label">
<label>{{ $i18n.get('label_status') }}</label>
@ -385,6 +388,9 @@ export default {
},
attachmentsList(){
return this.getAttachments();
},
lastUpdated() {
return this.getLastUpdated();
}
},
components: {
@ -405,7 +411,8 @@ export default {
]),
...mapGetters('item',[
'getMetadata',
'getAttachments'
'getAttachments',
'getLastUpdated'
]),
onSubmit() {
// Puts loading on Item edition

View File

@ -66,7 +66,7 @@
v-if="filter.filter_type != undefined">
<b-switch
size="is-small"
v-model="filter.enabled"
:value="filter.enabled"
@input="onChangeEnable($event, index)"/>
<a
:style="{ visibility: filter.collection_id != collectionId && !isRepositoryLevel? 'hidden' : 'visible' }"
@ -294,11 +294,11 @@ export default {
this.availableMetadatumList = availableMetadata;
},
onChangeEnable($event, index) {
this.activeFilterList[index].enabled = $event;
let filtersOrder = [];
for (let filter of this.activeFilterList) {
filtersOrder.push({'id': filter.id, 'enabled': filter.enabled});
}
filtersOrder[index].enabled = $event;
this.updateCollectionFiltersOrder({ collectionId: this.collectionId, filtersOrder: filtersOrder });
},
addMetadatumViaButton(metadatumType, metadatumIndex) {
@ -319,7 +319,7 @@ export default {
for (let filter of this.filterTypes) {
for (let supportedType of filter['supported_types']) {
if (choosenMetadatum.metadatum_type_object.primitive_type == supportedType)
if (choosenMetadatum.metadata_type_object.primitive_type == supportedType)
this.allowedFilterTypes.push(filter);
}
}
@ -442,7 +442,7 @@ export default {
this.isLoadingFilterTypes = false;
});
this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: 'yes' })
this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true })
.then(() => {
this.isLoadingFilters = false;
// Needs to be done after activeFilterList exists to compare and remove chosen metadata.

View File

@ -69,7 +69,7 @@
v-if="metadatum.id !== undefined">
<b-switch
size="is-small"
v-model="metadatum.enabled"
:value="metadatum.enabled"
@input="onChangeEnable($event, index)"/>
<a
:style="{ visibility:
@ -245,11 +245,11 @@ export default {
this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder });
},
onChangeEnable($event, index) {
this.activeMetadatumList[index].enabled = $event;
let metadataOrder = [];
for (let metadatum of this.activeMetadatumList) {
metadataOrder.push({'id': metadatum.id, 'enabled': metadatum.enabled});
}
metadataOrder[index].enabled = $event;
this.updateCollectionMetadataOrder({ collectionId: this.collectionId, metadataOrder: metadataOrder });
},
addMetadatumViaButton(metadatumType) {
@ -336,7 +336,7 @@ export default {
this.collectionId = this.$route.params.collectionId;
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true})
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true})
.then(() => {
this.isLoadingMetadata = false;
})

View File

@ -336,6 +336,7 @@ return apply_filters('tainacan-admin-i18n',[
'info_upload_a_source_to_see_metadata' => __( 'Upload a source file to load metadata.', 'tainacan' ),
'info_select_collection_to_list_metadata' => __( 'Select a target collection to list metadata.', 'tainacan' ),
'info_url_source_link_helper' => __( 'Link to file containing the data to be imported.', 'tainacan' ),
'info_updated_at' => __( 'Updated at', 'tainacan' ),
// Tainacan Metadatum Types
'tainacan-text' => __( 'Text', 'tainacan' ),
@ -345,6 +346,7 @@ return apply_filters('tainacan-admin-i18n',[
'tainacan-selectbox' => __( 'Select box', 'tainacan' ),
'tainacan-relationship' => __( 'Relationship', 'tainacan' ),
'tainacan-taxonomy' => __( 'Taxonomy', 'tainacan' ),
'tainacan-compound' => __( 'Compound', 'tainacan' ),
// Tainacan Filter Types
'tainacan-filter-custom-interval' => __( 'Custom Interval', 'tainacan' ),

View File

@ -344,7 +344,7 @@ class REST_Filters_Controller extends REST_Controller {
public function get_items( $request ) {
$args = $this->prepare_filters( $request );
if ($request['include_disabled'] === 'yes') {
if ($request['include_disabled'] === 'true') {
$args['include_disabled'] = true;
}

View File

@ -0,0 +1,90 @@
import axios from '../../../axios/axios';
// Actions related to background processes
export const fetchProcesses = ({ commit }) => {
return new Promise((resolve, reject) => {
axios.tainacan.get(`/bg-processes/`)
.then( res => {
let processes = res.data;
commit('setProcesses', processes);
resolve(processes)
})
.catch( error => {
reject(error);
})
});
};
export const updateProcess = ({ commit }, { id, status }) => {
return new Promise((resolve, reject) => {
axios.tainacan.patch(`/bg-processes/${id}/`, {
status: status,
})
.then( res => {
let process = res.data;
commit('setProcess', process);
resolve(process)
})
.catch( error => {
reject(error);
})
});
};
export const fetchProcess = ({ commit }, id) => {
return new Promise((resolve, reject) => {
axios.tainacan.get(`/bg-processes/${id}/`)
.then( res => {
let process = res.data;
commit('setProcess', process);
resolve(process)
})
.catch( error => {
reject(error);
})
});
};
export const fetchProcessLog = ({ commit }, { id: id, isFull: isFull }) => {
return new Promise((resolve, reject) => {
axios.tainacan.get(`/bg-processes/${id}/log`)
.then( res => {
let log = res.data;
commit('setProcessLog', log);
resolve(log)
})
.catch( error => {
reject(error);
})
});
};
export const fetchProcessErrorLog = ({ commit }, { id: id, isFull: isFull }) => {
return new Promise((resolve, reject) => {
axios.tainacan.get(`/bg-processes/${id}/log`)
.then( res => {
let errorLog = res.data;
commit('setProcessErrorLog', errorLog);
resolve(errorLog)
})
.catch( error => {
reject(error);
})
});
};
export const cleanProcesses = ({ commit }) => {
commit('cleanProcesses');
};
export const deleteProcess = ({ commit }, id) => {
return new Promise((resolve, reject) => {
axios.tainacan.delete('/bg-process/' + id)
.then( res => {
commit('deleteProcess', { id: id });
resolve( res );
}).catch((error) => {
reject( error );
});
});
};

View File

@ -0,0 +1,17 @@
export const getProcesses = state => {
return state.bg_processes;
}
export const getProcess = state => {
return state.bg_process;
}
export const getErrorLog = state => {
return state.error_log;
}
export const getLog = state => {
return state.log;
}

View File

@ -0,0 +1,19 @@
import * as actions from './actions';
import * as getters from './getters';
import * as mutations from './mutations';
const state = {
bg_processes: [],
bg_process: {},
log: {},
error_log: {}
};
export default {
namespaced: true,
state,
mutations,
actions,
getters
}

View File

@ -0,0 +1,28 @@
import Vue from 'vue';
export const setProcesses = ( state, processes ) => {
state.bg_processes = processes;
}
export const cleanProcesses = ( state ) => {
state.bg_processes = [];
}
export const setProcess = ( state, process ) => {
let index = state.bg_processes.findIndex(newProcess => newProcess.id === process.id);
if ( index >= 0){
Vue.set( state.bg_processes, index, process );
} else {
state.bg_processes.push( process );
}
state.bg_process = process;
}
export const setProcessLog = ( state, log ) => {
state.log = log;
}
export const setProcessErrorLog = ( state, errorLog ) => {
state.error_log = errorLog;
}

View File

@ -353,7 +353,7 @@ export const fetchUsers = ({ commit }, { search, exceptions }) => {
// Fetch Collections for choosing Parent Collection
export const fetchCollectionsForParent = ({ commit }) => {
return new Promise((resolve, reject) =>{
return new Promise((resolve, reject) => {
axios.tainacan.get('/collections/?fetch_only[0]=name&fetch_only[1]=id')
.then(res => {
let collections = res.data;

View File

@ -15,8 +15,8 @@ export const fetchFilters = ({ commit }, {collectionId, isRepositoryLevel, isCon
endpoint += '&context=edit';
}
if (includeDisabled === 'yes'){
endpoint += '&include_disabled=yes'
if (includeDisabled){
endpoint += '&include_disabled=' + includeDisabled;
}
axios.tainacan.get(endpoint)

View File

@ -8,6 +8,7 @@ export const sendMetadatum = ( { commit }, { item_id, metadatum_id, values }) =>
})
.then( res => {
commit('setSingleMetadata', { item_id: item_id, metadatum_id: metadatum_id, values: values });
commit('setLastUpdated');
resolve( res.data );
})
.catch(error => {
@ -16,7 +17,6 @@ export const sendMetadatum = ( { commit }, { item_id, metadatum_id, values }) =>
});
};
export const updateMetadata = ({ commit }, { item_id, metadatum_id, values }) => {
return new Promise((resolve, reject) => {
axios.tainacan.patch(`/item/${item_id}/metadata/${metadatum_id}`, {
@ -25,6 +25,7 @@ export const updateMetadata = ({ commit }, { item_id, metadatum_id, values }) =>
.then( res => {
let metadatum = res.data;
commit('setSingleMetadatum', metadatum);
commit('setLastUpdated');
resolve(metadatum)
})
.catch( error => {
@ -50,6 +51,7 @@ export const fetchMetadata = ({ commit }, item_id) => {
export const cleanMetadata = ({ commit }) => {
commit('cleanMetadata');
commit('setLastUpdated');
};
// Actions directly related to Item
@ -90,6 +92,7 @@ export const sendItem = ( { commit }, { collection_id, status }) => {
})
.then( res => {
commit('setItem', res.data);
commit('setLastUpdated');
resolve( res.data );
})
.catch(error => {
@ -105,6 +108,7 @@ export const updateItem = ({ commit }, { item_id, status }) => {
status: status
}).then( res => {
commit('setItem', res.data);
commit('setLastUpdated');
resolve( res.data );
}).catch( error => {
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });
@ -122,6 +126,7 @@ export const updateItemDocument = ({ commit }, { item_id, document, document_typ
let item = res.data;
commit('setItem', item);
commit('setLastUpdated');
resolve( res.data );
}).catch( error => {
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });
@ -140,6 +145,7 @@ export const sendAttachment = ( { commit }, { item_id, file }) => {
.then( res => {
let attachment = res.data;
commit('setSingleAttachment', attachment);
commit('setLastUpdated');
resolve( attachment );
})
.catch(error => {
@ -171,6 +177,7 @@ export const updateThumbnail = ({ commit }, { itemId, thumbnailId }) => {
}).then( res => {
let item = res.data
commit('setItem', item);
commit('setLastUpdated');
resolve( item );
}).catch( error => {
reject({ error_message: error['response']['data'].error_message, errors: error['response']['data'].errors });

View File

@ -6,6 +6,10 @@ export const getItem = state => {
return state.item;
}
export const getLastUpdated = state => {
return state.lastUpdated;
}
export const getItemTitle = state => {
return state.itemTitle;
}

View File

@ -8,7 +8,8 @@ const state = {
error: [],
itemTitle: '',
attachment: {},
attachments: []
attachments: [],
lastUpdated: ''
};

View File

@ -55,3 +55,10 @@ export const setSingleMetadatum = ( state, metadatum) => {
state.metadata.push( metadatum );
}
}
export const setLastUpdated = (state) => {
console.log(state.lastUpdated);
let now = new Date();
state.lastUpdated = now.toLocaleString();
}

View File

@ -1,6 +1,6 @@
import axios from '../../../axios/axios';
export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isContextEdit}) => {
export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isContextEdit, includeDisabled}) => {
return new Promise((resolve, reject) => {
let endpoint = '';
if (!isRepositoryLevel)
@ -9,9 +9,13 @@ export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isCont
endpoint = '/metadata/';
endpoint += '?nopaging=1';
if (isContextEdit)
endpoint += '&context=edit';
if (includeDisabled)
endpoint += '&include_disabled=' + includeDisabled;
axios.tainacan.get(endpoint)
.then((res) => {
let metadata = res.data;

View File

@ -9,6 +9,7 @@ import search from './modules/search/';
import taxonomy from './modules/taxonomy/';
import event from './modules/event';
import importer from './modules/importer';
import bgprocess from './modules/bgprocess';
Vue.use(Vuex);
@ -29,6 +30,7 @@ export default new Vuex.Store({
search,
taxonomy,
event,
importer
importer,
bgprocess
}
})