merge develop

This commit is contained in:
leogermani 2019-10-29 16:02:54 -03:00
commit f1a6385698
113 changed files with 2422 additions and 2388 deletions

View File

@ -45,21 +45,6 @@ install:
- echo 'if ( php -v|grep -q --only-matching --perl-regexp "5\.\\d+\.\\d+" );then /usr/local/bin/phpunit-5 $@;else /usr/local/bin/phpunit-6 $@;fi;exit $?' |sudo tee -a /usr/local/bin/phpunit > /dev/null - echo 'if ( php -v|grep -q --only-matching --perl-regexp "5\.\\d+\.\\d+" );then /usr/local/bin/phpunit-5 $@;else /usr/local/bin/phpunit-6 $@;fi;exit $?' |sudo tee -a /usr/local/bin/phpunit > /dev/null
- sudo chmod +x /usr/local/bin/phpunit - sudo chmod +x /usr/local/bin/phpunit
script: /usr/local/bin/phpunit # phpunit script: /usr/local/bin/phpunit # phpunit
before_deploy:
- echo "Seção executada antes do deploy!"
- openssl aes-256-cbc -K $encrypted_cb93ef43fcd2_key -iv $encrypted_cb93ef43fcd2_iv
-in deploy_rsa.enc -out /tmp/deploy_rsa -d
- eval "$(ssh-agent -s)"
- chmod 600 /tmp/deploy_rsa
- ssh-add /tmp/deploy_rsa
- echo -e "Host $ssh_host\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- ssh-add -l
deploy:
- provider: script
script: sshpass -p '$ssh_password' ssh $ssh_user@$ssh_host sh /home/l3p/atualiza_git/atualiza_todos.sh #MECHI AQUI!! #ssh $ssh_user@$ssh_host $script_deploy_tainacan
skip_cleanup: true
on:
branch: develop
cache: cache:
directories: directories:
- vendor - vendor

View File

@ -73,6 +73,7 @@ rsync -axz --exclude='vendor/bin/phpc*' --exclude='vendor/squizlabs' --exclude='
--exclude='pdf-viewer/pdfjs-dist/web/compressed.tracemonkey-pldi-09.pdf' \ --exclude='pdf-viewer/pdfjs-dist/web/compressed.tracemonkey-pldi-09.pdf' \
--exclude='vendor/tecnickcom/tcpdf/fonts' \ --exclude='vendor/tecnickcom/tcpdf/fonts' \
--exclude='vendor/smalot/pdfparser/src/Smalot/PdfParser/Tests/' \ --exclude='vendor/smalot/pdfparser/src/Smalot/PdfParser/Tests/' \
--exclude='vendor/tecnickcom/tcpdf/examples' \
src/* $wp_plugin_dir/ src/* $wp_plugin_dir/
rm -rf $wp_plugin_dir/scss rm -rf $wp_plugin_dir/scss

6
package-lock.json generated
View File

@ -1951,9 +1951,9 @@
} }
}, },
"buefy": { "buefy": {
"version": "0.8.5", "version": "0.8.6",
"resolved": "https://registry.npmjs.org/buefy/-/buefy-0.8.5.tgz", "resolved": "https://registry.npmjs.org/buefy/-/buefy-0.8.6.tgz",
"integrity": "sha512-yGQUhIsZWTodCx1rpfDTA32v5OjILpDIDAP+X6KoE6du3F3EZwJ/k5aT8D6Ba6AxNzVdDa2M7f0hzMddLbm38A==", "integrity": "sha512-7woxrdwANcnJbe7lofPxkJLGRRGIVwFXOo0kzEpiNB6alQj18NV6UrdAKse+LWCOADz+AeHe5gyc6qdgRjG5mw==",
"requires": { "requires": {
"bulma": "0.7.5" "bulma": "0.7.5"
} }

View File

@ -8,7 +8,7 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.0", "axios": "^0.19.0",
"buefy": "^0.8.5", "buefy": "^0.8.6",
"bulma": "^0.7.5", "bulma": "^0.7.5",
"mdi": "^2.2.43", "mdi": "^2.2.43",
"moment": "^2.22.2", "moment": "^2.22.2",

View File

@ -57,6 +57,7 @@ class Admin {
function load_admin_page() { function load_admin_page() {
add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_css' ), 90 ); add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_css' ), 90 );
add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_js' ), 90 ); add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_js' ), 90 );
add_action( 'admin_enqueue_scripts', array(&$this, 'add_theme_files') );
} }

View File

@ -298,7 +298,7 @@
<div class="status-radios"> <div class="status-radios">
<b-radio <b-radio
v-model="form.status" v-model="form.status"
v-for="(statusOption, index) of $statusHelper.getStatuses()" v-for="(statusOption, index) of $statusHelper.getStatuses().filter((status) => status.slug != 'draft')"
:key="index" :key="index"
:native-value="statusOption.slug"> :native-value="statusOption.slug">
<span class="icon has-text-gray"> <span class="icon has-text-gray">

View File

@ -74,7 +74,7 @@
{{ metadatum.name }} {{ metadatum.name }}
</span> </span>
<span class="label-details"> <span class="label-details">
({{ $i18n.get(metadatum.metadata_type_object.component) }}) <em>{{ (metadatum.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em> ({{ metadatum.metadata_type_object.name }}) <em>{{ (metadatum.collection_id != collectionId) ? $i18n.get('label_inherited') : '' }}</em>
</span> </span>
</option> </option>
</b-select> </b-select>
@ -93,7 +93,9 @@
<b-modal <b-modal
@close="onMetadatumEditionCanceled()" @close="onMetadatumEditionCanceled()"
:active.sync="isNewMetadatumModalActive" :active.sync="isNewMetadatumModalActive"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div <div
autofocus="true" autofocus="true"
tabindex="-1" tabindex="-1"

View File

@ -213,7 +213,9 @@
:active.sync="isTextModalActive" :active.sync="isTextModalActive"
:width="640" :width="640"
scroll="keep" scroll="keep"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div class="tainacan-modal-content"> <div class="tainacan-modal-content">
<div class="tainacan-modal-title"> <div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_write_text') }}</h2> <h2>{{ $i18n.get('instruction_write_text') }}</h2>
@ -251,10 +253,10 @@
:width="640" :width="640"
scroll="keep" scroll="keep"
trap-focus trap-focus
autofocus
role="dialog" role="dialog"
tabindex="-1" tabindex="-1"
aria-modal> aria-modal
aria-role="dialog">
<div class="tainacan-modal-content"> <div class="tainacan-modal-content">
<div class="tainacan-modal-title"> <div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_insert_url') }}</h2> <h2>{{ $i18n.get('instruction_insert_url') }}</h2>

View File

@ -115,7 +115,7 @@
<span <span
v-if="metadatum.required == 'yes'" v-if="metadatum.required == 'yes'"
class="required-metadatum-asterisk">*</span> class="required-metadatum-asterisk">*</span>
<span class="metadata-type">({{ $i18n.get(metadatum.metadata_type_object.component) }})</span> <span class="metadata-type">({{ metadatum.metadata_type_object.metadata }})</span>
<help-button <help-button
:title="metadatum.name" :title="metadatum.name"
:message="metadatum.description"/> :message="metadatum.description"/>

View File

@ -5,6 +5,15 @@
@submit.prevent="saveEdition(editForm)"> @submit.prevent="saveEdition(editForm)">
<div class="tainacan-page-title"> <div class="tainacan-page-title">
<h2>{{ $i18n.get("title_term_edition") }}</h2> <h2>{{ $i18n.get("title_term_edition") }}</h2>
<a
v-if="editForm && editForm.url != undefined && editForm.url!= ''"
target="_blank"
:href="editForm.url">
<span class="icon">
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-see"/>
</span>
<span class="menu-text">{{ $i18n.get('label_view_on_theme') }}</span>
</a>
<hr> <hr>
</div> </div>
@ -181,16 +190,6 @@
{{ $i18n.get('cancel') }} {{ $i18n.get('cancel') }}
</button> </button>
</div> </div>
<div class="control">
<a
type="button"
v-if="editForm.url != undefined && editForm.url!= ''"
class="button is-secondary"
target="_blank"
:href="editForm.url">
{{ $i18n.get('label_view_term') }}
</a>
</div>
<div class="control"> <div class="control">
<button <button
class="button is-success" class="button is-success"
@ -443,16 +442,21 @@
animation-duration: 0.5s; animation-duration: 0.5s;
.tainacan-page-title { .tainacan-page-title {
margin-bottom: 35px; margin-bottom: 30px;
display: flex;
flex-wrap: wrap;
align-items: baseline;
h2 { h2 {
font-size: 20px; font-size: 20px;
font-weight: 500; font-weight: 500;
color: $blue5; color: $blue5;
display: inline-block; display: inline-block;
margin-right: auto;
} }
hr{ hr {
margin: 3px 0px 4px 0px; margin: 3px 0px 4px 0px;
width: 100%;
height: 1px; height: 1px;
background-color: $secondary; background-color: $secondary;
} }

View File

@ -154,9 +154,9 @@
'approve', 'approve',
'notApprove' 'notApprove'
]), ]),
getThis(){ // getThis(){
return this; // return this;
}, // },
approveActivity(activity) { approveActivity(activity) {
this.approve(activity.id) this.approve(activity.id)
.then(data => { .then(data => {

View File

@ -96,7 +96,7 @@
<span <span
v-if="filter.filter_type_object != undefined" v-if="filter.filter_type_object != undefined"
class="label-details"> class="label-details">
({{ $i18n.get(filter.filter_type_object.component) }}) ({{ filter.filter_type_object.name }})
<span <span
class="not-saved" class="not-saved"
v-if="(editForms[filter.id] != undefined && editForms[filter.id].saved != true) ||filter.status == 'auto-draft'"> v-if="(editForms[filter.id] != undefined && editForms[filter.id].saved != true) ||filter.status == 'auto-draft'">
@ -235,7 +235,9 @@
ref="filterTypeModal" ref="filterTypeModal"
:width="680" :width="680"
:active.sync="isSelectingFilterType" :active.sync="isSelectingFilterType"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div <div
autofocus autofocus
role="dialog" role="dialog"
@ -527,7 +529,7 @@ export default {
collectionId: this.collectionId, collectionId: this.collectionId,
metadatumId: this.choosenMetadatum.id, metadatumId: this.choosenMetadatum.id,
name: this.choosenMetadatum.name, name: this.choosenMetadatum.name,
filterType: this.selectedFilterType.name, filterType: this.selectedFilterType.className,
status: 'auto-draft', status: 'auto-draft',
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
newIndex: this.newFilterIndex newIndex: this.newFilterIndex
@ -1173,6 +1175,10 @@ export default {
margin-left: -16px; margin-left: -16px;
} }
.field .collapse-handle {
display: flex;
}
input, select, textarea, input, select, textarea,
.input, .tags, .tag { .input, .tags, .tag {
pointer-events: none; pointer-events: none;

View File

@ -98,19 +98,17 @@
{{ metadatum.name }} {{ metadatum.name }}
</span> </span>
<span <span
v-if="metadatum.id != undefined" v-if="metadatum.id != undefined && metadatum.metadata_type_object"
class="label-details"> class="label-details">
({{ $i18n.get(metadatum.metadata_type_object.component) }}) ({{ metadatum.metadata_type_object.name }})
<em v-if="metadatum.collection_id != collectionId">{{ $i18n.get('label_inherited') }}</em> <em v-if="metadatum.collection_id != collectionId">{{ $i18n.get('label_inherited') }}</em>
<em <em
v-if="metadatum.metadata_type_object && v-if="metadatum.metadata_type_object.core &&
metadatum.metadata_type_object.core &&
metadatum.metadata_type_object.related_mapped_prop == 'title'"> metadatum.metadata_type_object.related_mapped_prop == 'title'">
{{ $i18n.get('label_core_title') }} {{ $i18n.get('label_core_title') }}
</em> </em>
<em <em
v-if="metadatum.metadata_type_object && v-if="metadatum.metadata_type_object.core &&
metadatum.metadata_type_object.core &&
metadatum.metadata_type_object.related_mapped_prop == 'description'"> metadatum.metadata_type_object.related_mapped_prop == 'description'">
{{ $i18n.get('label_core_description') }} {{ $i18n.get('label_core_description') }}
</em> </em>
@ -235,7 +233,7 @@
</div> </div>
</b-tab-item> </b-tab-item>
<!-- Exposer --------------- --> <!-- Mapping --------------- -->
<b-tab-item :label="$i18n.get('mapping')"> <b-tab-item :label="$i18n.get('mapping')">
<div> <div>
<section <section
@ -248,10 +246,9 @@
</span> </span>
</p> </p>
<p>{{ $i18n.get('info_there_is_no_metadatum') }}</p> <p>{{ $i18n.get('info_there_is_no_metadatum') }}</p>
<p>{{ $i18n.get('info_create_metadata') }}</p>
</div> </div>
</section> </section>
<section> <section v-else>
<div class="field is-grouped form-submit"> <div class="field is-grouped form-submit">
<b-select <b-select
id="mappers-options-dropdown" id="mappers-options-dropdown"
@ -373,7 +370,9 @@
<b-modal <b-modal
@close="onCancelNewMetadataMapperMetadata" @close="onCancelNewMetadataMapperMetadata"
:active.sync="isMapperMetadataCreating" :active.sync="isMapperMetadataCreating"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div <div
autofocus autofocus
role="dialog" role="dialog"

View File

@ -477,7 +477,7 @@
v-for="(attributeValue, attributeName, index) in activity.new_value"> v-for="(attributeValue, attributeName, index) in activity.new_value">
<p class="is-capitalized has-text-blue5 has-text-weight-bold"> <p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }} {{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small> <small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p> </p>
<div class="content"> <div class="content">

View File

@ -137,7 +137,7 @@
</b-field> </b-field>
<li v-if="finderColumn.children.length"> <li v-if="finderColumn.children.length">
<div <div
v-if="totalRemaining[key].remaining === true || (finderColumn.length < totalRemaining[key].remaining)" v-if="shouldShowMoreButton(key)"
@click="getMoreOptions(finderColumn, key)" @click="getMoreOptions(finderColumn, key)"
class="tainacan-show-more"> class="tainacan-show-more">
<span class="icon"> <span class="icon">
@ -206,7 +206,7 @@
</b-tab-item> </b-tab-item>
</b-tabs> </b-tabs>
<!--<pre>{{ hierarchicalPath }}</pre>--> <!--<pre>{{ hierarchicalPath }}</pre>-->
<!-- <pre>{{ totalRemaining }}</pre> --> <!--<pre>{{ totalRemaining }}</pre>-->
<!--<pre>{{ selected }}</pre>--> <!--<pre>{{ selected }}</pre>-->
<!--<pre>{{ options }}</pre>--> <!--<pre>{{ options }}</pre>-->
<!--<pre>{{ searchResults }}</pre>--> <!--<pre>{{ searchResults }}</pre>-->
@ -355,6 +355,9 @@
this.$refs.checkboxRadioModal.focus() this.$refs.checkboxRadioModal.focus()
}, },
methods: { methods: {
shouldShowMoreButton(key) {
return this.totalRemaining[key].remaining === true || (this.finderColumns[key].children.length < this.totalRemaining[key].remaining);
},
fetchSelectedLabels() { fetchSelectedLabels() {
let selected = this.selected instanceof Array ? this.selected : [this.selected]; let selected = this.selected instanceof Array ? this.selected : [this.selected];

View File

@ -25,14 +25,20 @@
:key="index" :key="index"
@click="onSelectCollection(collection)"> @click="onSelectCollection(collection)">
<h4>{{ collection.name }}</h4> <h4>{{ collection.name }}</h4>
<p>{{ collection.length > 200 ? (collection.description.substring(0,197) + '...') : collection.description }}</p> <p>{{ collection.description.length > 200 ? (collection.description.substring(0,197) + '...') : collection.description }}</p>
</div>
<div
v-if="collections.length <= 0"
class="block">
<p class="has-text-gray">
{{ $i18n.get('info_no_collection_created') }}
</p>
</div>
</div> </div>
<b-loading <b-loading
:is-full-page="false" :is-full-page="false"
:active.sync="isLoading" :active.sync="isLoading"
:can-cancel="false"/> :can-cancel="false"/>
</div>
<footer class="field is-grouped form-submit"> <footer class="field is-grouped form-submit">
<div class="control"> <div class="control">

View File

@ -12,7 +12,9 @@
<b-modal <b-modal
:active.sync="isPreviewModalActive" :active.sync="isPreviewModalActive"
scroll="keep" scroll="keep"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<!-- <div class="tainacan-modal-content"> <!-- <div class="tainacan-modal-content">
<div class="tainacan-modal-title"> <div class="tainacan-modal-title">
<h2>{{ $i18n.get('label_document') }}</h2> <h2>{{ $i18n.get('label_document') }}</h2>

View File

@ -33,7 +33,9 @@
:active.sync="isPreviewModalActive" :active.sync="isPreviewModalActive"
:width="1024" :width="1024"
scroll="keep" scroll="keep"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div <div
autofocus autofocus
role="dialog" role="dialog"

View File

@ -54,7 +54,7 @@ export default {
display: block; display: block;
border-radius: 5px; border-radius: 5px;
min-width: 250px; min-width: 250px;
min-width: 250px; max-width: 100%;
transition: margin-bottom 0.2s ease, opacity 0.3s ease; transition: margin-bottom 0.2s ease, opacity 0.3s ease;
position: absolute; position: absolute;
bottom: calc(100% - 6px); bottom: calc(100% - 6px);
@ -76,6 +76,7 @@ export default {
padding: 0.8em 1.0em 1.0em 1.0em; padding: 0.8em 1.0em 1.0em 1.0em;
font-size: 11px; font-size: 11px;
font-weight: normal; font-weight: normal;
white-space: normal;
} }
&:before { &:before {

View File

@ -18,6 +18,7 @@
</label> </label>
<div <div
v-if="collections && collections.length"
class="block"> class="block">
<div <div
v-for="(collection, key) in collections" v-for="(collection, key) in collections"
@ -31,6 +32,13 @@
</b-checkbox> </b-checkbox>
</div> </div>
</div> </div>
<div
v-else
class="block">
<p class="has-text-gray">
{{ $i18n.get('info_no_collection_created') }}
</p>
</div>
</b-collapse> </b-collapse>
</b-field> </b-field>
</template> </template>

View File

@ -1,4 +1,5 @@
<template> <template>
<transition name="filter-item">
<div <div
class="is-inline-flex" class="is-inline-flex"
v-if="filterTags != undefined && filterTags.length > 0"> v-if="filterTags != undefined && filterTags.length > 0">
@ -17,6 +18,7 @@
{{ $i18n.get('label_clear_filters') }} {{ $i18n.get('label_clear_filters') }}
</button> </button>
</div> </div>
</transition>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';

View File

@ -1,255 +0,0 @@
<template>
<div class="table-container">
<div class="selection-control">
<div class="field select-all is-pulled-left">
<span>
<b-checkbox disabled>{{ $i18n.get('label_select_all_items_page') }}</b-checkbox>
</span>
</div>
<div class="field is-pulled-right">
<b-dropdown
position="is-bottom-left"
disabled
trap-focus>
<button
class="button is-white"
slot="trigger">
<span>{{ $i18n.get('label_bulk_actions') }}</span>
<span class="icon">
<i class="tainacan-icon tainacan-icon-20px tainacan-icon-arrowdown"/>
</span>
</button>
</b-dropdown>
</div>
</div>
<div class="table-wrapper">
<table
v-if="viewMode == 'table'"
class="tainacan-table">
<thead>
<th class="skeleton column-default-width" />
</thead>
<tbody>
<tr
class="skeleton"
:key="item"
v-for="item in itemsPerPage">
<td class="column-default-width"/>
</tr>
</tbody>
</table>
<div
v-if="viewMode == 'cards' || viewMode == 'grid'"
:class="{
'tainacan-cards-container': viewMode == 'cards',
'tainacan-grid-container': viewMode == 'grid'
}">
<div
:key="item"
v-for="item in itemsPerPage"
class="skeleton"
:class="{
'tainacan-card': viewMode == 'cards',
'tainacan-grid-item': viewMode == 'grid'
}"/>
</div>
<masonry
:cols="getMasonryColsSettings()"
:gutter="viewMode == 'masonry' ? 25 : 30"
v-if="viewMode == 'masonry' || viewMode == 'records'"
:class="{
'tainacan-masonry-container': viewMode == 'masonry',
'tainacan-records-container': viewMode == 'records'
}">
<div
:key="item"
v-for="item in itemsPerPage"
:style="{'min-height': randomHeightForMasonryItem() + 'px' }"
class="skeleton"
:class="{
'tainacan-masonry-item': viewMode == 'masonry',
'tainacan-record': viewMode == 'records'
}"/>
</masonry>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
name: 'SkeletonItemsList',
computed: {
itemsPerPage(){
return this.getItemsPerPage();
},
viewMode() {
return this.getAdminViewMode();
},
},
methods: {
...mapGetters('search', [
'getItemsPerPage',
'getAdminViewMode',
]),
getMasonryColsSettings() {
if (this.viewMode == 'masonry')
return { default: 7, 1919: 6, 1407: 5, 1215: 4, 1023: 3, 767: 2, 343: 1 }
else
return { default: 4, 1919: 3, 1407: 2, 1215: 2, 1023: 1, 767: 1, 343: 1 }
},
randomHeightForMasonryItem() {
let min = 255;
let max = 255;
if (this.viewMode == 'masonry') {
min = 140;
max = 420;
} else if (this.viewMode == 'records') {
min = 380;
max = 480;
}
return Math.floor(Math.random()*(max-min+1)+min);
}
}
}
</script>
<style lang="scss" scoped>
@import '../../scss/_variables.scss';
// Selection Area
.selection-control {
padding: 6px 0px 0px 12px;
background: white;
height: 40px;
.select-all {
color: $gray4;
font-size: 0.875rem;
&:hover {
color: $gray4;
}
}
}
// Cards View Mode
.tainacan-cards-container {
min-height: 50vh;
padding: 0;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fill, 455px);
grid-gap: 0px;
justify-content: space-evenly;
animation-name: item-appear;
animation-duration: 0.5s;
@media screen and (max-width: 480px) {
width: 91.666666667%;
grid-template-columns: repeat(auto-fill, 100%);
}
.tainacan-card {
padding: 0px;
flex-basis: 0;
margin: 15px;
max-width: 425px;
min-width: 425px;
min-height: 210px;
max-height: 210px;
@media screen and (max-width: 480px) {
max-width: 100%;
min-width: 100%;
min-height: 171px;
max-height: 171px;
img {
width: 130px !important;
height: 130px !important;
}
}
}
}
// Thumbnails (Grid) View Mode
.tainacan-grid-container {
min-height: 50vh;
padding: 0;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fill, 285px);
grid-gap: 0px;
justify-content: space-evenly;
animation-name: appear;
animation-duration: 0.5s;
.tainacan-grid-item {
max-width: 255px;
min-height: 300px;
flex-basis: 0;
margin: 15px;
text-align: center;
}
}
// Masonry View Mode
.tainacan-masonry-container {
min-height: 50vh;
padding: 0;
display: flex;
flex-wrap: wrap;
flex-grow: 1;
flex-shrink: 1;
justify-content: space-evenly;
animation-name: item-appear;
animation-duration: 0.5s;
.tainacan-masonry-item {
display: block;
width: 100%;
flex-basis: 0;
margin-bottom: 25px;
}
}
// Records View Mode
.tainacan-records-container {
min-height: 50vh;
padding: 0;
display: flex;
flex-wrap: wrap;
flex-grow: 1;
flex-shrink: 1;
justify-content: space-evenly;
animation-name: item-appear;
animation-duration: 0.5s;
.tainacan-record {
background-color: #f6f6f6;
padding: 0px;
flex-basis: 0;
margin: 0 auto 30px auto;
width: 100%;
max-width: 425px;
min-height: 100px;
display: block;
}
}
// Table View Mode
table.tainacan-table {
border-spacing: 6px !important;
th { height: 38px; }
td { height: 52px; }
}
</style>

View File

@ -23,7 +23,6 @@ import FormRelationship from '../../classes/metadata-types/relationship/FormRela
import FormTaxonomy from '../../classes/metadata-types/taxonomy/FormTaxonomy.vue'; import FormTaxonomy from '../../classes/metadata-types/taxonomy/FormTaxonomy.vue';
import FormSelectbox from '../../classes/metadata-types/selectbox/FormSelectbox.vue'; import FormSelectbox from '../../classes/metadata-types/selectbox/FormSelectbox.vue';
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue'; import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue';
import FilterDate from '../../classes/filter-types/date/Date.vue'; import FilterDate from '../../classes/filter-types/date/Date.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue'; import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
@ -31,6 +30,7 @@ import FilterAutocomplete from '../../classes/filter-types/autocomplete/Autocomp
import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue'; import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue'; import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
import FilterNumericInterval from '../../classes/filter-types/numeric-interval/NumericInterval.vue'; import FilterNumericInterval from '../../classes/filter-types/numeric-interval/NumericInterval.vue';
import FilterDateInterval from '../../classes/filter-types/date-interval/DateInterval.vue';
import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue'; import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue';
import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue'; import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue';
@ -86,7 +86,6 @@ Vue.component('tainacan-form-item', TainacanFormItem);
Vue.component('tainacan-filter-item', TainacanFiltersList); Vue.component('tainacan-filter-item', TainacanFiltersList);
/* Filters */ /* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-numeric', FilterNumeric); Vue.component('tainacan-filter-numeric', FilterNumeric);
Vue.component('tainacan-filter-date', FilterDate); Vue.component('tainacan-filter-date', FilterDate);
Vue.component('tainacan-filter-selectbox', FilterSelectbox); Vue.component('tainacan-filter-selectbox', FilterSelectbox);
@ -97,6 +96,7 @@ Vue.component('tainacan-filter-taxonomy-checkbox', FilterTaxonomyCheckbox);
Vue.component('tainacan-filter-taxonomy-taginput', FilterTaxonomyTaginput); Vue.component('tainacan-filter-taxonomy-taginput', FilterTaxonomyTaginput);
Vue.component('tainacan-filter-numeric-interval', FilterNumericInterval); Vue.component('tainacan-filter-numeric-interval', FilterNumericInterval);
Vue.component('tainacan-filter-numeric-list-interval', FilterNumericListInterval); Vue.component('tainacan-filter-numeric-list-interval', FilterNumericListInterval);
Vue.component('tainacan-filter-date-interval', FilterDateInterval);
/* Filter Metadata Option forms */ /* Filter Metadata Option forms */
Vue.component('tainacan-filter-form-numeric', FormNumeric); Vue.component('tainacan-filter-form-numeric', FormNumeric);

