diff --git a/src/classes/importer/class-tainacan-bg-importer.php b/src/classes/importer/class-tainacan-bg-importer.php index e8789128a..899bc2e60 100644 --- a/src/classes/importer/class-tainacan-bg-importer.php +++ b/src/classes/importer/class-tainacan-bg-importer.php @@ -31,7 +31,7 @@ class Background_Importer extends Background_Process { $data = $batch->data; $key = $batch->key; - define('TAINACAN_DOING_IMPORT', true); + if (!defined('TAINACAN_DOING_IMPORT')) define('TAINACAN_DOING_IMPORT', true); $className = $data['class_name']; if (class_exists($className)) { diff --git a/src/classes/importer/class-tainacan-csv.php b/src/classes/importer/class-tainacan-csv.php index a9ff00104..19a5ac767 100644 --- a/src/classes/importer/class-tainacan-csv.php +++ b/src/classes/importer/class-tainacan-csv.php @@ -51,7 +51,13 @@ class CSV extends Importer { $this->set_option('item_comment_status_index', $index); } } 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; @@ -105,7 +111,16 @@ class CSV extends Importer { */ public function process_item( $index, $collection_definition ) { $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; @@ -157,9 +172,9 @@ class CSV extends Importer { foreach ( $collection_definition['mapping'] as $metadatum_id => $header) { $column = null; foreach ( $headers as $indexRaw => $headerRaw ) { - if( $headerRaw === $header ) { + if( (is_array($header) && $headerRaw === key($header)) || ($headerRaw === $header) ) { $column = $indexRaw; - } + } } if(is_null($column)) @@ -168,10 +183,33 @@ class CSV extends Importer { $valueToInsert = $this->handle_encoding( $values[ $column ] ); $metadatum = new \Tainacan\Entities\Metadatum($metadatum_id); - $processedItem[ $header ] = ( $metadatum->is_multiple() ) ? - explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert; - } + 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() ) ? + explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert; + } + } 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('item_status_index') ) ) $processedItem['special_item_status'] = ''; @@ -245,154 +283,167 @@ class CSV extends Importer { public function options_form() { ob_start(); ?> -
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
- -
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
- -
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
- -
-
- - - - - - - -
-
-
+
+
+
+ + + + + + + +
+
+
+
+
+

+
-
-

+ +
+ +
+
+
+
+
+ + + + + + + +
+
+
+
+
+

+
-
- -
-
- + +
+ +
+
+
+
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+
-
- - - - - - - -
-
-
-
-
-

+
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+
- -
-
-
-
- -

- on this link.', 'tainacan')); ?> -

-
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
+
+ +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+
+ +
+
+
+
+ +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+

+ : on this link.', 'tainacan')); ?> +

+
+
+
+ + $value) { + if( (is_array($value) && key($value) == $metadatum_source) || ($value == $metadatum_source) ) + $tainacan_metadatum_id = $id; + } $metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id ); if( $this->is_empty_value( $values ) ) continue; @@ -681,6 +735,19 @@ class CSV extends Importer { } $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 { $singleItemMetadata->set_value( $values ); } @@ -702,13 +769,33 @@ class CSV extends Importer { } foreach ( $itemMetadataArray as $itemMetadata ) { - $itemMetadata->set_item( $insertedItem ); // *I told you - if( $itemMetadata->validate() ) { - $result = $Tainacan_Item_Metadata->insert( $itemMetadata ); - } else { - $this->add_error_log('Error saving value for ' . $itemMetadata->get_metadatum()->get_name() . " in item " . $insertedItem->get_title()); - $this->add_error_log($itemMetadata->get_errors()); - continue; + if($itemMetadata instanceof Entities\Item_Metadata_Entity ) { + $itemMetadata->set_item( $insertedItem ); // *I told you + if( $itemMetadata->validate() ) { + $result = $Tainacan_Item_Metadata->insert( $itemMetadata ); + } else { + $this->add_error_log('Error saving value for ' . $itemMetadata->get_metadatum()->get_name() . " in item " . $insertedItem->get_title()); + $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 ){ @@ -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 * @return bool @@ -844,10 +944,13 @@ class CSV extends Importer { if( !is_numeric($metadatum_id) ) { $metadatum = $this->create_new_metadata( $header, $collection['id']); - - if( is_object($metadatum) ){ + if( is_object($metadatum) && $metadatum instanceof \Tainacan\Entities\Metadatum ){ unset($collection['mapping'][$metadatum_id]); $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]]; } } diff --git a/src/classes/importer/class-tainacan-flickr-importer.php b/src/classes/importer/class-tainacan-flickr-importer.php index 037682563..9865c2891 100644 --- a/src/classes/importer/class-tainacan-flickr-importer.php +++ b/src/classes/importer/class-tainacan-flickr-importer.php @@ -548,44 +548,49 @@ class Flickr_Importer extends Importer { public function options_form(){ ob_start(); ?> -
- -

- ', __('https://www.flickr.com/services/api/misc.api_keys.html', 'tainacan') ), - '' - ); ?> -

-
-

- -

-
- +
+
+
+ +

+ ', __('https://www.flickr.com/services/api/misc.api_keys.html', 'tainacan') ), + '' + ); ?> +

+
+

+ +

+
+ +
+
+
+
+
+ + +

+ +

+ - + https://www.flickr.com/photos/username +
+ - + https://www.flickr.com/photos/username/albums/123456 +
+ - + https://www.flickr.com/photos/username/123456 + +

+
- - -

- -

- - - https://www.flickr.com/photos/username -
- - - https://www.flickr.com/photos/username/albums/123456 -
- - - https://www.flickr.com/photos/username/123456 - -

- - - 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) ); if( is_array($properties) && count($properties) < 2 ){ @@ -953,6 +966,14 @@ abstract class Importer { $type = ucfirst($type); $newMetadatum->set_metadata_type('Tainacan\Metadata_Types\\'.$type); $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'); if( strcmp(strtolower($type), "taxonomy") === 0 ){ @@ -1001,12 +1022,16 @@ abstract class Importer { $newMetadatum->set_collection_key('no'); } + if(isset($parent_id) && $parent_id != null) { + $newMetadatum->set_parent($parent_id); + } + if($newMetadatum->validate()){ $inserted_metadata = $metadata_repo->insert( $newMetadatum ); $this->add_log('Metadata created: ' . $inserted_metadata->get_name()); return $inserted_metadata; - } else{ + } else { $this->add_log('Error creating metadata ' . $name . ' in collection ' . $collection_id); $this->add_log($newMetadatum->get_errors()); diff --git a/src/classes/importer/class-tainacan-oaipmh-importer.php b/src/classes/importer/class-tainacan-oaipmh-importer.php index 5f18f2e83..d9db9e3ab 100644 --- a/src/classes/importer/class-tainacan-oaipmh-importer.php +++ b/src/classes/importer/class-tainacan-oaipmh-importer.php @@ -839,29 +839,33 @@ class Oaipmh_Importer extends Importer { public function options_form(){ ob_start(); ?> -
- - - - - - - - -
-
-
-
-

-
-
-
-
-
- +
+
+
+ + + + + + + + +
+
+
+
+

+
+
+
+
+
+ +
+
diff --git a/src/classes/importer/class-tainacan-test-importer.php b/src/classes/importer/class-tainacan-test-importer.php index 50e1e50e1..b129691a5 100644 --- a/src/classes/importer/class-tainacan-test-importer.php +++ b/src/classes/importer/class-tainacan-test-importer.php @@ -104,198 +104,219 @@ class Test_Importer extends Importer { public function options_form() { ob_start(); ?> +
-
- - - - - - - -
-
-
-
-
-

-
-
-
-
- +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+
+ +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+
+ +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+
+ +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
- -
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
- -
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
- -
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
- +
-


-
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
+
-
- - - - - - - -
-
-
-
-
-

-
-
-
-
- +
+

-
-
- - - - - - - -
-
-
-
-
-

-
-
-
-
- -
-
+
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
-
- - - - - - - -
-
-
-
-
-

-
-
-
-
- +
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+ +
+
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+ +
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+
+
-
- - - -

- ', __('https://console.developers.google.com', 'tainacan') ), - '' - ); ?> -

-
-

- -

- -
- +
+
+
+ + + +

+ ', __('https://console.developers.google.com', 'tainacan') ), + '' + ); ?> +

+
+

+ +

+ +
+ +
+
+
+
+
+ + +

+ +

+ - + https://www.youtube.com/user/username +
+ - + https://www.youtube.com/playlist?123456 +
+ - + https://www.youtube.com/channel/123456 +
+ - + https://www.youtube.com/watch?v=123456 + +

+
- - - -

- -

- - - https://www.youtube.com/user/username -
- - - https://www.youtube.com/playlist?123456 -
- - - https://www.youtube.com/channel/123456 -
- - - https://www.youtube.com/watch?v=123456 - -

-
- - - - - +
+
+
+ + + + + + + +
+
+
+
+
+

+
+
- -
-
-
-
-
-

+
+
- -
-
-
-
- - - - - +
+
+ + + + + + + +
+
+
+
+
+

+

+
+
- -
-
-
-
-
-

-

-
-
- -
-
- + - + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); + $taxonomies = $Tainacan_Taxonomies->fetch( ['nopaging' => true], 'OBJECT' ); + foreach( $taxonomies as $taxonomie) { + ?> + + + +
+ + + +
- - -
- +
- -
-
- -
-
- -
-
- - - -
-
- - - - - - - - {{ $i18n.get('new_blank_collection') }} - -
-
+ class="columns"> + +
+
+
+

{{ $i18n.get('label_select_file') + ': ' + importer.tmp_file }}

+
@@ -118,10 +80,69 @@ id="tainacan-url-link-source" v-model="url"/> - -
+ +
+ + + +
+ +
+ + + +
+
+ + + + + + + + {{ $i18n.get('new_blank_collection') }} + +
+
+
+
+ +
+ +
+ +
+
+ +
+
@@ -168,6 +189,7 @@
+ @@ -286,7 +308,7 @@ export default { }, onUploadFile() { 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 => { this.importer = updatedImporter; resolve(); @@ -436,13 +458,9 @@ export default { @import "../../scss/_variables.scss"; - .columns.is-gapless { + /deep/ .columns { padding-left: var(--tainacan-one-column); padding-right: var(--tainacan-one-column); - - .column:not(:first-child) { - margin-left: var(--tainacan-one-column); - } } .field { @@ -474,7 +492,7 @@ export default { display: inline; } .drop-inner{ - padding: 1em 3em; + padding: 0.25em 0.5em; } .mapping-header-label { @@ -498,13 +516,16 @@ export default { .selected-source-file { border: 1px solid var(--tainacan-gray2); - padding: 2px 10px; - font-size: .75em; + padding: calc(0.375em - 1px) 10px !important; + font-size: .875em; + line-height: 1.5em; display: flex; justify-content: space-between; align-items: center; } - + hr { + margin: 0.5rem 0 1.5rem 0; + } diff --git a/src/views/admin/components/edition/importer-mapping-form.vue b/src/views/admin/components/edition/importer-mapping-form.vue index ac4d00c86..00ddd8ecd 100644 --- a/src/views/admin/components/edition/importer-mapping-form.vue +++ b/src/views/admin/components/edition/importer-mapping-form.vue @@ -25,32 +25,45 @@
+ + +
+

{{ $i18n.get('info_metadata_mapping_helper') }}

+
+ + + - - - +
- -
+ class="mapping-header" + v-if="importerSourceInfo.source_metadata.length > 0 || (importerSourceInfo.source_special_fields && importerSourceInfo.source_special_fields.length > 0)"> +

{{ $i18n.get('label_from_source_collection') }}

+
+ + + +
+

{{ $i18n.get('label_to_target_collection') }}

+
+
+ + +

{{ $i18n.get('info_select_collection_to_list_metadata') }}

-
-

{{ $i18n.get('info_upload_a_source_to_see_metadata') }}

+
+

{{ specialField }}

+

{{ $i18n.get('info_special_fields_mapped_default') }}

- +

{{ $i18n.get('info_no_metadata_source_file') }}

+

{{ $i18n.get('info_no_special_fields_available') }}

+ +
+ +
+
+

{{ $i18n.get('instruction_select_metadatum_type') }}

+
+
+
+ +
+
+ +
+
+
+
+
+
+

{{ $i18n.get('instruction_configure_new_metadatum') }}

+ + {{ $i18n.get('back') }} + +
+
+ +
+
+
+ + + + + {{ $i18n.get('label_add_more_metadata') }} +
+
+

{{ $i18n.get('info_upload_a_source_to_see_metadata') }}

+
@@ -277,10 +357,6 @@
- -
@@ -298,6 +374,7 @@ export default { importerId: Number, importer: null, isLoading: false, + isLoadingSourceInfo: false, isLoadingRun: false, mappedCollection: { 'id': Number, @@ -396,15 +473,18 @@ export default { this.importer = JSON.parse(JSON.stringify(res)); this.isLoading = false; + this.isLoadingSourceInfo = true; this.fetchImporterSourceInfo(this.sessionId) .then(importerSourceInfo => { this.importerSourceInfo = importerSourceInfo; this.mappedCollection['total_items'] = this.importerSourceInfo.source_total_items; - + + this.isLoadingSourceInfo = false; this.loadMetadata(); }) .catch((errors) => { + this.isLoadingSourceInfo = false; this.$console.log(errors); }); @@ -422,11 +502,13 @@ export default { this.fetchMetadata({ collectionId: this.collectionId, isRepositoryLevel: false, - isContextEdit: false + isContextEdit: false, + parent: 'any' }).then((resp) => { resp.request .then((metadata) => { this.collectionMetadata = JSON.parse(JSON.stringify(metadata)); + this.isFetchingCollectionMetadata = false; this.fetchMappingImporter({ collection: this.collectionId, sessionId: this.sessionId }) @@ -461,13 +543,46 @@ export default { 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']) { if (this.mappedCollection['mapping'][key] == sourceMetadatum) 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; }, + 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) { if (skipTitleCheck !== true) { @@ -506,18 +621,49 @@ export default { 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 = ''; 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; } if (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 this.collectionMetadata.push(""); @@ -571,7 +717,8 @@ export default { this.fetchMetadata({ collectionId: this.collectionId, isRepositoryLevel: false, - isContextEdit: false + isContextEdit: false, + parent: 'any' }).then((resp) => { resp.request .then((metadata) => { @@ -679,7 +826,7 @@ export default { } .source-metadatum { - padding: 2px 0; + padding: 2px 0 2px 8px; min-height: 35px; border-bottom: 1px solid var(--tainacan-gray2); width: 100%; @@ -687,6 +834,40 @@ export default { display: flex; justify-content: space-between; 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{ @@ -696,9 +877,33 @@ export default { padding: 1em 3em; } - .mapping-header-label { + .mapping-header { + display: flex; + justify-content: space-between; + align-items: center; 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 { diff --git a/src/views/admin/components/lists/processes-list.vue b/src/views/admin/components/lists/processes-list.vue index 30fb05bb1..879abde4f 100644 --- a/src/views/admin/components/lists/processes-list.vue +++ b/src/views/admin/components/lists/processes-list.vue @@ -586,7 +586,7 @@ } } .actions-cell { - width: 46px; + width: 52px; } .actions-container { align-items: center; diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index 738cb620c..c0df91c0a 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -257,6 +257,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_text' => __( 'Text', 'tainacan' ), 'label_url' => __( 'URL', 'tainacan' ), 'label_select_file' => __( 'Select File', 'tainacan' ), + 'label_selected_file' => __( 'Selected file', 'tainacan' ), 'label_expand_all' => __( 'Expand all', 'tainacan' ), 'label_collapse_all' => __( 'Collapse all', 'tainacan' ), 'label_view_term' => __( 'View Term', 'tainacan' ), @@ -306,7 +307,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_create_metadatum' => __( 'Create metadatum', 'tainacan' ), 'label_select_metadatum_type' => __( 'Select a metadatum type', '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_add_value' => __( 'Add value', 'tainacan' ), 'label_remove_value' => __( 'Remove value', 'tainacan' ),