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

View File

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

View File

@ -579,7 +579,8 @@
</div> </div>
</div> </div>
<b-modal <b-modal
class="tainacan-form filters-mobile-modal is-hidden-tablet" id="filters-mobile-modal"
class="tainacan-form is-hidden-tablet"
:active.sync="isFilterModalActive" :active.sync="isFilterModalActive"
:width="736"> :width="736">
<div class="modal-inner-content"> <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; justify-content: end !important;
} }
} }
.field:not(:last-child) {
margin-bottom: 1.125rem;
}
.field>.field:not(:last-child) {
margin-bottom: 0.5rem;
}
.label { .label {
font-weight: bold; font-weight: bold;
font-size: 14px; font-size: 14px;

View File

@ -22,6 +22,7 @@
@import "../scss/_modals.scss"; @import "../scss/_modals.scss";
@import "../scss/_tags.scss"; @import "../scss/_tags.scss";
@import "../scss/_notices.scss"; @import "../scss/_notices.scss";
@import "../scss/_filters-menu-modal.scss";
// Clears wordpress content // Clears wordpress content
body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter, body.tainacan-admin-page #wp-auth-check-wrap { body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter, body.tainacan-admin-page #wp-auth-check-wrap {
@ -162,3 +163,4 @@ a:hover {
.notices { .notices {
z-index: 99999999999999 !important; 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_configure_new_metadatum' => __( 'Configure new metadatum.', 'tainacan' ),
'instruction_insert_mapper_metadatum_info' => __( 'Insert the new mapper\'s metadatum info', '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_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. Other feedback to user.
'info_search_results' => __( 'Search Results', 'tainacan' ), 'info_search_results' => __( 'Search Results', 'tainacan' ),

View File

@ -41,6 +41,7 @@ export default {
@import "../admin/scss/_dropdown-and-autocomplete.scss"; @import "../admin/scss/_dropdown-and-autocomplete.scss";
@import "../admin/scss/_tooltips.scss"; @import "../admin/scss/_tooltips.scss";
@import "../admin/scss/_tainacan-form.scss"; @import "../admin/scss/_tainacan-form.scss";
@import "../admin/scss/_filters-menu-modal.scss";
.theme-items-list { .theme-items-list {
position: relative; position: relative;
@ -270,8 +271,41 @@ export default {
} }
} }
.filters-mobile-modal { #filters-mobile-modal {
// top: 95px; // 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 { .modal-close {
right: calc(8.3333333% + 20px); 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" :type="collectionType"
:message="collectionMessage"> :message="collectionMessage">
<label class="label is-inline"> <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 <help-button
:title="$i18n.getHelperTitle('tainacan-relationship', 'collection_id')" :title="$i18n.getHelperTitle('tainacan-relationship', 'collection_id')"
:message="$i18n.getHelperMessage('tainacan-relationship', 'collection_id')"/> :message="$i18n.getHelperMessage('tainacan-relationship', 'collection_id')"/>
</label> </label>
<b-select <b-select
name="metadata_type_relationship[collection_id]" name="metadata_type_relationship[collection_id]"
placeholder="Select the collection to fetch items" :placeholder="$i18n.get('instruction_select_collection_fetch_items' )"
v-model="collection" v-model="collection"
@change.native="emitValues()" @change.native="emitValues()"
@focus="clear()" @focus="clear()"
:loading="loading"> :loading="loading">
<option value="">Select...</option>
<option <option
v-for="option in collections" v-for="option in collections"
:value="option.id" :value="option.id"

View File

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

View File

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

View File

@ -252,6 +252,8 @@ class Items extends Repository {
$args['post_type'] = $cpt; $args['post_type'] = $cpt;
$args = apply_filters('tainacan_fetch_args', $args, 'items');
$wp_query = new \WP_Query( $args ); $wp_query = new \WP_Query( $args );
return $this->fetch_output( $wp_query, $output ); 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['post_type'] = Entities\Log::get_post_type();
$args = apply_filters('tainacan_fetch_args', $args, 'logs');
$wp_query = new \WP_Query( $args ); $wp_query = new \WP_Query( $args );
return $this->fetch_output( $wp_query, $output ); return $this->fetch_output( $wp_query, $output );

View File

@ -325,11 +325,31 @@ class Metadata extends Repository {
$args['post_type'] = Entities\Metadatum::get_post_type(); $args['post_type'] = Entities\Metadatum::get_post_type();
$args = apply_filters('tainacan_fetch_args', $args, 'metadata');
$wp_query = new \WP_Query($args); $wp_query = new \WP_Query($args);
return $this->fetch_output($wp_query, $output); 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 * fetch metadatum by collection, considering inheritance
* *

View File

@ -334,6 +334,14 @@ abstract class Repository {
$args['meta_query'] = $meta_query; $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; return $args;
} }

View File

@ -172,6 +172,8 @@ class Taxonomies extends Repository {
$args['post_type'] = Entities\Taxonomy::get_post_type(); $args['post_type'] = Entities\Taxonomy::get_post_type();
$args = apply_filters('tainacan_fetch_args', $args, 'taxonomies');
$wp_query = new \WP_Query($args); $wp_query = new \WP_Query($args);
return $this->fetch_output($wp_query, $output); 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_Theme_Helper = \Tainacan\Theme_Helper::get_instance();
$Tainacan_Search_Engine = new \Tainacan\Search_Engine(); $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 ) { foreach ( $headers as $indexRaw => $headerRaw ) {
if( $headerRaw === $header ){ if( $headerRaw === $header ){
$index = $indexRaw; $column = $indexRaw;
} }
} }
if(!isset($index)) if(!isset($column))
continue; continue;
$valueToInsert = $this->handle_encoding( $values[ $index ] ); $valueToInsert = $this->handle_encoding( $values[ $column ] );
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ? $processedItem[ $header ] = ( $metadatum->is_multiple() ) ?
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert; explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert;
@ -137,6 +137,12 @@ class CSV extends Importer {
$file = new \SplFileObject( $this->tmp_file, 'r' ); $file = new \SplFileObject( $this->tmp_file, 'r' );
$file->setFlags(\SplFileObject::SKIP_EMPTY); $file->setFlags(\SplFileObject::SKIP_EMPTY);
$file->seek( $index ); $file->seek( $index );
if( $index === 0 ){
$file->current();
$file->next();
}
$values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') ); $values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') );
if( is_array($values) && !empty($column_document) ){ if( is_array($values) && !empty($column_document) ){
@ -172,7 +178,7 @@ class CSV extends Importer {
$form .= '</div>'; $form .= '</div>';
$form .= '</div>'; $form .= '</div>';
$form = '<div class="field">'; $form .= '<div class="field">';
$form .= '<label class="label">' . __('Multivalued metadata delimiter', 'tainacan') . '</label>'; $form .= '<label class="label">' . __('Multivalued metadata delimiter', 'tainacan') . '</label>';
$form .= '<div class="control">'; $form .= '<div class="control">';
$form .= '<input type="text" class="input" name="multivalued_delimiter" value="' . $this->get_option('multivalued_delimiter') . '" />'; $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>'; $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; 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]->add_collection( $collection_definition );
$_SESSION['tainacan_importer'][$id]->set_option('encode','iso88591'); $_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) );
} }
} }