View File

@ -5,7 +5,6 @@ import VTooltip from 'v-tooltip';
import VueMasonry from 'vue-masonry-css'; import VueMasonry from 'vue-masonry-css';
// Custom elements // Custom elements
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue'; import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue';
import FilterDate from '../../classes/filter-types/date/Date.vue'; import FilterDate from '../../classes/filter-types/date/Date.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue'; import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
@ -44,11 +43,9 @@ Vue.use(RouterHelperPlugin);
Vue.use(StatusHelperPlugin); Vue.use(StatusHelperPlugin);
Vue.use(ConsolePlugin, {visual: false}); Vue.use(ConsolePlugin, {visual: false});
Vue.component('tainacan-filter-item', TaincanFiltersList); Vue.component('tainacan-filter-item', TaincanFiltersList);
/* Filters */ /* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-numeric', FilterNumeric); Vue.component('tainacan-filter-numeric', FilterNumeric);
Vue.component('tainacan-filter-date', FilterDate); Vue.component('tainacan-filter-date', FilterDate);
Vue.component('tainacan-filter-selectbox', FilterSelectbox); Vue.component('tainacan-filter-selectbox', FilterSelectbox);

View File

@ -140,7 +140,7 @@
{{ $i18n.getWithVariables('label_view_all_%s_collections', [collectionsTotal]) }} {{ $i18n.getWithVariables('label_view_all_%s_collections', [collectionsTotal]) }}
</span> </span>
<span <span
v-if="collectionsTotal != undefined && collectionsTotal == 1" v-if="collectionsTotal != undefined && collectionsTotal <= 1"
class="menu-text"> class="menu-text">
{{ $i18n.get('label_view_collections_list') }} {{ $i18n.get('label_view_collections_list') }}
</span> </span>

View File

@ -43,6 +43,7 @@
:date-parser="(date) => dateParser(date)" :date-parser="(date) => dateParser(date)"
size="is-small" size="is-small"
icon="calendar-today" icon="calendar-today"
:years-range="[-50, 3]"
:day-names="[ :day-names="[
$i18n.get('datepicker_short_sunday'), $i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'), $i18n.get('datepicker_short_monday'),
@ -509,7 +510,7 @@
color: $blue5; color: $blue5;
height: 27px; height: 27px;
font-size: 18px !important; font-size: 18px !important;
height: 1.5rem !important; height: 1.75rem !important;
} }
} }

View File

@ -122,6 +122,25 @@
</option> </option>
</b-select> </b-select>
</b-field> </b-field>
<!-- Textual Search -------------->
<b-field class="header-item">
<div class="control has-icons-right is-small is-clearfix">
<input
class="input is-small"
:placeholder="$i18n.get('instruction_search')"
type="search"
:aria-label="$i18n.get('instruction_search') + ' ' + $i18n.get('collections')"
autocomplete="on"
v-model="searchQuery"
@keyup.enter="searchCollections()">
<span
@click="searchCollections()"
class="icon is-right">
<i class="tainacan-icon tainacan-icon-search" />
</span>
</div>
</b-field>
</div> </div>
<div class="above-subheader"> <div class="above-subheader">
@ -141,11 +160,11 @@
</a> </a>
</li> </li>
<li <li
v-for="(statusOption, index) of $statusHelper.getStatuses()" v-for="(statusOption, index) of $statusHelper.getStatuses().filter((status) => status.slug != 'draft')"
:key="index" :key="index"
@click="onChangeTab(statusOption.slug)" @click="onChangeTab(statusOption.slug)"
:class="{ 'is-active': status == statusOption.slug}" :class="{ 'is-active': status == statusOption.slug}"
:style="{ marginRight: statusOption.slug == 'private' ? 'auto' : '', marginLeft: statusOption.slug == 'draft' ? 'auto' : '' }" :style="{ marginRight: statusOption.slug == 'private' ? 'auto' : '', marginLeft: statusOption.slug == 'trash' ? 'auto' : '' }"
v-tooltip="{ v-tooltip="{
content: $i18n.getWithVariables('info_%s_tab_' + statusOption.slug,[$i18n.get('collections')]), content: $i18n.getWithVariables('info_%s_tab_' + statusOption.slug,[$i18n.get('collections')]),
autoHide: true, autoHide: true,
@ -310,6 +329,7 @@ export default {
status: '', status: '',
order: 'desc', order: 'desc',
ordeBy: 'date', ordeBy: 'date',
searchQuery: '',
sortingOptions: [ sortingOptions: [
{ label: this.$i18n.get('label_title'), value: 'title' }, { label: this.$i18n.get('label_title'), value: 'title' },
{ label: this.$i18n.get('label_creation_date'), value: 'date' }, { label: this.$i18n.get('label_creation_date'), value: 'date' },
@ -405,7 +425,8 @@ export default {
status: this.status, status: this.status,
contextEdit: true, contextEdit: true,
order: this.order, order: this.order,
orderby: this.orderBy orderby: this.orderBy,
search: this.searchQuery
}) })
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
@ -427,7 +448,11 @@ export default {
hasModalCard: true, hasModalCard: true,
trapFocus: true trapFocus: true
}); });
} },
searchCollections() {
this.page = 1;
this.loadCollections();
},
}, },
created() { created() {
this.collectionsPerPage = this.$userPrefs.get('collections_per_page'); this.collectionsPerPage = this.$userPrefs.get('collections_per_page');
@ -473,18 +498,23 @@ export default {
@import '../../scss/_variables.scss'; @import '../../scss/_variables.scss';
.sub-header { .sub-header {
min-height: $subheader-height; min-height: $header-height;
height: $header-height; height: auto;
padding-left: 0; padding-left: 0;
padding-right: 0; padding-right: 0;
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
display: inline-flex; display: inline-flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex-wrap: wrap;
width: 100%; width: 100%;
.header-item { .header-item {
margin-bottom: 0 !important;
&:first-child {
margin-right: auto;
}
&:not(:last-child) { &:not(:last-child) {
padding-right: 0.5em; padding-right: 0.5em;
} }
@ -497,9 +527,13 @@ export default {
cursor: default; cursor: default;
} }
&:not(:first-child) {
.button { .button {
display: flex; display: flex;
align-items: center; align-items: center;
border-radius: 0 !important;
height: 1.95rem !important;
}
} }
.field { .field {
@ -515,14 +549,23 @@ export default {
font-size: 1.3125rem !important; font-size: 1.3125rem !important;
max-width: 26px; max-width: 26px;
} }
.icon {
pointer-events: all;
cursor: pointer;
color: $blue5;
height: 27px;
font-size: 18px !important;
height: 1.75rem !important;
}
} }
@media screen and (max-width: 769px) { @media screen and (max-width: 769px) {
height: 60px; height: 120px;
margin-top: -0.5em; margin-top: -0.5em;
padding-top: 0.9em; padding-top: 0.9em;
.header-item { .header-item:not(:last-child) {
padding-right: 0.2em; padding-right: 0.2em;
} }
} }

View File

@ -705,9 +705,6 @@
<div <div
v-if="(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].skeleton_template != undefined)" v-if="(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].skeleton_template != undefined)"
v-html="registeredViewModes[viewMode].skeleton_template"/> v-html="registeredViewModes[viewMode].skeleton_template"/>
<!-- Admin view modes skeleton -->
<!-- <skeleton-items-list v-if="!isOnTheme"/> -->
</div> </div>
<!-- Alert if custom metada is being used for sorting --> <!-- Alert if custom metada is being used for sorting -->
@ -794,13 +791,20 @@
</p> </p>
<router-link <router-link
v-if="!isSortingByCustomMetadata && !hasFiltered && (status == undefined || status == '') && !$route.query.iframemode" v-if="!isRepositoryLevel && !isSortingByCustomMetadata && !hasFiltered && (status == undefined || status == '') && !$route.query.iframemode"
id="button-create-item" id="button-create-item"
tag="button" tag="button"
class="button is-secondary" class="button is-secondary"
:to="{ path: $routerHelper.getNewItemPath(collectionId) }"> :to="{ path: $routerHelper.getNewItemPath(collectionId) }">
{{ $i18n.getFrom('items', 'add_new') }} {{ $i18n.getFrom('items', 'add_new') }}
</router-link> </router-link>
<button
v-else-if="isRepositoryLevel && !isSortingByCustomMetadata && !hasFiltered && (status == undefined || status == '') && !$route.query.iframemode"
id="button-create-item"
class="button is-secondary"
@click="onOpenCollectionsModal">
{{ $i18n.get('add_one_item') }}
</button>
</div> </div>
</section> </section>
@ -821,7 +825,9 @@
:active.sync="isFilterModalActive" :active.sync="isFilterModalActive"
:width="736" :width="736"
animation="slide-menu" animation="slide-menu"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div <div
ref="filters-mobile-modal" ref="filters-mobile-modal"
class="modal-inner-content" class="modal-inner-content"
@ -893,7 +899,6 @@
import FiltersTagsList from '../../components/search/filters-tags-list.vue'; import FiltersTagsList from '../../components/search/filters-tags-list.vue';
import FiltersItemsList from '../../components/search/filters-items-list.vue'; import FiltersItemsList from '../../components/search/filters-items-list.vue';
import Pagination from '../../components/search/pagination.vue' import Pagination from '../../components/search/pagination.vue'
import SkeletonItemsList from '../../components/search/skeleton-items-list.vue'
import AdvancedSearch from '../../components/advanced-search/advanced-search.vue'; import AdvancedSearch from '../../components/advanced-search/advanced-search.vue';
import AvailableImportersModal from '../../components/other/available-importers-modal.vue'; import AvailableImportersModal from '../../components/other/available-importers-modal.vue';
import ExposersModal from '../../components/other/exposers-modal.vue'; import ExposersModal from '../../components/other/exposers-modal.vue';
@ -1027,7 +1032,6 @@
ItemsList, ItemsList,
FiltersTagsList, FiltersTagsList,
FiltersItemsList, FiltersItemsList,
SkeletonItemsList,
Pagination, Pagination,
AdvancedSearch, AdvancedSearch,
ExposersModal ExposersModal
@ -1998,7 +2002,7 @@
.loading-container { .loading-container {
position: relative; position: relative;
min-height: 200px; min-height: 50vh;
height: auto; height: auto;
} }
} }
@ -2058,10 +2062,9 @@
} }
.table-container { .table-container {
padding-left: 4.166666667%; padding-left: $page-side-padding;
padding-right: 4.166666667%; padding-right: $page-side-padding;
min-height: 50vh; min-height: 50vh;
//height: calc(100% - 82px);
} }
.pagination-area { .pagination-area {

View File

@ -84,6 +84,25 @@
</option> </option>
</b-select> </b-select>
</b-field> </b-field>
<!-- Textual Search -------------->
<b-field class="header-item">
<div class="control has-icons-right is-small is-clearfix">
<input
class="input is-small"
:placeholder="$i18n.get('instruction_search')"
type="search"
:aria-label="$i18n.get('instruction_search') + ' ' + $i18n.get('taxonomies')"
autocomplete="on"
v-model="searchQuery"
@keyup.enter="searchTaxonomies()">
<span
@click="searchTaxonomies()"
class="icon is-right">
<i class="tainacan-icon tainacan-icon-search" />
</span>
</div>
</b-field>
</div> </div>
<div class="above-subheader"> <div class="above-subheader">
@ -231,6 +250,7 @@
status: '', status: '',
order: 'asc', order: 'asc',
ordeBy: 'date', ordeBy: 'date',
searchQuery: '',
sortingOptions: [ sortingOptions: [
{ label: this.$i18n.get('label_title'), value: 'title' }, { label: this.$i18n.get('label_title'), value: 'title' },
{ label: this.$i18n.get('label_creation_date'), value: 'date' }, { label: this.$i18n.get('label_creation_date'), value: 'date' },
@ -305,7 +325,8 @@
taxonomiesPerPage: this.taxonomiesPerPage, taxonomiesPerPage: this.taxonomiesPerPage,
status: this.status, status: this.status,
order: this.order, order: this.order,
orderby: this.orderBy orderby: this.orderBy,
search: this.searchQuery
}) })
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
@ -318,6 +339,10 @@
getLastTaxonomyNumber() { getLastTaxonomyNumber() {
let last = (Number(this.taxonomiesPerPage * (this.page - 1)) + Number(this.taxonomiesPerPage)); let last = (Number(this.taxonomiesPerPage * (this.page - 1)) + Number(this.taxonomiesPerPage));
return last > this.total ? this.total : last; return last > this.total ? this.total : last;
},
searchTaxonomies() {
this.page = 1;
this.load();
} }
}, },
computed: { computed: {
@ -371,10 +396,15 @@
display: inline-flex; display: inline-flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex-wrap: wrap;
width: 100%; width: 100%;
.header-item { .header-item {
margin-bottom: 0 !important;
&:first-child {
margin-right: auto;
}
&:not(:last-child) { &:not(:last-child) {
padding-right: 0.5em; padding-right: 0.5em;
} }
@ -387,9 +417,13 @@
cursor: default; cursor: default;
} }
&:not(:first-child) {
.button { .button {
display: flex; display: flex;
align-items: center; align-items: center;
border-radius: 0 !important;
height: 1.95rem !important;
}
} }
.field { .field {
@ -405,10 +439,19 @@
font-size: 1.3125rem !important; font-size: 1.3125rem !important;
max-width: 26px; max-width: 26px;
} }
.icon {
pointer-events: all;
cursor: pointer;
color: $blue5;
height: 27px;
font-size: 18px !important;
height: 1.75rem !important;
}
} }
@media screen and (max-width: 769px) { @media screen and (max-width: 769px) {
height: 60px; height: 160px;
margin-top: -0.5em; margin-top: -0.5em;
padding-top: 0.9em; padding-top: 0.9em;

View File

@ -682,8 +682,6 @@
v-if="(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].skeleton_template != undefined)" v-if="(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].skeleton_template != undefined)"
v-html="registeredViewModes[viewMode].skeleton_template"/> v-html="registeredViewModes[viewMode].skeleton_template"/>
<!-- Admin view modes skeleton -->
<!-- <skeleton-items-list v-if="!isOnTheme"/> -->
</div> </div>
<!-- Alert if custom metada is being used for sorting --> <!-- Alert if custom metada is being used for sorting -->
@ -798,7 +796,9 @@
:active.sync="isFilterModalActive" :active.sync="isFilterModalActive"
:width="736" :width="736"
animation="slide-menu" animation="slide-menu"
trap-focus> trap-focus
aria-modal
aria-role="dialog">
<div <div
autofocus="true" autofocus="true"
tabindex="-1" tabindex="-1"
@ -1918,7 +1918,7 @@
.loading-container { .loading-container {
position: relative; position: relative;
min-height: 200px; min-height: 50vh;
height: auto; height: auto;
} }
} }
@ -1938,8 +1938,8 @@
} }
.table-container { .table-container {
padding-left: 4.166666667%; padding-left: $page-side-padding;
padding-right: 4.166666667%; padding-right: $page-side-padding;
min-height: 50vh; min-height: 50vh;
//height: calc(100% - 82px); //height: calc(100% - 82px);
} }

View File

@ -68,7 +68,7 @@
} }
} }
&.is-mobile-modal { &.is-mobile-modal {
@media screen and (max-width: 1088px) { @media screen and (max-width: 768px) {
.dropdown-content { .dropdown-content {
max-height: 100vh; max-height: 100vh;
} }
@ -278,7 +278,7 @@
} }
} }
@media screen and (min-width: 1024px) { @media screen and (min-width: 768px) {
.datepicker-header { .datepicker-header {
margin-bottom: 0.5rem; margin-bottom: 0.5rem;

View File

@ -111,8 +111,9 @@ $addColors: (
); );
$colors: map-merge($colors, $addColors); $colors: map-merge($colors, $addColors);
// Small size // Bulma Variables
$size-small: 0.85em; // 0.75em on Bulma. $size-small: 0.85em; // 0.75em on Bulma.
$dropdown-mobile-breakpoint: $tablet;
// Tainacan Header and side menus // Tainacan Header and side menus
$header-height: 52px; $header-height: 52px;

View File

@ -78,12 +78,14 @@ body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter, bod
border: none; border: none;
border-radius: 0; border-radius: 0;
animation: none; animation: none;
height: 50px; height: 46px;
width: 50px; width: 46px;
background-size: initial;
} }
.loading-overlay.is-full-page .loading-icon::after { .loading-overlay.is-full-page .loading-icon::after {
height: 50px; height: 46px;
width: 50px; width: 46px;
background-size: initial;
top: calc(50% - 25px); top: calc(50% - 25px);
left: calc(50% - 25px); left: calc(50% - 25px);
} }

View File

@ -133,8 +133,9 @@ return apply_filters( 'tainacan-admin-i18n', [
'title_exporter_page' => __( 'Exporter', 'tainacan'), 'title_exporter_page' => __( 'Exporter', 'tainacan'),
// Labels (used mainly on Aria Labels and Inputs) // Labels (used mainly on Aria Labels and Inputs)
'label' => __( 'label', 'tainacan' ), 'label' => __( 'Label', 'tainacan' ),
'label_clean' => __( 'Clear', 'tainacan' ), 'label_clean' => __( 'Clear', 'tainacan' ),
'label_none' => __( 'None', 'tainacan' ),
'label_clear_filters' => __( 'Clear filters', 'tainacan' ), 'label_clear_filters' => __( 'Clear filters', 'tainacan' ),
'label_and' => __( 'and', 'tainacan' ), 'label_and' => __( 'and', 'tainacan' ),
'label_selected' => __( 'Selected', 'tainacan' ), 'label_selected' => __( 'Selected', 'tainacan' ),
@ -532,7 +533,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_no_terms_created_on_taxonomy' => __( 'No term was created for this taxonomy.', 'tainacan' ), 'info_no_terms_created_on_taxonomy' => __( 'No term was created for this taxonomy.', 'tainacan' ),
'info_no_terms_found' => __( 'No term was found here', 'tainacan' ), 'info_no_terms_found' => __( 'No term was found here', 'tainacan' ),
'info_no_more_terms_found' => __( 'No more terms found', 'tainacan' ), 'info_no_more_terms_found' => __( 'No more terms found', 'tainacan' ),
'info_no_item_created' => __( 'No item was created in this collection.', 'tainacan' ), 'info_no_item_created' => __( 'No item was created so far.', 'tainacan' ),
'info_no_page_found' => __( 'No page was found with this name.', 'tainacan' ), 'info_no_page_found' => __( 'No page was found with this name.', 'tainacan' ),
'info_no_user_found' => __( 'No user was found with this name.', 'tainacan' ), 'info_no_user_found' => __( 'No user was found with this name.', 'tainacan' ),
'info_no_item_found_filter' => __( 'No item was found here with these filters.', 'tainacan' ), 'info_no_item_found_filter' => __( 'No item was found here with these filters.', 'tainacan' ),
@ -582,7 +583,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_warning_taxonomy_not_saved' => __( 'Are you sure? The taxonomy is not saved, changes will be lost.', 'tainacan' ), 'info_warning_taxonomy_not_saved' => __( 'Are you sure? The taxonomy is not saved, changes will be lost.', 'tainacan' ),
'info_warning_terms_not_saved' => __( 'Are you sure? There are terms not saved, changes will be lost.', 'tainacan' ), 'info_warning_terms_not_saved' => __( 'Are you sure? There are terms not saved, changes will be lost.', 'tainacan' ),
'info_warning_orphan_terms' => __( 'Are you sure? This term is parent of other terms. These will be converted to root terms.', 'tainacan' ), 'info_warning_orphan_terms' => __( 'Are you sure? This term is parent of other terms. These will be converted to root terms.', 'tainacan' ),
'info_no_activities' => __( 'No activities', 'tainacan' ), 'info_no_activities' => __( 'No activities yet.', 'tainacan' ),
'info_logs_before' => __( 'Before', 'tainacan' ), 'info_logs_before' => __( 'Before', 'tainacan' ),
'info_logs_after' => __( 'After', 'tainacan' ), 'info_logs_after' => __( 'After', 'tainacan' ),
'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ), 'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ),
@ -664,31 +665,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_expose_only_displayed_metadata' => __( 'By checking this option, only metatada that are displayed on the current list will be exposed', 'tainacan' ), 'info_expose_only_displayed_metadata' => __( 'By checking this option, only metatada that are displayed on the current list will be exposed', 'tainacan' ),
'info_initial_value' => __( 'Initial value', 'tainacan' ), 'info_initial_value' => __( 'Initial value', 'tainacan' ),
'info_final_value' => __( 'Final value', 'tainacan' ), 'info_final_value' => __( 'Final value', 'tainacan' ),
'info_show_interval_on_tag' => __( 'Show interval on tag', 'tainacan' ), 'info_show_interval_on_tag' => __( 'Show applied interval on tags', 'tainacan' ),
// Tainacan Metadatum Types
'tainacan-text' => __( 'Text', 'tainacan' ),
'tainacan-textarea' => __( 'Text area', 'tainacan' ),
'tainacan-date' => __( 'Date', 'tainacan' ),
'tainacan-numeric' => __( 'Numeric', 'tainacan' ),
'tainacan-selectbox' => __( 'Select box', 'tainacan' ),
'tainacan-relationship' => __( 'Relationship', 'tainacan' ),
'tainacan-taxonomy' => __( 'Taxonomy', 'tainacan' ),
'tainacan-compound' => __( 'Compound', 'tainacan' ),
// Tainacan Filter Types
'tainacan-filter-custom-interval' => __( 'Custom Interval', 'tainacan' ),
'tainacan-filter-numeric' => __( 'Numeric', 'tainacan' ),
'tainacan-filter-date' => __( 'Date', 'tainacan' ),
'tainacan-filter-selectbox' => __( 'Select Box', 'tainacan' ),
'tainacan-filter-autocomplete' => __( 'Autocomplete', 'tainacan' ),
'tainacan-filter-taginput' => __( 'Tag Input', 'tainacan' ),
'tainacan-filter-checkbox' => __( 'Check Box', 'tainacan' ),
'tainacan-filter-taxonomy-taginput' => __( 'Taxonomy Tag Input', 'tainacan' ),
'tainacan-filter-taxonomy-checkbox' => __( 'Taxonomy Check Box', 'tainacan' ),
'tainacan-filter-taxonomy-selectbox' => __( 'Taxonomy Select Box', 'tainacan' ),
'tainacan-filter-numeric-interval' => __( 'Numeric Interval', 'tainacan' ),
'tainacan-filter-numeric-list-interval' => __( 'Numeric Interval List', 'tainacan' ),
// Datepicker months // Datepicker months
'datepicker_month_january' => __( 'January', 'tainacan' ), 'datepicker_month_january' => __( 'January', 'tainacan' ),

View File

@ -66,7 +66,7 @@ class REST_Controller extends \WP_REST_Controller {
'name' => 'title', 'name' => 'title',
'title' => 'title', 'title' => 'title',
'id' => 'p', 'id' => 'p',
'authorid' => 'author_id', 'authorid' => 'author',
'authorname' => 'author_name', 'authorname' => 'author_name',
'search' => 's', 'search' => 's',
'searchterm' => 'search', 'searchterm' => 'search',
@ -165,6 +165,7 @@ class REST_Controller extends \WP_REST_Controller {
$terms = get_terms([ $terms = get_terms([
'taxonomy' => $tax_query['taxonomy'], 'taxonomy' => $tax_query['taxonomy'],
'fields' => 'ids', 'fields' => 'ids',
'hide_empty' => isset($args['hide_empty']) ? $args['hide_empty'] : true,
'search' => $tax_query['terms'] 'search' => $tax_query['terms']
]); ]);
@ -179,6 +180,7 @@ class REST_Controller extends \WP_REST_Controller {
$terms = get_terms([ $terms = get_terms([
'taxonomy' => $tax_query['taxonomy'], 'taxonomy' => $tax_query['taxonomy'],
'fields' => 'ids', 'fields' => 'ids',
'hide_empty' => isset($args['hide_empty']) ? $args['hide_empty'] : true,
'search' => $tax_query['terms'] 'search' => $tax_query['terms']
]); ]);
if ($terms) { if ($terms) {
@ -270,11 +272,11 @@ class REST_Controller extends \WP_REST_Controller {
*/ */
public function get_fetch_only_param(){ public function get_fetch_only_param(){
return [ return [
'fetch_only' => [ 'fetch_only' => array(
'type' => 'string/array', 'type' => 'string/array',
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.', 'tainacan' ), 'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.', 'tainacan' ),
//TODO: explicar o fetch only meta.. cabe aqui? //TODO: explicar o fetch only meta.. cabe aqui?
] )
]; ];
} }
@ -286,11 +288,22 @@ class REST_Controller extends \WP_REST_Controller {
* @return array|void * @return array|void
*/ */
public function get_wp_query_params(){ public function get_wp_query_params(){
$query_params['id'] = array( $query_params['id'] = array(
'description' => __("Limit result to objects with specific id.", 'tainacan'), 'description' => __("Limit result to objects with specific id.", 'tainacan'),
'type' => 'integer', 'type' => 'integer',
); );
$query_params['context'] = array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
),
);
$query_params['search'] = array( $query_params['search'] = array(
'description' => __( 'Limit results to those matching a string.', 'tainacan' ), 'description' => __( 'Limit results to those matching a string.', 'tainacan' ),
'type' => 'string', 'type' => 'string',
@ -329,7 +342,7 @@ class REST_Controller extends \WP_REST_Controller {
'description' => __( 'Order sort attribute ascending or descending.', 'tainacan' ), 'description' => __( 'Order sort attribute ascending or descending.', 'tainacan' ),
'type' => 'string/array', 'type' => 'string/array',
'default' => 'desc', 'default' => 'desc',
'enum' => array( 'asc', 'desc' ), 'enum' => array( 'asc', 'desc', 'ASC', 'DESC' ),
); );
$query_params['orderby'] = array( $query_params['orderby'] = array(
@ -387,8 +400,26 @@ class REST_Controller extends \WP_REST_Controller {
), ),
'metacompare' => array( 'metacompare' => array(
'type' => 'string', 'type' => 'string',
'description' => __('Operator to test the meta_value. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, NOT EXISTS, REGEXP, NOT REGEXP or RLIKE.'), 'description' => __('Operator to test the metavalue'),
'default' => '=', 'default' => '=',
'enum' => array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'NOT EXISTS',
'REGEXP',
'NOT REGEXP',
'RLIKE'
)
), ),
'metaquery' => array( 'metaquery' => array(
'description' => __('Limits result set to items that have specific custom metadata'), 'description' => __('Limits result set to items that have specific custom metadata'),
@ -406,8 +437,24 @@ class REST_Controller extends \WP_REST_Controller {
), ),
'compare' => array( 'compare' => array(
'type' => 'string', 'type' => 'string',
'description' => __('Operator to test. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, EXISTS and NOT EXISTS.'), 'description' => __('Operator to test.'),
'default' => '=' 'default' => '=',
'enum' => array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS'
)
), ),
'relation' => array( 'relation' => array(
'type' => 'string', 'type' => 'string',
@ -457,8 +504,24 @@ class REST_Controller extends \WP_REST_Controller {
), ),
'compare' => array( 'compare' => array(
'type' => 'string', 'type' => 'string',
'description' => __('Operator to test. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, EXISTS and NOT EXISTS.'), 'description' => __('Operator to test.'),
'default' => '=' 'default' => '=',
'enum' => array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS'
)
), ),
'dayofweek' => array('type' => 'array'), 'dayofweek' => array('type' => 'array'),
'inclusive' => array( 'inclusive' => array(
@ -488,7 +551,14 @@ class REST_Controller extends \WP_REST_Controller {
), ),
'metadatum' => array( 'metadatum' => array(
'type' => 'string', 'type' => 'string',
'description' => __('Select taxonomy term by. Possible values are term_id, name, slug or term_taxonomy_id. Default value is term_id.') 'default' => 'term_id',
'description' => __('Select taxonomy term by'),
'enum' => array(
'term_id',
'name',
'slug',
'term_taxonomy_id'
)
), ),
'terms' => array( 'terms' => array(
'type' => 'int/string/array', 'type' => 'int/string/array',
@ -496,13 +566,24 @@ class REST_Controller extends \WP_REST_Controller {
), ),
'operator' => array( 'operator' => array(
'type' => 'string', 'type' => 'string',
'description' => __('Operator to test. Possible values are IN, NOT IN, AND, EXISTS and NOT EXISTS'), 'description' => __('Operator to test.'),
'default' => 'IN' 'default' => 'IN',
'enum' => array(
'IN',
'NOT IN',
'AND',
'EXISTS',
'NOT EXISTS'
)
), ),
'relation' => array( 'relation' => array(
'type' => 'string', 'type' => 'string',
'description' => __('The logical relationship between each inner taxonomy array when there is more than one. Possible values are AND, OR. Do not use with a single inner taxonomy array.'), 'description' => __('The logical relationship between each inner taxonomy array when there is more than one. Do not use with a single inner taxonomy array.'),
'default' => 'AND' 'default' => 'AND',
'enum' => array(
'AND',
'OR'
)
), ),
), ),
'type' => 'array' 'type' => 'array'

View File

@ -42,23 +42,33 @@ class REST_Background_Processes_Controller extends REST_Controller {
], ],
'all_users' => [ 'all_users' => [
'type' => 'bool', 'type' => 'bool',
'description' => __( 'Whether to return processes from all users (if current user is admin). Default false.', 'tainacan' ), 'description' => __( 'Whether to return processes from all users (if current user is admin).', 'tainacan' ),
'default' => false,
], ],
'status' => [ 'status' => [
'type' => 'string', 'type' => 'string',
'description' => __( '"open" returns only processes currently running. "closed" returns only finished or aborted. "all" returns all. Default "all"', 'tainacan' ), 'description' => __( '"open" returns only processes currently running. "closed" returns only finished or aborted. "all" returns all.', 'tainacan' ),
'default' => 'all',
'enum' => array(
'open',
'closed',
'all'
)
], ],
'perpage' => [ 'perpage' => [
'type' => 'integer', 'type' => 'integer',
'description' => __( 'Number of processes to return per page. Default 10', 'tainacan' ), 'description' => __( 'Number of processes to return per page', 'tainacan' ),
'default' => 10,
], ],
'paged' => [ 'paged' => [
'type' => 'integer', 'type' => 'integer',
'description' => __( 'Page to retrieve. Default 1', 'tainacan' ), 'description' => __( 'Page to retrieve', 'tainacan' ),
'default' => 1
], ],
'recent' => [ 'recent' => [
'type' => 'bool', 'type' => 'bool',
'description' => __( 'Returns only processes created or updated recently', 'tainacan' ), 'description' => __( 'Returns only processes created or updated recently', 'tainacan' ),
'default' => false
], ],
], ],
), ),
@ -82,6 +92,10 @@ class REST_Background_Processes_Controller extends REST_Controller {
'status' => [ 'status' => [
'type' => 'string', 'type' => 'string',
'description' => __( '"open" or "closed" ', 'tainacan' ), 'description' => __( '"open" or "closed" ', 'tainacan' ),
'enum' => array(
'open',
'closed'
)
] ]
], ],
), ),
@ -141,7 +155,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$user_q = $wpdb->prepare("AND user_id = %d", $request['user_id']); $user_q = $wpdb->prepare("AND user_id = %d", $request['user_id']);
} }
if ( isset($user_q['all_users']) && $user_q['all_users'] ) { if ( isset($request['all_users']) && $request['all_users'] ) {
$user_q = ""; $user_q = "";
} }
} }

