Merge branch 'develop' of https://github.com/tainacan/tainacan into develop

This commit is contained in:
weryques 2018-09-13 10:37:19 -03:00
commit 5ae12ecb03
12 changed files with 148 additions and 122 deletions

View File

@ -116,14 +116,14 @@
class="column-large-width" class="column-large-width"
@click="onClickCollection($event, collection.id, index)" @click="onClickCollection($event, collection.id, index)"
:label="$i18n.get('label_description')" :label="$i18n.get('label_description')"
:aria-label="$i18n.get('label_description') + ': ' + collection.description"> :aria-label="$i18n.get('label_description') + ': ' + (collection.description != undefined && collection.description != '') ? collection.description : `<span class='has-text-gray is-italic'>` + $i18n.get('label_description_not_informed') + `</span>`">
<p <p
v-tooltip="{ v-tooltip="{
content: collection.description, content: (collection.description != undefined && collection.description != '') ? collection.description : `<span class='has-text-gray is-italic'>` + $i18n.get('label_description_not_informed') + `</span>`,
autoHide: false, autoHide: false,
placement: 'auto-start' placement: 'auto-start'
}"> }"
{{ collection.description }}</p> v-html="(collection.description != undefined && collection.description != '') ? collection.description : `<span class='has-text-gray is-italic'>` + $i18n.get('label_description_not_informed') + `</span>`"/>
</td> </td>
<!-- Creation Date --> <!-- Creation Date -->
<td <td

View File

@ -91,14 +91,14 @@
class="column-large-width" class="column-large-width"
@click="onClickTaxonomy($event, taxonomy.id, index)" @click="onClickTaxonomy($event, taxonomy.id, index)"
:label="$i18n.get('label_description')" :label="$i18n.get('label_description')"
:aria-label="$i18n.get('label_description') + ': ' + taxonomy.description"> :aria-label="$i18n.get('label_description') + ': ' + taxonomy.description != undefined && taxonomy.description != '' ? taxonomy.description : `<span class='has-text-gray is-italic'>` + $i18n.get('label_description_not_informed') + `</span>`">
<p <p
v-tooltip="{ v-tooltip="{
content: taxonomy.description, content: taxonomy.description != undefined && taxonomy.description != '' ? taxonomy.description : `<span class='has-text-gray is-italic'>` + $i18n.get('label_description_not_informed') + `</span>`,
autoHide: false, autoHide: false,
placement: 'auto-start' placement: 'auto-start'
}"> }"
{{ taxonomy.description }}</p> v-html="(taxonomy.description != undefined && taxonomy.description != '') ? taxonomy.description : `<span class='has-text-gray is-italic'>` + $i18n.get('label_description_not_informed') + `</span>`" />
</td> </td>
<!-- Actions --> <!-- Actions -->
<td <td

View File

@ -438,8 +438,6 @@
applyFilter() { applyFilter() {
this.$parent.close(); this.$parent.close();
let selectedOptions = [];
if(this.isTaxonomy){ if(this.isTaxonomy){
this.$eventBusSearch.$emit('input', { this.$eventBusSearch.$emit('input', {
filter: 'checkbox', filter: 'checkbox',
@ -449,23 +447,6 @@
collection_id: this.collection_id, collection_id: this.collection_id,
terms: this.selected terms: this.selected
}); });
for (let selected of this.selected) {
for(let i in this.finderColumns){
let valueIndex = this.finderColumns[i].findIndex(option => option.value == selected);
if (valueIndex >= 0) {
selectedOptions.push(this.finderColumns[i][valueIndex]);
}
}
}
this.$eventBusSearch.$emit('sendValuesToTags', {
filterId: this.filter.id,
value: selectedOptions,
});
this.$emit('appliedCheckBoxModal', selectedOptions);
} else { } else {
this.$eventBusSearch.$emit('input', { this.$eventBusSearch.$emit('input', {
filter: 'checkbox', filter: 'checkbox',
@ -474,36 +455,9 @@
collection_id: this.collection_id ? this.collection_id : this.filter.collection_id, collection_id: this.collection_id ? this.collection_id : this.filter.collection_id,
value: this.selected, value: this.selected,
}); });
// if(!isNaN(this.selected[0])){
// for (let option of this.options) {
// let valueIndex = this.selected.findIndex(item => item == option.value);
// if (valueIndex >= 0) {
// selectedOptions.push(this.options[valueIndex].label);
// }
// }
// }
if(Array.isArray(this.selected)){
for (let aSelected of this.selected) {
let valueIndex = this.options.findIndex(option => option.value == aSelected);
if (valueIndex >= 0) {
selectedOptions.push(this.options[valueIndex]);
}
}
} else {
let valueIndex = this.options.findIndex(option => option.value == this.selected);
if (valueIndex >= 0) {
selectedOptions.push(this.options[valueIndex]);
}
} }
this.$emit('appliedCheckBoxModal', selectedOptions); this.$emit('appliedCheckBoxModal');
}
} }
} }
} }

