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"
@click="onClickCollection($event, collection.id, index)"
: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
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,
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>
<!-- Creation Date -->
<td

View File

@ -91,14 +91,14 @@
class="column-large-width"
@click="onClickTaxonomy($event, taxonomy.id, index)"
: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
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,
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>
<!-- Actions -->
<td

View File

@ -438,8 +438,6 @@
applyFilter() {
this.$parent.close();
let selectedOptions = [];
if(this.isTaxonomy){
this.$eventBusSearch.$emit('input', {
filter: 'checkbox',
@ -448,24 +446,7 @@
metadatum_id: this.metadatum_id,
collection_id: this.collection_id,
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 {
this.$eventBusSearch.$emit('input', {
filter: 'checkbox',
@ -474,36 +455,9 @@
collection_id: this.collection_id ? this.collection_id : this.filter.collection_id,
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>
<!-- View Modes Dropdown -->
<!-- <div
<div
v-if="isOnTheme"
class="search-control-item">
<b-field>
@ -372,7 +372,7 @@
</b-dropdown-item>
</b-dropdown>
</b-field>
</div> -->
</div>
<!-- Text simple search (used on mobile, instead of the one from filter list)-->
<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();
$args = $this->prepare_filters($request);
// handle filter with relationship metadata
if( $metadatum_type === 'Tainacan\Metadata_Types\Relationship' ){
$selected = $this->getRelationshipSelectedValues($request, $metadatum->get_id());
@ -99,14 +101,13 @@ class REST_Facets_Controller extends REST_Controller {
$args['posts_per_page'] = $request['number'];
}
if( $selected ){
//$args['postin'] = $selected;
}
$items = $this->items_repository->fetch($args, $options['collection_id'], 'WP_Query');
$ids = [];
if ($items->have_posts()) {
while ( $items->have_posts() ) {
$items->the_post();
$ids[] = (string) $items->post->ID;
$item = new Entities\Item($items->post);
$prepared_item = $restItemsClass->prepare_item_for_response($item, $request);
@ -117,10 +118,34 @@ class REST_Facets_Controller extends REST_Controller {
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_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']);
$selected = $this->getTaxonomySelectedValues($request, $options['taxonomy_id']);
@ -131,22 +156,42 @@ class REST_Facets_Controller extends REST_Controller {
} else {
if( $selected ){
//$args['include'] = $selected;
$terms = $this->terms_repository->fetch($args, $this->taxonomy);
// 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();
}
foreach ($terms as $term) {
array_push($response, $restTermClass->prepare_item_for_response( $term, $request ));
}
$this->set_pagination_properties_term_type( $args, $response );
} else {
}
// handle filter with Text metadata
else {
$metadatum_id = $metadatum->get_id();
$offset = '';
@ -174,10 +219,25 @@ class REST_Facets_Controller extends REST_Controller {
}
}
if($selected){
//foreach( $selected as $value ){
//$response[] = ['mvalue' => $value];
//}
// retrieve selected items
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 );
@ -343,7 +403,7 @@ class REST_Facets_Controller extends REST_Controller {
if( isset($request['current_query']['metaquery']) ){
foreach( $request['current_query']['metaquery'] as $metaquery ){
if( $metaquery['key'] === $metadatum_id ){
if( $metaquery['key'] == $metadatum_id ){
return $metaquery['value'];
@ -368,7 +428,7 @@ class REST_Facets_Controller extends REST_Controller {
if( isset($request['current_query']['metaquery']) ){
foreach( $request['current_query']['metaquery'] as $metaquery ){
if( $metaquery['key'] === $metadatum_id ){
if( $metaquery['key'] == $metadatum_id ){
return $metaquery['value'];
@ -379,6 +439,32 @@ class REST_Facets_Controller extends REST_Controller {
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 = '';
$searchSlug = '';
foreach ( $search_terms as $term ) {
$term = $wpdb->prepare("%s", $exact ? $term : "%". sanitize_title_with_dashes($term) . "%");
$searchSlug .= "{$searchand}(tter.slug LIKE $term)";
$term = $wpdb->prepare("%s", $exact ? $term : "%". $term . "%");
$searchSlug .= "{$searchand}(tter.name LIKE $term)";
$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 ) {
$searchSlug = "($searchSlug) OR (tter.slug LIKE $term)";
$searchSlug = "($searchSlug) OR (tter.name LIKE $term)";
}
if ( !empty( $searchSlug ) )
$search = " OR ({$searchSlug}) ";

View File

@ -1,7 +1,7 @@
<template>
<div class="block">
<div
v-for="(option, index) in options"
v-for="(option, index) in options.slice(0, filter.max_options)"
:key="index"
class="metadatum">
<b-checkbox
@ -12,7 +12,7 @@
</b-checkbox>
<div
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()"
v-html="option.seeMoreLink"/>
</div>
@ -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 = `<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: {}
},
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}`;

View File

@ -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 = `<a style="font-size: 0.75rem;"> ${ this.$i18n.get('label_view_all') } </a>`;
}
this.selectedValues();
}
}
}

View File

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

View File

@ -45,7 +45,7 @@
this.taxonomy = metadata_type_options.taxonomy_id;
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
@ -70,6 +70,7 @@
taxonomy: '',
terms:[], // object with names
totalTerms: 0,
allowNew: false,
offset: 0,
termsNumber: 40
}
@ -92,7 +93,6 @@
id: '',
disabled: false,
forcedComponentType: '',
allowNew: false,
maxtags: '',
allowSelectToCreate: false,
},
@ -103,6 +103,7 @@
} else if( this.metadatum.metadatum
&& this.metadatum.metadatum.metadata_type_options && 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 = ' ';
$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
$collection_id = tainacan_get_collection_id();
if ($collection_id) {
$props .= 'collection-id="' . $collection_id . '" ';
$collection = new \Tainacan\Entities\Collection($collection_id);
$props .= 'default-view-mode="' . $collection->get_default_view_mode() . '" ';
$props .= 'enabled-view-modes="' . implode(',', $collection->get_enabled_view_modes()) . '" ';
$default_view_mode = $collection->get_default_view_mode();
$enabled_view_modes = $collection->get_enabled_view_modes();
}
// if in a tainacan taxonomy
@ -197,6 +201,9 @@ function tainacan_the_faceted_search() {
$props .= 'term-id="' . $term->term_id . '" ';
$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>";
@ -278,7 +285,11 @@ function tainacan_register_view_mode($slug, $args = []) {
*/
function tainacan_get_item($post_id = 0) {
$post = get_post( $post_id );
if (!$post) {
return null;
}
$theme_helper = \Tainacan\Theme_Helper::get_instance();
if (!$theme_helper->is_post_an_item($post))