View File

@ -456,9 +456,6 @@ class REST_Bulkedit_Controller extends REST_Controller {
* @return array|void * @return array|void
*/ */
public function get_create_params($object_name = null) { public function get_create_params($object_name = null) {
$query_params['context']['default'] = 'view';
array_merge($query_params, parent::get_wp_query_params());
$query_params['title'] = array( $query_params['title'] = array(
'description' => __('Limits the result set to items with a specific title'), 'description' => __('Limits the result set to items with a specific title'),
@ -478,7 +475,11 @@ class REST_Bulkedit_Controller extends REST_Controller {
'description' => __( 'Whether to use the current query to select posts', 'tainacan' ), 'description' => __( 'Whether to use the current query to select posts', 'tainacan' ),
]; ];
$query_params = array_merge($query_params, parent::get_meta_queries_params()); $query_params = array_merge(
$query_params,
parent::get_wp_query_params(),
parent::get_meta_queries_params()
);
return $query_params; return $query_params;
} }

View File

@ -43,7 +43,7 @@ class REST_Collections_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'), 'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'), 'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_wp_query_params(), 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
), ),
array( array(
'methods' => \WP_REST_Server::CREATABLE, 'methods' => \WP_REST_Server::CREATABLE,
@ -58,7 +58,7 @@ class REST_Collections_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'), 'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'), 'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE), 'args' => $this->get_wp_query_params(),
), ),
array( array(
@ -73,8 +73,8 @@ class REST_Collections_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array( 'args' => array(
'permanently' => array( 'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'), 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
'default' => 'false' 'default' => '0',
), ),
) )
), ),
@ -476,12 +476,6 @@ class REST_Collections_Controller extends REST_Controller {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
);
$endpoint_args['name'] = array( $endpoint_args['name'] = array(
'description' => __('Limits the result set to collections with a specific name'), 'description' => __('Limits the result set to collections with a specific name'),
'type' => 'string', 'type' => 'string',

View File

@ -1,336 +0,0 @@
<?php
namespace Tainacan\API\EndPoints;
use \Tainacan\API\REST_Controller;
use Tainacan\Entities;
use Tainacan\Repositories;
use Tainacan\Entities\Entity;
use Tainacan\Tests\TAINACAN_REST_Collections_Controller;
class REST_Export_Controller extends REST_Controller {
private $item_metadata_repository;
private $items_repository;
private $collection_repository;
private $metadatum_repository;
public function __construct() {
$this->rest_base = 'export';
parent::__construct();
add_action('init', array(&$this, 'init_objects'), 11);
}
/**
* Initialize objects after post_type register
*
* @throws \Exception
*/
public function init_objects() {
$this->metadatum_repository = Repositories\Metadata::get_instance();
$this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
$this->items_repository = Repositories\Items::get_instance();
$this->collection_repository = Repositories\Collections::get_instance();
}
/**
* If POST on metadatum/collection/<collection_id>, then
* a metadatum will be created in matched collection and all your item will receive this metadatum
*
* If POST on metadatum/item/<item_id>, then a value will be added in a metadatum and metadatum passed
* id body of requisition
*
* Both of GETs return the metadatum of matched objects
*
* @throws \Exception
*/
public function register_routes() {
register_rest_route($this->namespace, '/' . $this->rest_base. '/collection/(?P<collection_id>[\d]+)',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
),
)
);
register_rest_route($this->namespace, '/' . $this->rest_base. '/item/(?P<item_id>[\d]+)',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
),
)
);
register_rest_route($this->namespace, '/' . $this->rest_base,
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_wp_query_params(),
)
)
);
}
/**
* @param \WP_REST_Request $request
*
* @return \WP_Error|\WP_REST_Response
*/
public function get_item( $request ) { }
/**
* @param \WP_REST_Request $request
*
* @return bool|\WP_Error
* @throws \Exception
*/
public function get_item_permissions_check( $request ) {
if(isset($request['collection_id'])) {
$collection = $this->collection_repository->fetch($request['collection_id']);
if($collection instanceof Entities\Collection) {
if (! $collection->can_read()) {
return false;
}
return true;
}
} elseif(isset($request['item_id'])) {
$item = $this->items_repository->fetch($request['item_id']);
if($item instanceof Entities\Item) {
if (! $item->can_read()) {
return false;
}
return true;
}
} else { // Exporting all
$dummy = new Entities\Collection();
return current_user_can($dummy->get_capabilities()->read); // Need to check Colletion by collection
}
return false;
}
/**
* @param \Tainacan\Entities\Item $item
* @param \WP_REST_Request $request
*
* @return array|\WP_Error|\WP_REST_Response
*/
public function prepare_item_for_response( $item, $request ) {
$items_metadata = $item->get_metadata();
$prepared_item = [];
foreach ($items_metadata as $item_metadata){
$prepared_item[] = $item_metadata->_toArray();
}
return $prepared_item;
}
/**
*
* @param \WP_REST_Request $request
* @param \WP_Query|Entities\Item $query
* @param array $args
* @return \WP_Error|number
*/
public function export($request, $query, $args) {
$type = \Tainacan\Exposers_Handler::request_has_type($request);
$path = wp_upload_dir();
$path = $path['path'];
$filename = $path.date('YmdHis').'-tainacan-export.'.$type->get_extension();
$pid = -1;
$log = \Tainacan\Entities\Log::create(
__('Export Process', 'tainacan'),
__('Exporting Data', 'tainacan').'\nArgs: '.print_r($args, true),
['file' => $filename],
[],
'processing'
);
$body = json_decode( $request->get_body(), true );
$background = ! (isset($body['export-background']) && $body['export-background'] == false);
if( $background ) {
$pid = pcntl_fork();
} else {
$pid = true;
}
if ($pid === -1) {
$error = new \WP_Error('could not fork');
$log = \Tainacan\Entities\Log::create(
__('Export Process Error', 'tainacan'),
__('Exporting Error', 'tainacan').'\\nArgs: '.print_r($args, true).'\\nError: could not fork',
$error,
[],
'error'
);
remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers_Handler::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers_Handler::get_instance(), 'rest_response'], 10, 2 ); // exposer types
return $log;
} elseif ($pid) { // we are the parent or run at foreground
try {
ignore_user_abort(true);
set_time_limit(0);
ini_set("memory_limit", "256M");
if($background) { // wait for child to respond and exit and reconnect database if is forked
$status = null;
pcntl_wait($status);
global $wpdb;
$wpdb->db_connect();
}
$response = [];
if(isset($request['collection_id'])) { // One Colletion
$collection_id = $request['collection_id'];
$items = $query;
if ($items->have_posts()) {
while ( $items->have_posts() ) { //TODO write line by line
$items->the_post();
$item = new Entities\Item($items->post);
$prepared_item = $this->prepare_item_for_response($item, $request);
array_push($response, $prepared_item);
}
wp_reset_postdata();
}
} elseif (isset($request['item_id'])) { // One Item
$item = new Entities\Item($request['item_id']);
if($item->get_id() > 0) {
$prepared_item = $this->prepare_item_for_response($item, $request);
$response = [$prepared_item];
}
} else { // Export All
$collections = $query;
$collection_controller = new REST_Collections_Controller();
if ($collections->have_posts()) {
while ($collections->have_posts()) {
$collections->the_post();
$collection_id = $collections->post->ID;
$collection = \Tainacan\Repositories\Repository::get_entity_by_post($collections->post);
$prepared_collection = $collection_controller->prepare_item_for_response($collection, $request);
$prepared_items = [];
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
if ($items->have_posts()) {
while ( $items->have_posts() ) { //TODO write line by line
$items->the_post();
$item = new Entities\Item($items->post);
$prepared_item = $this->prepare_item_for_response($item, $request);
array_push($prepared_items, $prepared_item);
}
wp_reset_postdata();
}
$prepared_collection['items'] = $prepared_items;
array_push($prepared_collection, $response);
}
wp_reset_postdata();
}
}
$rest_response = new \WP_REST_Response(apply_filters('tainacan-rest-response', $response, $request));
$data = $rest_response->get_data();
file_put_contents($filename, is_string($data) ? $data : print_r($data, true));
if($background) {
$log->set_status('publish');
$logs = \Tainacan\Repositories\Logs::get_instance();
$logs->update($log);
exit(1);
} else {
return $rest_response->get_data();
}
} catch (\Exception $e) {
if($background) {
exit(1);
} else {
throw $e;
}
}
} else { // we are the child
remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers_Handler::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers_Handler::get_instance(), 'rest_response'], 10, 2 ); // exposer types
return $log;
}
}
/**
* @param \WP_REST_Request $request
*
* @return \WP_Error|\WP_REST_Response
*/
public function get_items( $request ) {
$args = $this->prepare_filters($request); // TODO default args
$rest_response = new \WP_REST_Response([], 200); // TODO error, empty response
if(isset($request['collection_id'])) { // One Colletion
$collection_id = $request['collection_id'];
$items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
$response = $this->export($request, $items, $args);
$total_items = $items->found_posts;
$ret = $response instanceof Entity ? $response->__toArray() : $response;
$rest_response = new \WP_REST_Response($ret, 200);
$rest_response->header('X-WP-Total', (int) $total_items);
} elseif (isset($request['item_id'])) { // One Item
$item = new Entities\Item($request['item_id']);
if($item->get_id() > 0) {
$response = $this->export($request, $item, $args);
$total_items = 1;
$max_pages = 1;
$rest_response = new \WP_REST_Response($response->__toArray(), 200);
$rest_response->header('X-WP-Total', 1);
$rest_response->header('X-WP-TotalPages', 1);
}
} else { // Export All
$Tainacan_Collection = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collection->fetch(['post_status' => 'publish'], 'WP_Query');
$response = $this->export($request, $collections, $args);
$total_items = $collections->found_posts;
$ret = $response instanceof Entity ? $response->__toArray() : $response;
$rest_response = new \WP_REST_Response($ret, 200);
$rest_response->header('X-WP-Total', (int) $total_items);
}
return $rest_response;
}
/**
* @param \WP_REST_Request $request
*
* @return bool|\WP_Error
* @throws \Exception
*/
public function get_items_permissions_check( $request ) {
return $this->get_item_permissions_check($request);
}
}
?>

