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

This commit is contained in:
weryques 2018-07-31 10:08:13 -03:00
commit 80964bdb35
20 changed files with 279 additions and 26 deletions

View File

@ -7,7 +7,7 @@
:addons="false"
:type="formErrors['name'] != undefined ? 'is-danger' : ''"
:message="formErrors['name'] != undefined ? formErrors['name'] : ''">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_name') }}
<span
class="required-metadatum-asterisk"
@ -26,7 +26,7 @@
:addons="false"
:type="formErrors['description'] != undefined ? 'is-danger' : ''"
:message="formErrors['description'] != undefined ? formErrors['description'] : ''">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_description') }}
<help-button
:title="$i18n.getHelperTitle('filters', 'description')"
@ -43,7 +43,7 @@
:addons="false"
:type="formErrors['status'] != undefined ? 'is-danger' : ''"
:message="formErrors['status'] != undefined ? formErrors['status'] : ''">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_status') }}
<help-button
:title="$i18n.getHelperTitle('filters', 'status')"
@ -75,7 +75,7 @@
<b-field
:addons="false"
v-if="editForm.filter_type_object && editForm.filter_type_object.component.includes('checkbox')">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_max_options_to_show') }}
<help-button
:title="$i18n.getHelperTitle('filters', 'max_options')"

View File

@ -9,7 +9,7 @@
:addons="false"
:type="formErrors['name'] != undefined ? 'is-danger' : ''"
:message="formErrors['name'] != undefined ? formErrors['name'] : ''">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_name') }}
<span
class="required-metadatum-asterisk"
@ -28,7 +28,7 @@
:addons="false"
:type="formErrors['description'] != undefined ? 'is-danger' : ''"
:message="formErrors['description'] != undefined ? formErrors['description'] : ''">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_description') }}
<help-button
:title="$i18n.getHelperTitle('metadata', 'description')"
@ -43,7 +43,7 @@
<b-field
:addons="false">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_semantic_uri') }}
<help-button
:title="$i18n.getHelperTitle('metadata', 'semantic_uri')"
@ -60,7 +60,7 @@
:addons="false"
:type="formErrors['status'] != undefined ? 'is-danger' : ''"
:message="formErrors['status'] != undefined ? formErrors['status'] : ''">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_status') }}
<help-button
:title="$i18n.getHelperTitle('metadata', 'status')"
@ -95,7 +95,7 @@
:type="formErrors['display'] != undefined ? 'is-danger' : ''"
:message="formErrors['display'] != undefined ? formErrors['display'] : ''"
:addons="false">
<label class="label is-inline">
<label class="label is-inline-block">
{{ $i18n.get('label_display') }}
<help-button
:title="$i18n.getHelperTitle('metadata', 'display')"
@ -139,7 +139,7 @@
</b-field>
<b-field :addons="false">
<label class="label is-inline">{{ $i18n.get('label_options') }}</label>
<label class="label is-inline-block">{{ $i18n.get('label_options') }}</label>
<b-field
:type="formErrors['required'] != undefined ? 'is-danger' : ''"
:message="formErrors['required'] != undefined ? formErrors['required'] : ''">
@ -149,7 +149,7 @@
v-model="editForm.required"
true-value="yes"
false-value="no"
class="is-inline"
class="is-inline-block"
name="required">
{{ $i18n.get('label_required') }}
<help-button
@ -168,7 +168,7 @@
v-model="editForm.multiple"
true-value="yes"
false-value="no"
class="is-inline"
class="is-inline-block"
name="multiple">
{{ $i18n.get('label_allow_multiple') }}
<help-button
@ -186,7 +186,7 @@
v-model="editForm.unique"
true-value="yes"
false-value="no"
class="is-inline"
class="is-inline-block"
name="collecion_key">
{{ $i18n.get('label_unique_value') }}
<help-button

View File

@ -579,7 +579,8 @@
</div>
</div>
<b-modal
class="tainacan-form filters-mobile-modal is-hidden-tablet"
id="filters-mobile-modal"
class="tainacan-form is-hidden-tablet"
:active.sync="isFilterModalActive"
:width="736">
<div class="modal-inner-content">