View File

@ -271,7 +271,7 @@
</div> </div>
<!-- View Modes Dropdown --> <!-- View Modes Dropdown -->
<!-- <div <div
v-if="isOnTheme" v-if="isOnTheme"
class="search-control-item"> class="search-control-item">
<b-field> <b-field>
@ -372,7 +372,7 @@
</b-dropdown-item> </b-dropdown-item>
</b-dropdown> </b-dropdown>
</b-field> </b-field>
</div> --> </div>
<!-- Text simple search (used on mobile, instead of the one from filter list)--> <!-- Text simple search (used on mobile, instead of the one from filter list)-->
<div class="is-hidden-tablet search-control-item"> <div class="is-hidden-tablet search-control-item">

View File

@ -90,6 +90,8 @@ class REST_Facets_Controller extends REST_Controller {
$options = $metadatum->get_metadata_type_options(); $options = $metadatum->get_metadata_type_options();
$args = $this->prepare_filters($request); $args = $this->prepare_filters($request);
// handle filter with relationship metadata
if( $metadatum_type === 'Tainacan\Metadata_Types\Relationship' ){ if( $metadatum_type === 'Tainacan\Metadata_Types\Relationship' ){
$selected = $this->getRelationshipSelectedValues($request, $metadatum->get_id()); $selected = $this->getRelationshipSelectedValues($request, $metadatum->get_id());
@ -99,14 +101,13 @@ class REST_Facets_Controller extends REST_Controller {
$args['posts_per_page'] = $request['number']; $args['posts_per_page'] = $request['number'];
} }
if( $selected ){
//$args['postin'] = $selected;
}
$items = $this->items_repository->fetch($args, $options['collection_id'], 'WP_Query'); $items = $this->items_repository->fetch($args, $options['collection_id'], 'WP_Query');
$ids = [];
if ($items->have_posts()) { if ($items->have_posts()) {
while ( $items->have_posts() ) { while ( $items->have_posts() ) {
$items->the_post(); $items->the_post();
$ids[] = (string) $items->post->ID;
$item = new Entities\Item($items->post); $item = new Entities\Item($items->post);
$prepared_item = $restItemsClass->prepare_item_for_response($item, $request); $prepared_item = $restItemsClass->prepare_item_for_response($item, $request);
@ -117,10 +118,34 @@ class REST_Facets_Controller extends REST_Controller {
wp_reset_postdata(); wp_reset_postdata();
} }
// retrieve selected items
if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){
foreach( $selected as $index => $item_id ){
if( in_array($item_id,$ids) ){
continue;
}
$item = new Entities\Item($item_id);
$prepared_item = $restItemsClass->prepare_item_for_response($item, $request);
$response[$index] = $prepared_item;
if( isset($request['number']) && ($index+1) >= $request['number']){
break;
}
}
}
$this->total_items = $items->found_posts; $this->total_items = $items->found_posts;
$this->total_pages = ceil($this->total_items / (int) $items->query_vars['posts_per_page']); $this->total_pages = ceil($this->total_items / (int) $items->query_vars['posts_per_page']);
} else if ( $metadatum_type === 'Tainacan\Metadata_Types\Taxonomy' ){ }
// handle filter with Taxonomy metadata
else if ( $metadatum_type === 'Tainacan\Metadata_Types\Taxonomy' ){
$this->taxonomy = $this->taxonomy_repository->fetch($options['taxonomy_id']); $this->taxonomy = $this->taxonomy_repository->fetch($options['taxonomy_id']);
$selected = $this->getTaxonomySelectedValues($request, $options['taxonomy_id']); $selected = $this->getTaxonomySelectedValues($request, $options['taxonomy_id']);
@ -131,22 +156,42 @@ class REST_Facets_Controller extends REST_Controller {
} else { } else {
if( $selected ){ $terms = $this->terms_repository->fetch($args, $this->taxonomy);
//$args['include'] = $selected;
// retrieve selected items
if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){
$ids = $this->get_terms_ids( $terms );
foreach( $selected as $index => $term_id ){
if( in_array($term_id,$ids) ){
continue;
}
$term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy);
array_unshift($terms, $term_selected);
if( isset($request['number']) && ($index+1) >= $request['number']){
break;
}
}
} }
$terms = $this->terms_repository->fetch($args, $this->taxonomy);
$restTermClass = new REST_Terms_Controller(); $restTermClass = new REST_Terms_Controller();
} }
foreach ($terms as $term) { foreach ($terms as $term) {
array_push($response, $restTermClass->prepare_item_for_response( $term, $request )); array_push($response, $restTermClass->prepare_item_for_response( $term, $request ));
} }
$this->set_pagination_properties_term_type( $args, $response ); $this->set_pagination_properties_term_type( $args, $response );
} else { }
// handle filter with Text metadata
else {
$metadatum_id = $metadatum->get_id(); $metadatum_id = $metadatum->get_id();
$offset = ''; $offset = '';
@ -174,10 +219,25 @@ class REST_Facets_Controller extends REST_Controller {
} }
} }
if($selected){ // retrieve selected items
//foreach( $selected as $value ){
//$response[] = ['mvalue' => $value]; if( $selected && $request['getSelected'] && $request['getSelected'] === '1'){
//} $rawValues = $this->get_values( $response );
foreach( $selected as $index => $value ){
if( in_array($value,$rawValues) ){
continue;
}
$row = ['mvalue' => $value, 'metadatum_id' => $metadatum_id ];
$response[$index] = $row;
if( isset($request['number']) && ($index+1) >= $request['number']){
break;
}
}
} }
$this->set_pagination_properties_text_type( $collection_id, $metadatum_id, ($request['search']) ? $request['search'] : '' , $offset, $number ); $this->set_pagination_properties_text_type( $collection_id, $metadatum_id, ($request['search']) ? $request['search'] : '' , $offset, $number );
@ -343,7 +403,7 @@ class REST_Facets_Controller extends REST_Controller {
if( isset($request['current_query']['metaquery']) ){ if( isset($request['current_query']['metaquery']) ){
foreach( $request['current_query']['metaquery'] as $metaquery ){ foreach( $request['current_query']['metaquery'] as $metaquery ){
if( $metaquery['key'] === $metadatum_id ){ if( $metaquery['key'] == $metadatum_id ){
return $metaquery['value']; return $metaquery['value'];
@ -368,7 +428,7 @@ class REST_Facets_Controller extends REST_Controller {
if( isset($request['current_query']['metaquery']) ){ if( isset($request['current_query']['metaquery']) ){
foreach( $request['current_query']['metaquery'] as $metaquery ){ foreach( $request['current_query']['metaquery'] as $metaquery ){
if( $metaquery['key'] === $metadatum_id ){ if( $metaquery['key'] == $metadatum_id ){
return $metaquery['value']; return $metaquery['value'];
@ -379,6 +439,32 @@ class REST_Facets_Controller extends REST_Controller {
return []; return [];
} }
/**
*
*/
private function get_terms_ids( $terms ){
$ids = [];
foreach( $terms as $term ){
$ids[] = (string) $term->WP_Term->term_id;
}
return $ids;
}
/**
*
*/
private function get_values( $rows ){
$values = [];
foreach( $rows as $row ){
$values[] = $row['mvalue'];
}
return $values;
}
} }
?> ?>

View File

@ -329,14 +329,14 @@ class Search_Engine {
$searchand = ''; $searchand = '';
$searchSlug = ''; $searchSlug = '';
foreach ( $search_terms as $term ) { foreach ( $search_terms as $term ) {
$term = $wpdb->prepare("%s", $exact ? $term : "%". sanitize_title_with_dashes($term) . "%"); $term = $wpdb->prepare("%s", $exact ? $term : "%". $term . "%");
$searchSlug .= "{$searchand}(tter.slug LIKE $term)"; $searchSlug .= "{$searchand}(tter.name LIKE $term)";
$searchand = ' AND '; $searchand = ' AND ';
} }
$term = $wpdb->prepare("%s", $exact ? $term : "%". sanitize_title_with_dashes($s) . "%"); $term = $wpdb->prepare("%s", $exact ? $term : "%". $s . "%");
if ( count( $search_terms ) > 1 && $search_terms[0] != $s ) { if ( count( $search_terms ) > 1 && $search_terms[0] != $s ) {
$searchSlug = "($searchSlug) OR (tter.slug LIKE $term)"; $searchSlug = "($searchSlug) OR (tter.name LIKE $term)";
} }
if ( !empty( $searchSlug ) ) if ( !empty( $searchSlug ) )
$search = " OR ({$searchSlug}) "; $search = " OR ({$searchSlug}) ";

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="block"> <div class="block">
<div <div
v-for="(option, index) in options" v-for="(option, index) in options.slice(0, filter.max_options)"
:key="index" :key="index"
class="metadatum"> class="metadatum">
<b-checkbox <b-checkbox
@ -12,7 +12,7 @@
</b-checkbox> </b-checkbox>
<div <div
class="view-all-button-container" class="view-all-button-container"
v-if="option.seeMoreLink && index == options.length - 1" v-if="option.seeMoreLink && index == options.slice(0, filter.max_options).length - 1"
@click="openCheckboxModal()" @click="openCheckboxModal()"
v-html="option.seeMoreLink"/> v-html="option.seeMoreLink"/>
</div> </div>
@ -112,7 +112,7 @@
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
this.metadatum_object.metadata_type_options.collection_id : this.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 promise
.then(() => { .then(() => {
if(this.options.length > this.filter.max_options){ if(this.options.length > this.filter.max_options){
@ -122,7 +122,7 @@
this.$console.error(error); this.$console.error(error);
}) })
} else { } 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 promise
.then(() => { .then(() => {
if(this.options.length > this.filter.max_options){ if(this.options.length > this.filter.max_options){
@ -200,22 +200,9 @@
query: this.query query: this.query
}, },
events: { 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 = `<a style="font-size: 0.75rem;"> ${ this.$i18n.get('label_view_all') } </a>`;
}
this.selectedValues();
} }
} }
} }

View File

@ -18,10 +18,10 @@ export const filter_type_mixin = {
query: {} query: {}
}, },
methods: { 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 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){ if(offset != undefined && number != undefined){
url += `offset=${offset}&number=${number}&`; url += `offset=${offset}&number=${number}&`;
@ -102,9 +102,9 @@ export const filter_type_mixin = {
this.$console.error(error); 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 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){ if(offset != undefined && number != undefined){
url += `offset=${offset}&number=${number}`; url += `offset=${offset}&number=${number}`;

View File

@ -99,7 +99,7 @@
let query_items = { 'current_query': this.query }; let query_items = { 'current_query': this.query };
axios.get('/collection/'+ this.collection +'/facets/' + this.metadatum 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 => { .then( res => {
for (let item of res.data) { for (let item of res.data) {
@ -213,23 +213,10 @@
query: this.query query: this.query
}, },
events: { events: {
appliedCheckBoxModal: (options) => { this. appliedCheckBoxModal(options) } appliedCheckBoxModal: () => this.loadOptions()
}, },
width: 'calc(100% - 8.333333333%)', 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 = `<a style="font-size: 0.75rem;"> ${ this.$i18n.get('label_view_all') } </a>`;
}
this.selectedValues();
} }
} }
} }

View File

@ -12,7 +12,7 @@
</span> </span>
<div> <div>
<transition name="fade"> <!-- <transition name="fade"> -->
<section <section
v-if="showForm" v-if="showForm"
@ -43,7 +43,7 @@
@click="save">{{ $i18n.get('save') }}</a> @click="save">{{ $i18n.get('save') }}</a>
</section> </section>
</transition> <!-- </transition> -->
</div> </div>
</div> </div>

View File

@ -45,7 +45,7 @@
this.taxonomy = metadata_type_options.taxonomy_id; this.taxonomy = metadata_type_options.taxonomy_id;
if( metadata_type_options && metadata_type_options.allow_new_terms && this.metadatum.item ){ if( metadata_type_options && metadata_type_options.allow_new_terms && this.metadatum.item ){
this.allowNew = metadata_type_options.allow_new_terms === 'yes' this.allowNew = metadata_type_options.allow_new_terms == 'yes';
} }
// This condition is temporary // This condition is temporary
@ -70,6 +70,7 @@
taxonomy: '', taxonomy: '',
terms:[], // object with names terms:[], // object with names
totalTerms: 0, totalTerms: 0,
allowNew: false,
offset: 0, offset: 0,
termsNumber: 40 termsNumber: 40
} }
@ -92,7 +93,6 @@
id: '', id: '',
disabled: false, disabled: false,
forcedComponentType: '', forcedComponentType: '',
allowNew: false,
maxtags: '', maxtags: '',
allowSelectToCreate: false, allowSelectToCreate: false,
}, },
@ -103,6 +103,7 @@
} else if( this.metadatum.metadatum } else if( this.metadatum.metadatum
&& this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.input_type ){ && this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.input_type ){
return this.metadatum.metadatum.metadata_type_options.input_type; return this.metadatum.metadatum.metadata_type_options.input_type;
} }
} }
}, },

View File

@ -182,13 +182,17 @@ function tainacan_the_faceted_search() {
$props = ' '; $props = ' ';
$default_view_mode = apply_filters( 'tainacan-default-view-mode-for-themes', 'masonry' );
$enabled_view_modes = apply_filters( 'tainacan-enabled-view-modes-for-themes', ['table', 'cards', 'masonry'] );
// if in a collection page // if in a collection page
$collection_id = tainacan_get_collection_id(); $collection_id = tainacan_get_collection_id();
if ($collection_id) { if ($collection_id) {
$props .= 'collection-id="' . $collection_id . '" '; $props .= 'collection-id="' . $collection_id . '" ';
$collection = new \Tainacan\Entities\Collection($collection_id); $collection = new \Tainacan\Entities\Collection($collection_id);
$props .= 'default-view-mode="' . $collection->get_default_view_mode() . '" '; $default_view_mode = $collection->get_default_view_mode();
$props .= 'enabled-view-modes="' . implode(',', $collection->get_enabled_view_modes()) . '" '; $enabled_view_modes = $collection->get_enabled_view_modes();
} }
// if in a tainacan taxonomy // if in a tainacan taxonomy
@ -198,6 +202,9 @@ function tainacan_the_faceted_search() {
$props .= 'taxonomy="' . $term->taxonomy . '" '; $props .= 'taxonomy="' . $term->taxonomy . '" ';
} }
$props .= 'default-view-mode="' . $default_view_mode . '" ';
$props .= 'enabled-view-modes="' . implode(',', $enabled_view_modes) . '" ';
echo "<div id='tainacan-items-page' $props ></div>"; echo "<div id='tainacan-items-page' $props ></div>";
} }
@ -279,6 +286,10 @@ function tainacan_register_view_mode($slug, $args = []) {
function tainacan_get_item($post_id = 0) { function tainacan_get_item($post_id = 0) {
$post = get_post( $post_id ); $post = get_post( $post_id );
if (!$post) {
return null;
}
$theme_helper = \Tainacan\Theme_Helper::get_instance(); $theme_helper = \Tainacan\Theme_Helper::get_instance();
if (!$theme_helper->is_post_an_item($post)) if (!$theme_helper->is_post_an_item($post))