Improvements on Importer Page.

This commit is contained in:
Mateus Machado Luna 2018-06-19 17:59:15 -03:00
parent ea2d86a58b
commit 9787688585
6 changed files with 29 additions and 15 deletions

View File

@ -15,7 +15,8 @@
:title="$i18n.get('label_source_file')"
:message="$i18n.get('info_source_file_upload')"/>
<br>
<b-upload
<b-upload
v-if="importer.tmp_file == undefined"
:value="importerFile"
@input="onUploadFile($event)"
drag-drop>
@ -137,7 +138,7 @@ export default {
},
mappedCollection: {
'id': Number,
'map': Array,
'mapping': {},
'total_items': Number
},
importerTypes: [],
@ -146,7 +147,7 @@ export default {
importerSourceInfo: null,
collections: [],
collectionMetadata: [],
collectionId: Number
collectionId: undefined
}
},
methods: {
@ -209,7 +210,7 @@ export default {
});
},
checkIfMetadatumIsAvailable(metadatumId) {
return this.mappedCollection.map[metadatumId] != undefined;
return this.mappedCollection['mapping'][metadatumId] != undefined;
},
onRunImporter() {
if (this.importer.manual_collection) {
@ -217,7 +218,7 @@ export default {
.then(updatedImporter => {
this.importer = updatedImporter;
this.runImporter({ sessionId: this.sessionId })
this.runImporter(this.sessionId)
.then(backgroundProcess => {
this.$console.log(backgroundProcess);
})
@ -229,7 +230,7 @@ export default {
this.$console.log(errors);
});
} else {
this.runImporter({ sessionId: this.sessionId })
this.runImporter(this.sessionId)
.then(backgroundProcess => {
this.$console.log(backgroundProcess);
})
@ -253,7 +254,7 @@ export default {
},
onSelectCollection(collectionId) {
this.collectionId = collectionId;
this.mappedCollection.id = collectionId;
this.mappedCollection['id'] = collectionId;
// Generates options for metadata listing
this.isFetchingCollectionMetadata = true;
@ -270,7 +271,7 @@ export default {
},
onSelectCollectionMetadata(selectedMetadatum, sourceMetadatum) {
this.isFetchingCollectionMetadata = true;
this.mappedCollection.map[selectedMetadatum] = sourceMetadatum;
this.mappedCollection['mapping'][selectedMetadatum] = sourceMetadatum;
this.isFetchingCollectionMetadata = false;
}
},

View File

@ -46,6 +46,7 @@ html {
// Link (hover is the same color as secondary
a:hover {
color: $secondary;
//text-decoration: underline;
}
// Page settings

View File

@ -56,7 +56,7 @@ class REST_Importers_Controller extends REST_Controller {
'description' => __( 'The URL to be used by the importer', 'tainacan' ),
],
'collection' => [
'type' => 'array',
'type' => 'array/object',
'description' => __( 'The array describing the destination collectino as expected by the importer', 'tainacan' ),
],
'options' => [
@ -272,7 +272,7 @@ class REST_Importers_Controller extends REST_Controller {
}
public function run() {
public function run($request) {
$session_id = $request['session_id'];
$importer = $_SESSION['tainacan_importer'][$session_id];
@ -286,8 +286,16 @@ class REST_Importers_Controller extends REST_Controller {
global $Tainacan_Importer_Handler;
$process = $Tainacan_Importer_Handler->add_to_queue($importer);
if (false === $process) {
return new \WP_REST_Response([
'error_message' => __('Error starting importer', 'tainacan' ),
'session_id' => $session_id
], 400);
}
$response = [
'bg_process_id' => $process->get_id()
'bg_process_id' => $process->ID
];
return new \WP_REST_Response( $response, 200 );

View File

@ -36,7 +36,7 @@ abstract class Background_Process extends \WP_Background_Process {
* ID of the process in the database
* @var false|int
*/
protected $ID = false;
public $ID = false;
/**
* Prefix

View File

@ -35,8 +35,12 @@ class Importer_Handler {
function add_to_queue(\Tainacan\Importer\Importer $importer_object) {
$data = $importer_object->_to_Array(true);
$importer_object = $this->bg_importer->data($data)->save()->dispatch();
return $importer_object;
$bg_process = $this->bg_importer->data($data)->save();
if ( is_wp_error($bg_process->dispatch()) ) {
return false;
}
return $bg_process;
}
/**

View File

@ -116,7 +116,7 @@ export const fetchImporterSourceInfo = ({ commit }, sessionId ) => {
});
};
export const runImporter = ( { commit } , { importerId }) => {
export const runImporter = ( { commit } , importerId ) => {
return new Promise(( resolve, reject ) => {
axios.tainacan.post('importers/session/' + importerId + '/run')