Metadata mapping on Importers Page.

This commit is contained in:
Mateus Machado Luna 2018-06-19 16:44:12 -03:00
parent 99d1425ff6
commit ea2d86a58b
4 changed files with 132 additions and 32 deletions

View File

@ -43,7 +43,8 @@
:message="$i18n.get('info_target_collection_helper')"/>
<b-select
id="tainacan-select-target-collection"
v-model="form.collectionId"
:value="collectionId"
@input="onSelectCollection($event)"
:loading="isFetchingCollections"
:placeholder="$i18n.get('instruction_select_a_target_collection')">
<option
@ -62,21 +63,37 @@
<help-button
:title="$i18n.get('label_metadata_mapping')"
:message="$i18n.get('info_metadata_mapping_helper')"/>
<div class="columns">
<div class="column">
<ol v-if="importerSourceInfo != undefined">
<li
v-for="(source_metadatum, index) of importerSourceInfo.source_metadata"
:key="index">{{ source_metadatum }}</li>
</ol>
<div v-else>
Upload a source to load metadata.
</div>
</div>
<div class="column">
<div>Select collection to list metadada. (no implemented)</div>
<div
v-if="importerSourceInfo != undefined &&
importerSourceInfo != null">
<div
class="source-metadatum"
v-for="(source_metadatum, index) of importerSourceInfo.source_metadata"
:key="index"><p>{{ source_metadatum }}</p>
<b-select
v-if="collectionMetadata != undefined &&
collectionMetadata.length > 0 &&
!isFetchingCollectionMetadata"
@input="onSelectCollectionMetadata($event, source_metadatum)"
:placeholder="$i18n.get('label_select_metadatum')">
<option
v-for="(metadatum, index) of collectionMetadata"
:key="index"
:value="metadatum.id"
:disabled="checkIfMetadatumIsAvailable(metadatum.id)">{{ metadatum.name }}
</option>
</b-select>
<p v-if="collectionMetadata == undefined || collectionMetadata.length <= 0">{{ $i18n.get('info_select_collection_to_list_metadata') }}</p>
</div>
</div>
<div
v-if="importerSourceInfo == undefined ||
importerSourceInfo == null">
<p>{{ $i18n.get('info_upload_a_source_to_see_metadata') }}</p>
</div>
</b-field>
<!-- Form submit -------------------------------- -->
@ -90,8 +107,9 @@
</div>
<div class="control">
<button
:disabled="sessionId == undefined || importer == undefined"
id="button-submit-collection-creation"
@click.prevent="runImporter"
@click.prevent="onRunImporter"
class="button is-success">{{ $i18n.get('run') }}</button>
</div>
</div>
@ -115,13 +133,20 @@ export default {
isLoading: false,
isFetchingCollections: false,
form: {
collectionId: Number
},
mappedCollection: {
'id': Number,
'map': Array,
'total_items': Number
},
importerTypes: [],
importerType: '',
importerFile: {},
importerSourceInfo: {},
importerSourceInfo: null,
collections: [],
collectionMetadata: [],
collectionId: Number
}
},
methods: {
@ -132,10 +157,14 @@ export default {
'updateImporter',
'updateImporterFile',
'fetchImporterSourceInfo',
'updateImporterCollection',
'runImporter'
]),
...mapActions('collection', [
'fetchCollectionsForParent',
'fetchCollectionsForParent'
]),
...mapActions('metadata', [
'fetchMetadata'
]),
createImporter() {
// Puts loading on Draft Importer creation
@ -169,7 +198,7 @@ export default {
this.fetchImporterSourceInfo(this.sessionId)
.then(importerSourceInfo => {
this.importerSourceInfo = importerSourceInfo;
console.log(this.importerSourceInfo);
this.mappedCollection['total_items'] = this.importerSourceInfo.source_total_items;
})
.catch((errors) => {
this.$console.log(errors);
@ -179,14 +208,35 @@ export default {
this.$console.log(errors);
});
},
runImporter() {
this.runImporter({ sessionId: this.sessionId })
.then(backgroundProcess => {
this.$console.log(backgroundProcess);
})
.catch((errors) => {
this.$console.log(errors);
});
checkIfMetadatumIsAvailable(metadatumId) {
return this.mappedCollection.map[metadatumId] != undefined;
},
onRunImporter() {
if (this.importer.manual_collection) {
this.updateImporterCollection({ sessionId: this.sessionId, collection: this.mappedCollection })
.then(updatedImporter => {
this.importer = updatedImporter;
this.runImporter({ sessionId: this.sessionId })
.then(backgroundProcess => {
this.$console.log(backgroundProcess);
})
.catch((errors) => {
this.$console.log(errors);
});
})
.catch((errors) => {
this.$console.log(errors);
});
} else {
this.runImporter({ sessionId: this.sessionId })
.then(backgroundProcess => {
this.$console.log(backgroundProcess);
})
.catch((errors) => {
this.$console.log(errors);
});
}
},
loadCollections() {
// Generates options for target collection
@ -200,11 +250,31 @@ export default {
this.$console.error(error);
this.isFetchingCollections = false;
});
},
onSelectCollection(collectionId) {
this.collectionId = collectionId;
this.mappedCollection.id = collectionId;
// Generates options for metadata listing
this.isFetchingCollectionMetadata = true;
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: false, isContextEdit: false })
.then((metadata) => {
this.collectionMetadata = metadata;
this.isFetchingCollectionMetadata = false;
})
.catch((error) => {
this.$console.error(error);
this.isFetchingCollectionMetadata = false;
});
},
onSelectCollectionMetadata(selectedMetadatum, sourceMetadatum) {
this.isFetchingCollectionMetadata = true;
this.mappedCollection.map[selectedMetadatum] = sourceMetadatum;
this.isFetchingCollectionMetadata = false;
}
},
created(){
this.importerType = this.$route.params.importerSlug;
this.createImporter();
}
@ -228,6 +298,16 @@ export default {
line-height: 1.2em;
}
.source-metadatum {
padding: 2px 0;
border-bottom: 1px solid $tainacan-input-background;
width: 100%;
margin-bottom: 6px;
display: flex;
justify-content: space-between;
align-items: center;
}
.drop-inner{
padding: 1rem 3rem;
}

