Merge pull request #400 from tainacan/compound_import_csv

Compound import csv
This commit is contained in:
vnmedeiros 2020-07-08 14:41:57 -03:00 committed by GitHub
commit 785e156681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1070 additions and 673 deletions

View File

@ -31,7 +31,7 @@ class Background_Importer extends Background_Process {
$data = $batch->data; $data = $batch->data;
$key = $batch->key; $key = $batch->key;
define('TAINACAN_DOING_IMPORT', true); if (!defined('TAINACAN_DOING_IMPORT')) define('TAINACAN_DOING_IMPORT', true);
$className = $data['class_name']; $className = $data['class_name'];
if (class_exists($className)) { if (class_exists($className)) {

View File

@ -50,10 +50,16 @@ class CSV extends Importer {
} else if( $rawColumn === 'special_comment_status' ) { } else if( $rawColumn === 'special_comment_status' ) {
$this->set_option('item_comment_status_index', $index); $this->set_option('item_comment_status_index', $index);
} }
} else {
if ( preg_match ('/.*\|compound\(.*\)/', $rawColumn ) ) {
$data = preg_split("/[()]+/", $rawColumn, -1, PREG_SPLIT_NO_EMPTY);
$parent = $data[0] . ( isset($data[2]) ? $data[2] : '' );
$columns[] = [$parent => explode($this->get_option('delimiter'), $data[1])];
} else { } else {
$columns[] = $rawColumn; $columns[] = $rawColumn;
} }
} }
}
return $columns; return $columns;
} }
} }
@ -105,7 +111,16 @@ class CSV extends Importer {
*/ */
public function process_item( $index, $collection_definition ) { public function process_item( $index, $collection_definition ) {
$processedItem = []; $processedItem = [];
$headers = $this->raw_source_metadata(); $compoundHeaders = [];
$headers = array_map(function ($header) use (&$compoundHeaders) {
if ( preg_match ('/.*\|compound\(.*\)/', $header ) ) {
$data = preg_split("/[()]+/", $header, -1, PREG_SPLIT_NO_EMPTY);
$header = $data[0] . ( isset($data[2]) ? $data[2] : '' );
$compoundHeaders[$header] = $data[1];
return $header;
}
return $header;
}, $this->raw_source_metadata());
$item_line = (int) $index + 2; $item_line = (int) $index + 2;
@ -157,7 +172,7 @@ class CSV extends Importer {
foreach ( $collection_definition['mapping'] as $metadatum_id => $header) { foreach ( $collection_definition['mapping'] as $metadatum_id => $header) {
$column = null; $column = null;
foreach ( $headers as $indexRaw => $headerRaw ) { foreach ( $headers as $indexRaw => $headerRaw ) {
if( $headerRaw === $header ) { if( (is_array($header) && $headerRaw === key($header)) || ($headerRaw === $header) ) {
$column = $indexRaw; $column = $indexRaw;
} }
} }
@ -168,10 +183,33 @@ class CSV extends Importer {
$valueToInsert = $this->handle_encoding( $values[ $column ] ); $valueToInsert = $this->handle_encoding( $values[ $column ] );
$metadatum = new \Tainacan\Entities\Metadatum($metadatum_id); $metadatum = new \Tainacan\Entities\Metadatum($metadatum_id);
if( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Compound' ) {
$valueToInsert = $metadatum->is_multiple()
? explode( $this->get_option('multivalued_delimiter'), $valueToInsert)
: [$valueToInsert];
$key = key($header);
$returnValue = [];
foreach($valueToInsert as $index => $metadatumValue) {
$childrenHeaders = str_getcsv($compoundHeaders[$key], $this->get_option('delimiter'), $this->get_option('enclosure'));
$childrenValue = str_getcsv($metadatumValue, $this->get_option('delimiter'), $this->get_option('enclosure'));
if ( sizeof($childrenHeaders) != sizeof($childrenValue) ) {
$this->add_error_log(' Mismatch count headers childrens and row columns ');
return false;
}
$tmp = [];
foreach($childrenValue as $i => $value ) {
$tmp[ $childrenHeaders[$i] ] = $value;
}
$returnValue[] = $tmp;
}
$processedItem[ $key ] = $returnValue;
} else {
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ? $processedItem[ $header ] = ( $metadatum->is_multiple() ) ?
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert; explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert;
} }
}
if( !empty( $this->get_option('document_index') ) ) $processedItem['special_document'] = ''; if( !empty( $this->get_option('document_index') ) ) $processedItem['special_document'] = '';
if( !empty( $this->get_option('attachment_index') ) ) $processedItem['special_attachments'] = ''; if( !empty( $this->get_option('attachment_index') ) ) $processedItem['special_attachments'] = '';
if( !empty( $this->get_option('item_status_index') ) ) $processedItem['special_item_status'] = ''; if( !empty( $this->get_option('item_status_index') ) ) $processedItem['special_item_status'] = '';
@ -245,6 +283,8 @@ class CSV extends Importer {
public function options_form() { public function options_form() {
ob_start(); ob_start();
?> ?>
<div class="columns is-multiline">
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label> <label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -266,7 +306,8 @@ class CSV extends Importer {
<input class="input" type="text" name="delimiter" value="<?php echo esc_attr($this->get_option('delimiter')); ?>"> <input class="input" type="text" name="delimiter" value="<?php echo esc_attr($this->get_option('delimiter')); ?>">
</div> </div>
</div> </div>
</div>
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('Multivalued metadata delimiter', 'tainacan'); ?></label> <label class="label"><?php _e('Multivalued metadata delimiter', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -288,7 +329,8 @@ class CSV extends Importer {
<input class="input" type="text" name="multivalued_delimiter" value="<?php echo $this->get_option('multivalued_delimiter'); ?>"> <input class="input" type="text" name="multivalued_delimiter" value="<?php echo $this->get_option('multivalued_delimiter'); ?>">
</div> </div>
</div> </div>
</div>
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('Enclosure', 'tainacan'); ?></label> <label class="label"><?php _e('Enclosure', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -310,8 +352,9 @@ class CSV extends Importer {
<input class="input" type="text" name="enclosure" value="<?php echo $this->get_option('enclosure'); ?>"> <input class="input" type="text" name="enclosure" value="<?php echo $this->get_option('enclosure'); ?>">
</div> </div>
</div> </div>
</div>
<div class="field is-grouped"> <div class="column">
<div class="field is-expanded"> <div class="field is-expanded">
<label class="label"><?php _e('File Encoding', 'tainacan'); ?></label> <label class="label"><?php _e('File Encoding', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -330,7 +373,7 @@ class CSV extends Importer {
</div> </div>
</span> </span>
<div class="control is-clearfix"> <div class="control is-clearfix">
<div class="select"> <div class="select is-fullwidth">
<select name="encode"> <select name="encode">
<option value="utf8" <?php selected($this->get_option('encode'), 'utf8'); ?> >UTF-8</option> <option value="utf8" <?php selected($this->get_option('encode'), 'utf8'); ?> >UTF-8</option>
<option value="iso88591" <?php selected($this->get_option('encode'), 'iso88591'); ?> >ISO-88591</option> <option value="iso88591" <?php selected($this->get_option('encode'), 'iso88591'); ?> >ISO-88591</option>
@ -338,7 +381,12 @@ class CSV extends Importer {
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<div class="columns">
<div class="column">
<div class="field is-expanded"> <div class="field is-expanded">
<label class="label"><?php _e('Repeated Item', 'tainacan'); ?></label> <label class="label"><?php _e('Repeated Item', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -357,22 +405,18 @@ class CSV extends Importer {
</div> </div>
</span> </span>
<div class="control is-clearfix"> <div class="control is-clearfix">
<div class="select"> <div class="select is-fullwidth">
<select name="repeated_item"> <select name="repeated_item">
<option value="update" <?php selected($this->get_option('repeated_item'), 'update'); ?> >Update</option> <option value="update" <?php selected($this->get_option('repeated_item'), 'update'); ?> ><?php _e('Update', 'tainacan'); ?></option>
<option value="ignore" <?php selected($this->get_option('repeated_item'), 'ignore'); ?> >Ignore</option> <option value="ignore" <?php selected($this->get_option('repeated_item'), 'ignore'); ?> ><?php _e('Ignore', 'tainacan'); ?></option>
</select> </select>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="field"> <div class="column is-three-quarters">
<label class="label"><?php _e('Importing attachments', 'tainacan'); ?></label> <div class="field is-expanded">
<p>
<?php echo nl2br(__('Check the documentation to learn how to set up your .csv file correctly for importing files <a href="https://tainacan.github.io/tainacan-wiki/#/importers?id=importador-csv-items">on this link.</a>', 'tainacan')); ?>
</p>
<br>
<label class="label"><?php _e('Server path', 'tainacan'); ?></label> <label class="label"><?php _e('Server path', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
<a class="help-button has-text-secondary"> <a class="help-button has-text-secondary">
@ -392,7 +436,14 @@ class CSV extends Importer {
<div class="control is-clearfix"> <div class="control is-clearfix">
<input class="input" type="text" name="server_path" value="<?php echo $this->get_option('server_path'); ?>"> <input class="input" type="text" name="server_path" value="<?php echo $this->get_option('server_path'); ?>">
</div> </div>
<p class="help">
<strong><?php _e('Importing attachments', 'tainacan'); ?>: </strong><?php echo nl2br(__('Check the documentation to learn how to set up your .csv file correctly for importing files <a href="https://tainacan.github.io/tainacan-wiki/#/importers?id=importador-csv-items">on this link.</a>', 'tainacan')); ?>
</p>
</div> </div>
</div>
</div>
<?php <?php
@ -658,7 +709,10 @@ class CSV extends Importer {
continue; continue;
} }
$tainacan_metadatum_id = array_search( $metadatum_source, $collection_definition['mapping'] ); foreach($collection_definition['mapping'] as $id => $value) {
if( (is_array($value) && key($value) == $metadatum_source) || ($value == $metadatum_source) )
$tainacan_metadatum_id = $id;
}
$metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id ); $metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id );
if( $this->is_empty_value( $values ) ) continue; if( $this->is_empty_value( $values ) ) continue;
@ -681,6 +735,19 @@ class CSV extends Importer {
} }
$singleItemMetadata->set_value( $terms ); $singleItemMetadata->set_value( $terms );
} }
} elseif( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Compound' ) {
$children_mapping = $collection_definition['mapping'][$tainacan_metadatum_id][$metadatum_source];
$singleItemMetadata = [];
foreach($values as $compoundValue) {
$tmp = [];
foreach($children_mapping as $tainacan_children_metadatum_id => $tainacan_children_header) {
$metadatumChildren = $Tainacan_Metadata->fetch( $tainacan_children_metadatum_id, 'OBJECT' );
$compoundItemMetadata = new Entities\Item_Metadata_Entity( $item, $metadatumChildren);
$compoundItemMetadata->set_value($compoundValue[$tainacan_children_header]);
$tmp[] = $compoundItemMetadata;
}
$singleItemMetadata[] = $tmp;
}
} else { } else {
$singleItemMetadata->set_value( $values ); $singleItemMetadata->set_value( $values );
} }
@ -702,6 +769,7 @@ class CSV extends Importer {
} }
foreach ( $itemMetadataArray as $itemMetadata ) { foreach ( $itemMetadataArray as $itemMetadata ) {
if($itemMetadata instanceof Entities\Item_Metadata_Entity ) {
$itemMetadata->set_item( $insertedItem ); // *I told you $itemMetadata->set_item( $insertedItem ); // *I told you
if( $itemMetadata->validate() ) { if( $itemMetadata->validate() ) {
$result = $Tainacan_Item_Metadata->insert( $itemMetadata ); $result = $Tainacan_Item_Metadata->insert( $itemMetadata );
@ -710,6 +778,25 @@ class CSV extends Importer {
$this->add_error_log($itemMetadata->get_errors()); $this->add_error_log($itemMetadata->get_errors());
continue; continue;
} }
} elseif ( is_array($itemMetadata) ) {
if($updating_item == true) {
$this->deleteAllValuesCompoundItemMetadata($insertedItem, $itemMetadata[0][0]->get_metadatum()->get_parent());
}
foreach($itemMetadata as $compoundItemMetadata) {
$parent_meta_id = null;
foreach($compoundItemMetadata as $itemChildren) {
$itemChildren->set_parent_meta_id($parent_meta_id);
if( $itemChildren->validate() ) {
$item_children_metadata = $Tainacan_Item_Metadata->insert($itemChildren);
$parent_meta_id = $item_children_metadata->get_parent_meta_id();
} else {
$this->add_error_log('Error saving value for ' . $itemChildren->get_metadatum()->get_name() . " in item " . $insertedItem->get_title());
$this->add_error_log($itemChildren->get_errors());
continue;
}
}
}
}
//if( $result ){ //if( $result ){
// $values = ( is_array( $itemMetadata->get_value() ) ) ? implode( PHP_EOL, $itemMetadata->get_value() ) : $itemMetadata->get_value(); // $values = ( is_array( $itemMetadata->get_value() ) ) ? implode( PHP_EOL, $itemMetadata->get_value() ) : $itemMetadata->get_value();
@ -740,6 +827,19 @@ class CSV extends Importer {
} }
} }
private function deleteAllValuesCompoundItemMetadata($item, $compoundMetadataID) {
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$compound_metadata = $Tainacan_Metadata->fetch($compoundMetadataID, 'OBJECT');
$compound_item_metadata = new Entities\Item_Metadata_Entity($item, $compound_metadata);
$compound_item_metadata_value = $compound_item_metadata->get_value();
foreach($compound_item_metadata_value as $item_metadata_value) {
foreach ($item_metadata_value as $itemMetadata) {
$Tainacan_Item_Metadata->remove_compound_value($item, $compound_metadata, $itemMetadata->get_parent_meta_id());
}
}
}
/** /**
* @param $value * @param $value
* @return bool * @return bool
@ -844,10 +944,13 @@ class CSV extends Importer {
if( !is_numeric($metadatum_id) ) { if( !is_numeric($metadatum_id) ) {
$metadatum = $this->create_new_metadata( $header, $collection['id']); $metadatum = $this->create_new_metadata( $header, $collection['id']);
if( is_object($metadatum) && $metadatum instanceof \Tainacan\Entities\Metadatum ){
if( is_object($metadatum) ){
unset($collection['mapping'][$metadatum_id]); unset($collection['mapping'][$metadatum_id]);
$collection['mapping'][$metadatum->get_id()] = $header; $collection['mapping'][$metadatum->get_id()] = $header;
} elseif ( is_array($metadatum) && sizeof($metadatum) == 2) {
$parent_header = key($header);
unset($collection['mapping'][$metadatum_id]);
$collection['mapping'][$metadatum[0]->get_id()] = [$parent_header=>$metadatum[1]];
} }
} }

View File

@ -548,6 +548,8 @@ class Flickr_Importer extends Importer {
public function options_form(){ public function options_form(){
ob_start(); ob_start();
?> ?>
<div class="columns">
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('API ID', 'tainacan'); ?></label> <label class="label"><?php _e('API ID', 'tainacan'); ?></label>
<p> <p>
@ -567,24 +569,27 @@ class Flickr_Importer extends Importer {
<input class="input" type="text" name="api_id" value=""> <input class="input" type="text" name="api_id" value="">
</div> </div>
</div> </div>
</div>
<div class="column">
<div class="field">
<label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label> <label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label>
<p> <p>
<?php _e('The following URL types are supported:', 'tainacan'); ?> <?php _e('The following URL types are supported:', 'tainacan'); ?>
<br/><br/> <br/><br/>
<?php _e('User profile', 'tainacan'); ?> - <?php _e('User profile', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.flickr.com/photos/username <?php _e('Example: ', 'tainacan'); ?> <code>https://www.flickr.com/photos/username</code>
<br/> <br/>
<?php _e('Albums', 'tainacan'); ?> - <?php _e('Albums', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.flickr.com/photos/username/albums/123456 <?php _e('Example: ', 'tainacan'); ?> <code>https://www.flickr.com/photos/username/albums/123456</code>
<br/> <br/>
<?php _e('Photos', 'tainacan'); ?> - <?php _e('Photos', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.flickr.com/photos/username/123456 <?php _e('Example: ', 'tainacan'); ?> <code>https://www.flickr.com/photos/username/123456</code>
</p> </p>
</div>
</div>
</div>
<?php <?php

View File

@ -923,10 +923,23 @@ abstract class Importer {
* @return bool * @return bool
* @throws \Exception * @throws \Exception
*/ */
public function create_new_metadata( $metadata_description, $collection_id){ public function create_new_metadata( $metadata_description, $collection_id, $parent_id = null){
$taxonomy_repo = \Tainacan\Repositories\Taxonomies::get_instance(); $taxonomy_repo = \Tainacan\Repositories\Taxonomies::get_instance();
$metadata_repo = \Tainacan\Repositories\Metadata::get_instance(); $metadata_repo = \Tainacan\Repositories\Metadata::get_instance();
if(is_array($metadata_description)) {
$parent_metadata_description = key($metadata_description);
$parent_compound = $this->create_new_metadata($parent_metadata_description, $collection_id);
if($parent_compound == false) return false;
$children_mapping = [];
foreach($metadata_description[$parent_metadata_description] as $children_metadata_description) {
$children_compound = $this->create_new_metadata($children_metadata_description, $collection_id, $parent_compound->get_id());
if ( $children_compound == false )
return false;
$children_mapping[$children_compound->get_id()] = $children_metadata_description;
}
return [$parent_compound, $children_mapping];
}
$properties = array_filter( explode('|', $metadata_description) ); $properties = array_filter( explode('|', $metadata_description) );
if( is_array($properties) && count($properties) < 2 ){ if( is_array($properties) && count($properties) < 2 ){
@ -953,6 +966,14 @@ abstract class Importer {
$type = ucfirst($type); $type = ucfirst($type);
$newMetadatum->set_metadata_type('Tainacan\Metadata_Types\\'.$type); $newMetadatum->set_metadata_type('Tainacan\Metadata_Types\\'.$type);
$newMetadatum->set_collection_id( (isset($collection_id)) ? $collection_id : 'default'); $newMetadatum->set_collection_id( (isset($collection_id)) ? $collection_id : 'default');
$newMetadatum->set_status('auto-draft');
if($newMetadatum->validate()) {
$newMetadatum = $metadata_repo->insert( $newMetadatum );
} else {
$this->add_log('Error creating metadata ' . $name . ' in collection ' . $collection_id);
$this->add_log($newMetadatum->get_errors());
return false;
}
$newMetadatum->set_status('publish'); $newMetadatum->set_status('publish');
if( strcmp(strtolower($type), "taxonomy") === 0 ){ if( strcmp(strtolower($type), "taxonomy") === 0 ){
@ -1001,6 +1022,10 @@ abstract class Importer {
$newMetadatum->set_collection_key('no'); $newMetadatum->set_collection_key('no');
} }
if(isset($parent_id) && $parent_id != null) {
$newMetadatum->set_parent($parent_id);
}
if($newMetadatum->validate()){ if($newMetadatum->validate()){
$inserted_metadata = $metadata_repo->insert( $newMetadatum ); $inserted_metadata = $metadata_repo->insert( $newMetadatum );

View File

@ -839,6 +839,8 @@ class Oaipmh_Importer extends Importer {
public function options_form(){ public function options_form(){
ob_start(); ob_start();
?> ?>
<div class="columns">
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('Create set as', 'tainacan'); ?></label> <label class="label"><?php _e('Create set as', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -865,6 +867,8 @@ class Oaipmh_Importer extends Importer {
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<?php <?php
return ob_get_clean(); return ob_get_clean();

View File

@ -104,7 +104,9 @@ class Test_Importer extends Importer {
public function options_form() { public function options_form() {
ob_start(); ob_start();
?> ?>
<div class="columns is-multiline">
<div class="column is-half">
<div class="field"> <div class="field">
<label class="label"><?php _e('Number of items in collection 1', 'tainacan'); ?></label> <label class="label"><?php _e('Number of items in collection 1', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -126,7 +128,9 @@ class Test_Importer extends Importer {
<input class="input" type="number" name="items_col_1" value="<?php echo $this->get_option('items_col_1'); ?>"> <input class="input" type="number" name="items_col_1" value="<?php echo $this->get_option('items_col_1'); ?>">
</div> </div>
</div> </div>
</div>
<div class="column is-half">
<div class="field"> <div class="field">
<label class="label"><?php _e('Number of extra metadata to create in first collection', 'tainacan'); ?></label> <label class="label"><?php _e('Number of extra metadata to create in first collection', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -148,7 +152,9 @@ class Test_Importer extends Importer {
<input class="input" type="number" name="additonal_metadata" value="<?php echo $this->get_option('additonal_metadata'); ?>"> <input class="input" type="number" name="additonal_metadata" value="<?php echo $this->get_option('additonal_metadata'); ?>">
</div> </div>
</div> </div>
</div>
<div class="column is-half">
<div class="field"> <div class="field">
<label class="label"><?php _e('Create second collection with a relationship', 'tainacan'); ?></label> <label class="label"><?php _e('Create second collection with a relationship', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -177,7 +183,9 @@ class Test_Importer extends Importer {
</label> </label>
</div> </div>
</div> </div>
</div>
<div class="column is-half">
<div class="field"> <div class="field">
<label class="label"><?php _e('Number of items in collection 2', 'tainacan'); ?></label> <label class="label"><?php _e('Number of items in collection 2', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -199,10 +207,18 @@ class Test_Importer extends Importer {
<input class="input" type="number" name="items_col_2" value="<?php echo $this->get_option('items_col_2'); ?>"> <input class="input" type="number" name="items_col_2" value="<?php echo $this->get_option('items_col_2'); ?>">
</div> </div>
</div> </div>
</div>
</div>
<hr> <hr>
<h2><?php _e('Images', 'tainacan') ?></h2><br>
<div class="columns is-multiline">
<div class="column is-12">
<h2><?php _e('Images', 'tainacan') ?></h2>
</div>
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('Add random images from flickr', 'tainacan'); ?></label> <label class="label"><?php _e('Add random images from flickr', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -232,6 +248,30 @@ class Test_Importer extends Importer {
</div> </div>
</div> </div>
<div class="field">
<label class="label"><?php _e('Keyword Search', 'tainacan'); ?></label>
<span class="help-wrapper">
<a class="help-button has-text-secondary">
<span class="icon is-small">
<i class="tainacan-icon tainacan-icon-help" ></i>
</span>
</a>
<div class="help-tooltip">
<div class="help-tooltip-header">
<h5><?php _e('Keyword Search', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Optionally ype one keyword which it will be used to find images in flickr (e.g. dogs, cat). Default is "kitten".', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="keyword_images" value="<?php echo $this->get_option('keyword_images'); ?>">
</div>
</div>
</div>
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('Horizontal image size (0 for random)', 'tainacan'); ?></label> <label class="label"><?php _e('Horizontal image size (0 for random)', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -275,27 +315,8 @@ class Test_Importer extends Importer {
<input class="input" type="number" name="vertical_image_size" value="<?php echo $this->get_option('vertical_image_size'); ?>"> <input class="input" type="number" name="vertical_image_size" value="<?php echo $this->get_option('vertical_image_size'); ?>">
</div> </div>
</div> </div>
</div>
<div class="field">
<label class="label"><?php _e('Keyword Search', 'tainacan'); ?></label>
<span class="help-wrapper">
<a class="help-button has-text-secondary">
<span class="icon is-small">
<i class="tainacan-icon tainacan-icon-help" ></i>
</span>
</a>
<div class="help-tooltip">
<div class="help-tooltip-header">
<h5><?php _e('Keyword Search', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Optionally ype one keyword which it will be used to find images in flickr (e.g. dogs, cat). Default is "kitten".', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="keyword_images" value="<?php echo $this->get_option('keyword_images'); ?>">
</div>
</div> </div>
<?php <?php

View File

@ -378,6 +378,8 @@ class Youtube_Importer extends Importer {
public function options_form(){ public function options_form(){
ob_start(); ob_start();
?> ?>
<div class="columns">
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('API Key', 'tainacan'); ?></label> <label class="label"><?php _e('API Key', 'tainacan'); ?></label>
@ -400,25 +402,30 @@ class Youtube_Importer extends Importer {
<input class="input" type="text" name="api_id" value="<?php echo $this->get_option('api_id'); ?>"> <input class="input" type="text" name="api_id" value="<?php echo $this->get_option('api_id'); ?>">
</div> </div>
</div> </div>
</div>
<div class="column">
<div class="field">
<label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label> <label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label>
<p> <p>
<?php _e('The following URL types are supported:', 'tainacan'); ?> <?php _e('The following URL types are supported:', 'tainacan'); ?>
<br/><br/> <br/><br/>
<?php _e('User profile', 'tainacan'); ?> - <?php _e('User profile', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/user/username <?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/user/username</code>
<br/> <br/>
<?php _e('Playlists', 'tainacan'); ?> - <?php _e('Playlists', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/playlist?123456 <?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/playlist?123456</code>
<br/> <br/>
<?php _e('Channels', 'tainacan'); ?> - <?php _e('Channels', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/channel/123456 <?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/channel/123456</code>
<br/> <br/>
<?php _e('Videos', 'tainacan'); ?> - <?php _e('Videos', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/watch?v=123456 <?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/watch?v=123456</code>
</p> </p>
</div>
</div>
</div>
<?php <?php

View File

@ -40,6 +40,8 @@ class Term_Importer extends Importer {
public function options_form() { public function options_form() {
ob_start(); ob_start();
?> ?>
<div class="columns">
<div class="column">
<div class="field"> <div class="field">
<label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label> <label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -61,7 +63,9 @@ class Term_Importer extends Importer {
<input class="input" type="text" name="delimiter" value="<?php echo $this->get_option('delimiter'); ?>"> <input class="input" type="text" name="delimiter" value="<?php echo $this->get_option('delimiter'); ?>">
</div> </div>
</div> </div>
</div>
<div class="column">
<div class="field import_term_csv_taxonomies"> <div class="field import_term_csv_taxonomies">
<label class="label"><?php _e('Target taxonomy:', 'tainacan'); ?></label> <label class="label"><?php _e('Target taxonomy:', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
@ -81,7 +85,7 @@ class Term_Importer extends Importer {
</div> </div>
</span> </span>
<div class="control is-clearfix"> <div class="control is-clearfix">
<div class="select"> <div class="select is-fullwidth">
<select name="select_taxonomy" class="select_taxonomy"> <select name="select_taxonomy" class="select_taxonomy">
<option value="" selected><?php _e('Create a new taxonomy', 'tainacan'); ?></option> <option value="" selected><?php _e('Create a new taxonomy', 'tainacan'); ?></option>
<?php <?php
@ -100,9 +104,10 @@ class Term_Importer extends Importer {
<input class="input new_taxonomy" type="text" name="new_taxonomy" value="<?php echo $this->get_option('new_taxonomy'); ?>" placeholder="<?php _e('New taxonomy name', 'tainacan'); ?>" > <input class="input new_taxonomy" type="text" name="new_taxonomy" value="<?php echo $this->get_option('new_taxonomy'); ?>" placeholder="<?php _e('New taxonomy name', 'tainacan'); ?>" >
</div> </div>
</div>
</div> </div>
</div>
<?php <?php
return ob_get_clean(); return ob_get_clean();
} }

View File

@ -11,55 +11,12 @@
class="tainacan-form" class="tainacan-form"
label-width="120px" label-width="120px"
v-if="importer != undefined && importer != null"> v-if="importer != undefined && importer != null">
<div class="columns is-gapless">
<div
v-if="importer.options_form != undefined && importer.options_form != null && importer.options_form != ''"
class="column">
<!-- Importer custom options -->
<form id="importerOptionsForm">
<div v-html="importer.options_form"/>
</form>
</div>
<div <div
v-if="importer.manual_collection || importer.accepts.file || importer.accepts.url" v-if="importer.manual_collection || importer.accepts.file || importer.accepts.url"
class="column"> class="columns">
<!-- Target collection selection -------------------------------- -->
<b-field <div class="column">
v-if="importer.manual_collection"
:addons="false"
:label="$i18n.get('label_target_collection')">
<help-button
:title="$i18n.get('label_target_collection')"
:message="$i18n.get('info_target_collection_helper')"/>
<br>
<div class="is-inline">
<b-select
expanded
id="tainacan-select-target-collection"
:value="collectionId"
@input="onSelectCollection($event)"
:loading="isFetchingCollections"
:placeholder="$i18n.get('instruction_select_a_target_collection')">
<option
v-for="collection of collections"
v-if="collection.current_user_can_edit_items"
:key="collection.id"
:value="collection.id">{{ collection.name }}
</option>
</b-select>
<router-link
v-if="$userCaps.hasCapability('tnc_rep_edit_collections')"
tag="a"
style="font-size: 0.875em;"
class="add-link"
:to="{ path: $routerHelper.getNewCollectionPath(), query: { fromImporter: true }}">
<span class="icon">
<i class="tainacan-icon tainacan-icon-add"/>
</span>
{{ $i18n.get('new_blank_collection') }}
</router-link>
</div>
</b-field>
<!-- File Source input --> <!-- File Source input -->
<b-field <b-field
v-if="importer.accepts.file" v-if="importer.accepts.file"
@ -104,6 +61,11 @@
</span> </span>
</a> </a>
</div> </div>
<div
class="control selected-source-file"
v-if="importerFile == undefined && importer.tmp_file">
<p>{{ $i18n.get('label_select_file') + ': ' + importer.tmp_file }}</p>
</div>
</b-field> </b-field>
<!-- URL source input -------------------------------- --> <!-- URL source input -------------------------------- -->
@ -118,10 +80,69 @@
id="tainacan-url-link-source" id="tainacan-url-link-source"
v-model="url"/> v-model="url"/>
</b-field> </b-field>
</div>
<div
v-if="importer.manual_collection"
style="margin-top: 2em;"
class="column is-narrow">
<span class="icon">
<i class="tainacan-icon tainacan-icon-pointer tainacan-icon-36px has-text-gray2" />
</span>
</div>
<div
v-if="importer.manual_collection"
class="column">
<!-- Target collection selection -------------------------------- -->
<b-field
:addons="false"
:label="$i18n.get('label_target_collection')">
<help-button
:title="$i18n.get('label_target_collection')"
:message="$i18n.get('info_target_collection_helper')"/>
<br>
<div class="is-inline">
<b-select
expanded
id="tainacan-select-target-collection"
:value="collectionId"
@input="onSelectCollection($event)"
:loading="isFetchingCollections"
:placeholder="$i18n.get('instruction_select_a_target_collection')">
<option
v-for="collection of collections"
v-if="collection.current_user_can_edit_items"
:key="collection.id"
:value="collection.id">{{ collection.name }}
</option>
</b-select>
<router-link
v-if="$userCaps.hasCapability('tnc_rep_edit_collections')"
tag="a"
style="font-size: 0.875em;"
class="add-link"
:to="{ path: $routerHelper.getNewCollectionPath(), query: { fromImporter: true }}">
<span class="icon">
<i class="tainacan-icon tainacan-icon-add"/>
</span>
{{ $i18n.get('new_blank_collection') }}
</router-link>
</div>
</b-field>
</div>
</div> </div>
<hr v-if="(importer.manual_collection || importer.accepts.file || importer.accepts.url) && (importer.options_form != undefined && importer.options_form != null && importer.options_form != '')">
<div v-if="importer.options_form != undefined && importer.options_form != null && importer.options_form != ''">
<!-- Importer custom options -->
<form id="importerOptionsForm">
<div v-html="importer.options_form"/>
</form>
</div> </div>
<!-- Form submit -------------------------------- --> <!-- Form submit -------------------------------- -->
<div class="columns is-gapless field is-grouped form-submit"> <div class="columns is-gapless field is-grouped form-submit">
<div class="control"> <div class="control">
@ -168,6 +189,7 @@
</div> </div>
</div> </div>
</form> </form>
<b-loading <b-loading
:active.sync="isLoading" :active.sync="isLoading"
:can-cancel="false"/> :can-cancel="false"/>
@ -286,7 +308,7 @@ export default {
}, },
onUploadFile() { onUploadFile() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.updateImporterFile({ sessionId: this.sessionId, file: (this.importerFile.length != undefined && this.importerFile.length > 0) ? this.importerFile[0] : this.importerFile}) this.updateImporterFile({ sessionId: this.sessionId, file: (this.importerFile && this.importerFile.length != undefined && this.importerFile.length > 0) ? this.importerFile[0] : this.importerFile})
.then(updatedImporter => { .then(updatedImporter => {
this.importer = updatedImporter; this.importer = updatedImporter;
resolve(); resolve();
@ -436,13 +458,9 @@ export default {
@import "../../scss/_variables.scss"; @import "../../scss/_variables.scss";
.columns.is-gapless { /deep/ .columns {
padding-left: var(--tainacan-one-column); padding-left: var(--tainacan-one-column);
padding-right: var(--tainacan-one-column); padding-right: var(--tainacan-one-column);
.column:not(:first-child) {
margin-left: var(--tainacan-one-column);
}
} }
.field { .field {
@ -474,7 +492,7 @@ export default {
display: inline; display: inline;
} }
.drop-inner{ .drop-inner{
padding: 1em 3em; padding: 0.25em 0.5em;
} }
.mapping-header-label { .mapping-header-label {
@ -498,13 +516,16 @@ export default {
.selected-source-file { .selected-source-file {
border: 1px solid var(--tainacan-gray2); border: 1px solid var(--tainacan-gray2);
padding: 2px 10px; padding: calc(0.375em - 1px) 10px !important;
font-size: .75em; font-size: .875em;
line-height: 1.5em;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
} }
hr {
margin: 0.5rem 0 1.5rem 0;
}
</style> </style>

View File

@ -25,32 +25,45 @@
</nav> </nav>
</div> </div>
<b-loading
:active.sync="isLoading"
:can-cancel="false"/>
<form <form
class="tainacan-form" class="tainacan-form"
label-width="120px" label-width="120px"
v-if="importer != undefined && importer != null"> v-if="importer != undefined && importer != null">
<p>{{ $i18n.get('info_metadata_mapping_helper') }}</p>
<br>
<b-loading
:is-full-page="false"
:active.sync="isLoadingSourceInfo"
:can-cancel="false"/>
<!-- Metadata Mapping --> <!-- Metadata Mapping -->
<b-field
v-if="importer.manual_mapping"
:addons="false"
:label="$i18n.get('label_metadata_mapping')">
<help-button
:title="$i18n.get('label_metadata_mapping')"
:message="$i18n.get('info_metadata_mapping_helper')"/>
<div <div
v-if="importerSourceInfo != undefined && v-if="importerSourceInfo != undefined &&
importerSourceInfo != null && importerSourceInfo != null &&
!isLoading"> !isLoading">
<template v-if="importerSourceInfo.source_metadata.length > 0 || (importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0)"> <div
<p class="mapping-header-label is-pulled-left">{{ $i18n.get('label_from_source_collection') }}</p> class="mapping-header"
<p class="mapping-header-label is-pulled-right">{{ $i18n.get('label_to_target_collection') }}</p> v-if="importerSourceInfo.source_metadata.length > 0 || (importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0)">
</template> <p>{{ $i18n.get('label_from_source_collection') }}</p>
<hr>
<span class="icon">
<i class="tainacan-icon tainacan-icon-pointer" />
</span>
<hr>
<p>{{ $i18n.get('label_to_target_collection') }}</p>
</div>
<div <div
class="source-metadatum" class="source-metadatum"
v-for="(sourceMetadatum, index) of importerSourceInfo.source_metadata" v-for="(sourceMetadatum, index) of importerSourceInfo.source_metadata"
:key="index"> :key="index">
<template v-if="typeof sourceMetadatum == 'string'">
<p>{{ sourceMetadatum }}</p> <p>{{ sourceMetadatum }}</p>
<b-select <b-select
v-if="collectionMetadata != undefined && v-if="collectionMetadata != undefined &&
@ -59,7 +72,7 @@
:value="checkCurrentSelectedCollectionMetadatum(sourceMetadatum)" :value="checkCurrentSelectedCollectionMetadatum(sourceMetadatum)"
@input="onSelectCollectionMetadata($event, sourceMetadatum)" @input="onSelectCollectionMetadata($event, sourceMetadatum)"
:placeholder="$i18n.get('label_select_metadatum')"> :placeholder="$i18n.get('label_select_metadatum')">
<option :value="undefined"> <option :value="null">
{{ $i18n.get('label_select_metadatum') }} {{ $i18n.get('label_select_metadatum') }}
</option> </option>
<option <option
@ -71,6 +84,7 @@
v-for="(collectionMetadatum, metadatumIndex) of collectionMetadata" v-for="(collectionMetadatum, metadatumIndex) of collectionMetadata"
:key="metadatumIndex" :key="metadatumIndex"
:value="collectionMetadatum.id" :value="collectionMetadatum.id"
v-if="!checkIfMetadatumIsChild(collectionMetadatum)"
:disabled="checkIfMetadatumIsAvailable(collectionMetadatum.id)"> :disabled="checkIfMetadatumIsAvailable(collectionMetadatum.id)">
<span class="metadatum-name"> <span class="metadatum-name">
{{ collectionMetadatum.name }} {{ collectionMetadatum.name }}
@ -80,6 +94,73 @@
</span> </span>
</option> </option>
</b-select> </b-select>
</template>
<template v-else-if="typeof sourceMetadatum == 'object' && Object.entries(sourceMetadatum)[0]">
<p>{{ Object.entries(sourceMetadatum)[0][0] }}</p>
<b-select
v-if="collectionMetadata != undefined &&
collectionMetadata.length > 0 &&
!isFetchingCollectionMetadata"
:value="checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true)"
@input="onSelectCollectionMetadata($event, Object.entries(sourceMetadatum)[0][0], true, Object.entries(sourceMetadatum)[0][1])"
:placeholder="$i18n.get('label_select_metadatum')">
<option :value="null">
{{ $i18n.get('label_select_metadatum') }}
</option>
<option
v-if="collection && collection.current_user_can_edit_metadata"
:value="'create_metadata' + index">
{{ $i18n.get('label_create_metadatum') }}
</option>
<option
v-for="(collectionMetadatum, metadatumIndex) of collectionMetadata"
:key="metadatumIndex"
:value="collectionMetadatum.id"
v-if="!checkIfMetadatumIsChild(collectionMetadatum)"
:disabled="!checkIfMetadatumIsCompound(collectionMetadatum) || checkIfMetadatumIsAvailable(collectionMetadatum.id)">
<span class="metadatum-name">
{{ collectionMetadatum.name }}
</span>
<span class="label-details">
({{ collectionMetadatum.metadata_type_object.name }}) <em>{{ (collectionMetadatum.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em>
</span>
</option>
</b-select>
<div
:class="{ 'disabled-child-source-metadatum': [undefined, null, false, 'create_metadata' + index].includes(checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true)) }"
class="child-source-metadatum">
<div
class="source-metadatum"
v-for="(childSourceMetadatum, childIndex) of Object.entries(sourceMetadatum)[0][1]"
:key="childIndex">
<p>{{ childSourceMetadatum }}</p>
<b-select
v-if="collectionMetadata != undefined &&
collectionMetadata.length > 0 &&
!isFetchingCollectionMetadata"
:disabled="[undefined, null, false, 'create_metadata' + index].includes(checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true))"
:value="checkCurrentSelectedCollectionChildMetadatum(childSourceMetadatum, checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true))"
@input="onSelectCollectionChildMetadata($event, childSourceMetadatum, checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true), Object.entries(sourceMetadatum)[0][0])"
:placeholder="$i18n.get('label_select_metadatum')">
<option :value="null">
{{ $i18n.get('label_select_metadatum') }}
</option>
<option
v-for="(collectionMetadatum, metadatumIndex) of getChildOfSelectedCompoundMetadata(sourceMetadatum)"
:key="metadatumIndex"
:value="collectionMetadatum.id"
:disabled="checkIfChildMetadatumIsAvailable(collectionMetadatum.id, checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true), Object.entries(sourceMetadatum)[0][0])">
<span class="metadatum-name">
{{ collectionMetadatum.name }}
</span>
<span class="label-details">
({{ collectionMetadatum.metadata_type_object.name }}) <em>{{ (collectionMetadatum.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em>
</span>
</option>
</b-select>
</div>
</div>
</template>
<p v-if="collectionMetadata == undefined || collectionMetadata.length <= 0">{{ $i18n.get('info_select_collection_to_list_metadata') }}</p> <p v-if="collectionMetadata == undefined || collectionMetadata.length <= 0">{{ $i18n.get('info_select_collection_to_list_metadata') }}</p>
</div> </div>
<div <div
@ -174,7 +255,6 @@
importerSourceInfo == null"> importerSourceInfo == null">
<p>{{ $i18n.get('info_upload_a_source_to_see_metadata') }}</p> <p>{{ $i18n.get('info_upload_a_source_to_see_metadata') }}</p>
</div> </div>
</b-field>
<!-- Form submit -------------------------------- --> <!-- Form submit -------------------------------- -->
<div class="field is-grouped form-submit"> <div class="field is-grouped form-submit">
@ -277,10 +357,6 @@
</div> </div>
</form> </form>
</b-modal> </b-modal>
<b-loading
:active.sync="isLoading"
:can-cancel="false"/>
</div> </div>
</template> </template>
@ -298,6 +374,7 @@ export default {
importerId: Number, importerId: Number,
importer: null, importer: null,
isLoading: false, isLoading: false,
isLoadingSourceInfo: false,
isLoadingRun: false, isLoadingRun: false,
mappedCollection: { mappedCollection: {
'id': Number, 'id': Number,
@ -396,15 +473,18 @@ export default {
this.importer = JSON.parse(JSON.stringify(res)); this.importer = JSON.parse(JSON.stringify(res));
this.isLoading = false; this.isLoading = false;
this.isLoadingSourceInfo = true;
this.fetchImporterSourceInfo(this.sessionId) this.fetchImporterSourceInfo(this.sessionId)
.then(importerSourceInfo => { .then(importerSourceInfo => {
this.importerSourceInfo = importerSourceInfo; this.importerSourceInfo = importerSourceInfo;
this.mappedCollection['total_items'] = this.importerSourceInfo.source_total_items; this.mappedCollection['total_items'] = this.importerSourceInfo.source_total_items;
this.isLoadingSourceInfo = false;
this.loadMetadata(); this.loadMetadata();
}) })
.catch((errors) => { .catch((errors) => {
this.isLoadingSourceInfo = false;
this.$console.log(errors); this.$console.log(errors);
}); });
@ -422,11 +502,13 @@ export default {
this.fetchMetadata({ this.fetchMetadata({
collectionId: this.collectionId, collectionId: this.collectionId,
isRepositoryLevel: false, isRepositoryLevel: false,
isContextEdit: false isContextEdit: false,
parent: 'any'
}).then((resp) => { }).then((resp) => {
resp.request resp.request
.then((metadata) => { .then((metadata) => {
this.collectionMetadata = JSON.parse(JSON.stringify(metadata)); this.collectionMetadata = JSON.parse(JSON.stringify(metadata));
this.isFetchingCollectionMetadata = false; this.isFetchingCollectionMetadata = false;
this.fetchMappingImporter({ collection: this.collectionId, sessionId: this.sessionId }) this.fetchMappingImporter({ collection: this.collectionId, sessionId: this.sessionId })
@ -461,13 +543,46 @@ export default {
return false; return false;
}, },
checkCurrentSelectedCollectionMetadatum(sourceMetadatum) { checkIfChildMetadatumIsAvailable(metadatumId, parentId, parentSource) {
if (this.mappedCollection['mapping'][parentId] &&
this.mappedCollection['mapping'][parentId][parentSource] &&
this.mappedCollection['mapping'][parentId][parentSource][metadatumId] &&
this.importerSourceInfo != undefined &&
this.importerSourceInfo != null)
return true;
else
return false;
},
checkIfMetadatumIsCompound(metadatum) {
return metadatum.metadata_type_object && metadatum.metadata_type_object.component && metadatum.metadata_type_object.component == 'tainacan-compound';
},
checkCurrentSelectedCollectionMetadatum(sourceMetadatum, isCompound) {
for (let key in this.mappedCollection['mapping']) { for (let key in this.mappedCollection['mapping']) {
if (this.mappedCollection['mapping'][key] == sourceMetadatum) if (this.mappedCollection['mapping'][key] == sourceMetadatum)
return key; return key;
if (isCompound && Object.keys(this.mappedCollection['mapping'][key]) && Object.keys(this.mappedCollection['mapping'][key])[0] && Object.keys(this.mappedCollection['mapping'][key])[0] == sourceMetadatum)
return key;
} }
return undefined; return undefined;
}, },
checkCurrentSelectedCollectionChildMetadatum(sourceMetadatum, parent) {
if (this.mappedCollection['mapping'][parent] && Object.values(this.mappedCollection['mapping'][parent]) && Object.values(this.mappedCollection['mapping'][parent])[0]) {
let parentMappings = Object.values(this.mappedCollection['mapping'][parent])[0]
for (let key in parentMappings) {
if (parentMappings[key] == sourceMetadatum)
return key;
}
return undefined;
}
return undefined;
},
checkIfMetadatumIsChild(metadatum) {
return metadatum.parent && metadatum.parent > 0;
},
getChildOfSelectedCompoundMetadata(sourceMetadatum) {
return this.collectionMetadata.filter((metadatum) => metadatum.parent == this.checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true));
},
onRunImporter(skipTitleCheck) { onRunImporter(skipTitleCheck) {
if (skipTitleCheck !== true) { if (skipTitleCheck !== true) {
@ -506,18 +621,49 @@ export default {
this.$console.log(errors); this.$console.log(errors);
}); });
}, },
onSelectCollectionMetadata(selectedMetadatum, sourceMetadatum) { onSelectCollectionChildMetadata(selectedMetadatum, sourceMetadatum, parentId, parentSource) {
if (this.mappedCollection['mapping'][parentId] && this.mappedCollection['mapping'][parentId] && this.mappedCollection['mapping'][parentId][parentSource]) {
let parentMappings = Array.isArray(this.mappedCollection['mapping'][parentId][parentSource]) ? {} : this.mappedCollection['mapping'][parentId][parentSource];
let removedKey = '';
for (let key in parentMappings) {
if (parentMappings[key] == sourceMetadatum)
removedKey = key;
}
if (removedKey != '')
delete parentMappings[removedKey];
if (selectedMetadatum)
parentMappings[selectedMetadatum] = sourceMetadatum;
this.mappedCollection['mapping'][parentId][parentSource] = parentMappings;
// Necessary for causing reactivity to re-check if metadata remains available
this.collectionMetadata.push("");
this.collectionMetadata.pop();
}
},
onSelectCollectionMetadata(selectedMetadatum, sourceMetadatum, isCompound, childSourceMetadata) {
let removedKey = ''; let removedKey = '';
for (let key in this.mappedCollection['mapping']) { for (let key in this.mappedCollection['mapping']) {
if (this.mappedCollection['mapping'][key] == sourceMetadatum) if (this.mappedCollection['mapping'][key] == sourceMetadatum)
removedKey = key; removedKey = key;
if (isCompound && Object.keys(this.mappedCollection['mapping'][key]) && Object.keys(this.mappedCollection['mapping'][key])[0] && Object.keys(this.mappedCollection['mapping'][key])[0] == sourceMetadatum)
removedKey = key;
} }
if (removedKey != '') if (removedKey != '')
delete this.mappedCollection['mapping'][removedKey]; delete this.mappedCollection['mapping'][removedKey];
this.mappedCollection['mapping'][selectedMetadatum] = sourceMetadatum; let mappingValue = '';
if (isCompound) {
mappingValue = {}
mappingValue[sourceMetadatum] = childSourceMetadata;
} else {
mappingValue = sourceMetadatum;
}
this.mappedCollection['mapping'][selectedMetadatum] = mappingValue;
// Necessary for causing reactivity to re-check if metadata remains available // Necessary for causing reactivity to re-check if metadata remains available
this.collectionMetadata.push(""); this.collectionMetadata.push("");
@ -571,7 +717,8 @@ export default {
this.fetchMetadata({ this.fetchMetadata({
collectionId: this.collectionId, collectionId: this.collectionId,
isRepositoryLevel: false, isRepositoryLevel: false,
isContextEdit: false isContextEdit: false,
parent: 'any'
}).then((resp) => { }).then((resp) => {
resp.request resp.request
.then((metadata) => { .then((metadata) => {
@ -679,7 +826,7 @@ export default {
} }
.source-metadatum { .source-metadatum {
padding: 2px 0; padding: 2px 0 2px 8px;
min-height: 35px; min-height: 35px;
border-bottom: 1px solid var(--tainacan-gray2); border-bottom: 1px solid var(--tainacan-gray2);
width: 100%; width: 100%;
@ -687,6 +834,40 @@ export default {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex-wrap: wrap;
&>p {
font-weight: normal;
transition: font-weight 0.1s ease;
}
&:hover {
&>p {
font-weight: bold;
}
}
}
.child-source-metadatum {
flex-basis: 100%;
border-left: 1px solid var(--tainacan-gray2);
padding-left: 1em;
opacity: 1;
transition: border-left 0.2s ease, opacity 0.2s ease;
.source-metadatum {
border-bottom: none;
margin-bottom: 0;
margin-top: 2px;
padding-top: 8px;
padding-bottom: 0px;
border-top: 1px solid var(--tainacan-gray2);
}
&.disabled-child-source-metadatum {
border-left: 1px solid var(--tainacan-gray1);
opacity: 0.70;
}
} }
.is-inline .control{ .is-inline .control{
@ -696,9 +877,33 @@ export default {
padding: 1em 3em; padding: 1em 3em;
} }
.mapping-header-label { .mapping-header {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--tainacan-info-color); color: var(--tainacan-info-color);
margin: 12px 0 6px 0; font-size: 0.875em;
font-weight: bold;
margin: 18px 0 6px 0;
p {
white-space: nowrap;
}
hr {
width: 100%;
margin-left: 12px;
margin-right: 12px;
height: 1px;
}
@media screen and (max-width: 768px) {
p {
white-space: normal;
}
hr {
display: none;
}
}
} }
.modal .animation-content { .modal .animation-content {

View File

@ -586,7 +586,7 @@
} }
} }
.actions-cell { .actions-cell {
width: 46px; width: 52px;
} }
.actions-container { .actions-container {
align-items: center; align-items: center;

View File

@ -257,6 +257,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_text' => __( 'Text', 'tainacan' ), 'label_text' => __( 'Text', 'tainacan' ),
'label_url' => __( 'URL', 'tainacan' ), 'label_url' => __( 'URL', 'tainacan' ),
'label_select_file' => __( 'Select File', 'tainacan' ), 'label_select_file' => __( 'Select File', 'tainacan' ),
'label_selected_file' => __( 'Selected file', 'tainacan' ),
'label_expand_all' => __( 'Expand all', 'tainacan' ), 'label_expand_all' => __( 'Expand all', 'tainacan' ),
'label_collapse_all' => __( 'Collapse all', 'tainacan' ), 'label_collapse_all' => __( 'Collapse all', 'tainacan' ),
'label_view_term' => __( 'View Term', 'tainacan' ), 'label_view_term' => __( 'View Term', 'tainacan' ),
@ -306,7 +307,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_create_metadatum' => __( 'Create metadatum', 'tainacan' ), 'label_create_metadatum' => __( 'Create metadatum', 'tainacan' ),
'label_select_metadatum_type' => __( 'Select a metadatum type', 'tainacan' ), 'label_select_metadatum_type' => __( 'Select a metadatum type', 'tainacan' ),
'label_add_more_metadata' => __( 'Add more metadata', 'tainacan' ), 'label_add_more_metadata' => __( 'Add more metadata', 'tainacan' ),
'label_from_source_collection' => __( 'From source collection', 'tainacan' ), 'label_from_source_collection' => __( 'From source file', 'tainacan' ),
'label_to_target_collection' => __( 'To target collection', 'tainacan' ), 'label_to_target_collection' => __( 'To target collection', 'tainacan' ),
'label_add_value' => __( 'Add value', 'tainacan' ), 'label_add_value' => __( 'Add value', 'tainacan' ),
'label_remove_value' => __( 'Remove value', 'tainacan' ), 'label_remove_value' => __( 'Remove value', 'tainacan' ),