View File

@ -0,0 +1,61 @@
#filters-mobile-modal {
// top: 95px;
@keyframes slide-menu {
from {
-ms-transform: translate(-100%, 0); /* IE 9 */
-webkit-transform: translate(-100%, 0); /* Safari */
transform: translate(-100%, 0);
}
to {
-ms-transform: translate(0, 0); /* IE 9 */
-webkit-transform: translate(0, 0); /* Safari */
transform: translate(0, 0);
}
}
animation-name: slide-menu;
animation-duration: 0.3s;
animation-timing-function: ease-out;
@keyframes appear {
from {
opacity: 0.0;
visibility: hidden;
}
to {
opacity: 1.0;
visibility: visible;
}
}
.modal-background {
animation-name: appear;
animation-duration: 0.6s;
animation-timing-function: ease-in;
}
.modal-close {
right: calc(8.3333333% + 20px);
background-color: $gray1;
&:hover {
background-color: $gray1;
}
&::before, &::after {
background-color: $secondary;
}
}
.modal-content {
background-color: white;
margin: 0 8.3333333% 0 0;
padding: 24px $page-side-padding;
border-radius: 0;
height: 100%;
max-height: 100%;
overflow-y: auto;
h3 {
font-size: 100%;
}
}
}

View File

@ -16,6 +16,12 @@
justify-content: end !important;
}
}
.field:not(:last-child) {
margin-bottom: 1.125rem;
}
.field>.field:not(:last-child) {
margin-bottom: 0.5rem;
}
.label {
font-weight: bold;
font-size: 14px;

View File

@ -22,6 +22,7 @@
@import "../scss/_modals.scss";
@import "../scss/_tags.scss";
@import "../scss/_notices.scss";
@import "../scss/_filters-menu-modal.scss";
// Clears wordpress content
body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter, body.tainacan-admin-page #wp-auth-check-wrap {
@ -161,4 +162,5 @@ a:hover {
// Buefy notices (toast, snackbar...)
.notices {
z-index: 99999999999999 !important;
}
}

View File

@ -303,6 +303,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'instruction_configure_new_metadatum' => __( 'Configure new metadatum.', 'tainacan' ),
'instruction_insert_mapper_metadatum_info' => __( 'Insert the new mapper\'s metadatum info', 'tainacan' ),
'instruction_select_max_options_to_show' => __( 'Select max options to show', 'tainacan' ),
'instruction_select_collection_fetch_items' => __( 'Select a collection to fecth items', 'tainacan' ),
// Info. Other feedback to user.
'info_search_results' => __( 'Search Results', 'tainacan' ),

View File

@ -41,6 +41,7 @@ export default {
@import "../admin/scss/_dropdown-and-autocomplete.scss";
@import "../admin/scss/_tooltips.scss";
@import "../admin/scss/_tainacan-form.scss";
@import "../admin/scss/_filters-menu-modal.scss";
.theme-items-list {
position: relative;
@ -270,8 +271,41 @@ export default {
}
}
.filters-mobile-modal {
#filters-mobile-modal {
// top: 95px;
@keyframes slide-menu {
from {
-ms-transform: translate(-100%, 0); /* IE 9 */
-webkit-transform: translate(-100%, 0); /* Safari */
transform: translate(-100%, 0);
}
to {
-ms-transform: translate(0, 0); /* IE 9 */
-webkit-transform: translate(0, 0); /* Safari */
transform: translate(0, 0);
}
}
animation-name: slide-menu;
animation-duration: 0.3s;
animation-timing-function: ease-out;
@keyframes appear {
from {
opacity: 0.0;
visibility: hidden;
}
to {
opacity: 1.0;
visibility: visible;
}
}
.modal-background {
animation-name: appear;
animation-duration: 0.6s;
animation-timing-function: ease-in;
}
.modal-close {
right: calc(8.3333333% + 20px);

View File

@ -0,0 +1,87 @@
<?php
/**
* This class implements the integration of Tainacan with ElasticPress, a WordPress plugin that connects your WordPress installation with Elastic Search
*
* https://github.com/10up/ElasticPress
* https://www.elasticpress.io/
*
*
*/
namespace Tainacan;
class Elastic_Press {
function __construct($ajax_query=false) {
add_action('init', [&$this, 'init']);
}
function init() {
if (!class_exists('EP_API')) {
return; // ElasticPress not active
}
add_filter('tainacan_fetch_args', [&$this, 'filter_args'], 10, 2);
}
function filter_args($args, $type) {
if ($type == 'items') {
$args['ep_integrate'] = true;
$args = $this->add_items_args($args);
}
return $args;
}
private function add_items_args($args) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
if (is_array($args['post_type']) && isset($args['s']) && !empty($args['s'])) {
$meta_ids = [];
$taxonomies = [];
foreach ( $args['post_type'] as $cpt ) {
$col = $Tainacan_Collections->fetch_by_db_identifier($cpt);
$taxonomies = array_merge( $taxonomies, get_object_taxonomies($cpt) );
if ($col) {
$metadata = $Tainacan_Metadata->fetch_by_collection($col, ['posts_per_page' => -1], 'OBJECT');
foreach ($metadata as $meta) {
$meta_ids[] = $meta->get_id();
}
}
}
$search_fields = [
'post_title',
'post_content',
'post_excerpt'
];
if (!empty($meta_ids)) {
$search_fields['meta'] = array_unique($meta_ids);
}
if (!empty($taxonomies)) {
$search_fields['taxonomies'] = array_unique($taxonomies);
}
$args['search_fields'] = $search_fields;
}
return $args;
}
} // END

View File

@ -6,19 +6,18 @@
:type="collectionType"
:message="collectionMessage">
<label class="label is-inline">
{{ $i18n.get('label_related_collection') }}<span :class="collectionType" >&nbsp;*&nbsp;</span>
{{ $i18n.get('label_collection_related') }}<span :class="collectionType" >&nbsp;*&nbsp;</span>
<help-button
:title="$i18n.getHelperTitle('tainacan-relationship', 'collection_id')"
:message="$i18n.getHelperMessage('tainacan-relationship', 'collection_id')"/>
</label>
<b-select
name="metadata_type_relationship[collection_id]"
placeholder="Select the collection to fetch items"
:placeholder="$i18n.get('instruction_select_collection_fetch_items' )"
v-model="collection"
@change.native="emitValues()"
@focus="clear()"
:loading="loading">
<option value="">Select...</option>
<option
v-for="option in collections"
:value="option.id"

View File

@ -336,6 +336,8 @@ class Collections extends Repository {
// TODO: Pegar coleções registradas via código
$args = apply_filters('tainacan_fetch_args', $args, 'collections');
$wp_query = new \WP_Query( $args );
return $this->fetch_output( $wp_query, $output );

View File

@ -248,6 +248,8 @@ class Filters extends Repository {
$args = $this->parse_fetch_args($args);
$args['post_type'] = Entities\Filter::get_post_type();
$args = apply_filters('tainacan_fetch_args', $args, 'filters');
$wp_query = new \WP_Query($args);
return $this->fetch_output($wp_query, $output);

View File

@ -252,6 +252,8 @@ class Items extends Repository {
$args['post_type'] = $cpt;
$args = apply_filters('tainacan_fetch_args', $args, 'items');
$wp_query = new \WP_Query( $args );
return $this->fetch_output( $wp_query, $output );

View File

@ -200,6 +200,8 @@ class Logs extends Repository {
$args['post_type'] = Entities\Log::get_post_type();
$args = apply_filters('tainacan_fetch_args', $args, 'logs');
$wp_query = new \WP_Query( $args );
return $this->fetch_output( $wp_query, $output );

View File

@ -324,11 +324,31 @@ class Metadata extends Repository {
$args = $this->parse_fetch_args($args);
$args['post_type'] = Entities\Metadatum::get_post_type();
$args = apply_filters('tainacan_fetch_args', $args, 'metadata');
$wp_query = new \WP_Query($args);
return $this->fetch_output($wp_query, $output);
}
}
/**
* fetch metadata IDs based on WP_Query args
*
* to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/)
* You can also use a mapped property, such as name and description, as an argument and it will be mapped to the
* appropriate WP_Query argument
*
* @param array $args WP_Query args || int $args the item id
*
* @return Array array of IDs;
*/
public function fetch_ids( $args = [] ) {
$args['fields'] = 'ids';
return $this->fetch( $args )->get_posts();
}
/**
* fetch metadatum by collection, considering inheritance

View File

@ -333,6 +333,14 @@ abstract class Repository {
}
$args['meta_query'] = $meta_query;
// Map orderby parameter
if ( isset($args['orderby']) ) {
if ( array_key_exists($args['orderby'], $map) ) {
$args['orderby'] = $map[ $args['orderby'] ]['map'];
}
}
return $args;

View File

@ -172,7 +172,9 @@ class Taxonomies extends Repository {
$args['post_type'] = Entities\Taxonomy::get_post_type();
$wp_query = new \WP_Query($args);
$args = apply_filters('tainacan_fetch_args', $args, 'taxonomies');
$wp_query = new \WP_Query($args);
return $this->fetch_output($wp_query, $output);
}
}

View File

@ -136,5 +136,6 @@ require_once(__DIR__ . '/../theme-helper/template-tags.php');
$Tainacan_Theme_Helper = \Tainacan\Theme_Helper::get_instance();
$Tainacan_Search_Engine = new \Tainacan\Search_Engine();
$Tainacan_Elastic_press = new \Tainacan\Elastic_Press();
?>

View File

@ -106,14 +106,14 @@ class CSV extends Importer {
foreach ( $headers as $indexRaw => $headerRaw ) {
if( $headerRaw === $header ){
$index = $indexRaw;
$column = $indexRaw;
}
}
if(!isset($index))
if(!isset($column))
continue;
$valueToInsert = $this->handle_encoding( $values[ $index ] );
$valueToInsert = $this->handle_encoding( $values[ $column ] );
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ?
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert;
@ -137,8 +137,14 @@ class CSV extends Importer {
$file = new \SplFileObject( $this->tmp_file, 'r' );
$file->setFlags(\SplFileObject::SKIP_EMPTY);
$file->seek( $index );
$values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') );
if( $index === 0 ){
$file->current();
$file->next();
}
$values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') );
if( is_array($values) && !empty($column_document) ){
$this->handle_document( $values[$column_document], $inserted_item);
}
@ -172,7 +178,7 @@ class CSV extends Importer {
$form .= '</div>';
$form .= '</div>';
$form = '<div class="field">';
$form .= '<div class="field">';
$form .= '<label class="label">' . __('Multivalued metadata delimiter', 'tainacan') . '</label>';
$form .= '<div class="control">';
$form .= '<input type="text" class="input" name="multivalued_delimiter" value="' . $this->get_option('multivalued_delimiter') . '" />';
@ -210,6 +216,13 @@ class CSV extends Importer {
$form .= '</div>';
$form .= '</div>';
$form .= '<div class="field">';
$form .= '<label class="label">' . __('Server path', 'tainacan') . '</label>';
$form .= '<div class="control">';
$form .= '<input type="text" class="input" size="1" name="server_path" value="' . $this->get_option('server_path') . '" />';
$form .= '</div>';
$form .= '</div>';
return $form;
}

View File

@ -483,6 +483,16 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$_SESSION['tainacan_importer'][$id]->add_collection( $collection_definition );
$_SESSION['tainacan_importer'][$id]->set_option('encode','iso88591');
$this->assertEquals(1, $_SESSION['tainacan_importer'][$id]->run(), 'first step should import 1 item');
while($_SESSION['tainacan_importer'][$id]->run()){
continue;
}
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_source_number_of_items(), count( $items ) );
// test row 5
$document_id = $items[0]->get_document();
$this->assertFalse( is_numeric($document_id) );
}
}