@@ -112,7 +112,7 @@
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
this.metadatum_object.metadata_type_options.collection_id : this.collection_id;
- promise = this.getValuesRelationship( collectionTarget, null, [], 0, this.filter.max_options);
+ promise = this.getValuesRelationship( collectionTarget, null, [], 0, this.filter.max_options, false, '1');
promise
.then(() => {
if(this.options.length > this.filter.max_options){
@@ -122,7 +122,7 @@
this.$console.error(error);
})
} else {
- promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, [], 0, this.filter.max_options );
+ promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' );
promise
.then(() => {
if(this.options.length > this.filter.max_options){
@@ -200,22 +200,9 @@
query: this.query
},
events: {
- appliedCheckBoxModal: (options) => { this. appliedCheckBoxModal(options) }
+ appliedCheckBoxModal: () => this.loadOptions()
}
});
- },
- appliedCheckBoxModal(options) {
- this.options = this.options.concat(options)
- for(let i = 0; i < this.options.length; ++i) {
- for(let j = i + 1; j < this.options.length; ++j) {
- if(this.options[i].value == this.options[j].value)
- this.options.splice(j--, 1);
- }
- if (i == this.options.length - 1)
- this.options[i].seeMoreLink = `
${ this.$i18n.get('label_view_all') } `;
- }
-
- this.selectedValues();
}
}
}
diff --git a/src/classes/filter-types/filter-types-mixin.js b/src/classes/filter-types/filter-types-mixin.js
index 828bd1181..b815fba35 100644
--- a/src/classes/filter-types/filter-types-mixin.js
+++ b/src/classes/filter-types/filter-types-mixin.js
@@ -18,10 +18,10 @@ export const filter_type_mixin = {
query: {}
},
methods: {
- getValuesPlainText(metadatumId, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal) {
+ getValuesPlainText(metadatumId, search, isRepositoryLevel, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') {
let query_items = { 'current_query': this.query };
- let url = `/collection/${this.collection}/facets/${metadatumId}?`;
+ let url = `/collection/${this.collection}/facets/${metadatumId}?getSelected=${getSelected}&`;
if(offset != undefined && number != undefined){
url += `offset=${offset}&number=${number}&`;
@@ -102,9 +102,9 @@ export const filter_type_mixin = {
this.$console.error(error);
});
},
- getValuesRelationship(collectionTarget, search, valuesToIgnore, offset, number, isInCheckboxModal) {
+ getValuesRelationship(collectionTarget, search, valuesToIgnore, offset, number, isInCheckboxModal, getSelected = '0') {
let query_items = { 'current_query': this.query };
- let url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + '?';
+ let url = '/collection/' + this.filter.collection_id + '/facets/' + this.filter.metadatum.metadatum_id + `?getSelected=${getSelected}&`;
if(offset != undefined && number != undefined){
url += `offset=${offset}&number=${number}`;
diff --git a/src/classes/filter-types/taxonomy/Checkbox.vue b/src/classes/filter-types/taxonomy/Checkbox.vue
index f3b736746..2532c547b 100644
--- a/src/classes/filter-types/taxonomy/Checkbox.vue
+++ b/src/classes/filter-types/taxonomy/Checkbox.vue
@@ -99,7 +99,7 @@
let query_items = { 'current_query': this.query };
axios.get('/collection/'+ this.collection +'/facets/' + this.metadatum
- + `?hideempty=0&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items))
+ + `?getSelected=1&hideempty=0&order=asc&parent=0&number=${this.filter.max_options}&` + qs.stringify(query_items))
.then( res => {
for (let item of res.data) {
@@ -213,23 +213,10 @@
query: this.query
},
events: {
- appliedCheckBoxModal: (options) => { this. appliedCheckBoxModal(options) }
+ appliedCheckBoxModal: () => this.loadOptions()
},
width: 'calc(100% - 8.333333333%)',
});
- },
- appliedCheckBoxModal(options) {
- this.options = this.options.concat(options)
- for(let i = 0; i < this.options.length; ++i) {
- for(let j = i + 1; j < this.options.length; ++j) {
- if(this.options[i].value == this.options[j].value)
- this.options.splice(j--, 1);
- }
- if (i == this.options.length - 1)
- this.options[i].seeMoreLink = `
${ this.$i18n.get('label_view_all') } `;
- }
-
- this.selectedValues();
}
}
}
diff --git a/src/classes/metadata-types/text/class-tainacan-text.php b/src/classes/metadata-types/text/class-tainacan-text.php
index 78fc0513b..da4540584 100644
--- a/src/classes/metadata-types/text/class-tainacan-text.php
+++ b/src/classes/metadata-types/text/class-tainacan-text.php
@@ -8,6 +8,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
* Class TainacanMetadatumType
*/
class Text extends Metadata_Type {
+ use \Tainacan\Traits\Formatter_Text;
function __construct(){
// call metadatum type constructor
@@ -26,5 +27,27 @@ class Text extends Metadata_Type {
item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_metadatum()->get_name().'">';
- }
+ }
+
+ /**
+ * Get the value as a HTML string with links
+ * @return string
+ */
+ public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
+ $value = $item_metadata->get_value();
+ $return = '';
+ if ( $item_metadata->is_multiple() ) {
+ $total = sizeof($value);
+ $count = 0;
+ foreach ( $value as $el ) {
+ $return .= $this->make_clickable_links($el);
+ $count ++;
+ if ($count <= $total)
+ $return .= ', ';
+ }
+ } else {
+ $return = $this->make_clickable_links($value);
+ }
+ return $return;
+ }
}
\ No newline at end of file
diff --git a/src/classes/metadata-types/textarea/class-tainacan-textarea.php b/src/classes/metadata-types/textarea/class-tainacan-textarea.php
index 18997da3c..f1dfc4780 100644
--- a/src/classes/metadata-types/textarea/class-tainacan-textarea.php
+++ b/src/classes/metadata-types/textarea/class-tainacan-textarea.php
@@ -8,6 +8,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
* Class TainacanMetadatumType
*/
class Textarea extends Metadata_Type {
+ use \Tainacan\Traits\Formatter_Text;
function __construct(){
// call metadatum type constructor
@@ -21,11 +22,33 @@ class Textarea extends Metadata_Type {
* @return string
*/
- public function render( $itemMetadata ){
+ public function render( $itemMetadata ) {
return '
get_value() ).'\'
name="'.$itemMetadata->get_metadatum()->get_name().'">';
}
+
+ /**
+ * Get the value as a HTML string with links and breakline tag.
+ * @return string
+ */
+ public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
+ $value = $item_metadata->get_value();
+ $return = '';
+ if ( $item_metadata->is_multiple() ) {
+ $total = sizeof($value);
+ $count = 0;
+ foreach ( $value as $el ) {
+ $return .= nl2br($this->make_clickable_links($el));
+ $count ++;
+ if ($count <= $total)
+ $return .= ', ';
+ }
+ } else {
+ $return = nl2br($this->make_clickable_links($value));
+ }
+ return $return;
+ }
}
\ No newline at end of file
diff --git a/src/classes/traits/class-tainacan-formatter-text.php b/src/classes/traits/class-tainacan-formatter-text.php
new file mode 100644
index 000000000..5dcdfd53f
--- /dev/null
+++ b/src/classes/traits/class-tainacan-formatter-text.php
@@ -0,0 +1,23 @@
+
+ */
+ public function make_clickable_links($text) {
+ $url = '~(?:(http|https|ftp|ftps)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?$0', $text);
+ return $text;
+ }
+}
\ No newline at end of file
diff --git a/tests/test-importer.php b/tests/test-importer.php
index 1a9a59392..93cde402b 100644
--- a/tests/test-importer.php
+++ b/tests/test-importer.php
@@ -500,12 +500,17 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$this->assertFalse( is_numeric($document_id) );
$attachments = $items[0]->get_attachments();
- $this->assertEquals( 1, count( $attachments ) );
- $this->assertTrue( count($items[2]->get_attachments()) > 0 );
+ if(@file_get_contents ( 'https://www.w3schools.com/w3css/img_lights.jpg' ))
+ $this->assertEquals( 1, count( $attachments ) );
+
+ if(@file_get_contents ( 'https://www.youtube.com/watch?v=V8dpmD4HG5s&start_radio=1&list=RDEMZS6OrHEAut8dOA38mVtVpg' ))
+ $this->assertTrue( count($items[2]->get_attachments()) > 0 );
$document_id = $items[2]->get_document();
- $this->assertTrue( is_numeric($document_id) );
+
+ if(@file_get_contents ( 'https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg' ))
+ $this->assertTrue( is_numeric($document_id) );
$document = $items[3]->get_document();
$this->assertTrue( wp_http_validate_url($document) !== false );
diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php
index b999ca1c9..289346ed3 100644
--- a/tests/test-item-metadata.php
+++ b/tests/test-item-metadata.php
@@ -243,5 +243,64 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
//first 2 metadata are repository metadata
$this->assertTrue( in_array('metadado', $names) );
- }
+ }
+
+ function test_metadata_text_textarea() {
+ $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
+
+ $collection = $this->tainacan_entity_factory->create_entity(
+ 'collection',
+ array(
+ 'name' => 'teste'
+ ),
+ true
+ );
+
+ $i = $this->tainacan_entity_factory->create_entity(
+ 'item',
+ array(
+ 'title' => 'item teste',
+ 'description' => 'description',
+ 'collection' => $collection,
+ 'status' => 'publish'
+ ),
+ true
+ );
+
+ $metadatum_text = $this->tainacan_entity_factory->create_entity(
+ 'metadatum',
+ array(
+ 'name' => 'metadadoText',
+ 'description' => 'descricao',
+ 'collection_id' => $collection->get_id(),
+ 'metadata_type' => 'Tainacan\Metadata_Types\Text',
+ ),
+ true
+ );
+
+ $metadatum_textarea = $this->tainacan_entity_factory->create_entity(
+ 'metadatum',
+ array(
+ 'name' => 'metadadoTextarea',
+ 'description' => 'descricao',
+ 'collection_id' => $collection->get_id(),
+ 'metadata_type' => 'Tainacan\Metadata_Types\Textarea',
+ ),
+ true
+ );
+
+ $value_text = 'GOOGLE: www.google.com';
+ $item_metadata_text = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_text);
+ $item_metadata_text->set_value($value_text);
+
+ $value_textarea = 'GOOGLE: www.google.com \n GOOGLE: https://www.google.com';
+ $item_metadata_textarea = new \Tainacan\Entities\Item_Metadata_Entity($i, $metadatum_textarea);
+ $item_metadata_textarea->set_value($value_textarea);
+
+ $response_text = 'GOOGLE:
www.google.com';
+ $response_textarea = 'GOOGLE:
www.google.com \n GOOGLE:
https://www.google.com';
+
+ $this->assertEquals($item_metadata_text->get_value_as_html(), $response_text);
+ $this->assertEquals($item_metadata_textarea->get_value_as_html(), $response_textarea);
+ }
}
\ No newline at end of file