View File

@ -59,7 +59,6 @@ class REST_Filter_Types_Controller extends REST_Controller {
$filter_type = new $name(); $filter_type = new $name();
$filter_arr = $filter_type->_toArray(); $filter_arr = $filter_type->_toArray();
$filter_arr['name'] = $item;
return $filter_arr; return $filter_arr;
} }

View File

@ -83,8 +83,8 @@ class REST_Filters_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array( 'args' => array(
'permanently' => array( 'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'), 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
'default' => 'false' 'default' => '0'
), ),
) )
), ),
@ -122,13 +122,11 @@ class REST_Filters_Controller extends REST_Controller {
if(empty($received_type)){ if(empty($received_type)){
throw new \InvalidArgumentException('The type can\'t be empty'); throw new \InvalidArgumentException('The type can\'t be empty');
} elseif(!strrchr($received_type, '_')){ } elseif(!strrchr($received_type, '_')){
$received_type = ucfirst(strtolower($received_type)); $type = ucfirst(strtolower($received_type));
} else { } else {
$received_type = ucwords(strtolower($received_type), '_'); $type = ucwords(strtolower($received_type), '_\\');
} }
$type = "Tainacan\Filter_Types\\$received_type";
$filter_type = new $type(); $filter_type = new $type();
foreach ($filter as $attribute => $value){ foreach ($filter as $attribute => $value){
@ -467,10 +465,9 @@ class REST_Filters_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) { public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array( $endpoint_args = array_merge(
'type' => 'string', $endpoint_args,
'default' => 'view', parent::get_wp_query_params()
'items' => array( 'view, edit' )
); );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) { } elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->filter_repository->get_map(); $map = $this->filter_repository->get_map();
@ -496,16 +493,17 @@ class REST_Filters_Controller extends REST_Controller {
* @return array|void * @return array|void
*/ */
public function get_wp_query_params() { public function get_wp_query_params() {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_wp_query_params());
$query_params['name'] = array( $query_params['name'] = array(
'description' => __('Limits the result set to filters with a specific name'), 'description' => __('Limits the result set to filters with a specific name'),
'type' => 'string', 'type' => 'string',
); );
$query_params = array_merge($query_params, parent::get_meta_queries_params()); $query_params = array_merge(
$query_params,
parent::get_wp_query_params(),
parent::get_meta_queries_params()
);
return $query_params; return $query_params;
} }

View File

@ -267,7 +267,7 @@ class REST_Importers_Controller extends REST_Controller {
if ( method_exists($importer, 'get_source_special_fields') ) { if ( method_exists($importer, 'get_source_special_fields') ) {
$response['source_special_fields'] = $importer->get_source_special_fields(); $response['source_special_fields'] = $importer->get_source_special_fields();
} }
$Tainacan_Importer_Handler->save_importer_instance($importer);
return new \WP_REST_Response( $response, 200 ); return new \WP_REST_Response( $response, 200 );
} }

View File

@ -56,7 +56,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'), 'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'), 'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_wp_query_params(), 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
) )
) )
); );
@ -268,7 +268,12 @@ class REST_Item_Metadata_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) { public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = []; $endpoint_args = [];
if ($method === \WP_REST_Server::EDITABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args = array_merge(
$endpoint_args,
$this->get_wp_query_params()
);
} elseif ($method === \WP_REST_Server::EDITABLE) {
$endpoint_args['values'] = [ $endpoint_args['values'] = [
'type' => 'array/string/object/integer', 'type' => 'array/string/object/integer',
'items' => [ 'items' => [
@ -290,7 +295,15 @@ class REST_Item_Metadata_Controller extends REST_Controller {
* @return array * @return array
*/ */
public function get_wp_query_params() { public function get_wp_query_params() {
$query_params['context']['default'] = 'view'; $query_params['context'] = array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
),
);
return $query_params; return $query_params;
} }

View File

@ -80,8 +80,8 @@ class REST_Items_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array( 'args' => array(
'permanently' => array( 'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection', 'tainacan'), 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection', 'tainacan'),
'default' => 'false' 'default' => '0'
), ),
) )
), ),
@ -757,15 +757,18 @@ class REST_Items_Controller extends REST_Controller {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['fetch_only'] = array(
'type' => 'string/array',
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ),
);
$endpoint_args['context'] = array( $endpoint_args['context'] = array(
'type' => 'string', 'type' => 'string',
'default' => 'view', 'default' => 'view',
'items' => array( 'view, edit' ) 'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
),
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_fetch_only_param()
); );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) { } elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->items_repository->get_map(); $map = $this->items_repository->get_map();
@ -791,16 +794,16 @@ class REST_Items_Controller extends REST_Controller {
* @return array|void * @return array|void
*/ */
public function get_wp_query_params() { public function get_wp_query_params() {
$query_params['context']['default'] = 'view';
array_merge($query_params, parent::get_wp_query_params());
$query_params['title'] = array( $query_params['title'] = array(
'description' => __('Limits the result set to items with a specific title'), 'description' => __('Limits the result set to items with a specific title'),
'type' => 'string', 'type' => 'string',
); );
$query_params = array_merge($query_params, parent::get_meta_queries_params()); $query_params = array_merge(
$query_params,
parent::get_wp_query_params(),
parent::get_meta_queries_params()
);
return $query_params; return $query_params;
} }

View File

@ -38,7 +38,17 @@ class REST_Logs_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'), 'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'), 'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE) 'args' => array(
'context' => array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
)
),
),
), ),
'schema' => [$this, 'get_schema'] 'schema' => [$this, 'get_schema']
) )
@ -351,10 +361,9 @@ class REST_Logs_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) { public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array( $endpoint_args = array_merge(
'type' => 'string', $endpoint_args,
'default' => 'view', parent::get_wp_query_params()
'items' => array( 'view' )
); );
} }

View File

@ -44,24 +44,33 @@ class REST_Metadata_Controller extends REST_Controller {
public function register_routes() { public function register_routes() {
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<metadatum_id>[\d]+)', register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<metadatum_id>[\d]+)',
array( array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => array(
'context' => array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
)
),
),
),
array( array(
'methods' => \WP_REST_Server::EDITABLE, 'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item'), 'callback' => array($this, 'update_item'),
'permission_callback' => array($this, 'update_item_permissions_check'), 'permission_callback' => array($this, 'update_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE) 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
), ),
// ENDPOINT X. THIS ENDPOINT DO THE SAME THING OF ENDPOINT Z. I hope in a brief future it function changes.
array( array(
'methods' => \WP_REST_Server::DELETABLE, 'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'), 'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
), ),
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
),
'schema' => [$this, 'get_schema'] 'schema' => [$this, 'get_schema']
) )
); );
@ -84,28 +93,38 @@ class REST_Metadata_Controller extends REST_Controller {
); );
register_rest_route($this->namespace, '/' . $this->rest_base, register_rest_route($this->namespace, '/' . $this->rest_base,
array( array(
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'create_item'),
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
),
array( array(
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'), 'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'), 'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_wp_query_params(), 'args' => $this->get_wp_query_params(),
), ),
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'create_item'),
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
),
'schema' => [$this, 'get_schema'], 'schema' => [$this, 'get_schema'],
) )
); );
register_rest_route($this->namespace, '/'. $this->rest_base . '/(?P<metadatum_id>[\d]+)', register_rest_route($this->namespace, '/'. $this->rest_base . '/(?P<metadatum_id>[\d]+)',
array( array(
// ENDPOINT Z.
array( array(
'methods' => \WP_REST_Server::DELETABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'delete_item'), 'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'delete_item_permissions_check') 'permission' => array($this, 'get_item_permissions_check'),
'args' => array(
'context' => array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
)
),
),
), ),
array( array(
'methods' => \WP_REST_Server::EDITABLE, 'methods' => \WP_REST_Server::EDITABLE,
@ -114,10 +133,9 @@ class REST_Metadata_Controller extends REST_Controller {
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE) 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
), ),
array( array(
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'get_item'), 'callback' => array($this, 'delete_item'),
'permission' => array($this, 'get_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check')
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
), ),
'schema' => [$this, 'get_schema'], 'schema' => [$this, 'get_schema'],
) )
@ -564,10 +582,9 @@ class REST_Metadata_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) { public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array( $endpoint_args = array_merge(
'type' => 'string', $endpoint_args,
'default' => 'view', parent::get_wp_query_params()
'items' => array( 'view, edit' )
); );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) { } elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->metadatum_repository->get_map(); $map = $this->metadatum_repository->get_map();

View File

@ -54,7 +54,21 @@ class REST_Taxonomies_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE, 'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'), 'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'), 'permission_callback' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE) 'args' => array(
'context' => array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
)
),
'fetch_only' => array(
'type' => 'string/array',
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.', 'tainacan' ),
)
)
), ),
array( array(
'methods' => \WP_REST_Server::DELETABLE, 'methods' => \WP_REST_Server::DELETABLE,
@ -62,8 +76,8 @@ class REST_Taxonomies_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array( 'args' => array(
'permanently' => array( 'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'), 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
'default' => 'false', 'default' => '0',
), ),
) )
), ),
@ -452,15 +466,10 @@ class REST_Taxonomies_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) { public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['fetch_only'] = array( $endpoint_args = array_merge(
'type' => 'string/array', $endpoint_args,
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ), parent::get_wp_query_params(),
); parent::get_fetch_only_param()
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
); );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) { } elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->taxonomy_repository->get_map(); $map = $this->taxonomy_repository->get_map();

View File

