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

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

View File

@ -46,6 +46,7 @@ html {
// Link (hover is the same color as secondary // Link (hover is the same color as secondary
a:hover { a:hover {
color: $secondary; color: $secondary;
//text-decoration: underline;
} }
// Page settings // 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' ), 'description' => __( 'The URL to be used by the importer', 'tainacan' ),
], ],
'collection' => [ 'collection' => [
'type' => 'array', 'type' => 'array/object',
'description' => __( 'The array describing the destination collectino as expected by the importer', 'tainacan' ), 'description' => __( 'The array describing the destination collectino as expected by the importer', 'tainacan' ),
], ],
'options' => [ 'options' => [
@ -272,7 +272,7 @@ class REST_Importers_Controller extends REST_Controller {
} }
public function run() { public function run($request) {
$session_id = $request['session_id']; $session_id = $request['session_id'];
$importer = $_SESSION['tainacan_importer'][$session_id]; $importer = $_SESSION['tainacan_importer'][$session_id];
@ -286,8 +286,16 @@ class REST_Importers_Controller extends REST_Controller {
global $Tainacan_Importer_Handler; global $Tainacan_Importer_Handler;
$process = $Tainacan_Importer_Handler->add_to_queue($importer); $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 = [ $response = [
'bg_process_id' => $process->get_id() 'bg_process_id' => $process->ID
]; ];
return new \WP_REST_Response( $response, 200 ); 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 * ID of the process in the database
* @var false|int * @var false|int
*/ */
protected $ID = false; public $ID = false;
/** /**
* Prefix * Prefix

View File

@ -35,8 +35,12 @@ class Importer_Handler {
function add_to_queue(\Tainacan\Importer\Importer $importer_object) { function add_to_queue(\Tainacan\Importer\Importer $importer_object) {
$data = $importer_object->_to_Array(true); $data = $importer_object->_to_Array(true);
$importer_object = $this->bg_importer->data($data)->save()->dispatch(); $bg_process = $this->bg_importer->data($data)->save();
return $importer_object; 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 ) => { return new Promise(( resolve, reject ) => {
axios.tainacan.post('importers/session/' + importerId + '/run') axios.tainacan.post('importers/session/' + importerId + '/run')