View File

@ -52,7 +52,7 @@ return apply_filters('tainacan-admin-i18n',[
'new_blank_collection' => __( 'New Blank Collection', 'tainacan' ),
'split' => __( 'Split', 'tainacan' ),
'unified' => __( 'Unified', 'tainacan' ),
'add_another_search_criteria' => __( 'Add another search criteria', 'tainacan' ),
'add_more_one_search_criteria' => __( 'Add more one search criteria', 'tainacan' ),
'clear_search' => __( 'Clear search', 'tainacan' ),
'run' => __( 'Run', 'tainacan' ),
@ -144,7 +144,7 @@ return apply_filters('tainacan-admin-i18n',[
'label_yes' => __( 'Yes', 'tainacan' ),
'label_no' => __( 'No', 'tainacan' ),
'label_approved' => __( 'Approved', 'tainacan' ),
'label_related_collection' => __( 'Related Collection', 'tainacan' ),
'label_collection_related' => __( 'Collection Related', 'tainacan' ),
'label_metadata_for_search' => __( 'Metadata for search', 'tainacan' ),
'label_allow_repeated_items' => __( 'Allow repeated items', 'tainacan' ),
'label_select_taxonomy' => __( 'Select taxonomy', 'tainacan' ),
@ -222,6 +222,7 @@ return apply_filters('tainacan-admin-i18n',[
'label_target_collection' => __( 'Target Collection', 'tainacan' ),
'label_source_file' => __( 'Source file', 'tainacan' ),
'label_metadata_mapping' => __( 'Metadata mapping', 'tainacan' ),
'label_select_metadatum' => __( 'Select metadatum', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),
@ -280,7 +281,7 @@ return apply_filters('tainacan-admin-i18n',[
'info_warning_selected_items_delete' => __( 'Do you really want to permanently delete the selected items?', 'tainacan' ),
'info_warning_selected_items_trash' => __( 'Do you really want to trash the selected items?', 'tainacan' ),
'info_warning_selected_taxonomies_delete' => __( 'Do you really want to delete the selected taxonomies?', 'tainacan' ),
'info_warning_collection_related' => __( 'The metadata related collection is required', 'tainacan' ),
'info_warning_collection_related' => __( 'The metadata Collection related is required', 'tainacan' ),
'info_warning_no_metadata_found' => __( 'No metadata found in this collection', 'tainacan' ),
'info_showing_items' => __( 'Showing items ', 'tainacan' ),
'info_showing_collections' => __( 'Showing collections ', 'tainacan' ),
@ -318,6 +319,9 @@ return apply_filters('tainacan-admin-i18n',[
'info_target_collection_helper' => __( 'The collection to which imported data will be send.', 'tainacan' ),
'info_source_file_upload' => __( 'The file containing the data to be imported.', 'tainacan' ),
'info_metadata_mapping_helper' => __( 'Map each file metadata with the corresponding one in selected collection.', 'tainacan' ),
'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' ),
// Tainacan Metadatum Types
'tainacan-text' => __( 'Text', 'tainacan' ),
'tainacan-textarea' => __( 'Text area', 'tainacan' ),

View File

@ -63,6 +63,23 @@ export const updateImporter = ( { commit }, { sessionId, options }) => {
});
};
export const updateImporterCollection = ( { commit }, { sessionId, collection }) => {
return new Promise(( resolve, reject ) => {
console.log(collection)
axios.tainacan.put('importers/session/' + sessionId, {
collection: collection
})
.then( res => {
let importer = res.data;
commit('setImporter', importer);
resolve( importer );
})
.catch(error => {
reject(error);
});
});
};
export const updateImporterFile = ( { commit }, { sessionId, file }) => {
return new Promise(( resolve, reject ) => {

View File

@ -1,5 +1,4 @@
import axios from '../../../axios/axios';
import qs from 'qs';
export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isContextEdit}) => {
return new Promise((resolve, reject) => {