@ -56,8 +56,9 @@ class REST_Terms_Controller extends REST_Controller {
'callback' => array($this, 'delete_item'), 'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check'), 'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => [ 'args' => [
'info' => [ 'permanently' => [
'description' => __('Delete term permanently.') 'description' => __('Delete term permanently.'),
'default' => '1'
] ]
] ]
), ),
@ -420,10 +421,9 @@ class REST_Terms_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) { public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = []; $endpoint_args = [];
if($method === \WP_REST_Server::READABLE) { if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array( $endpoint_args = array_merge(
'type' => 'string', $endpoint_args,
'default' => 'view', parent::get_wp_query_params()
'items' => array( 'view, edit' )
); );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) { } elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->terms_repository->get_map(); $map = $this->terms_repository->get_map();

View File

@ -19,7 +19,6 @@ $rest_background_processes_controller = new \Tainacan\API\EndPoints\REST_Back
$rest_bulkedit_controller = new \Tainacan\API\EndPoints\REST_Bulkedit_Controller(); $rest_bulkedit_controller = new \Tainacan\API\EndPoints\REST_Bulkedit_Controller();
$rest_exposers_controller = new \Tainacan\API\EndPoints\REST_Exposers_Controller(); $rest_exposers_controller = new \Tainacan\API\EndPoints\REST_Exposers_Controller();
$rest_roles_controller = new \Tainacan\API\EndPoints\REST_Roles_Controller(); $rest_roles_controller = new \Tainacan\API\EndPoints\REST_Roles_Controller();
new \Tainacan\API\EndPoints\REST_Export_Controller();
new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller(); new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller();
$rest_facets_controller = new \Tainacan\API\EndPoints\REST_Facets_Controller(); $rest_facets_controller = new \Tainacan\API\EndPoints\REST_Facets_Controller();
$rest_oaipmh_expose_controller = new \Tainacan\API\EndPoints\REST_Oaipmh_Expose_Controller(); $rest_oaipmh_expose_controller = new \Tainacan\API\EndPoints\REST_Oaipmh_Expose_Controller();

View File

@ -584,7 +584,7 @@ class Elastic_Press {
} }
if($search != '') { if($search != '') {
$formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field.name.raw" => "*$search*"]]; $formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field.name.sortable" => "*$search*"]];
} }
} else { } else {
$aggs[$id] = [ $aggs[$id] = [
@ -613,7 +613,7 @@ class Elastic_Press {
$field_relationship_label = "$field_relationship_label[0].$field_relationship_label[1].relationship_label"; $field_relationship_label = "$field_relationship_label[0].$field_relationship_label[1].relationship_label";
//$formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field" => "*$search*"]]; //$formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field" => "*$search*"]];
$formatted_args['query']['bool']['must'][] = ["bool"=>["should"=>[ $formatted_args['query']['bool']['must'][] = ["bool"=>["should"=>[
["wildcard"=>["$field"=>"*$search*"]], ["wildcard"=>["$id.value.sortable"=>"*$search*"]],
["wildcard"=>["$field_relationship_label"=>"*$search*"]] //pega nome do metadado é melhor! ["wildcard"=>["$field_relationship_label"=>"*$search*"]] //pega nome do metadado é melhor!
]]]; ]]];
} }

View File

@ -11,6 +11,8 @@ class Private_Files {
private static $instance = null; private static $instance = null;
public $dir_separator;
public static function get_instance() { public static function get_instance() {
if(!isset(self::$instance)) { if(!isset(self::$instance)) {
self::$instance = new self(); self::$instance = new self();
@ -20,6 +22,11 @@ class Private_Files {
} }
protected function __construct() { protected function __construct() {
// Once upon a time I thought I had to worry about Windows and use DIRECTORY_SEPARATOR
// but this only gave me frustration and bugs.
$this->dir_separator = '/';
add_filter('wp_handle_upload_prefilter', [$this, 'pre_upload']); add_filter('wp_handle_upload_prefilter', [$this, 'pre_upload']);
add_filter('wp_handle_sideload_prefilter', [$this, 'pre_upload']); add_filter('wp_handle_sideload_prefilter', [$this, 'pre_upload']);
add_filter('wp_handle_upload', [$this, 'post_upload']); add_filter('wp_handle_upload', [$this, 'post_upload']);
@ -160,8 +167,8 @@ class Private_Files {
$path['path'] = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month) $path['path'] = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
$path['url'] = str_replace($path['subdir'], '/' . $tainacan_basepath . '/' . $col_id_url . '/' . $item_id_url, $path['url']); $path['url'] = str_replace($path['subdir'], '/' . $tainacan_basepath . '/' . $col_id_url . '/' . $item_id_url, $path['url']);
$path['path'] .= DIRECTORY_SEPARATOR . $tainacan_basepath . DIRECTORY_SEPARATOR . $col_id . '/' . $item_id; $path['path'] .= $this->dir_separator . $tainacan_basepath . $this->dir_separator . $col_id . $this->dir_separator . $item_id;
$path['subdir'] = DIRECTORY_SEPARATOR . $tainacan_basepath . DIRECTORY_SEPARATOR . $col_id . '/' . $item_id; $path['subdir'] = $this->dir_separator . $tainacan_basepath . $this->dir_separator . $col_id . $this->dir_separator . $item_id;
} }
@ -193,31 +200,31 @@ class Private_Files {
$requested_uri = str_replace('/' . $this->get_private_folder_prefix(), '/', $requested_uri); $requested_uri = str_replace('/' . $this->get_private_folder_prefix(), '/', $requested_uri);
$file_path = \str_replace( '/', DIRECTORY_SEPARATOR, str_replace($base_upload_url, '', $requested_uri) ); $file_path = \str_replace( '/', $this->dir_separator, str_replace($base_upload_url, '', $requested_uri) );
$file = $upload_dir['basedir'] . $file_path; $file = $upload_dir['basedir'] . $file_path;
$existing_file = false; $existing_file = false;
$file_dirs = explode(DIRECTORY_SEPARATOR, $file); $file_dirs = explode($this->dir_separator, $file);
$file_dirs_size = sizeof($file_dirs); $file_dirs_size = sizeof($file_dirs);
$item_id = $file_dirs[$file_dirs_size-2]; $item_id = $file_dirs[$file_dirs_size-2];
$collection_id = $file_dirs[$file_dirs_size-3]; $collection_id = $file_dirs[$file_dirs_size-3];
// private item // private item
$prefixed_file = str_replace( DIRECTORY_SEPARATOR . $item_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $item_id . DIRECTORY_SEPARATOR, $file); $prefixed_file = str_replace( $this->dir_separator . $item_id . $this->dir_separator, $this->dir_separator . $this->get_private_folder_prefix() . $item_id . $this->dir_separator, $file);
if ( \file_exists( $prefixed_file ) ) { if ( \file_exists( $prefixed_file ) ) {
$existing_file = $prefixed_file; $existing_file = $prefixed_file;
} }
// private collection // private collection
$prefixed_collection = str_replace( DIRECTORY_SEPARATOR . $collection_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $collection_id . DIRECTORY_SEPARATOR, $file); $prefixed_collection = str_replace( $this->dir_separator . $collection_id . $this->dir_separator, $this->dir_separator . $this->get_private_folder_prefix() . $collection_id . $this->dir_separator, $file);
if ( !$existing_file && \file_exists( $prefixed_collection ) ) { if ( !$existing_file && \file_exists( $prefixed_collection ) ) {
$existing_file = $prefixed_collection; $existing_file = $prefixed_collection;
} }
// private both // private both
$prefixed_both = str_replace( DIRECTORY_SEPARATOR . $collection_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $collection_id . DIRECTORY_SEPARATOR, $prefixed_file); $prefixed_both = str_replace( $this->dir_separator . $collection_id . $this->dir_separator, $this->dir_separator . $this->get_private_folder_prefix() . $collection_id . $this->dir_separator, $prefixed_file);
if ( !$existing_file && \file_exists( $prefixed_both ) ) { if ( !$existing_file && \file_exists( $prefixed_both ) ) {
$existing_file = $prefixed_both; $existing_file = $prefixed_both;
} }
@ -255,7 +262,7 @@ class Private_Files {
*/ */
function image_get_intermediate_size($data, $post_id, $size) { function image_get_intermediate_size($data, $post_id, $size) {
$data['path'] = str_replace(DIRECTORY_SEPARATOR . $this->get_private_folder_prefix(), DIRECTORY_SEPARATOR, $data['path']); $data['path'] = str_replace($this->dir_separator . $this->get_private_folder_prefix(), $this->dir_separator, $data['path']);
$data['url'] = str_replace('/' . $this->get_private_folder_prefix(), '/', $data['url']); $data['url'] = str_replace('/' . $this->get_private_folder_prefix(), '/', $data['url']);
return $data; return $data;
@ -278,8 +285,8 @@ class Private_Files {
*/ */
function update_item_and_collection($obj) { function update_item_and_collection($obj) {
$folder = DIRECTORY_SEPARATOR; $folder = $this->dir_separator;
$check_folder = DIRECTORY_SEPARATOR; $check_folder = $this->dir_separator;
$check = false; $check = false;
if ( $obj instanceof \Tainacan\Entities\Collection ) { if ( $obj instanceof \Tainacan\Entities\Collection ) {
@ -298,11 +305,11 @@ class Private_Files {
$collection = $obj->get_collection(); $collection = $obj->get_collection();
$col_status_object = get_post_status_object($collection->get_status()); $col_status_object = get_post_status_object($collection->get_status());
$folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . DIRECTORY_SEPARATOR; $folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . $this->dir_separator;
$check_folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . DIRECTORY_SEPARATOR; $check_folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . $this->dir_separator;
$folder .= DIRECTORY_SEPARATOR; $folder .= $this->dir_separator;
$check_folder .= DIRECTORY_SEPARATOR; $check_folder .= $this->dir_separator;
$status_obj = get_post_status_object($obj->get_status()); $status_obj = get_post_status_object($obj->get_status());
@ -317,8 +324,8 @@ class Private_Files {
$upload_dir = wp_get_upload_dir(); $upload_dir = wp_get_upload_dir();
$base_dir = $upload_dir['basedir']; $base_dir = $upload_dir['basedir'];
$full_path = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . $folder; $full_path = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $folder;
$full_path_check = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . $check_folder; $full_path_check = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $check_folder;
if (\file_exists($full_path_check)) { if (\file_exists($full_path_check)) {
rename($full_path_check, $full_path); rename($full_path_check, $full_path);
@ -346,7 +353,7 @@ class Private_Files {
$upload_dir = wp_get_upload_dir(); $upload_dir = wp_get_upload_dir();
$base_dir = $upload_dir['basedir']; $base_dir = $upload_dir['basedir'];
$full_path = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $prefix; $full_path = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $this->dir_separator . '*' . $this->dir_separator . $prefix;
foreach ($ids as $id) { foreach ($ids as $id) {
$folder = $full_path . $id; $folder = $full_path . $id;
@ -355,9 +362,9 @@ class Private_Files {
if (sizeof($found) == 1 && isset($found[0])) { if (sizeof($found) == 1 && isset($found[0])) {
if ($status_obj->public) { if ($status_obj->public) {
$target = str_replace(DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $id, DIRECTORY_SEPARATOR . $id, $found[0]); $target = str_replace($this->dir_separator . $this->get_private_folder_prefix() . $id, $this->dir_separator . $id, $found[0]);
} else { } else {
$target = str_replace(DIRECTORY_SEPARATOR . $id, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $id, $found[0]); $target = str_replace($this->dir_separator . $id, $this->dir_separator . $this->get_private_folder_prefix() . $id, $found[0]);
} }
rename($found[0], $target); rename($found[0], $target);

View File

@ -366,7 +366,7 @@ class Entity {
$attributes = []; $attributes = [];
foreach($map as $prop => $content) { foreach($map as $prop => $content) {
$attributes[$prop] = $this->get_mapped_property($prop); $attributes[$prop] = $this->get($prop);
} }
$hook_prefix = self::get_post_type(); $hook_prefix = self::get_post_type();

View File

@ -152,7 +152,7 @@ class Filter extends Entity {
} }
$object_type = new $class_name(); $object_type = new $class_name();
$object_type->set_options( $this->get_filter_type_options() ); $object_type->set_options( $this->get_mapped_property('filter_type_options') );
return $object_type; return $object_type;
} }
@ -171,6 +171,10 @@ class Filter extends Entity {
* @return array Configurations for the filter type object * @return array Configurations for the filter type object
*/ */
function get_filter_type_options(){ function get_filter_type_options(){
$object = $this->get_filter_type_object();
if ($object) {
return $object->get_options(); // merge with dedault filter type options
}
return $this->get_mapped_property('filter_type_options'); return $this->get_mapped_property('filter_type_options');
} }

View File

@ -444,25 +444,29 @@ class Item_Metadata_Entity extends Entity {
} }
if ($this->is_required() && !$one_filled) { if ($this->is_required() && !$one_filled) {
$this->add_error('required', $metadatum->get_name() . ' is required'); // translators: %s = metadatum name. ex: Title is required
$this->add_error( 'required', sprintf( __('%s is required', 'tainacan'), $metadatum->get_name() ) );
return false; return false;
} }
if (!$valid) { if (!$valid) {
$this->add_error('invalid', $metadatum->get_name() . ' is invalid'); // translators: %s = metadatum name. ex: Title is invalid
$this->add_error( 'invalid', sprintf( __('%s is invalid', 'tainacan'), $metadatum->get_name() ) );
return false; return false;
} }
$this->set_as_valid(); $this->set_as_valid();
return true; return true;
} else { } else {
$this->add_error('invalid', $metadatum->get_name() . ' is invalid'); // translators: %s = metadatum name. ex: Title is invalid
$this->add_error( 'invalid', sprintf( __('%s is invalid', 'tainacan'), $metadatum->get_name() ) );
return false; return false;
} }
} else { } else {
if( is_array($value) ){ if( is_array($value) ){
$this->add_error('not_multiple', $metadatum->get_name() . ' do not accept array as value'); // translators: %s = metadatum name. ex: Title accepts only one single value and not a list of values
$this->add_error( 'not_multiple', sprintf( __('%s accepts only one single value and not a list of values', 'tainacan'), $metadatum->get_name() ) );
return false; return false;
} }
@ -480,7 +484,8 @@ class Item_Metadata_Entity extends Entity {
], $item->get_collection()); ], $item->get_collection());
if ($test->have_posts()) { if ($test->have_posts()) {
$this->add_error('key_exists', $metadatum->get_name() . ' is a collection key and there is another item with the same value'); // translators: %s = metadatum name. ex: Register ID is a collection key and there is another item with the same value
$this->add_error( 'key_exists', sprintf( __('%s is a collection key and there is another item with the same value', 'tainacan'), $metadatum->get_name() ) );
return false; return false;
} }
} }

View File

@ -120,6 +120,14 @@ class Log extends Entity {
return $this->get_mapped_property( 'date' ); return $this->get_mapped_property( 'date' );
} }
/**
* Return the log slug
*
* @return mixed|null
*/
function get_slug() {
return $this->get_mapped_property( 'slug' );
}
/** /**
* Return the Log description * Return the Log description
@ -228,7 +236,7 @@ class Log extends Entity {
} }
public function get_object_type() { public function get_object_type() {
$this->get_mapped_property('object_type'); return $this->get_mapped_property('object_type');
} }
public function set_object_type($value) { public function set_object_type($value) {
@ -236,7 +244,7 @@ class Log extends Entity {
} }
public function get_object_id() { public function get_object_id() {
$this->get_mapped_property('object_id'); return $this->get_mapped_property('object_id');
} }
public function set_object_id($value) { public function set_object_id($value) {
@ -258,7 +266,7 @@ class Log extends Entity {
} }
public function get_action() { public function get_action() {
$this->get_mapped_property('action'); return $this->get_mapped_property('action');
} }
public function set_action($value) { public function set_action($value) {

View File

@ -178,7 +178,7 @@ class Metadatum extends Entity {
} }
$object_type = new $class_name(); $object_type = new $class_name();
$object_type->set_options( $this->get_metadata_type_options() ); $object_type->set_options( $this->get_mapped_property('metadata_type_options') );
return $object_type; return $object_type;
} }
@ -197,6 +197,10 @@ class Metadatum extends Entity {
* @return array Configurations for the metadatum type object * @return array Configurations for the metadatum type object
*/ */
function get_metadata_type_options(){ function get_metadata_type_options(){
$object = $this->get_metadata_type_object();
if ($object) {
return $object->get_options(); // merge with dedault metadata type options
}
return $this->get_mapped_property('metadata_type_options'); return $this->get_mapped_property('metadata_type_options');
} }

View File

@ -81,6 +81,7 @@ class Taxonomy extends Entity {
'rewrite' => [ 'rewrite' => [
'slug' => $this->get_slug() 'slug' => $this->get_slug()
], ],
'update_count_callback' => '_update_generic_term_count'
); );
if (taxonomy_exists($this->get_db_identifier())){ if (taxonomy_exists($this->get_db_identifier())){

View File

@ -54,11 +54,11 @@
}, },
watch: { watch: {
'query.metaquery'() { 'query.metaquery'() {
this.selectedValues(); this.updateSelectedValues();
}, },
}, },
mounted() { mounted() {
this.selectedValues(); this.updateSelectedValues();
}, },
methods: { methods: {
onSelect(option){ onSelect(option){
@ -74,7 +74,7 @@
collection_id: this.collectionId, collection_id: this.collectionId,
value: this.selected value: this.selected
}); });
this.selectedValues(); this.updateSelectedValues();
}, },
search: _.debounce( function(query) { search: _.debounce( function(query) {
@ -111,7 +111,7 @@
}); });
} }
}, 500), }, 500),
selectedValues(){ updateSelectedValues(){
if (!this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery )) if (!this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ))
return false; return false;
@ -122,8 +122,11 @@
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') { if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') {
axios.get('/items/' + metadata.value + '?fetch_only=title,thumbnail') let endpoint = '/items/' + metadata.value + '?fetch_only=title,thumbnail';
axios.get(endpoint)
.then( res => { .then( res => {
let item = res.data; let item = res.data;
this.label = item.title; this.label = item.title;
this.selected = item.title; this.selected = item.title;
@ -136,11 +139,11 @@
} else { } else {
this.label = metadata.value; this.label = metadata.value;
this.selected = metadata.value; this.selected = metadata.value;
this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected }); this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected });
} }
} else { } else {
return false; this.label = '';
this.selected = '';
} }
} }
} }

View File

@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Autocomplete extends Filter_Type { class Autocomplete extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Autocomplete'); $this->set_name( __('Autocomplete', 'tainacan') );
$this->set_supported_types(['string','long_string','item']); $this->set_supported_types(['string','long_string','item']);
$this->set_component('tainacan-filter-autocomplete'); $this->set_component('tainacan-filter-autocomplete');
$this->set_use_max_options(false); $this->set_use_max_options(false);

View File

@ -70,7 +70,7 @@
this.loadOptions(); this.loadOptions();
}, },
methods: { methods: {
loadOptions(skipSelected) { loadOptions() {
let promise = null; let promise = null;
// Cancels previous Request // Cancels previous Request
@ -82,27 +82,18 @@
else else
promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' ); promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' );
if (skipSelected != undefined && skipSelected == true) {
promise.request promise.request
.then(() => { .then(() => {
if (this.options.length > this.filter.max_options) this.updateSelectedValues();
this.options.splice(this.filter.max_options);
}).catch((error) => {
this.$console.error(error);
});
} else {
promise.request
.then(() => {
this.selectedValues();
}) })
.catch( (error) => { .catch( (error) => {
if (isCancel(error)) { if (isCancel(error)) {
this.$console.log('Request canceled: ' + error.message); this.$console.log('Request canceled: ' + error.message);
this.selectedValues(); this.updateSelectedValues();
} else } else
this.$console.error( error ); this.$console.error( error );
}); });
}
// Search Request Token for cancelling // Search Request Token for cancelling
this.getOptionsValuesCancel = promise.source; this.getOptionsValuesCancel = promise.source;
}, },
@ -115,7 +106,7 @@
value: this.selected value: this.selected
}); });
}, },
selectedValues() { updateSelectedValues() {
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;

View File

@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Checkbox extends Filter_Type { class Checkbox extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Checkbox List'); $this->set_name( __('Checkbox List', 'tainacan') );
$this->set_supported_types(['string','long_string','item']); $this->set_supported_types(['string','long_string','item']);
$this->set_component('tainacan-filter-checkbox'); $this->set_component('tainacan-filter-checkbox');
$this->set_preview_template(' $this->set_preview_template('

View File

@ -1,269 +0,0 @@
<template>
<div>
<!-- Date -->
<div v-if="metadatumType === 'Tainacan\\Metadata_Types\\Date'">
<b-datepicker
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
v-model="date_init"
size="is-small"
@focus="isTouched = true"
@input="validate_values()"
editable
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
icon="calendar-today"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
$i18n.get('datepicker_short_tuesday'),
$i18n.get('datepicker_short_wednesday'),
$i18n.get('datepicker_short_thursday'),
$i18n.get('datepicker_short_friday'),
$i18n.get('datepicker_short_saturday'),
]"/>
<p class="is-size-7 has-text-centered is-marginless">{{ $i18n.get('label_until') }}</p>
<b-datepicker
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
v-model="date_end"
size="is-small"
@input="validate_values()"
@focus="isTouched = true"
editable
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
icon="calendar-today"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
$i18n.get('datepicker_short_tuesday'),
$i18n.get('datepicker_short_wednesday'),
$i18n.get('datepicker_short_thursday'),
$i18n.get('datepicker_short_friday'),
$i18n.get('datepicker_short_saturday'),
]"/>
</div>
<!-- Numeric -->
<div v-else>
<b-input
type="number"
:aria-labelledby="'filter-label-id-' + filter.id"
size="is-small"
step="any"
@input="validate_values"
v-model="value_init"/>
<p class="is-size-7 has-text-centered is-marginless">{{ $i18n.get('label_until') }}</p>
<b-input
type="number"
:aria-labelledby="'filter-label-id-' + filter.id"
size="is-small"
step="any"
@input="validate_values"
@focus="isTouched = true"
v-model="value_end"/>
</div>
</div>
</template>
<script>
import { wpAjax, dateInter } from "../../../admin/js/mixins";
import { filterTypeMixin } from '../filter-types-mixin';
import moment from 'moment';
export default {
mixins: [
wpAjax,
dateInter,
filterTypeMixin
],
mounted() {
this.selectedValues();
},
data(){
return {
value_init: '',
value_end: '',
date_init: undefined,
date_end: undefined,
isTouched: false,
isValid: false,
clear: false,
type: 'DECIMAL'
}
},
watch: {
isTouched( val ){
if ( val && this.date_init === null)
this.date_init = new Date();
if ( val && this.date_end === null)
this.date_end = new Date();
},
'query.metaquery'() {
this.selectedValues();
}
},
methods: {
// only validate if the first value is higher than first
validate_values: _.debounce( function (){
if( this.metadatumType === 'Tainacan\\Metadata_Types\\Date' ){
if (this.date_init === undefined)
this.date_init = new Date();
if (this.date_end === undefined)
this.date_end = new Date();
if ( this.date_init > this.date_end ) {
this.error_message();
return
}
} else {
if (this.value_init.constructor == Number)
this.value_init = this.value_init.valueOf();
if (this.value_end.constructor == Number)
this.value_end = this.value_end.valueOf();
this.value_init = parseFloat(this.value_init);
this.value_end = parseFloat(this.value_end);
if (isNaN(this.value_init) || isNaN(this.value_end))
return
if (this.value_init > this.value_end) {
this.error_message();
return;
}
}
this.emit();
}, 800),
// message for error
error_message(){
if ( !this.isTouched ) return false;
this.$buefy.toast.open({
duration: 3000,
message: this.$i18n.get('info_error_first_value_greater'),
position: 'is-bottom',
type: 'is-danger'
})
},
dateFormatter(dateObject){
return moment(dateObject, moment.ISO_8601).format(this.dateFormat);
},
dateParser(dateString){
return moment(dateString, this.dateFormat).toDate();
},
selectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId);
if (index >= 0) {
let metadata = this.query.metaquery[ index ];
if( metadata.value && metadata.value.length > 0 && this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric'){
this.value_init = parseFloat(metadata.value[0]);
this.value_end = parseFloat(metadata.value[1]);
this.isValid = true;
} else if( metadata.value && metadata.value.length > 0 ){
this.date_init = new Date(metadata.value[0]);
this.date_end = new Date(metadata.value[1]);
this.isValid = true;
}
if (metadata.value[0] != undefined && metadata.value[1] != undefined)
this.$emit('sendValuesToTags', {
label: (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric' ? (metadata.value[0] + ' - ' + metadata.value[1]) : this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1])),
value: [metadata.value[0], metadata.value[1]]
});
} else {
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric') {
this.value_init = '';
this.value_end = '';
} else {
this.date_init = null;
this.date_end = null;
}
}
},
// emit the operation for listeners
emit() {
let values = [];
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Date') {
if (this.date_init === null && this.date_end === null) {
values = [];
this.type = 'DATE';
this.isValid = false;
this.clear = true;
} else {
let date_init = this.date_init.getUTCFullYear() + '-' +
('00' + (this.date_init.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + this.date_init.getUTCDate()).slice(-2);
let date_end = this.date_end.getUTCFullYear() + '-' +
('00' + (this.date_end.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + this.date_end.getUTCDate()).slice(-2);
values = [ date_init, date_end ];
this.type = 'DATE';
this.isValid = true;
this.clear = false;
}
} else {
if (this.value_init === null || this.value_end === null
|| this.value_init === '' || this.value_end === ''){
return;
} else {
values = [ this.value_init, this.value_end ];
if(this.value_init !== this.value_end && (this.value_init % 1 !== 0 && this.value_end % 1 == 0)) {
this.type = 'DECIMAL';
} else if(this.value_init !== this.value_end &&
this.value_init % 1 !== 0 &&
this.value_end % 1 !== 0) {
this.type = '';
} else if(this.value_init !== this.value_end &&
!(this.value_init % 1 == 0 && this.value_end % 1 !== 0)){
this.type = 'DECIMAL';
} else {
this.type = '';
}
//this.isValid = true;
//this.clear = false;
}
}
this.$emit('input', {
filter: 'range',
type: this.type,
compare: 'BETWEEN',
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: values
});
if (values[0] != undefined && values[1] != undefined)
this.$emit( 'sendValuesToTags', {
label: (this.metadatumType === 'Tainacan\\Metadata_Types\\Numeric' ? (values[0] + ' - ' + values[1]) : this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1])),
value: [ values[0], values[1] ]
});
}
}
}
</script>
<style scoped>
.field {
margin-bottom: 0.125rem !important;
}
p.is-size-7 {
margin-bottom: 0.125rem !important;
}
</style>

View File

