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

@ -51,7 +51,13 @@ class CSV extends Importer {
$this->set_option('item_comment_status_index', $index); $this->set_option('item_comment_status_index', $index);
} }
} else { } else {
$columns[] = $rawColumn; 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 {
$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,9 +172,9 @@ 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;
} }
} }
if(is_null($column)) if(is_null($column))
@ -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);
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ? if( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Compound' ) {
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert; $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() ) ?
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,154 +283,167 @@ class CSV extends Importer {
public function options_form() { public function options_form() {
ob_start(); ob_start();
?> ?>
<div class="field"> <div class="columns is-multiline">
<label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label> <div class="column">
<span class="help-wrapper"> <div class="field">
<a class="help-button has-text-secondary"> <label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label>
<span class="icon is-small"> <span class="help-wrapper">
<i class="tainacan-icon tainacan-icon-help" ></i> <a class="help-button has-text-secondary">
</span> <span class="icon is-small">
</a> <i class="tainacan-icon tainacan-icon-help" ></i>
<div class="help-tooltip"> </span>
<div class="help-tooltip-header"> </a>
<h5><?php _e('CSV Delimiter', 'tainacan'); ?></h5> <div class="help-tooltip">
</div> <div class="help-tooltip-header">
<div class="help-tooltip-body"> <h5><?php _e('CSV Delimiter', 'tainacan'); ?></h5>
<p><?php _e('The character used to separate each column in your CSV (e.g. , or ;)', 'tainacan'); ?></p> </div>
</div> <div class="help-tooltip-body">
</div> <p><?php _e('The character used to separate each column in your CSV (e.g. , or ;)', 'tainacan'); ?></p>
</span> </div>
<div class="control is-clearfix">
<input class="input" type="text" name="delimiter" value="<?php echo esc_attr($this->get_option('delimiter')); ?>">
</div>
</div>
<div class="field">
<label class="label"><?php _e('Multivalued metadata delimiter', '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('Multivalued metadata delimiter', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character used to separate each value inside a cell with multiple values (e.g. ||). Note that the target metadatum must accept multiple values.', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="multivalued_delimiter" value="<?php echo $this->get_option('multivalued_delimiter'); ?>">
</div>
</div>
<div class="field">
<label class="label"><?php _e('Enclosure', '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('Enclosure', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character that wraps the content of each cell in your CSV. (e.g. ")', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="enclosure" value="<?php echo $this->get_option('enclosure'); ?>">
</div>
</div>
<div class="field is-grouped">
<div class="field is-expanded">
<label class="label"><?php _e('File Encoding', '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('File Encoding', 'tainacan'); ?></h5>
</div> </div>
<div class="help-tooltip-body"> </span>
<p><?php _e('The encoding of the CSV file.', 'tainacan'); ?></p> <div class="control is-clearfix">
<input class="input" type="text" name="delimiter" value="<?php echo esc_attr($this->get_option('delimiter')); ?>">
</div>
</div>
</div>
<div class="column">
<div class="field">
<label class="label"><?php _e('Multivalued metadata delimiter', '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('Multivalued metadata delimiter', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character used to separate each value inside a cell with multiple values (e.g. ||). Note that the target metadatum must accept multiple values.', 'tainacan'); ?></p>
</div>
</div> </div>
</div> </span>
</span> <div class="control is-clearfix">
<div class="control is-clearfix"> <input class="input" type="text" name="multivalued_delimiter" value="<?php echo $this->get_option('multivalued_delimiter'); ?>">
<div class="select"> </div>
<select name="encode"> </div>
<option value="utf8" <?php selected($this->get_option('encode'), 'utf8'); ?> >UTF-8</option> </div>
<option value="iso88591" <?php selected($this->get_option('encode'), 'iso88591'); ?> >ISO-88591</option> <div class="column">
</select> <div class="field">
<label class="label"><?php _e('Enclosure', '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('Enclosure', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character that wraps the content of each cell in your CSV. (e.g. ")', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="enclosure" value="<?php echo $this->get_option('enclosure'); ?>">
</div> </div>
</div> </div>
</div> </div>
<div class="field is-expanded"> <div class="column">
<label class="label"><?php _e('Repeated Item', 'tainacan'); ?></label> <div class="field is-expanded">
<span class="help-wrapper"> <label class="label"><?php _e('File Encoding', 'tainacan'); ?></label>
<a class="help-button has-text-secondary"> <span class="help-wrapper">
<span class="icon is-small"> <a class="help-button has-text-secondary">
<i class="tainacan-icon tainacan-icon-help" ></i> <span class="icon is-small">
</span> <i class="tainacan-icon tainacan-icon-help" ></i>
</a> </span>
<div class="help-tooltip"> </a>
<div class="help-tooltip-header"> <div class="help-tooltip">
<h5><?php _e('Repeated Item', 'tainacan'); ?></h5> <div class="help-tooltip-header">
</div> <h5><?php _e('File Encoding', 'tainacan'); ?></h5>
<div class="help-tooltip-body"> </div>
<p><?php _e('Choose the action when a repeated item is found', 'tainacan'); ?></p> <div class="help-tooltip-body">
<p><?php _e('The encoding of the CSV file.', 'tainacan'); ?></p>
</div>
</div> </div>
</span>
<div class="control is-clearfix">
<div class="select is-fullwidth">
<select name="encode">
<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>
</select>
</div> </div>
</span>
<div class="control is-clearfix">
<div class="select">
<select name="repeated_item">
<option value="update" <?php selected($this->get_option('repeated_item'), 'update'); ?> >Update</option>
<option value="ignore" <?php selected($this->get_option('repeated_item'), 'ignore'); ?> >Ignore</option>
</select>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="field"> <div class="columns">
<label class="label"><?php _e('Importing attachments', 'tainacan'); ?></label>
<p> <div class="column">
<?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')); ?> <div class="field is-expanded">
</p> <label class="label"><?php _e('Repeated Item', 'tainacan'); ?></label>
<br> <span class="help-wrapper">
<label class="label"><?php _e('Server path', 'tainacan'); ?></label> <a class="help-button has-text-secondary">
<span class="help-wrapper"> <span class="icon is-small">
<a class="help-button has-text-secondary"> <i class="tainacan-icon tainacan-icon-help" ></i>
<span class="icon is-small"> </span>
<i class="tainacan-icon tainacan-icon-help" ></i> </a>
</span> <div class="help-tooltip">
</a> <div class="help-tooltip-header">
<div class="help-tooltip"> <h5><?php _e('Repeated Item', 'tainacan'); ?></h5>
<div class="help-tooltip-header"> </div>
<h5><?php _e('Server path', 'tainacan'); ?></h5> <div class="help-tooltip-body">
</div> <p><?php _e('Choose the action when a repeated item is found', 'tainacan'); ?></p>
<div class="help-tooltip-body"> </div>
<p><?php _e("When using CSV special field to add documents or attachments that you've uploaded to the server, inform the full path to the folder here (e.g. /home/user/files/)", 'tainacan'); ?></p> </div>
</div> </span>
</div> <div class="control is-clearfix">
</span> <div class="select is-fullwidth">
<div class="control is-clearfix"> <select name="repeated_item">
<input class="input" type="text" name="server_path" value="<?php echo $this->get_option('server_path'); ?>"> <option value="update" <?php selected($this->get_option('repeated_item'), 'update'); ?> ><?php _e('Update', 'tainacan'); ?></option>
</div> <option value="ignore" <?php selected($this->get_option('repeated_item'), 'ignore'); ?> ><?php _e('Ignore', 'tainacan'); ?></option>
</div> </select>
</div>
</div>
</div>
</div>
<div class="column is-three-quarters">
<div class="field is-expanded">
<label class="label"><?php _e('Server path', '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('Server path', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e("When using CSV special field to add documents or attachments that you've uploaded to the server, inform the full path to the folder here (e.g. /home/user/files/)", 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="server_path" value="<?php echo $this->get_option('server_path'); ?>">
</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>
<?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,13 +769,33 @@ class CSV extends Importer {
} }
foreach ( $itemMetadataArray as $itemMetadata ) { foreach ( $itemMetadataArray as $itemMetadata ) {
$itemMetadata->set_item( $insertedItem ); // *I told you if($itemMetadata instanceof Entities\Item_Metadata_Entity ) {
if( $itemMetadata->validate() ) { $itemMetadata->set_item( $insertedItem ); // *I told you
$result = $Tainacan_Item_Metadata->insert( $itemMetadata ); if( $itemMetadata->validate() ) {
} else { $result = $Tainacan_Item_Metadata->insert( $itemMetadata );
$this->add_error_log('Error saving value for ' . $itemMetadata->get_metadatum()->get_name() . " in item " . $insertedItem->get_title()); } else {
$this->add_error_log($itemMetadata->get_errors()); $this->add_error_log('Error saving value for ' . $itemMetadata->get_metadatum()->get_name() . " in item " . $insertedItem->get_title());
continue; $this->add_error_log($itemMetadata->get_errors());
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 ){
@ -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,44 +548,49 @@ class Flickr_Importer extends Importer {
public function options_form(){ public function options_form(){
ob_start(); ob_start();
?> ?>
<div class="field"> <div class="columns">
<label class="label"><?php _e('API ID', 'tainacan'); ?></label> <div class="column">
<p> <div class="field">
<?php printf( <label class="label"><?php _e('API ID', 'tainacan'); ?></label>
# translators %s are for opening and closing the link <p>
__('In order to import photos from Flickr you need to %sapply for a Flickr API Key%s.', 'tainacan'), <?php printf(
# translator you may get the link to the console in the current language. e.g. https://console.developers.google.com/?hl=pt-br # translators %s are for opening and closing the link
sprintf('<a target="_blank" href="%s">', __('https://www.flickr.com/services/api/misc.api_keys.html', 'tainacan') ), __('In order to import photos from Flickr you need to %sapply for a Flickr API Key%s.', 'tainacan'),
'</a>' # translator you may get the link to the console in the current language. e.g. https://console.developers.google.com/?hl=pt-br
); ?> sprintf('<a target="_blank" href="%s">', __('https://www.flickr.com/services/api/misc.api_keys.html', 'tainacan') ),
</p> '</a>'
<br/> ); ?>
<p> </p>
<?php _e('Get your API Key and paste it below:', 'tainacan'); ?> <br/>
</p> <p>
<div class="control is-clearfix"> <?php _e('Get your API Key and paste it below:', 'tainacan'); ?>
<input class="input" type="text" name="api_id" value=""> </p>
<div class="control is-clearfix">
<input class="input" type="text" name="api_id" value="">
</div>
</div>
</div>
<div class="column">
<div class="field">
<label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label>
<p>
<?php _e('The following URL types are supported:', 'tainacan'); ?>
<br/><br/>
<?php _e('User profile', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.flickr.com/photos/username</code>
<br/>
<?php _e('Albums', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.flickr.com/photos/username/albums/123456</code>
<br/>
<?php _e('Photos', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.flickr.com/photos/username/123456</code>
</p>
</div>
</div> </div>
</div> </div>
<label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label>
<p>
<?php _e('The following URL types are supported:', 'tainacan'); ?>
<br/><br/>
<?php _e('User profile', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.flickr.com/photos/username
<br/>
<?php _e('Albums', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.flickr.com/photos/username/albums/123456
<br/>
<?php _e('Photos', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.flickr.com/photos/username/123456
</p>
<?php <?php
return ob_get_clean(); return ob_get_clean();

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,12 +1022,16 @@ 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 );
$this->add_log('Metadata created: ' . $inserted_metadata->get_name()); $this->add_log('Metadata created: ' . $inserted_metadata->get_name());
return $inserted_metadata; return $inserted_metadata;
} else{ } else {
$this->add_log('Error creating metadata ' . $name . ' in collection ' . $collection_id); $this->add_log('Error creating metadata ' . $name . ' in collection ' . $collection_id);
$this->add_log($newMetadatum->get_errors()); $this->add_log($newMetadatum->get_errors());

View File

@ -839,29 +839,33 @@ class Oaipmh_Importer extends Importer {
public function options_form(){ public function options_form(){
ob_start(); ob_start();
?> ?>
<div class="field"> <div class="columns">
<label class="label"><?php _e('Create set as', 'tainacan'); ?></label> <div class="column">
<span class="help-wrapper"> <div class="field">
<a class="help-button has-text-secondary"> <label class="label"><?php _e('Create set as', 'tainacan'); ?></label>
<span class="icon is-small"> <span class="help-wrapper">
<i class="tainacan-icon tainacan-icon-help" ></i> <a class="help-button has-text-secondary">
</span> <span class="icon is-small">
</a> <i class="tainacan-icon tainacan-icon-help" ></i>
<vdiv class="help-tooltip"> </span>
<div class="help-tooltip-header"> </a>
<h5><?php _e('Create set as', 'tainacan'); ?></h5> <vdiv class="help-tooltip">
</div> <div class="help-tooltip-header">
<div class="help-tooltip-body"> <h5><?php _e('Create set as', 'tainacan'); ?></h5>
<p><?php _e('Choose the action to manipulate sets', 'tainacan'); ?></p> </div>
</div> <div class="help-tooltip-body">
</vdiv> <p><?php _e('Choose the action to manipulate sets', 'tainacan'); ?></p>
</span> </div>
<div class="control is-clearfix"> </vdiv>
<div class="select"> </span>
<select name="using_set"> <div class="control is-clearfix">
<option value="collection" <?php selected($this->get_option('using_set'), 'collection'); ?> ><?php _e('Collections', 'tainacan'); ?></option> <div class="select">
<option value="taxonomy" <?php selected($this->get_option('using_set'), 'taxonomy'); ?> ><?php _e('Taxonomies', 'tainacan'); ?></option> <select name="using_set">
</select> <option value="collection" <?php selected($this->get_option('using_set'), 'collection'); ?> ><?php _e('Collections', 'tainacan'); ?></option>
<option value="taxonomy" <?php selected($this->get_option('using_set'), 'taxonomy'); ?> ><?php _e('Taxonomies', 'tainacan'); ?></option>
</select>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -104,198 +104,219 @@ class Test_Importer extends Importer {
public function options_form() { public function options_form() {
ob_start(); ob_start();
?> ?>
<div class="columns is-multiline">
<div class="field"> <div class="column is-half">
<label class="label"><?php _e('Number of items in collection 1', 'tainacan'); ?></label> <div class="field">
<span class="help-wrapper"> <label class="label"><?php _e('Number of items in collection 1', 'tainacan'); ?></label>
<a class="help-button has-text-secondary"> <span class="help-wrapper">
<span class="icon is-small"> <a class="help-button has-text-secondary">
<i class="tainacan-icon tainacan-icon-help" ></i> <span class="icon is-small">
</span> <i class="tainacan-icon tainacan-icon-help" ></i>
</a> </span>
<div class="help-tooltip"> </a>
<div class="help-tooltip-header"> <div class="help-tooltip">
<h5><?php _e('Number of items in collection 1', 'tainacan'); ?></h5> <div class="help-tooltip-header">
</div> <h5><?php _e('Number of items in collection 1', 'tainacan'); ?></h5>
<div class="help-tooltip-body"> </div>
<p><?php _e('The total of items to created in first collection (e.g. 20)', 'tainacan'); ?></p> <div class="help-tooltip-body">
</div> <p><?php _e('The total of items to created in first collection (e.g. 20)', 'tainacan'); ?></p>
</div> </div>
</span> </div>
<div class="control is-clearfix"> </span>
<input class="input" type="number" name="items_col_1" value="<?php echo $this->get_option('items_col_1'); ?>"> <div class="control is-clearfix">
<input class="input" type="number" name="items_col_1" value="<?php echo $this->get_option('items_col_1'); ?>">
</div>
</div>
</div>
<div class="column is-half">
<div class="field">
<label class="label"><?php _e('Number of extra metadata to create in first collection', '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('Number of extra metadata', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Create additional text metadata with random values in first collection', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="additonal_metadata" value="<?php echo $this->get_option('additonal_metadata'); ?>">
</div>
</div>
</div>
<div class="column is-half">
<div class="field">
<label class="label"><?php _e('Create second collection with a relationship', '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('Create second collection', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Create second collection with a relationship with the first collection created', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<label class="checkbox">
<input
type="checkbox"
name="second_collection"
<?php echo ( $this->get_option('second_collection') && $this->get_option('second_collection') === 'yes' ) ? 'checked' : '' ?>
value="yes">
<?php _e('Yes', 'tainacan'); ?>
</label>
</div>
</div>
</div>
<div class="column is-half">
<div class="field">
<label class="label"><?php _e('Number of items in collection 2', '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('Number of items in collection 2', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The total of items to created in second collection (e.g. 20)', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="items_col_2" value="<?php echo $this->get_option('items_col_2'); ?>">
</div>
</div>
</div> </div>
</div> </div>
<div class="field">
<label class="label"><?php _e('Number of extra metadata to create in first collection', '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('Number of extra metadata', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Create additional text metadata with random values in first collection', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="additonal_metadata" value="<?php echo $this->get_option('additonal_metadata'); ?>">
</div>
</div>
<div class="field">
<label class="label"><?php _e('Create second collection with a relationship', '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('Create second collection', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Create second collection with a relationship with the first collection created', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<label class="checkbox">
<input
type="checkbox"
name="second_collection"
<?php echo ( $this->get_option('second_collection') && $this->get_option('second_collection') === 'yes' ) ? 'checked' : '' ?>
value="yes">
<?php _e('Yes', 'tainacan'); ?>
</label>
</div>
</div>
<div class="field">
<label class="label"><?php _e('Number of items in collection 2', '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('Number of items in collection 2', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The total of items to created in second collection (e.g. 20)', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="items_col_2" value="<?php echo $this->get_option('items_col_2'); ?>">
</div>
</div>
<hr> <hr>
<h2><?php _e('Images', 'tainacan') ?></h2><br>
<div class="field"> <div class="columns is-multiline">
<label class="label"><?php _e('Add random images from flickr', '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('Add random images from flickr', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Add random images from flickr using [https://loremflickr.com/] in first collection', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<label class="checkbox">
<input
type="checkbox"
name="add_random_images"
<?php echo ( $this->get_option('add_random_images') && $this->get_option('add_random_images') === 'yes' ) ? 'checked' : '' ?>
value="yes">
<?php _e('Yes', 'tainacan'); ?>
</label>
</div>
</div>
<div class="field"> <div class="column is-12">
<label class="label"><?php _e('Horizontal image size (0 for random)', 'tainacan'); ?></label> <h2><?php _e('Images', 'tainacan') ?></h2>
<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('Horizontal image size', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Horizontal image size in pixels ( 0 for random size )', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="horizontal_image_size" value="<?php echo $this->get_option('horizontal_image_size'); ?>">
</div> </div>
</div>
<div class="field"> <div class="column">
<label class="label"><?php _e('Vertical image size (0 for random)', 'tainacan'); ?></label> <div class="field">
<span class="help-wrapper"> <label class="label"><?php _e('Add random images from flickr', 'tainacan'); ?></label>
<a class="help-button has-text-secondary"> <span class="help-wrapper">
<span class="icon is-small"> <a class="help-button has-text-secondary">
<i class="tainacan-icon tainacan-icon-help" ></i> <span class="icon is-small">
</span> <i class="tainacan-icon tainacan-icon-help" ></i>
</a> </span>
<div class="help-tooltip"> </a>
<div class="help-tooltip-header"> <div class="help-tooltip">
<h5><?php _e('Vertical image size', 'tainacan'); ?></h5> <div class="help-tooltip-header">
</div> <h5><?php _e('Add random images from flickr', 'tainacan'); ?></h5>
<div class="help-tooltip-body"> </div>
<p><?php _e('Vertical image size in pixels ( 0 for random size )', 'tainacan'); ?></p> <div class="help-tooltip-body">
</div> <p><?php _e('Add random images from flickr using [https://loremflickr.com/] in first collection', 'tainacan'); ?></p>
</div> </div>
</span> </div>
<div class="control is-clearfix"> </span>
<input class="input" type="number" name="vertical_image_size" value="<?php echo $this->get_option('vertical_image_size'); ?>"> <div class="control is-clearfix">
</div> <label class="checkbox">
</div> <input
type="checkbox"
name="add_random_images"
<?php echo ( $this->get_option('add_random_images') && $this->get_option('add_random_images') === 'yes' ) ? 'checked' : '' ?>
value="yes">
<?php _e('Yes', 'tainacan'); ?>
</label>
</div>
</div>
<div class="field"> <div class="field">
<label class="label"><?php _e('Keyword Search', 'tainacan'); ?></label> <label class="label"><?php _e('Keyword Search', 'tainacan'); ?></label>
<span class="help-wrapper"> <span class="help-wrapper">
<a class="help-button has-text-secondary"> <a class="help-button has-text-secondary">
<span class="icon is-small"> <span class="icon is-small">
<i class="tainacan-icon tainacan-icon-help" ></i> <i class="tainacan-icon tainacan-icon-help" ></i>
</span> </span>
</a> </a>
<div class="help-tooltip"> <div class="help-tooltip">
<div class="help-tooltip-header"> <div class="help-tooltip-header">
<h5><?php _e('Keyword Search', 'tainacan'); ?></h5> <h5><?php _e('Keyword Search', 'tainacan'); ?></h5>
</div> </div>
<div class="help-tooltip-body"> <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> <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>
</div> </div>
</span> </span>
<div class="control is-clearfix"> <div class="control is-clearfix">
<input class="input" type="text" name="keyword_images" value="<?php echo $this->get_option('keyword_images'); ?>"> <input class="input" type="text" name="keyword_images" value="<?php echo $this->get_option('keyword_images'); ?>">
</div>
</div>
</div> </div>
<div class="column">
<div class="field">
<label class="label"><?php _e('Horizontal image size (0 for random)', '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('Horizontal image size', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Horizontal image size in pixels ( 0 for random size )', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="horizontal_image_size" value="<?php echo $this->get_option('horizontal_image_size'); ?>">
</div>
</div>
<div class="field">
<label class="label"><?php _e('Vertical image size (0 for random)', '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('Vertical image size', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Vertical image size in pixels ( 0 for random size )', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<input class="input" type="number" name="vertical_image_size" value="<?php echo $this->get_option('vertical_image_size'); ?>">
</div>
</div>
</div>
</div> </div>
<?php <?php

View File

@ -378,47 +378,54 @@ class Youtube_Importer extends Importer {
public function options_form(){ public function options_form(){
ob_start(); ob_start();
?> ?>
<div class="field"> <div class="columns">
<label class="label"><?php _e('API Key', 'tainacan'); ?></label> <div class="column">
<div class="field">
<label class="label"><?php _e('API Key', 'tainacan'); ?></label>
<p>
<?php printf(
# translators %s are for opening and closing the link <p>
__('In order to import videos from Youtube you need to create a project and get an API Key from the %sGoogle Developers Console%s.', 'tainacan'), <?php printf(
# translator you may get the link to the console in the current language. e.g. https://console.developers.google.com/?hl=pt-br # translators %s are for opening and closing the link
sprintf('<a target="_blank" href="%s">', __('https://console.developers.google.com', 'tainacan') ), __('In order to import videos from Youtube you need to create a project and get an API Key from the %sGoogle Developers Console%s.', 'tainacan'),
'</a>' # translator you may get the link to the console in the current language. e.g. https://console.developers.google.com/?hl=pt-br
); ?> sprintf('<a target="_blank" href="%s">', __('https://console.developers.google.com', 'tainacan') ),
</p> '</a>'
<br/> ); ?>
<p> </p>
<?php _e('Get your API Key and paste it below:', 'tainacan'); ?> <br/>
</p> <p>
<?php _e('Get your API Key and paste it below:', 'tainacan'); ?>
<div class="control is-clearfix"> </p>
<input class="input" type="text" name="api_id" value="<?php echo $this->get_option('api_id'); ?>">
<div class="control is-clearfix">
<input class="input" type="text" name="api_id" value="<?php echo $this->get_option('api_id'); ?>">
</div>
</div>
</div>
<div class="column">
<div class="field">
<label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label>
<p>
<?php _e('The following URL types are supported:', 'tainacan'); ?>
<br/><br/>
<?php _e('User profile', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/user/username</code>
<br/>
<?php _e('Playlists', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/playlist?123456</code>
<br/>
<?php _e('Channels', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/channel/123456</code>
<br/>
<?php _e('Videos', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> <code>https://www.youtube.com/watch?v=123456</code>
</p>
</div>
</div> </div>
</div> </div>
<label class="label"><?php _e('Supported URLs', 'tainacan'); ?></label>
<p>
<?php _e('The following URL types are supported:', 'tainacan'); ?>
<br/><br/>
<?php _e('User profile', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/user/username
<br/>
<?php _e('Playlists', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/playlist?123456
<br/>
<?php _e('Channels', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/channel/123456
<br/>
<?php _e('Videos', 'tainacan'); ?> -
<?php _e('Example: ', 'tainacan'); ?> https://www.youtube.com/watch?v=123456
</p>
<?php <?php

View File

@ -40,69 +40,74 @@ class Term_Importer extends Importer {
public function options_form() { public function options_form() {
ob_start(); ob_start();
?> ?>
<div class="field"> <div class="columns">
<label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label> <div class="column">
<span class="help-wrapper"> <div class="field">
<a class="help-button has-text-secondary"> <label class="label"><?php _e('CSV Delimiter', 'tainacan'); ?></label>
<span class="icon is-small"> <span class="help-wrapper">
<i class="tainacan-icon tainacan-icon-help" ></i> <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('CSV Delimiter', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character used to separate each column in your CSV (e.g. , or ;)', 'tainacan'); ?></p>
</div>
</div>
</span> </span>
</a> <div class="control is-clearfix">
<div class="help-tooltip"> <input class="input" type="text" name="delimiter" value="<?php echo $this->get_option('delimiter'); ?>">
<div class="help-tooltip-header">
<h5><?php _e('CSV Delimiter', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('The character used to separate each column in your CSV (e.g. , or ;)', 'tainacan'); ?></p>
</div> </div>
</div> </div>
</span>
<div class="control is-clearfix">
<input class="input" type="text" name="delimiter" value="<?php echo $this->get_option('delimiter'); ?>">
</div> </div>
</div>
<div class="field import_term_csv_taxonomies"> <div class="column">
<label class="label"><?php _e('Target taxonomy:', 'tainacan'); ?></label> <div class="field import_term_csv_taxonomies">
<span class="help-wrapper"> <label class="label"><?php _e('Target taxonomy:', 'tainacan'); ?></label>
<a class="help-button has-text-secondary"> <span class="help-wrapper">
<span class="icon is-small"> <a class="help-button has-text-secondary">
<i class="tainacan-icon tainacan-icon-help" ></i> <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('Existing Taxonomy', 'tainacan'); ?></h5>
</div>
<div class="help-tooltip-body">
<p><?php _e('Inform the taxonomy you want to import the terms to.', 'tainacan'); ?></p>
<p><?php _e('Select an existing taxonomy or create a new one on the fly.', 'tainacan'); ?></p>
</div>
</div>
</span> </span>
</a> <div class="control is-clearfix">
<div class="help-tooltip"> <div class="select is-fullwidth">
<div class="help-tooltip-header"> <select name="select_taxonomy" class="select_taxonomy">
<h5><?php _e('Existing Taxonomy', 'tainacan'); ?></h5> <option value="" selected><?php _e('Create a new taxonomy', 'tainacan'); ?></option>
</div>
<div class="help-tooltip-body">
<p><?php _e('Inform the taxonomy you want to import the terms to.', 'tainacan'); ?></p>
<p><?php _e('Select an existing taxonomy or create a new one on the fly.', 'tainacan'); ?></p>
</div>
</div>
</span>
<div class="control is-clearfix">
<div class="select">
<select name="select_taxonomy" class="select_taxonomy">
<option value="" selected><?php _e('Create a new taxonomy', 'tainacan'); ?></option>
<?php
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$taxonomies = $Tainacan_Taxonomies->fetch( ['nopaging' => true], 'OBJECT' );
foreach( $taxonomies as $taxonomie) {
?>
<option value="<?php echo $taxonomie->get_db_identifier();?>"><?php echo $taxonomie->get_name() ?> </option>
<?php <?php
} $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
?> $taxonomies = $Tainacan_Taxonomies->fetch( ['nopaging' => true], 'OBJECT' );
</select> foreach( $taxonomies as $taxonomie) {
?>
<option value="<?php echo $taxonomie->get_db_identifier();?>"><?php echo $taxonomie->get_name() ?> </option>
<?php
}
?>
</select>
</div>
<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>
<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>
<?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
<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
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>
<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>
<!-- 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 <div
v-if="importer.manual_mapping" v-if="importerSourceInfo != undefined &&
:addons="false" importerSourceInfo != null &&
:label="$i18n.get('label_metadata_mapping')"> !isLoading">
<help-button
:title="$i18n.get('label_metadata_mapping')"
:message="$i18n.get('info_metadata_mapping_helper')"/>
<div <div
v-if="importerSourceInfo != undefined && class="mapping-header"
importerSourceInfo != null && v-if="importerSourceInfo.source_metadata.length > 0 || (importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0)">
!isLoading"> <p>{{ $i18n.get('label_from_source_collection') }}</p>
<template v-if="importerSourceInfo.source_metadata.length > 0 || (importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0)"> <hr>
<p class="mapping-header-label is-pulled-left">{{ $i18n.get('label_from_source_collection') }}</p> <span class="icon">
<p class="mapping-header-label is-pulled-right">{{ $i18n.get('label_to_target_collection') }}</p> <i class="tainacan-icon tainacan-icon-pointer" />
</template> </span>
<div <hr>
class="source-metadatum" <p>{{ $i18n.get('label_to_target_collection') }}</p>
v-for="(sourceMetadatum, index) of importerSourceInfo.source_metadata" </div>
:key="index"> <div
class="source-metadatum"
v-for="(sourceMetadatum, index) of importerSourceInfo.source_metadata"
: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,101 +94,167 @@
</span> </span>
</option> </option>
</b-select> </b-select>
<p v-if="collectionMetadata == undefined || collectionMetadata.length <= 0">{{ $i18n.get('info_select_collection_to_list_metadata') }}</p> </template>
</div> <template v-else-if="typeof sourceMetadatum == 'object' && Object.entries(sourceMetadatum)[0]">
<div <p>{{ Object.entries(sourceMetadatum)[0][0] }}</p>
v-if="importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0" <b-select
class="source-metadatum" v-if="collectionMetadata != undefined &&
:key="specialFieldIndex" collectionMetadata.length > 0 &&
v-for="(specialField, specialFieldIndex) of importerSourceInfo.source_special_fields"> !isFetchingCollectionMetadata"
<p style="font-style: italic">{{ specialField }}</p> :value="checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true)"
<p>{{ $i18n.get('info_special_fields_mapped_default') }}</p> @input="onSelectCollectionMetadata($event, Object.entries(sourceMetadatum)[0][0], true, Object.entries(sourceMetadatum)[0][1])"
</div> :placeholder="$i18n.get('label_select_metadatum')">
<p v-if="importerSourceInfo.source_metadata.length <= 0">{{ $i18n.get('info_no_metadata_source_file') }}<br></p> <option :value="null">
<p v-if="(!importerSourceInfo.source_special_fields || importerSourceInfo.source_special_fields.length <= 0)">{{ $i18n.get('info_no_special_fields_available') }}<br></p> {{ $i18n.get('label_select_metadatum') }}
<b-modal </option>
@close="onMetadatumEditionCanceled()" <option
:active.sync="isNewMetadatumModalActive" v-if="collection && collection.current_user_can_edit_metadata"
trap-focus :value="'create_metadata' + index">
aria-modal {{ $i18n.get('label_create_metadatum') }}
aria-role="dialog"> </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 <div
autofocus="true" :class="{ 'disabled-child-source-metadatum': [undefined, null, false, 'create_metadata' + index].includes(checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true)) }"
tabindex="-1" class="child-source-metadatum">
role="dialog" <div
aria-modal> class="source-metadatum"
<b-loading v-for="(childSourceMetadatum, childIndex) of Object.entries(sourceMetadatum)[0][1]"
:is-full-page="isFullPage" :key="childIndex">
:active.sync="isLoadingMetadatumTypes"/> <p>{{ childSourceMetadatum }}</p>
<div <b-select
v-if="selectedMetadatumType == undefined && !isEditingMetadatum" v-if="collectionMetadata != undefined &&
class="tainacan-modal-content"> collectionMetadata.length > 0 &&
<div class="tainacan-modal-title"> !isFetchingCollectionMetadata"
<h2>{{ $i18n.get('instruction_select_metadatum_type') }}</h2> :disabled="[undefined, null, false, 'create_metadata' + index].includes(checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true))"
<hr> :value="checkCurrentSelectedCollectionChildMetadatum(childSourceMetadatum, checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true))"
</div> @input="onSelectCollectionChildMetadata($event, childSourceMetadatum, checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true), Object.entries(sourceMetadatum)[0][0])"
<section class="tainacan-form"> :placeholder="$i18n.get('label_select_metadatum')">
<div class="metadata-types-container"> <option :value="null">
<div {{ $i18n.get('label_select_metadatum') }}
class="metadata-type" </option>
v-for="(metadatumType, index) of metadatumTypes" <option
:key="index" v-for="(collectionMetadatum, metadatumIndex) of getChildOfSelectedCompoundMetadata(sourceMetadatum)"
@click="onSelectMetadatumType(metadatumType)"> :key="metadatumIndex"
<h4>{{ metadatumType.name }}</h4> :value="collectionMetadatum.id"
</div> :disabled="checkIfChildMetadatumIsAvailable(collectionMetadatum.id, checkCurrentSelectedCollectionMetadatum(Object.entries(sourceMetadatum)[0][0], true), Object.entries(sourceMetadatum)[0][0])">
</div> <span class="metadatum-name">
<div class="field is-grouped form-submit"> {{ collectionMetadatum.name }}
<div class="control"> </span>
<button <span class="label-details">
id="button-cancel-importer-edition" ({{ collectionMetadatum.metadata_type_object.name }}) <em>{{ (collectionMetadatum.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em>
class="button is-outlined" </span>
type="button" </option>
@click="onMetadatumEditionCanceled(); isNewMetadatumModalActive = false"> </b-select>
{{ $i18n.get('cancel') }}</button>
</div>
</div>
</section>
</div>
<div
v-if="isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_configure_new_metadatum') }}</h2>
<a
class="back-link"
@click="isEditingMetadatum = false">
{{ $i18n.get('back') }}
</a>
<hr>
</div>
<metadatum-edition-form
:collection-id="collectionId"
:is-repository-level="false"
@onEditionFinished="onMetadatumEditionFinished()"
@onEditionCanceled="onMetadatumEditionCanceled()"
:index="0"
:original-metadatum="metadatum"
:edited-metadatum="editedMetadatum"
:is-on-modal="true"/>
</div> </div>
</div> </div>
</b-modal> </template>
<a <p v-if="collectionMetadata == undefined || collectionMetadata.length <= 0">{{ $i18n.get('info_select_collection_to_list_metadata') }}</p>
v-if="collectionId != null && collectionId != undefined && importerSourceInfo.source_metadata.length > 0 && collection && collection.current_user_can_edit_metadata"
style="font-size: 0.875em;"
class="is-inline is-pulled-right add-link has-text-secondary"
@click="createNewMetadatum()">
<span class="icon">
<i class="tainacan-icon tainacan-icon-add"/>
</span>
{{ $i18n.get('label_add_more_metadata') }}</a>
</div> </div>
<div <div
v-if="importerSourceInfo == undefined || v-if="importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0"
importerSourceInfo == null"> class="source-metadatum"
<p>{{ $i18n.get('info_upload_a_source_to_see_metadata') }}</p> :key="specialFieldIndex"
v-for="(specialField, specialFieldIndex) of importerSourceInfo.source_special_fields">
<p style="font-style: italic">{{ specialField }}</p>
<p>{{ $i18n.get('info_special_fields_mapped_default') }}</p>
</div> </div>
</b-field> <p v-if="importerSourceInfo.source_metadata.length <= 0">{{ $i18n.get('info_no_metadata_source_file') }}<br></p>
<p v-if="(!importerSourceInfo.source_special_fields || importerSourceInfo.source_special_fields.length <= 0)">{{ $i18n.get('info_no_special_fields_available') }}<br></p>
<b-modal
@close="onMetadatumEditionCanceled()"
:active.sync="isNewMetadatumModalActive"
trap-focus
aria-modal
aria-role="dialog">
<div
autofocus="true"
tabindex="-1"
role="dialog"
aria-modal>
<b-loading
:is-full-page="isFullPage"
:active.sync="isLoadingMetadatumTypes"/>
<div
v-if="selectedMetadatumType == undefined && !isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_select_metadatum_type') }}</h2>
<hr>
</div>
<section class="tainacan-form">
<div class="metadata-types-container">
<div
class="metadata-type"
v-for="(metadatumType, index) of metadatumTypes"
:key="index"
@click="onSelectMetadatumType(metadatumType)">
<h4>{{ metadatumType.name }}</h4>
</div>
</div>
<div class="field is-grouped form-submit">
<div class="control">
<button
id="button-cancel-importer-edition"
class="button is-outlined"
type="button"
@click="onMetadatumEditionCanceled(); isNewMetadatumModalActive = false">
{{ $i18n.get('cancel') }}</button>
</div>
</div>
</section>
</div>
<div
v-if="isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_configure_new_metadatum') }}</h2>
<a
class="back-link"
@click="isEditingMetadatum = false">
{{ $i18n.get('back') }}
</a>
<hr>
</div>
<metadatum-edition-form
:collection-id="collectionId"
:is-repository-level="false"
@onEditionFinished="onMetadatumEditionFinished()"
@onEditionCanceled="onMetadatumEditionCanceled()"
:index="0"
:original-metadatum="metadatum"
:edited-metadatum="editedMetadatum"
:is-on-modal="true"/>
</div>
</div>
</b-modal>
<a
v-if="collectionId != null && collectionId != undefined && importerSourceInfo.source_metadata.length > 0 && collection && collection.current_user_can_edit_metadata"
style="font-size: 0.875em;"
class="is-inline is-pulled-right add-link has-text-secondary"
@click="createNewMetadatum()">
<span class="icon">
<i class="tainacan-icon tainacan-icon-add"/>
</span>
{{ $i18n.get('label_add_more_metadata') }}</a>
</div>
<div
v-if="importerSourceInfo == undefined ||
importerSourceInfo == null">
<p>{{ $i18n.get('info_upload_a_source_to_see_metadata') }}</p>
</div>
<!-- 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;
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; removedKey = key;
} }
if (removedKey != '') if (removedKey != '')
delete this.mappedCollection['mapping'][removedKey]; delete this.mappedCollection['mapping'][removedKey];
let mappingValue = '';
if (isCompound) {
mappingValue = {}
mappingValue[sourceMetadatum] = childSourceMetadata;
this.mappedCollection['mapping'][selectedMetadatum] = sourceMetadatum; } 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' ),