@ -1,74 +0,0 @@
<?php
namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Class TainacanMetadatumType
*/
class Custom_Interval extends Filter_Type {
function __construct(){
$this->set_name('Custom Interval');
$this->set_supported_types(['float','date']);
$this->set_component('tainacan-filter-custom-interval');
$this->set_use_max_options(false);
$this->set_preview_template('
<div>
<div class="b-numberinput field is-grouped">
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-minus"></i>
</span>
</button>
</p>
<div class="control is-small is-clearfix">
<input type="number" step="0.01" class="input is-small" value="6">
</div>
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-plus"></i>
</span>
</button>
</p>
</div>
<p class="is-size-7 has-text-centered is-marginless">until</p>
<div class="b-numberinput field is-grouped">
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-minus"></i>
</span>
</button>
</p>
<div class="control is-small is-clearfix">
<input type="number" step="0.01" class="input is-small" value="10">
</div>
<p class="control">
<button type="button" class="button is-primary is-small">
<span class="icon is-small">
<i class="mdi mdi-plus"></i>
</span>
</button>
</p>
</div>
</div>
');
}
/**
* @param $filter
* @return string
* @internal param $metadatum
*/
public function render( $filter ){
$type = ( $filter->get_metadatum()->get_metadata_type() === 'Tainacan\Metadata_Types\Date' ) ? 'date' : 'numeric';
return '<tainacan-filter-custom-interval
name="'.$filter->get_name().'"
collection_id="'.$filter->get_collection_id().'"
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-custom-interval>';
}
}

View File

@ -0,0 +1,181 @@
<template>
<div>
<b-datepicker
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
v-model="dateInit"
size="is-small"
@focus="isTouched = true"
@input="validadeValues()"
editable
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
icon="calendar-today"
:years-range="[-200, 100]"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
$i18n.get('datepicker_short_tuesday'),
$i18n.get('datepicker_short_wednesday'),
$i18n.get('datepicker_short_thursday'),
$i18n.get('datepicker_short_friday'),
$i18n.get('datepicker_short_saturday'),
]"/>
<p class="is-size-7 has-text-centered is-marginless">{{ $i18n.get('label_until') }}</p>
<b-datepicker
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('label_selectbox_init')"
v-model="dateEnd"
size="is-small"
@input="validadeValues()"
@focus="isTouched = true"
editable
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
icon="calendar-today"
:years-range="[-200, 50]"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
$i18n.get('datepicker_short_tuesday'),
$i18n.get('datepicker_short_wednesday'),
$i18n.get('datepicker_short_thursday'),
$i18n.get('datepicker_short_friday'),
$i18n.get('datepicker_short_saturday'),
]"/>
</div>
</template>
<script>
import { wpAjax, dateInter } from "../../../admin/js/mixins";
import { filterTypeMixin } from '../filter-types-mixin';
import moment from 'moment';
export default {
mixins: [
wpAjax,
dateInter,
filterTypeMixin
],
data(){
return {
dateInit: undefined,
dateEnd: undefined,
isTouched: false
}
},
watch: {
isTouched( val ){
if ( val && this.dateInit === null)
this.dateInit = new Date();
if ( val && this.dateEnd === null)
this.dateEnd = new Date();
},
'query.metaquery'() {
this.updateSelectedValues();
}
},
mounted() {
this.updateSelectedValues();
},
methods: {
// only validate if the first value is higher than first
validadeValues: _.debounce( function (){
if (this.dateInit === undefined)
this.dateInit = new Date();
if (this.dateEnd === undefined)
this.dateEnd = new Date();
if (this.dateInit > this.dateEnd) {
this.showErrorMessage();
return
}
this.emit();
}, 800),
showErrorMessage(){
if ( !this.isTouched ) return false;
this.$buefy.toast.open({
duration: 3000,
message: this.$i18n.get('info_error_first_value_greater'),
position: 'is-bottom',
type: 'is-danger'
})
},
dateFormatter(dateObject){
return moment(dateObject, moment.ISO_8601).format(this.dateFormat);
},
dateParser(dateString){
return moment(dateString, this.dateFormat).toDate();
},
updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId);
if (index >= 0) {
let metadata = this.query.metaquery[ index ];
if (metadata.value && metadata.value.length > 0){
this.dateInit = new Date(metadata.value[0]);
this.dateEnd = new Date(metadata.value[1]);
}
if (metadata.value[0] != undefined && metadata.value[1] != undefined)
this.$emit('sendValuesToTags', {
label: this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1]),
value: [metadata.value[0], metadata.value[1]]
});
} else {
this.dateInit = null;
this.dateEnd = null;
}
},
// emit the operation for listeners
emit() {
let values = [];
if (this.dateInit === null && this.dateEnd === null) {
values = [];
} else {
let dateInit = this.dateInit.getUTCFullYear() + '-' +
('00' + (this.dateInit.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + this.dateInit.getUTCDate()).slice(-2);
let dateEnd = this.dateEnd.getUTCFullYear() + '-' +
('00' + (this.dateEnd.getUTCMonth() + 1)).slice(-2) + '-' +
('00' + this.dateEnd.getUTCDate()).slice(-2);
values = [ dateInit, dateEnd ];
}
this.$emit('input', {
filter: 'range',
type: 'DATE',
compare: 'BETWEEN',
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: values
});
if (values[0] != undefined && values[1] != undefined)
this.$emit( 'sendValuesToTags', {
label: this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1]),
value: [ values[0], values[1] ]
});
}
}
}
</script>
<style scoped>
.field {
margin-bottom: 0.125rem !important;
}
p.is-size-7 {
margin-bottom: 0.125rem !important;
}
</style>

View File

@ -0,0 +1,55 @@
<?php
namespace Tainacan\Filter_Types;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Class TainacanMetadatumType
*/
class Date_Interval extends Filter_Type {
function __construct(){
$this->set_name( __('Date Interval', 'tainacan') );
$this->set_supported_types(['date']);
$this->set_component('tainacan-filter-date-interval');
$this->set_use_max_options(false);
$this->set_preview_template('
<div>
<div class="datepicker control is-small">
<div class="dropdown is-bottom-left is-mobile-modal">
<div role="button" class="dropdown-trigger">
<div class="control has-icons-left is-small is-clearfix">
<input type="text" autocomplete="off" placeholder=" '. __('Select a date', 'tainacan') .'" class="input is-small">
<span class="icon is-left is-small"><i class="mdi mdi-calendar-today"></i></span>
</div>
</div>
</div>
</div>
<p class="is-size-7 has-text-centered is-marginless">until</p>
<div class="datepicker control is-small">
<div class="dropdown is-bottom-left is-mobile-modal">
<div role="button" class="dropdown-trigger">
<div class="control has-icons-left is-small is-clearfix">
<input type="text" autocomplete="off" placeholder=" '. __('Select a date', 'tainacan') .'" class="input is-small">
<span class="icon is-left is-small"><i class="mdi mdi-calendar-today"></i></span>
</div>
</div>
</div>
</div>
</div>
');
}
/**
* @param $filter
* @return string
* @internal param $metadatum
*/
public function render( $filter ){
return '<tainacan-filter-date-interval
name="'.$filter->get_name().'"
collection_id="'.$filter->get_collection_id().'"
metadatum_id="'.$filter->get_metadatum()->get_id().'"></tainacan-filter-date-interval>';
}
}

View File

@ -78,6 +78,7 @@
:date-parser="(date) => dateParser(date)" :date-parser="(date) => dateParser(date)"
size="is-small" size="is-small"
icon="calendar-today" icon="calendar-today"
:years-range="[-200, 50]"
:day-names="[ :day-names="[
$i18n.get('datepicker_short_sunday'), $i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'), $i18n.get('datepicker_short_monday'),
@ -121,7 +122,7 @@
filterTypeMixin filterTypeMixin
], ],
mounted() { mounted() {
this.selectedValues(); this.updateSelectedValues();
}, },
data(){ data(){
return { return {
@ -131,7 +132,7 @@
}, },
watch: { watch: {
'query.metaquery'() { 'query.metaquery'() {
this.selectedValues(); this.updateSelectedValues();
} }
}, },
computed: { computed: {
@ -151,7 +152,7 @@
} }
}, },
methods: { methods: {
selectedValues(){ updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;

View File

@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Date extends Filter_Type { class Date extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Date'); $this->set_name( __('Date', 'tainacan') );
$this->set_supported_types(['date']); $this->set_supported_types(['date']);
$this->set_component('tainacan-filter-date'); $this->set_component('tainacan-filter-date');
// $this->set_form_component('tainacan-filter-form-date'); // $this->set_form_component('tainacan-filter-form-date');

View File

@ -228,4 +228,8 @@ abstract class Filter_Type {
public function set_form_component($form_component){ public function set_form_component($form_component){
$this->form_component = $form_component; $this->form_component = $form_component;
} }
public function get_filter_type() {
return str_replace( 'Tainacan\Filter_Types\\', '', get_class($this) );
}
} }

View File

@ -22,7 +22,7 @@ export const filterTypeMixin = {
this.collectionId = this.filter.collection_id ? this.filter.collection_id : this.collectionId; this.collectionId = this.filter.collection_id ? this.filter.collection_id : this.collectionId;
this.metadatumId = this.filter.metadatum.metadatum_id ? this.filter.metadatum.metadatum_id : this.metadatumId; this.metadatumId = this.filter.metadatum.metadatum_id ? this.filter.metadatum.metadatum_id : this.metadatumId;
this.filterTypeOptions = this.filter.filter_type_options ? this.filter.filter_type_options : this.filterTypeOptions; this.filterTypeOptions = this.filter.filter_type_options ? this.filter.filter_type_options : this.filterTypeOptions;
this.metadatumType = this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType; this.metadatumType = this.filter.metadatum.metadata_type_object && this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType;
} }
}; };

View File

@ -3,7 +3,7 @@
<b-numberinput <b-numberinput
:aria-labelledby="'filter-label-id-' + filter.id" :aria-labelledby="'filter-label-id-' + filter.id"
size="is-small" size="is-small"
@input="validate_values()" @input="validadeValues()"
:step="filterTypeOptions.step" :step="filterTypeOptions.step"
v-model="valueInit" v-model="valueInit"
/> />
@ -11,7 +11,7 @@
<b-numberinput <b-numberinput
:aria-labelledby="'filter-label-id-' + filter.id" :aria-labelledby="'filter-label-id-' + filter.id"
size="is-small" size="is-small"
@input="validate_values()" @input="validadeValues()"
:step="filterTypeOptions.step" :step="filterTypeOptions.step"
v-model="valueEnd"/> v-model="valueEnd"/>
@ -24,29 +24,45 @@
mixins: [ filterTypeMixin ], mixins: [ filterTypeMixin ],
data(){ data(){
return { return {
valueInit: 0, valueInit: null,
valueEnd: 10, valueEnd: null
isValid: false,
withError: false
} }
}, },
mounted() { mounted() {
this.selectedValues(); this.updateSelectedValues();
},
watch: {
'query.metaquery'() {
this.updateSelectedValues();
}
}, },
methods: { methods: {
// only validate if the first value is higher than first // only validate if the first value is higher than first
validate_values: _.debounce( function (){ validadeValues: _.debounce( function () {
if ( parseFloat( this.valueInit ) > parseFloat( this.valueEnd )) { if (this.valueInit == null || this.valueEnd == null)
//this.valueEnd = parseFloat( this.valueInit ) + 1; return
//this.withError = true;
if (this.valueInit.constructor == Number)
this.valueInit = this.valueInit.valueOf();
if (this.valueEnd.constructor == Number)
this.valueEnd = this.valueEnd.valueOf();
this.valueInit = parseFloat(this.valueInit);
this.valueEnd = parseFloat(this.valueEnd);
if (isNaN(this.valueInit) || isNaN(this.valueEnd))
return
if (this.valueInit > this.valueEnd) {
this.showErrorMessage();
return; return;
} }
//this.withError = false;
this.emit(); this.emit();
}, 600), }, 600),
// message for error // message for error
error_message(){ showErrorMessage(){
this.$buefy.toast.open({ this.$buefy.toast.open({
duration: 3000, duration: 3000,
message: this.$i18n.get('info_error_first_value_greater'), message: this.$i18n.get('info_error_first_value_greater'),
@ -61,7 +77,6 @@
this.$emit('input', { this.$emit('input', {
type: type, type: type,
//filter: 'range',
compare: 'BETWEEN', compare: 'BETWEEN',
metadatum_id: this.metadatumId, metadatum_id: this.metadatumId,
collection_id: this.collectionId, collection_id: this.collectionId,
@ -71,7 +86,7 @@
if (values[0] != undefined && values[1] != undefined) if (values[0] != undefined && values[1] != undefined)
this.$emit('sendValuesToTags', { label: values[0] + ' - ' + values[1], value: values }); this.$emit('sendValuesToTags', { label: values[0] + ' - ' + values[1], value: values });
}, },
selectedValues(){ updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;
@ -79,15 +94,16 @@
if ( index >= 0 ){ if ( index >= 0 ){
let metaquery = this.query.metaquery[ index ]; let metaquery = this.query.metaquery[ index ];
if ( metaquery.value && metaquery.value.length > 1 ) { if ( metaquery.value && metaquery.value.length > 1 ) {
this.valueInit = metaquery.value[0]; this.valueInit = new Number(metaquery.value[0]);
this.valueEnd = metaquery.value[1]; this.valueEnd = new Number(metaquery.value[1]);
} }
if (metaquery.value[0] != undefined && metaquery.value[1] != undefined) if (metaquery.value[0] != undefined && metaquery.value[1] != undefined)
this.$emit('sendValuesToTags', { label: this.valueInit + ' - ' + this.valueEnd, value: metaquery.values }); this.$emit('sendValuesToTags', { label: this.valueInit + ' - ' + this.valueEnd, value: metaquery.value });
} else { } else {
return false; this.valueInit = null;
this.valueEnd = null;
} }
}, },
} }

View File

@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Numeric_Interval extends Filter_Type { class Numeric_Interval extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Numeric Interval'); $this->set_name( __('Numeric Interval', 'tainacan') );
$this->set_supported_types(['float']); $this->set_supported_types(['float']);
$this->set_component('tainacan-filter-numeric-interval'); $this->set_component('tainacan-filter-numeric-interval');
$this->set_form_component('tainacan-filter-form-numeric-interval'); $this->set_form_component('tainacan-filter-form-numeric-interval');

View File

@ -1,4 +1,22 @@
<template> <template>
<div>
<b-field :addons="false">
<label class="label is-inline">
{{ $i18n.getHelperTitle('tainacan-filter-numeric-list-interval', 'showIntervalOnTag') }}<span>&nbsp;</span>
<help-button
:title="$i18n.getHelperTitle('tainacan-filter-numeric-list-interval', 'showIntervalOnTag')"
:message="$i18n.getHelperMessage('tainacan-filter-numeric-list-interval', 'showIntervalOnTag')"/>
</label>
<div>
<b-field>
<b-checkbox
v-model="showIntervalOnTag"
@input="onUpdateShowIntervalOnTag()">
{{ $i18n.get('info_show_interval_on_tag') }}
</b-checkbox>
</b-field>
</div>
</b-field>
<b-field :addons="false"> <b-field :addons="false">
<label class="label is-inline"> <label class="label is-inline">
{{ $i18n.getHelperTitle('tainacan-filter-numeric-list-interval', 'intervals') }}<span>&nbsp;</span> {{ $i18n.getHelperTitle('tainacan-filter-numeric-list-interval', 'intervals') }}<span>&nbsp;</span>
@ -6,27 +24,6 @@
:title="$i18n.getHelperTitle('tainacan-filter-numeric-list-interval', 'intervals')" :title="$i18n.getHelperTitle('tainacan-filter-numeric-list-interval', 'intervals')"
:message="$i18n.getHelperMessage('tainacan-filter-numeric-list-interval', 'intervals')"/> :message="$i18n.getHelperMessage('tainacan-filter-numeric-list-interval', 'intervals')"/>
</label> </label>
<div>
<b-field>
<b-checkbox v-model="showIntervalOnTag">
{{ $i18n.get('info_show_interval_on_tag') }}
</b-checkbox>
</b-field>
</div>
<div v-if="intervals.length == 0" >
<br>
<a
role="button"
@click="addInterval()"
class="is-inline add-link">
<span class="icon is-small">
<i class="tainacan-icon has-text-secondary tainacan-icon-add"/>
</span>
&nbsp;{{ $i18n.get('add_value') }}
</a>
</div>
<transition-group name="filter-item"> <transition-group name="filter-item">
<div <div
class="options-input" class="options-input"
@ -34,23 +31,25 @@
:key="index"> :key="index">
<b-field> <b-field>
<b-input <b-input
expanded="true" expanded
:placeholder="$i18n.get('label')" :placeholder="$i18n.get('label')"
@input="onUpdate(interval)" @input="onUpdate(interval)"
v-model="interval.label" /> v-model="interval.label" />
</b-field> </b-field>
<b-field> <b-field>
<b-input <b-input
expanded
type="number" type="number"
step="0.01" step="0.01"
:placeholder="$i18n.get('info_initial_value')" :placeholder="$i18n.get('info_initial_value')"
@input="onUpdate(interval)" @input="onUpdate(interval, true)"
v-model="interval.from" /> v-model="interval.from" />
<b-input <b-input
expanded
type="number" type="number"
step="0.01" step="0.01"
:placeholder="$i18n.get('info_final_value')" :placeholder="$i18n.get('info_final_value')"
@input="onUpdate(interval)" @input="onUpdate(interval, true)"
v-model="interval.to" /> v-model="interval.to" />
</b-field> </b-field>
<p class="control"> <p class="control">
@ -65,7 +64,9 @@
&nbsp;{{ $i18n.get('add_value') }} &nbsp;{{ $i18n.get('add_value') }}
</a> </a>
</p> </p>
<p class="control"> <p
v-if="intervals.length > 1"
class="control">
<a <a
role="button" role="button"
@click="removeInterval(index)" @click="removeInterval(index)"
@ -80,6 +81,7 @@
</div> </div>
</transition-group> </transition-group>
</b-field> </b-field>
</div>
</template> </template>
<script> <script>
@ -99,14 +101,16 @@
} }
}, },
methods: { methods: {
onUpdate(interval) { onUpdate: _.debounce( function(interval, validade) {
if (interval.to == null || interval.from == null || if (validade != undefined && validade == true &&
(interval.to == null || interval.from == null ||
interval.to == "" || interval.from == "" || interval.to == "" || interval.from == "" ||
Number(interval.to) < Number(interval.from)) { Number(interval.to) < Number(interval.from))
if(this.isValid) { ) {
this.isValid = false; this.isValid = false;
this.error_message()
} if (interval.to != '' && interval.from != '' && interval.to != null && interval.from != null)
this.showErrorMessage()
} else { } else {
this.isValid = true; this.isValid = true;
this.$emit('input', { this.$emit('input', {
@ -114,8 +118,16 @@
showIntervalOnTag: this.showIntervalOnTag showIntervalOnTag: this.showIntervalOnTag
}); });
} }
}, 600),
onUpdateShowIntervalOnTag() {
if (this.isValid) {
this.$emit('input', {
intervals: this.intervals,
showIntervalOnTag: this.showIntervalOnTag
});
}
}, },
error_message() { showErrorMessage() {
this.$buefy.toast.open({ this.$buefy.toast.open({
duration: 3000, duration: 3000,
message: this.$i18n.get('info_error_first_value_greater'), message: this.$i18n.get('info_error_first_value_greater'),
@ -143,7 +155,14 @@
} }
}, },
created() { created() {
this.intervals = this.value && this.value.intervals ? this.value.intervals : []; this.intervals =
this.value && this.value.intervals && this.value.intervals.length > 0 ?
this.value.intervals :
[{
label: '',
to: null,
from: null
}];
this.showIntervalOnTag = this.value && this.value.showIntervalOnTag != undefined ? this.value.showIntervalOnTag : true; this.showIntervalOnTag = this.value && this.value.showIntervalOnTag != undefined ? this.value.showIntervalOnTag : true;
} }
} }
@ -164,6 +183,12 @@
} }
.field.has-addons { .field.has-addons {
margin-bottom: 0.125rem; margin-bottom: 0.125rem;
width: 100%;
display: flex;
flex-wrap: wrap;
&>.control {
flex-basis: 50%;
}
} }
} }

View File

@ -1,11 +1,12 @@
<template> <template>
<div> <div>
<b-select <b-select
expanded
:placeholder="$i18n.get('instruction_select_a_interval')" :placeholder="$i18n.get('instruction_select_a_interval')"
@input="changeInterval" @input="changeInterval"
v-model="selectedInterval"> v-model="selectedInterval">
<option value=""> <option value="">
{{ $i18n.get('label_clean') }} {{ $i18n.get('label_selectbox_init') }}...
</option> </option>
<option <option
v-for="(interval, index) in filterTypeOptions.intervals" v-for="(interval, index) in filterTypeOptions.intervals"
@ -25,12 +26,16 @@
return { return {
valueInit: 0, valueInit: 0,
valueEnd: 10, valueEnd: 10,
isValid: false,
selectedInterval: '' selectedInterval: ''
} }
}, },
mounted() { mounted() {
this.selectedValues(); this.updateSelectedValues();
},
watch: {
'query.metaquery'() {
this.updateSelectedValues();
}
}, },
methods: { methods: {
changeInterval() { changeInterval() {
@ -40,16 +45,16 @@
this.emit(); this.emit();
} else { } else {
this.$emit('input', { this.$emit('input', {
filter: 'range', type: 'DECIMAL',
compare: 'BETWEEN', compare: 'BETWEEN',
metadatum_id: this.metadatumId, metadatum_id: this.metadatumId,
collection_id: this.collectionId, collection_id: this.collectionId,
value: '' value: [null, null]
}); });
this.valueEnd = null; this.valueEnd = null;
this.valueInit = null; this.valueInit = null;
this.$emit('sendValuesToTags', { label: '', value: null });
} }
}, },
// emit the operation for listeners // emit the operation for listeners
emit() { emit() {
@ -63,12 +68,12 @@
value: values value: values
}); });
if (values[0] != undefined && values[1] != undefined) { if (values[0] != undefined && values[1] != undefined && this.selectedInterval !== '') {
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${values[0]}-${values[1]})` : ''); let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? ` (${values[0]}-${values[1]})` : '');
this.$emit('sendValuesToTags', { label: labelValue, value: values }); this.$emit('sendValuesToTags', { label: labelValue, value: values });
} }
}, },
selectedValues(){ updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;
@ -88,11 +93,16 @@
this.selectedInterval = this.filterTypeOptions.intervals.findIndex( this.selectedInterval = this.filterTypeOptions.intervals.findIndex(
anInterval => anInterval.from == this.valueInit && anInterval.to == this.valueEnd anInterval => anInterval.from == this.valueInit && anInterval.to == this.valueEnd
); );
this.selectedInterval = this.selectedInterval >= 0 ? this.selectedInterval : '';
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? `(${this.valueInit}-${this.valueEnd})` : ''); if (this.selectedInterval !== '') {
let labelValue = this.filterTypeOptions.intervals[this.selectedInterval].label + (this.filterTypeOptions.showIntervalOnTag ? ` (${this.valueInit}-${this.valueEnd})` : '');
this.$emit('sendValuesToTags', { label: labelValue, value: [ this.valueInit, this.valueEnd ] }); this.$emit('sendValuesToTags', { label: labelValue, value: [ this.valueInit, this.valueEnd ] });
}
} else { } else {
return false; this.valueInit = null;
this.valueEnd = null;
this.selectedInterval = '';
} }
}, },
} }

View File

@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Numeric_List_Interval extends Filter_Type { class Numeric_List_Interval extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Numeric Interval List'); $this->set_name( __('Numeric Interval List', 'tainacan') );
$this->set_supported_types(['float']); $this->set_supported_types(['float']);
$this->set_component('tainacan-filter-numeric-list-interval'); $this->set_component('tainacan-filter-numeric-list-interval');
$this->set_form_component('tainacan-filter-form-numeric-list-interval'); $this->set_form_component('tainacan-filter-form-numeric-list-interval');
@ -47,7 +47,11 @@ class Numeric_List_Interval extends Filter_Type {
return [ return [
'intervals' => [ 'intervals' => [
'title' => __('Predefined intervals','tainacan'), 'title' => __('Predefined intervals','tainacan'),
'description' => __('Predefined intervals','tainacan') 'description' => __('A list of predefined intervals that the filter will offer on a select box.','tainacan')
],
'showIntervalOnTag' => [
'title' => __('Interval on tags', 'tainacan'),
'description' => __('Whether the applyed interval values should appear on filter tags.')
] ]
]; ];
} }

View File

@ -79,7 +79,7 @@
filterTypeMixin filterTypeMixin
], ],
mounted() { mounted() {
this.selectedValues(); this.updateSelectedValues();
}, },
data(){ data(){
return { return {
@ -101,8 +101,13 @@
} }
} }
}, },
watch: {
'query.metaquery'() {
this.updateSelectedValues();
}
},
methods: { methods: {
selectedValues(){ updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;
@ -121,7 +126,7 @@
this.$emit('sendValuesToTags', { label: this.comparator + ' ' + this.value, value: this.value }); this.$emit('sendValuesToTags', { label: this.comparator + ' ' + this.value, value: this.value });
} else { } else {
return false; this.value = null;
} }
}, },

View File

@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Numeric extends Filter_Type { class Numeric extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Numeric'); $this->set_name( __('Numeric', 'tainacan') );
$this->set_supported_types(['float']); $this->set_supported_types(['float']);
$this->set_component('tainacan-filter-numeric'); $this->set_component('tainacan-filter-numeric');
$this->set_form_component('tainacan-filter-form-numeric'); $this->set_form_component('tainacan-filter-form-numeric');

View File

@ -32,26 +32,14 @@
mixins: [filterTypeMixin, dynamicFilterTypeMixin], mixins: [filterTypeMixin, dynamicFilterTypeMixin],
data(){ data(){
return { return {
options: [] options: [],
selected: ''
} }
}, },
watch: { watch: {
selected(value) { 'query.metaquery'() {
if (value) if (!this.isUsingElasticSearch)
this.$emit('sendValuesToTags', { label: value, value: value }); this.loadOptions();
}
},
computed: {
selected() {
if ( this.query && this.query.metaquery && Array.isArray( this.query.metaquery ) ) {
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
if ( index >= 0){
let metadata = this.query.metaquery[ index ];
return metadata.value;
}
}
return undefined;
} }
}, },
mounted(){ mounted(){
@ -68,6 +56,7 @@
promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel ); promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel );
promise.request promise.request
.then(() => { .then(() => {
this.updateSelectedValues();
}) })
.catch( error => { .catch( error => {
if (isCancel(error)) if (isCancel(error))
@ -79,13 +68,33 @@
// Search Request Token for cancelling // Search Request Token for cancelling
this.getOptionsValuesCancel = promise.source; this.getOptionsValuesCancel = promise.source;
}, },
onSelect(value){ updateSelectedValues() {
if ( this.query && this.query.metaquery && Array.isArray( this.query.metaquery ) ) {
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
if ( index >= 0) {
let metadata = this.query.metaquery[ index ];
if (this.selected != metadata.value) {
this.selected = metadata.value;
}
} else {
this.selected = '';
}
} else {
this.selected = '';
}
this.$emit('sendValuesToTags', { label: this.selected, value: this.selected })
},
onSelect(value) {
this.$emit('input', { this.$emit('input', {
filter: 'selectbox', filter: 'selectbox',
metadatum_id: this.metadatumId, metadatum_id: this.metadatumId,
collection_id: this.collectionId, collection_id: this.collectionId,
value: ( value ) ? value : '' value: value
}); });
this.updateSelectedValues();
} }
} }
} }

View File

@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Selectbox extends Filter_Type { class Selectbox extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Select Box'); $this->set_name( __('Select Box', 'tainacan') );
$this->set_supported_types(['string', 'long_string']); $this->set_supported_types(['string', 'long_string']);
$this->set_component('tainacan-filter-selectbox'); $this->set_component('tainacan-filter-selectbox');
$this->set_use_max_options(false); $this->set_use_max_options(false);

View File

@ -11,6 +11,7 @@
:remove-on-keys="[]" :remove-on-keys="[]"
field="label" field="label"
attached attached
@input="onSelect"
@typing="search" @typing="search"
:aria-close-label="$i18n.get('remove_value')" :aria-close-label="$i18n.get('remove_value')"
:aria-labelledby="'filter-label-id-' + filter.id" :aria-labelledby="'filter-label-id-' + filter.id"
@ -53,21 +54,26 @@
return { return {
results:'', results:'',
selected:[], selected:[],
options: [] options: [],
relatedCollectionId: ''
} }
}, },
watch: { watch: {
selected(newVal, oldVal) { 'query.metaquery'() {
const isEqual = (newVal.length == oldVal.length) && newVal.every((element, index) => { this.updateSelectedValues();
return element === oldVal[index]; }
}); },
created() {
if (!isEqual) if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' &&
this.onSelect(); this.filter.metadatum &&
this.filter.metadatum.metadata_type_object &&
this.filter.metadatum.metadata_type_object.options &&
this.filter.metadatum.metadata_type_object.options.collection_id) {
this.relatedCollectionId = this.filter.metadatum.metadata_type_object.options.collection_id;
} }
}, },
mounted() { mounted() {
this.selectedValues(); this.updateSelectedValues();
}, },
methods: { methods: {
search: _.debounce( function(query) { search: _.debounce( function(query) {
@ -99,22 +105,29 @@
this.getOptionsValuesCancel = promise.source; this.getOptionsValuesCancel = promise.source;
}, 500), }, 500),
selectedValues(){ updateSelectedValues() {
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) ) if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false; return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId ); let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
if ( index >= 0){ if (index >= 0) {
let metadata = this.query.metaquery[ index ]; let metadata = this.query.metaquery[ index ];
if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' ) { if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' ) {
let query = qs.stringify({ postin: metadata.value, fetch_only: 'title,thumbnail', fetch_only_meta: '' }); let query = qs.stringify({ postin: metadata.value, fetch_only: 'title,thumbnail', fetch_only_meta: '' });
let endpoint = '/items/';
axios.get('/items?' + query) if (this.relatedCollectionId != '')
endpoint = '/collection/' + this.relatedCollectionId + endpoint;
axios.get(endpoint + '?' + query)
.then( res => { .then( res => {
if (res.data.items) { if (res.data.items) {
this.selected = [];
for (let item of res.data.items) { for (let item of res.data.items) {
let existingItem = this.selected.findIndex((anItem) => item.id == anItem.id);
if (existingItem < 0) {
this.selected.push({ this.selected.push({
label: item.title, label: item.title,
value: item.id, value: item.id,
@ -122,37 +135,37 @@
}); });
} }
} }
this.$emit( 'sendValuesToTags', {
label: this.selected.map((option) => option.label),
value: this.selected.map((option) => option.value)
});
}
}) })
.catch(error => { .catch(error => {
this.$console.log(error); this.$console.log(error);
}); });
} else { } else {
for (let item of metadata.value) { this.selected = [];
for (let item of metadata.value)
this.selected.push({ label: item, value: item, img: null }); this.selected.push({ label: item, value: item, img: null });
}
this.$emit( 'sendValuesToTags', {
label: this.selected.map((option) => option.label),
value: this.selected.map((option) => option.value)
});
} }
} else { } else {
return false; this.selected = [];
} }
}, },
onSelect() { onSelect() {
let values = [];
let labels = [];
if( this.selected.length > 0 ){
for(let val of this.selected){
values.push( val.value );
labels.push( val.label );
}
}
this.$emit('input', { this.$emit('input', {
filter: 'taginput', filter: 'taginput',
compare: 'IN', compare: 'IN',
metadatum_id: this.metadatumId, metadatum_id: this.metadatumId,
collection_id: this.collectionId, collection_id: this.collectionId,
value: values value: this.selected.map((option) => option.value)
}); });
this.$emit( 'sendValuesToTags', { label: labels, value: values });
} }
} }
} }

View File

@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Taginput extends Filter_Type { class Taginput extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Tag Input'); $this->set_name( __('Tag Input', 'tainacan') );
$this->set_supported_types(['string','long_string','item']); $this->set_supported_types(['string','long_string','item']);
$this->set_component('tainacan-filter-taginput'); $this->set_component('tainacan-filter-taginput');
$this->set_use_max_options(false); $this->set_use_max_options(false);

View File

@ -57,8 +57,7 @@
data() { data() {
return { return {
isLoadingItems: Boolean, isLoadingItems: Boolean,
isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false, isUsingElasticSearch: tainacan_plugin.wp_elasticpress == "1" ? true : false
reloadDueFiltering: Boolean
} }
}, },
mounted() { mounted() {
@ -67,12 +66,9 @@
this.isLoadingOptions = isLoadingItems; this.isLoadingOptions = isLoadingItems;
}); });
} }
// We listen to event, but reload event if hasFiltered is negative, as
// an empty query also demands filters reloading.
this.$eventBusSearch.$on('hasFiltered', this.reloadFilter);
}, },
methods: { methods: {
onInput(inputEvent){ onInput(inputEvent) {
this.$eventBusSearch.$emit('input', inputEvent); this.$eventBusSearch.$emit('input', inputEvent);
}, },
onSendValuesToTags($event) { onSendValuesToTags($event) {
@ -83,16 +79,11 @@
taxonomy: $event.taxonomy, taxonomy: $event.taxonomy,
metadatumId: this.filter.metadatum_id metadatumId: this.filter.metadatum_id
}); });
},
reloadFilter() {
this.reloadDueFiltering = !this.reloadDueFiltering;
} }
}, },
beforeDestroy() { beforeDestroy() {
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.$eventBusSearch.$off('isLoadingItems'); this.$eventBusSearch.$off('isLoadingItems');
this.$eventBusSearch.$off('hasFiltered', this.reloadFilter);
} }
} }
</script> </script>
@ -212,7 +203,7 @@
} }
.datepicker { .datepicker {
@media screen and (min-width: 1024px) { @media screen and (min-width: 768px) {
.datepicker-header { .datepicker-header {
@ -220,7 +211,7 @@
max-width: 165px !important; max-width: 165px !important;
} }
.pagination .pagination-list .control { .pagination .pagination-list .control {
width: 74px !important; width: 77px !important;
.select { .select {
min-width: 100% !important; min-width: 100% !important;
@ -230,14 +221,13 @@
font-size: 0.75rem !important; font-size: 0.75rem !important;
height: 24px !important; height: 24px !important;
min-width: 100% !important; min-width: 100% !important;
}
&:not(.is-loading)::after { &:not(.is-loading)::after {
margin-top: -13px !important; margin-top: -13px !important;
} }
} }
} }
} }
}
.datepicker-cell { .datepicker-cell {
padding: 0.15rem 0.175rem !important; padding: 0.15rem 0.175rem !important;
} }

View File

@ -60,7 +60,7 @@
options: [], options: [],
selected: [], selected: [],
taxonomy: '', taxonomy: '',
taxonomy_id: Number taxonomyId: ''
} }
}, },
watch: { watch: {
@ -80,6 +80,16 @@
this.loadOptions(); this.loadOptions();
} }
}, },
created() {
if (this.filter.metadatum &&
this.filter.metadatum.metadata_type_object &&
this.filter.metadatum.metadata_type_object.options &&
this.filter.metadatum.metadata_type_object.options.taxonomy &&
this.filter.metadatum.metadata_type_object.options.taxonomy_id) {
this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
this.taxonomy = this.filter.metadatum.metadata_type_object.options.taxonomy;
}
},
mounted(){ mounted(){
this.loadOptions(); this.loadOptions();
}, },
@ -87,7 +97,7 @@
...mapGetters('search', [ ...mapGetters('search', [
'getFacets' 'getFacets'
]), ]),
loadOptions(skipSelected) { loadOptions() {
if (!this.isUsingElasticSearch) { if (!this.isUsingElasticSearch) {
let promise = null; let promise = null;
const source = CancelToken.source(); const source = CancelToken.source();
@ -123,7 +133,7 @@
}); });
promise.request promise.request
.then((res) => { .then((res) => {
this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data, skipSelected); this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data);
this.isLoadingOptions = false; this.isLoadingOptions = false;
}) })
.catch( error => { .catch( error => {
@ -143,14 +153,14 @@
for (const facet in this.facetsFromItemSearch) { for (const facet in this.facetsFromItemSearch) {
if (facet == this.filter.id) { if (facet == this.filter.id) {
if (Array.isArray(this.facetsFromItemSearch[facet])) if (Array.isArray(this.facetsFromItemSearch[facet]))
this.prepareOptionsForTaxonomy(this.facetsFromItemSearch[facet], skipSelected); this.prepareOptionsForTaxonomy(this.facetsFromItemSearch[facet]);
else else
this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]), skipSelected); this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]));
} }
} }
} }
}, },
selectedValues(){ updateSelectedValues(){
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) ) if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false; return false;
@ -164,7 +174,6 @@
return false; return false;
} }
let onlyLabels = []; let onlyLabels = [];
for (let selected of this.selected) { for (let selected of this.selected) {
@ -240,7 +249,7 @@
props: { props: {
parent: parent, parent: parent,
filter: this.filter, filter: this.filter,
taxonomy_id: this.taxonomy_id, taxonomy_id: this.taxonomyId,
selected: this.selected, selected: this.selected,
metadatumId: this.metadatumId, metadatumId: this.metadatumId,
taxonomy: this.taxonomy, taxonomy: this.taxonomy,
@ -257,12 +266,7 @@
trapFocus: true trapFocus: true
}); });
}, },
prepareOptionsForTaxonomy(items, skipSelected) { prepareOptionsForTaxonomy(items) {
if (items[0] != undefined) {
this.taxonomy = items[0].taxonomy;
this.taxonomy_id = items[0].taxonomy_id;
}
this.options = []; this.options = [];
this.options = items.slice(); // copy array. this.options = items.slice(); // copy array.
@ -287,9 +291,7 @@
} }
} }
} }
if (skipSelected == undefined || skipSelected == false) { this.updateSelectedValues();
this.selectedValues();
}
}, },
updatesIsLoading(isLoadingOptions) { updatesIsLoading(isLoadingOptions) {
this.isLoadingOptions = isLoadingOptions; this.isLoadingOptions = isLoadingOptions;

View File

@ -15,6 +15,7 @@
:aria-labelledby="'filter-label-id-' + filter.id" :aria-labelledby="'filter-label-id-' + filter.id"
:class="{'has-selected': selected != undefined && selected != []}" :class="{'has-selected': selected != undefined && selected != []}"
@typing="search" @typing="search"
@input="onSelect"
:placeholder="$i18n.get('info_type_to_add_terms')"> :placeholder="$i18n.get('info_type_to_add_terms')">
<template slot-scope="props"> <template slot-scope="props">
<div class="media"> <div class="media">
@ -42,25 +43,31 @@
export default { export default {
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ], mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
created(){ created() {
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId; if (this.filter.metadatum &&
this.filter.metadatum.metadata_type_object &&
if (this.isRepositoryLevel || this.collectionId == 'default'){ this.filter.metadatum.metadata_type_object.options &&
endpoint = '/metadata/' + this.metadatumId; this.filter.metadatum.metadata_type_object.options.taxonomy &&
this.filter.metadatum.metadata_type_object.options.taxonomy_id) {
this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
this.taxonomy = this.filter.metadatum.metadata_type_object.options.taxonomy;
} }
},
axios.get(endpoint) watch: {
.then( res => { 'query.taxquery'() {
let metadatum = res.data; this.updateSelectedValues();
this.selectedValues( metadatum.metadata_type_options.taxonomy_id ); }
}); },
mounted() {
this.updateSelectedValues();
}, },
data(){ data(){
return { return {
results:'', results:'',
selected:[], selected:[],
options: [], options: [],
taxonomy: '' taxonomy: '',
taxonomyId: ''
} }
}, },
methods: { methods: {
@ -76,16 +83,14 @@
let endpoint = this.isRepositoryLevel ? '/facets/' + this.metadatumId : '/collection/'+ this.collectionId +'/facets/' + this.metadatumId; let endpoint = this.isRepositoryLevel ? '/facets/' + this.metadatumId : '/collection/'+ this.collectionId +'/facets/' + this.metadatumId;
endpoint += '?order=asc&' + qs.stringify(query_items); endpoint += '?order=asc&' + qs.stringify(query_items);
let valuesToIgnore = []; let valuesToIgnore = [];
for(let val of this.selected){ for(let val of this.selected)
valuesToIgnore.push( val.value ); valuesToIgnore.push( val.value );
}
return axios.get(endpoint).then( res => { return axios.get(endpoint).then( res => {
for (let term of res.data.values) { for (let term of res.data.values) {
this.taxonomy = term.taxonomy;
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) { if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == term.value); let indexToIgnore = valuesToIgnore.findIndex(value => value == term.value);
if (indexToIgnore < 0) { if (indexToIgnore < 0) {
@ -114,52 +119,54 @@
this.$console.log(error); this.$console.log(error);
}); });
}, 500), }, 500),
selectedValues( taxonomyId ){ updateSelectedValues(){
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) ) if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false; return false;
this.taxonomy = 'tnc_tax_' + taxonomyId; let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy);
let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy ); if (index >= 0) {
if ( index >= 0){
let metadata = this.query.taxquery[ index ]; let metadata = this.query.taxquery[ index ];
this.selected = [];
for ( let id of metadata.terms ){ if (metadata.terms && metadata.terms.length) {
this.getTerm( taxonomyId, id ); this.getTerms(metadata)
.then(() => {
this.$emit( 'sendValuesToTags', {
label: this.selected.map((option) => option.label),
value: this.selected.map((option) => option.value),
taxonomy: this.taxonomy
});
});
} }
} else { } else {
return false; this.selected = [];
} }
}, },
onSelect() { onSelect() {
let values = [];
let labels = [];
if( this.selected.length > 0 ){
for(let val of this.selected){
values.push( val.value );
labels.push( val.label );
}
}
this.$emit('input', { this.$emit('input', {
filter: 'taginput', filter: 'taginput',
compare: 'IN', compare: 'IN',
taxonomy: this.taxonomy, taxonomy: this.taxonomy,
metadatum_id: this.metadatumId, metadatum_id: this.metadatumId,
collection_id: this.collectionId, collection_id: this.collectionId,
terms: values terms: this.selected.map((option) => option.value)
}); });
this.$emit('sendValuesToTags', { label: labels, taxonomy: this.taxonomy, value: values });
}, },
getTerm( taxonomy, id ){ getTerms(metadata) {
//getting a specific value from api, does not need be in fecat api
return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc' ) let params = {
'include': metadata.terms,
'order': 'asc'
};
return axios.get('/taxonomy/' + this.taxonomyId + '/terms/?' + qs.stringify(params) )
.then( res => { .then( res => {
this.selected.push({ label: res.data.name, value: res.data.id }); this.selected = res.data.map(term => { return { label: term.name, value: term.id } });
}) })
.catch(error => { .catch(error => {
this.$console.log(error); this.$console.log(error);
}); })
} }
} }
} }

View File

@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class TaxonomyCheckbox extends Filter_Type { class TaxonomyCheckbox extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Taxonomy Checkbox List'); $this->set_name( __('Taxonomy Checkbox List', 'tainacan') );
$this->set_supported_types(['term']); $this->set_supported_types(['term']);
$this->set_component('tainacan-filter-taxonomy-checkbox'); $this->set_component('tainacan-filter-taxonomy-checkbox');
$this->set_preview_template(' $this->set_preview_template('

View File

@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class TaxonomyTaginput extends Filter_Type { class TaxonomyTaginput extends Filter_Type {
function __construct(){ function __construct(){
$this->set_name('Taxonomy Tag Input'); $this->set_name( __('Taxonomy Tag Input', 'tainacan') );
$this->set_supported_types(['term']); $this->set_supported_types(['term']);
$this->set_component('tainacan-filter-taxonomy-taginput'); $this->set_component('tainacan-filter-taxonomy-taginput');
$this->set_use_max_options(false); $this->set_use_max_options(false);

View File

@ -19,7 +19,7 @@ class Core_Title extends Metadata_Type {
$this->set_core(true); $this->set_core(true);
$this->set_related_mapped_prop('title'); $this->set_related_mapped_prop('title');
$this->set_component('tainacan-text'); $this->set_component('tainacan-text');
$this->set_name( __('Core Description', 'tainacan') ); $this->set_name( __('Core Title', 'tainacan') );
$this->set_description( __('The "Core Title" is a compulsory metadata automatically created for all collections by default. It is the main metadatum of the item and where the basic research tools will do their searches.', 'tainacan') ); $this->set_description( __('The "Core Title" is a compulsory metadata automatically created for all collections by default. It is the main metadatum of the item and where the basic research tools will do their searches.', 'tainacan') );
} }

View File

@ -148,7 +148,7 @@ class Relationship extends Metadata_Type {
} }
} catch (Exception $e) { } catch (\Exception $e) {
// item not found // item not found
} }
@ -164,7 +164,7 @@ class Relationship extends Metadata_Type {
$return .= $this->get_item_html($item); $return .= $this->get_item_html($item);
} }
} catch (Exception $e) { } catch (\Exception $e) {
// item not found // item not found
} }

View File

@ -28,7 +28,7 @@
v-if="metadatum.metadatum.required == 'yes'" v-if="metadatum.metadatum.required == 'yes'"
class="required-metadatum-asterisk" class="required-metadatum-asterisk"
:class="metadatumTypeMessage">*</span> :class="metadatumTypeMessage">*</span>
<span class="metadata-type">({{ $i18n.get(metadatum.metadatum.metadata_type_object.component) }})</span> <span class="metadata-type">({{ metadatum.metadatum.metadata_type_object.name }})</span>
<help-button <help-button
:title="metadatum.metadatum.name" :title="metadatum.metadatum.name"
:message="metadatum.metadatum.description"/> :message="metadatum.metadatum.description"/>
@ -46,7 +46,7 @@
<div v-if="metadatum.metadatum.multiple == 'yes'"> <div v-if="metadatum.metadatum.multiple == 'yes'">
<div <div
v-if="index > 0" v-if="index > 0"
v-for="(input, index) in inputsList " v-for="(input, index) in inputs"
:key="index" :key="index"
class="multiple-inputs"> class="multiple-inputs">
<component <component
@ -98,39 +98,33 @@
export default { export default {
name: 'TainacanFormItem', name: 'TainacanFormItem',
props: { props: {
metadatum: { metadatum: Object,
type: Object isCollapsed: true
},
isCollapsed: true // Metadatum Collapses
}, },
data(){ data(){
return { return {
inputs: [], inputs: [],
metadatumTypeMessage:'' metadatumTypeMessage: ''
} }
}, },
computed: { computed: {
inputsList() {
return this.inputs;
},
getErrorMessage() { getErrorMessage() {
let errorMessage = '';
let msg = '';
let errors = eventBus.getErrors(this.metadatum.metadatum.id); let errors = eventBus.getErrors(this.metadatum.metadatum.id);
if ( errors) { if (errors) {
this.setMetadatumTypeMessage('is-danger'); this.setMetadatumTypeMessage('is-danger');
for (let error of errors) { for (let error of errors) {
for (let index of Object.keys(error)) { for (let index of Object.keys(error)) {
// this.$console.log(index); // this.$console.log(index);
msg += error[index] + '\n'; errorMessage += error[index] + '\n';
} }
} }
} else { } else {
this.setMetadatumTypeMessage(''); this.setMetadatumTypeMessage('');
} }
return msg; return errorMessage;
} }
}, },
created(){ created(){
@ -142,54 +136,42 @@
}, },
changeValue: _.debounce(function() { changeValue: _.debounce(function() {
if(this.metadatum.value != this.inputs){ if (this.metadatum.value != this.inputs) {
if(this.inputs.length > 0 && this.inputs[0].value){ if (this.inputs.length > 0 && this.inputs[0].value) {
let terms = []; let terms = this.inputs.map(term => term.value)
for(let term of this.inputs){ if (this.metadatum.value instanceof Array){
terms.push(term.value); let equal = [];
for (let meta of terms) {
let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
if (foundIndex >= 0)
equal.push(this.metadatum.value[foundIndex]);
} }
if(this.metadatum.value instanceof Array){ if (equal.length == terms.length && this.metadatum.value.length <= equal.length)
let eq = [];
for(let meta of terms){
let found = this.metadatum.value.find((element) => {
return meta == element.id;
});
if(found){
eq.push(found);
}
}
if(eq.length == terms.length && this.metadatum.value.length <= eq.length){
return; return;
}
}
} else if(this.metadatum.value.constructor.name == 'Object'){
if(this.metadatum.value.id == this.inputs){ }
} else if (this.metadatum.value.constructor.name == 'Object') {
if (this.metadatum.value.id == this.inputs)
return; return;
}
} else if(this.metadatum.value instanceof Array){
let eq = [];
for(let meta of this.inputs){ } else if (this.metadatum.value instanceof Array) {
let found = this.metadatum.value.find((element) => { let equal = [];
return meta == element.id;
});
if(found){ for (let meta of this.inputs) {
eq.push(found); let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
}
if (foundIndex >= 0)
equal.push(this.metadatum.value[foundIndex]);
} }
if(eq.length == this.inputs.length && this.metadatum.value.length <= eq.length){ if (equal.length == this.inputs.length && this.metadatum.value.length <= equal.length)
return; return;
} }
}
eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } ); eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } );
} }
@ -198,9 +180,9 @@
if (this.metadatum.value instanceof Array) { if (this.metadatum.value instanceof Array) {
this.inputs = this.metadatum.value.slice(0); this.inputs = this.metadatum.value.slice(0);
if (this.inputs.length === 0){ if (this.inputs.length === 0)
this.inputs.push(''); this.inputs.push('');
}
} else { } else {
this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value); this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value);
} }
@ -213,11 +195,11 @@
this.inputs.splice(index, 1); this.inputs.splice(index, 1);
this.changeValue(); this.changeValue();
}, },
isTextInputComponent( component ){ isTextInputComponent(component){
let array = ['tainacan-relationship','tainacan-taxonomy']; let array = ['tainacan-relationship','tainacan-taxonomy'];
return !( array.indexOf( component ) >= 0 ); return !( array.indexOf( component ) >= 0 );
}, },
setMetadatumTypeMessage( message ){ setMetadatumTypeMessage(message){
this.metadatumTypeMessage = message; this.metadatumTypeMessage = message;
} }
} }

View File

@ -85,10 +85,8 @@
<script> <script>
import { tainacan as axios } from '../../../js/axios/axios'; import { tainacan as axios } from '../../../js/axios/axios';
import BCheckbox from "../../../../node_modules/buefy/src/components/checkbox/Checkbox.vue";
export default { export default {
components: {BCheckbox},
props: { props: {
value: [ String, Object, Array ], value: [ String, Object, Array ],
metadatum: [ String, Object ], metadatum: [ String, Object ],

View File

@ -12,7 +12,7 @@
:options="getOptions(0)"/> :options="getOptions(0)"/>
<a <a
class="add-new-term" class="add-new-term"
v-if="(this.getComponent == 'tainacan-taxonomy-checkbox' || this.getComponent == 'tainacan-taxonomy-radio') && v-if="(getComponent == 'tainacan-taxonomy-checkbox' || getComponent == 'tainacan-taxonomy-radio') &&
terms.length < totalTerms" terms.length < totalTerms"
@click="openCheckboxModal()"> @click="openCheckboxModal()">
{{ $i18n.get('label_view_all') }} {{ $i18n.get('label_view_all') }}
@ -47,14 +47,12 @@
this.taxonomy_id = metadata_type_options.taxonomy_id; this.taxonomy_id = metadata_type_options.taxonomy_id;
this.taxonomy = metadata_type_options.taxonomy; this.taxonomy = metadata_type_options.taxonomy;
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, used by bulk edition modal
if(this.component != 'tainacan-taxonomy-tag-input' || this.forcedComponentType != 'tainacan-taxonomy-tag-input'){ if (this.component != 'tainacan-taxonomy-tag-input' || this.forcedComponentType != 'tainacan-taxonomy-tag-input')
this.getTermsFromTaxonomy(); this.getTermsFromTaxonomy();
}
this.getTermsId(); this.getTermsId();
}, },
@ -80,7 +78,6 @@
}, },
watch: { watch: {
valueComponent( val ){ valueComponent( val ){
this.valueComponent = val;
this.$emit('input', val); this.$emit('input', val);
this.$emit('blur'); this.$emit('blur');
} }

View File

@ -99,7 +99,7 @@
throw error; throw error;
}); });
}, 500), }, 500),
selectedValues(){ updateSelectedValues(){
let selected = []; let selected = [];
for( let term of this.value){ for( let term of this.value){
@ -112,10 +112,9 @@
let val = this.selected; let val = this.selected;
let results = []; let results = [];
if (val.length > 0){ if (val.length > 0) {
for( let term of val ){ for (let term of val)
results.push( term.value ); results.push( term.value );
}
this.$emit('input', results); this.$emit('input', results);
this.$emit('blur'); this.$emit('blur');
@ -125,9 +124,8 @@
let val = this.selected; let val = this.selected;
let results = []; let results = [];
for( let term of val ){ for (let term of val)
results.push( term.value ); results.push(term.value);
}
this.$emit('input', results); this.$emit('input', results);
this.$emit('blur'); this.$emit('blur');

View File

@ -1151,7 +1151,7 @@ class Metadata extends Repository {
} }
$number = is_integer($args['number']) && $args['number'] >=1 ? $args['number'] : $total; $number = ctype_digit($args['number']) && $args['number'] >=1 ? $args['number'] : $total;
if( $number < 1){ if( $number < 1){
$pages = 1; $pages = 1;
} else { } else {
@ -1212,7 +1212,7 @@ class Metadata extends Repository {
$results = $wpdb->get_col($query); $results = $wpdb->get_col($query);
$total = $wpdb->get_var($total_query); $total = $wpdb->get_var($total_query);
$number = is_integer($args['number']) && $args['number'] >=1 ? $args['number'] : $total; $number = ctype_digit($args['number']) && $args['number'] >=1 ? $args['number'] : $total;
if( $number < 1){ if( $number < 1){
$pages = 1; $pages = 1;
} else { } else {

View File

@ -132,7 +132,6 @@ $Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Taxonomy');
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
//register filter type //register filter type
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Custom_Interval');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Date'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Date');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Selectbox'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Selectbox');
@ -141,6 +140,7 @@ $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Taginput');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Checkbox'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Checkbox');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyTaginput'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyTaginput');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyCheckbox'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\TaxonomyCheckbox');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Date_Interval');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_Interval'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_Interval');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_List_Interval'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Numeric_List_Interval');

View File

@ -121,7 +121,7 @@
</div> </div>
<!-- Swiper buttons are hidden as they actually swipe from slide to slide --> <!-- Swiper buttons are hidden as they actually swipe from slide to slide -->
</div> </div>
<div v-else-if="isLoading && !autoPlay"> <div v-else-if="isLoading && !autoPlay && !loopSlides">
<div :class="'tainacan-carousel has-arrows-' + arrowsPosition"> <div :class="'tainacan-carousel has-arrows-' + arrowsPosition">
<swiper <swiper
role="list" role="list"

View File

@ -59,6 +59,7 @@
}"> }">
<swiper-slide <swiper-slide
role="listitem" role="listitem"
ref="myItemSwiperSlide"
:key="index" :key="index"
v-for="(item, index) of items" v-for="(item, index) of items"
class="item-list-item"> class="item-list-item">
@ -121,7 +122,7 @@
</div> </div>
<!-- Swiper buttons are hidden as they actually swipe from slide to slide --> <!-- Swiper buttons are hidden as they actually swipe from slide to slide -->
</div> </div>
<div v-else-if="isLoading && !autoPlay"> <div v-else-if="isLoading && !autoPlay && !loopSlides">
<div :class="'tainacan-carousel has-arrows-' + arrowsPosition"> <div :class="'tainacan-carousel has-arrows-' + arrowsPosition">
<swiper <swiper
role="list" role="list"
@ -133,7 +134,7 @@
<swiper-slide <swiper-slide
role="listitem" role="listitem"
:key="index" :key="index"
ref="myItemSwiper" ref="myItemSwiperSlideSkeleton"
v-for="(item, index) of 18" v-for="(item, index) of 18"
class="item-list-item skeleton"> class="item-list-item skeleton">
<a> <a>
@ -219,7 +220,7 @@ export default {
1600: { slidesPerView: 6 }, 1600: { slidesPerView: 6 },
}, },
autoplay: this.autoPlay ? { delay: this.autoPlaySpeed*1000 } : false, autoplay: this.autoPlay ? { delay: this.autoPlaySpeed*1000 } : false,
loop: this.loopSlides loop: this.loopSlides ? this.loopSlides : false
}, },
errorMessage: 'No items found.' errorMessage: 'No items found.'
} }

View File

@ -111,7 +111,7 @@
</div> </div>
<!-- Swiper buttons are hidden as they actually swipe from slide to slide --> <!-- Swiper buttons are hidden as they actually swipe from slide to slide -->
</div> </div>
<div v-else-if="isLoading && !autoPlay"> <div v-else-if="isLoading && !autoPlay && !loopSlides">
<div :class="'tainacan-carousel has-arrows-' + arrowsPosition"> <div :class="'tainacan-carousel has-arrows-' + arrowsPosition">
<swiper <swiper
role="list" role="list"
@ -240,7 +240,7 @@ export default {
this.termsRequestSource = axios.CancelToken.source(); this.termsRequestSource = axios.CancelToken.source();
let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ include: this.selectedTerms }) + '&fetch_only=name,url,header_image'; let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ include: this.selectedTerms }) + '&fetch_only=id,name,url,header_image';
this.tainacanAxios.get(endpoint, { cancelToken: this.termsRequestSource.token }) this.tainacanAxios.get(endpoint, { cancelToken: this.termsRequestSource.token })
.then(response => { .then(response => {

View File

@ -210,7 +210,7 @@ registerBlockType('tainacan/carousel-terms-list', {
terms = []; terms = [];
let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ include: selectedTerms }) + '&fetch_only=name,url,header_image'; let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ include: selectedTerms }) + '&fetch_only=id,name,url,header_image';
tainacan.get(endpoint, { cancelToken: itemsRequestSource.token }) tainacan.get(endpoint, { cancelToken: itemsRequestSource.token })
.then(response => { .then(response => {
@ -227,8 +227,9 @@ registerBlockType('tainacan/carousel-terms-list', {
} else { } else {
let promises = []; let promises = [];
for (let term of response.data) { for (let term of response.data) {
console.log(term)
promises.push( promises.push(
tainacan.get('/items/?perpage=3&fetch_only=name,url,thumbnailt&taxquery[0][taxonomy]=tnc_tax_' + taxonomyId + '&taxquery[0][terms][0]=' + term.id + '&taxquery[0][compare]=IN') tainacan.get('/items/?perpage=3&fetch_only=name,url,thumbnail&taxquery[0][taxonomy]=tnc_tax_' + taxonomyId + '&taxquery[0][terms][0]=' + term.id + '&taxquery[0][compare]=IN')
.then(response => { return({ term: term, termItems: response.data.items }) }) .then(response => { return({ term: term, termItems: response.data.items }) })
.catch((error) => console.log(error)) .catch((error) => console.log(error))
); );

View File

@ -510,7 +510,7 @@ class Test_Importer extends Importer {
'options' => [ 'options' => [
'collection_id' => $col2->get_id(), 'collection_id' => $col2->get_id(),
'repeated' => 'yes', 'repeated' => 'yes',
'search' => [ $col2_core_title->get_id() ] 'search' => $col2_core_title->get_id()
] ]
], $col1 ); ], $col1 );

View File

@ -6,7 +6,6 @@ export default {
router: options.router, router: options.router,
store: options.store, store: options.store,
data: { data: {
componentsTag: [],
errors : [], errors : [],
query: {}, query: {},
collectionId: undefined, collectionId: undefined,
@ -16,7 +15,7 @@ export default {
}, },
created() { created() {
this.$on('input', data => { this.$on('input', data => {
console.log("inputei")
this.$store.dispatch('search/setPage', 1); this.$store.dispatch('search/setPage', 1);
if (data.taxonomy) if (data.taxonomy)
this.addTaxquery(data); this.addTaxquery(data);
@ -187,7 +186,7 @@ export default {
if (filterTag.singleLabel != undefined || filterTag.label != undefined) { if (filterTag.singleLabel != undefined || filterTag.label != undefined) {
if (filterTag.taxonomy) if (filterTag.taxonomy) {
this.$store.dispatch('search/remove_taxquery', { this.$store.dispatch('search/remove_taxquery', {
filterId: filterTag.filterId, filterId: filterTag.filterId,
label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label, label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label,
@ -195,7 +194,7 @@ export default {
taxonomy: filterTag.taxonomy, taxonomy: filterTag.taxonomy,
value: filterTag.value value: filterTag.value
}); });
else } else {
this.$store.dispatch('search/remove_metaquery', { this.$store.dispatch('search/remove_metaquery', {
filterId: filterTag.filterId, filterId: filterTag.filterId,
label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label, label: filterTag.singleLabel ? filterTag.singleLabel : filterTag.label,
@ -204,6 +203,8 @@ export default {
value: filterTag.value value: filterTag.value
}); });
} }
this.$store.dispatch('search/removeFilterTag', filterTag);
}
this.updateURLQueries(); this.updateURLQueries();
}, },
addFetchOnly( metadatum, ignorePrefs, metadatumIDs ){ addFetchOnly( metadatum, ignorePrefs, metadatumIDs ){
@ -379,26 +380,7 @@ export default {
this.$store.dispatch('search/cleanMetaQueries'); this.$store.dispatch('search/cleanMetaQueries');
this.$store.dispatch('search/cleanTaxQueries'); this.$store.dispatch('search/cleanTaxQueries');
this.updateURLQueries(); this.updateURLQueries();
},
/* Dev interfaces methods */
registerComponent( name ){
if (this.componentsTag.indexOf(name) < 0) {
this.componentsTag.push( name );
} }
},
getAllComponents(){
const components = [];
for( let component of this.componentsTag ){
const eventElements = document.getElementsByTagName( component );
if( eventElements ) {
for (let eventElement of eventElements){
components.push( eventElement );
}
}
}
return components;
},
} }
}); });
} }

View File

@ -4,14 +4,10 @@ import store from './store/store'
export const eventBus = new Vue({ export const eventBus = new Vue({
store, store,
data: { data: {
componentsTag: [],
errors : [] errors : []
}, },
created(){ created() {
if( tainacan_plugin.components ){ this.$on('input', this.updateValue);
this.componentsTag = tainacan_plugin.components;
}
this.$on('input', this.updateValue );
}, },
watch: { watch: {
errors() { errors() {
@ -19,66 +15,45 @@ export const eventBus = new Vue({
} }
}, },
methods : { methods : {
registerComponent( name ){
if (this.componentsTag.indexOf(name) < 0) {
this.componentsTag.push( name );
}
},
// listener(){
// const components = this.getAllComponents();
// for (let eventElement of components){
// eventElement.addEventListener('input', (event) => {
// if (event.detail && event.detail[0] ){
// this.updateValue({
// item_id: $(eventElement).attr("item_id"),
// metadatum_id: $(eventElement).attr("metadatum_id"),
// values: event.detail
// })
// }
// });
// }
// },
updateValue(data){ updateValue(data){
this.$emit('isUpdatingValue', true); this.$emit('isUpdatingValue', true);
if ( data.item_id ){ if (data.item_id) {
if(data.values.length > 0 && data.values[0].value){ if (data.values.length > 0 && data.values[0].value) {
let val = []; let val = [];
for(let i of data.values){ for (let i of data.values)
val.push(i.value); val.push(i.value);
}
data.values = val; data.values = val;
} }
let values = ( Array.isArray( data.values[0] ) ) ? data.values[0] : data.values ; let values = ( Array.isArray( data.values[0] ) ) ? data.values[0] : data.values ;
const promisse = this.$store.dispatch('item/updateMetadata',
{ item_id: data.item_id, metadatum_id: data.metadatum_id, values: values });
promisse.then( () => { this.$store.dispatch('item/updateMetadata', {
item_id: data.item_id,
metadatum_id: data.metadatum_id,
values: values
})
.then(() => {
this.$emit('isUpdatingValue', false); this.$emit('isUpdatingValue', false);
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id ); let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id );
if ( index >= 0){ if ( index >= 0)
this.errors.splice( index, 1); this.errors.splice( index, 1);
}
}) })
.catch((error) => { .catch((error) => {
this.$emit('isUpdatingValue', false); this.$emit('isUpdatingValue', false);
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id ); let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id );
let messages = []; let messages = [];
for (let index in error) { for (let index in error)
messages.push(error[index]); messages.push(error[index]);
}
if ( index >= 0){ if ( index >= 0)
Vue.set( this.errors, index, { metadatum_id: data.metadatum_id, errors: messages }); Vue.set( this.errors, index, { metadatum_id: data.metadatum_id, errors: messages });
} else { else
this.errors.push( { metadatum_id: data.metadatum_id, errors: messages } ); this.errors.push( { metadatum_id: data.metadatum_id, errors: messages } );
}
}); });
} }
}, },
@ -86,51 +61,12 @@ export const eventBus = new Vue({
let error = this.errors.find( errorItem => errorItem.metadatum_id == metadatum_id ); let error = this.errors.find( errorItem => errorItem.metadatum_id == metadatum_id );
return ( error ) ? error.errors : false return ( error ) ? error.errors : false
}, },
clearAllErrors(){ clearAllErrors() {
this.errors = []; this.errors = [];
},
setValues(){
const metadatum = this.$store.getters['item/getMetadata'];
if( metadatum ){
for(let singleMetadata of metadatum){
const eventElement = this.getComponentById( singleMetadata.metadatum_id );
eventElement.value = singleMetadata.values;
}
}
},
getAllComponents(){
const components = [];
for( let component of this.componentsTag ){
const eventElements = document.getElementsByTagName( component );
if( eventElements ) {
for (let eventElement of eventElements){
components.push( eventElement );
}
}
}
let elements = document.querySelectorAll('[web-component="true"]');
if( elements ) {
for (let eventElement of elements){
components.push( eventElement );
}
}
return components;
},
getComponentById( metadatum_id ){
for( let component of this.componentsTag ){
const eventElements = document.getElementsByTagName( component );
if( eventElements ) {
for (let eventElement of eventElements){
if( eventElement.metadatum_id === metadatum_id ){
return eventElement;
}
}
}
}
} }
}, },
beforeUpdate() { beforeUpdate() {
this.$off('input', this.updateValue ); this.$off('input', this.updateValue);
} }
}); });

Some files were not shown because too many files have changed in this diff Show More