Merge branch 'release/0.13'

This commit is contained in:
leogermani 2019-10-29 14:35:14 -03:00
commit 7925186017
197 changed files with 8586 additions and 5327 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
- sudo chmod +x /usr/local/bin/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:
directories:
- vendor

View File

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

View File

@ -31,5 +31,7 @@ sass -E 'UTF-8' --cache-location .tmp/sass-cache-10 src/gutenberg-blocks/tainaca
sass -E 'UTF-8' --cache-location .tmp/sass-cache-11 src/gutenberg-blocks/tainacan-facets/facets-list/facets-list.scss:src/assets/css/tainacan-gutenberg-block-facets-list.css
sass -E 'UTF-8' --cache-location .tmp/sass-cache-12 src/gutenberg-blocks/tainacan-terms/carousel-terms-list/carousel-terms-list.scss:src/assets/css/tainacan-gutenberg-block-carousel-terms-list.css
echo "Compilação do Sass Concluído!"
exit 0

6
package-lock.json generated
View File

@ -1951,9 +1951,9 @@
}
},
"buefy": {
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/buefy/-/buefy-0.8.3.tgz",
"integrity": "sha512-01aHoCy4LAD08MmUahXC8mVqtGK/kzJ45ysXskwLWILAhyLMqkZ5fvdMKD9Ky6iDsMttPHdwUe2csmdnIx9caw==",
"version": "0.8.6",
"resolved": "https://registry.npmjs.org/buefy/-/buefy-0.8.6.tgz",
"integrity": "sha512-7woxrdwANcnJbe7lofPxkJLGRRGIVwFXOo0kzEpiNB6alQj18NV6UrdAKse+LWCOADz+AeHe5gyc6qdgRjG5mw==",
"requires": {
"bulma": "0.7.5"
}

View File

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

View File

@ -41,14 +41,14 @@ class Admin {
array( &$this, 'admin_page' ),
plugin_dir_url( __FILE__ ) . 'images/tainacan_logo_symbol.svg'
);
add_submenu_page(
$this->menu_slug,
__('System check', 'tainacan'),
__('System check', 'tainacan'),
'manage_options',
'tainacan_systemcheck',
array( &$this, 'systemcheck_page' )
add_submenu_page(
$this->menu_slug,
__('System check', 'tainacan'),
__('System check', 'tainacan'),
'manage_options',
'tainacan_systemcheck',
array( &$this, 'systemcheck_page' )
);
add_action( 'load-' . $page_suffix, array( &$this, 'load_admin_page' ) );
@ -57,6 +57,7 @@ class Admin {
function load_admin_page() {
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_theme_files') );
}
@ -74,18 +75,18 @@ class Admin {
function add_theme_files() {
global $TAINACAN_BASE_URL;
// wp_enqueue_style( 'style', $TAINACAN_BASE_URL . '/assets/css/fonts/materialdesignicons.css' );
wp_enqueue_style( 'tainacan-fonts', $TAINACAN_BASE_URL . '/assets/css/fonts/tainacanicons.css', [], TAINACAN_VERSION );
wp_enqueue_style( 'roboto-fonts', 'https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700,700i', [], TAINACAN_VERSION );
wp_enqueue_script('underscore');
}
function add_admin_css() {
global $TAINACAN_BASE_URL;
wp_enqueue_style( 'tainacan-admin-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-admin.css', [], TAINACAN_VERSION );
// $undesired_wp_styles = [
// 'admin-menu',
// 'admin-bar',
@ -119,14 +120,14 @@ class Admin {
//
// wp_dequeue_style( $undesired_wp_styles );
// wp_deregister_style( $undesired_wp_styles );
}
function add_admin_js() {
global $TAINACAN_BASE_URL;
wp_enqueue_script( 'tainacan-user-admin', $TAINACAN_BASE_URL . '/assets/user_admin-components.js', ['underscore', 'media-editor', 'media-views', 'customize-controls'], TAINACAN_VERSION, true );
$settings = $this->get_admin_js_localization_params();
wp_localize_script( 'tainacan-user-admin', 'tainacan_plugin', $settings );
@ -134,23 +135,23 @@ class Admin {
wp_enqueue_script('underscore');
wp_enqueue_script('jcrop');
wp_enqueue_script( 'customize-controls' );
do_action('tainacan-enqueue-admin-scripts');
}
/**
* Also used by DevInterface
*/
function get_admin_js_localization_params() {
global $TAINACAN_BASE_URL, $TAINACAN_API_MAX_ITEMS_PER_PAGE;
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$tainacan_admin_i18n = require( 'tainacan-admin-i18n.php' );
$entities_labels = [
@ -222,33 +223,33 @@ class Admin {
}
$filter_types = $Tainacan_Filters->fetch_filter_types();
foreach ( $filter_types as $index => $filter_type){
$class = new $filter_type;
$settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels();
}
$settings['form_hooks'] = Admin_Hooks::get_instance()->get_registered_hooks();
$wp_post_types = get_post_types(['show_ui' => true], 'objects');
if (isset($wp_post_types['attachment'])) {
unset($wp_post_types['attachment']);
}
$wp_post_types = array_map(function($i) {
return [
'slug' => $i->name,
'label' => $i->label
];
}, $wp_post_types);
$settings['wp_post_types'] = $wp_post_types;
// add an alternative to enable select all items in all pages while we temporarly disable bulk edit for all (see #199)
$settings['enable_select_all_items_pages'] = defined('TAINACAN_ENABLE_SELECT_ALL_ITEMS_PAGES') ? TAINACAN_ENABLE_SELECT_ALL_ITEMS_PAGES : false;
$settings['enable_select_all_items_pages'] = defined('TAINACAN_ENABLE_SELECT_ALL_ITEMS_PAGES') ? TAINACAN_ENABLE_SELECT_ALL_ITEMS_PAGES : false;
return $settings;
}
function admin_body_class( $classes ) {
@ -334,7 +335,7 @@ class Admin {
wp_die();
}
public function systemcheck_page() {
require_once('system-check/class-tainacan-system-check.php');
$check = new System_Check();

View File

@ -1,5 +1,12 @@
<template>
<div class="tainacan-modal-content this-tainacan-modal-content">
<div
aria-labelledby="alert-dialog-title"
autofocus
role="alertdialog"
tabindex="-1"
aria-modal
class="tainacan-modal-content this-tainacan-modal-content"
ref="bulkEditionModal">
<header class="tainacan-modal-title">
<h2>{{ modalTitle }}
<small class="tainacan-total-objects-info">
@ -17,7 +24,7 @@
<b-select
:loading="metadataIsLoading"
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone, 'hidden-select-arrow': !!bulkEditionProcedures[criterion].metadatumID}"
:disabled="!!bulkEditionProcedures[criterion].metadatumID || metadataIsLoading"
class="tainacan-bulk-edition-field tainacan-bulk-edition-field-not-last"
:placeholder="$i18n.get('instruction_select_a_metadatum')"
@ -40,7 +47,7 @@
</b-select>
<b-select
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone, 'hidden-select-arrow': !!bulkEditionProcedures[criterion].action }"
v-if="bulkEditionProcedures[criterion] &&
bulkEditionProcedures[criterion].metadatumID"
:disabled="!!bulkEditionProcedures[criterion].action"
@ -118,7 +125,7 @@
v-else-if="bulkEditionProcedures[criterion] &&
bulkEditionProcedures[criterion].metadatumID == 'status'">
<b-select
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone, 'hidden-select-arrow': bulkEditionProcedures[criterion].isDone}"
:disabled="bulkEditionProcedures[criterion].isDone"
class="tainacan-bulk-edition-field tainacan-bulk-edition-field-last"
:placeholder="$i18n.get('instruction_select_a_status2')"
@ -353,6 +360,10 @@
this.groupID = this.getGroupID();
});
},
mounted() {
if (this.$refs.bulkEditionModal)
this.$refs.bulkEditionModal.focus();
},
computed: {
metadata() {
return this.getMetadata();
@ -370,10 +381,10 @@
add: this.$i18n.get('add_value'),
redefine: this.$i18n.get('set_new_value'),
remove: this.$i18n.get('remove_value'),
replace: this.$i18n.get('replace_value'),
replace: this.$i18n.get('replace_value')
},
editionActionsForNotMultiple: {
redefine: this.$i18n.get('set_new_value'),
redefine: this.$i18n.get('set_new_value')
},
bulkEditionProcedures: {
1: {
@ -432,7 +443,7 @@
let index = this.editionCriteria.indexOf(criterion);
this.dones[index] = !withError;
this.$set(this.bulkEditionProcedures[criterion], 'isExecuting', false);
},
executeBulkEditionProcedure(criterion){

View File

@ -204,7 +204,8 @@
ref="enabledViewModesDropdown"
:mobile-modal="true"
:disabled="Object.keys(registeredViewModes).length < 0"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-white"
slot="trigger"
@ -297,7 +298,7 @@
<div class="status-radios">
<b-radio
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"
:native-value="statusOption.slug">
<span class="icon has-text-gray">

View File

@ -142,10 +142,12 @@
...mapActions('collection', [
'fetchCollections'
]),
updateExporterOptions(){
runExporter(){
this.runButtonLoading = true;
let formElement = document.getElementById('exporterOptionsForm');
let formData = new FormData(formElement);
let options = {};
for (let [key, value] of formData.entries())
@ -153,21 +155,9 @@
let exporterSessionUpdated = {
body: {
options: options,
},
id: this.exporterSession.id,
};
return this.updateExporterSession(exporterSessionUpdated)
.then(exporterSessionUpdated => this.verifyError(exporterSessionUpdated));
},
runExporter(){
this.runButtonLoading = true;
let exporterSessionUpdated = {
body: {
mapping_selected: this.selectedMapping ? this.selectedMapping : this.selectedMapping,
send_email: this.sendEmail
mapping_selected: this.selectedMapping,
send_email: this.sendEmail,
options: options
},
id: this.exporterSession.id,
};
@ -176,26 +166,28 @@
exporterSessionUpdated['body']['collection'] = {
id: this.selectedCollection
};
}
}
this.updateExporterSession(exporterSessionUpdated)
.then(exporterSessionUpdated => {
this.verifyError(exporterSessionUpdated);
.then(() => {
if (!this.formErrorMessage) {
this.runExporterSession(this.exporterSession.id)
.then((bgp) => {
this.runButtonLoading = false;
this.$router.push(this.$routerHelper.getProcessesPage(bgp.bg_process_id));
})
.catch((error) => {
this.formErrorMessage = error.error_message;
this.runButtonLoading = false;
});
}
this.updateExporterOptions().then(() => {
if(!this.formErrorMessage) {
this.runExporterSession(this.exporterSession.id)
.then((bgp) => {
this.runButtonLoading = false;
this.$router.push(this.$routerHelper.getProcessesPage(bgp.bg_process_id));
})
.catch(() => {
this.runButtonLoading = false;
});
}
});
})
.catch(() => this.runButtonLoading = false);
.catch((error) => {
this.formErrorMessage = error.error_message;
this.runButtonLoading = false;
});
},
formIsValid(){
return (
@ -204,15 +196,6 @@
this.exporterSession.accept_no_mapping) &&
!this.formErrorMessage
);
},
verifyError(response){
if(response.constructor.name === 'Object' &&
(response.data && response.data.status &&
response.data.status.toString().split('')[0] != 2) || response.error_message) {
this.formErrorMessage = response.data.error_message;
} else {
this.exporterSession = response.data;
}
}
},
created(){

View File

@ -74,7 +74,7 @@
{{ metadatum.name }}
</span>
<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>
</option>
</b-select>
@ -92,60 +92,69 @@
<p v-if="(!importerSourceInfo.source_special_fields || importerSourceInfo.source_special_fields.length <= 0)">{{ $i18n.get('info_no_special_fields_available') }}<br></p>
<b-modal
@close="onMetadatumEditionCanceled()"
:active.sync="isNewMetadatumModalActive">
<b-loading
:is-full-page="isFullPage"
:active.sync="isLoadingMetadatumTypes"/>
:active.sync="isNewMetadatumModalActive"
trap-focus
aria-modal
aria-role="dialog">
<div
v-if="selectedMetadatumType == undefined && !isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_select_metadatum_type') }}</h2>
<hr>
</div>
<section class="tainacan-form">
<div class="metadata-types-container">
<div
class="metadata-type"
v-for="(metadatumType, index) of metadatumTypes"
:key="index"
@click="onSelectMetadatumType(metadatumType)">
<h4>{{ metadatumType.name }}</h4>
</div>
autofocus="true"
tabindex="-1"
role="dialog"
aria-modal>
<b-loading
:is-full-page="isFullPage"
:active.sync="isLoadingMetadatumTypes"/>
<div
v-if="selectedMetadatumType == undefined && !isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_select_metadatum_type') }}</h2>
<hr>
</div>
<div class="field is-grouped form-submit">
<div class="control">
<button
id="button-cancel-importer-edition"
class="button is-outlined"
type="button"
@click="onMetadatumEditionCanceled(); isNewMetadatumModalActive = false">
{{ $i18n.get('cancel') }}</button>
<section class="tainacan-form">
<div class="metadata-types-container">
<div
class="metadata-type"
v-for="(metadatumType, index) of metadatumTypes"
:key="index"
@click="onSelectMetadatumType(metadatumType)">
<h4>{{ metadatumType.name }}</h4>
</div>
</div>
</div>
</section>
</div>
<div
v-if="isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_configure_new_metadatum') }}</h2>
<a
class="back-link"
@click="isEditingMetadatum = false">
{{ $i18n.get('back') }}
</a>
<hr>
<div class="field is-grouped form-submit">
<div class="control">
<button
id="button-cancel-importer-edition"
class="button is-outlined"
type="button"
@click="onMetadatumEditionCanceled(); isNewMetadatumModalActive = false">
{{ $i18n.get('cancel') }}</button>
</div>
</div>
</section>
</div>
<div
v-if="isEditingMetadatum"
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_configure_new_metadatum') }}</h2>
<a
class="back-link"
@click="isEditingMetadatum = false">
{{ $i18n.get('back') }}
</a>
<hr>
</div>
<metadatum-edition-form
:collection-id="collectionId"
:is-repository-level="false"
@onEditionFinished="onMetadatumEditionFinished()"
@onEditionCanceled="onMetadatumEditionCanceled()"
:index="0"
:original-metadatum="metadatum"
:edited-metadatum="editedMetadatum"
:is-on-modal="true"/>
</div>
<metadatum-edition-form
:collection-id="collectionId"
:is-repository-level="false"
@onEditionFinished="onMetadatumEditionFinished()"
@onEditionCanceled="onMetadatumEditionCanceled()"
:index="0"
:original-metadatum="metadatum"
:edited-metadatum="editedMetadatum"
:is-on-modal="true"/>
</div>
</b-modal>
<a

View File

@ -337,7 +337,8 @@ export default {
this.amountFinished --;
});
}
}
},
trapFocus: true
});
},
},

View File

@ -212,7 +212,10 @@
:can-cancel="false"
:active.sync="isTextModalActive"
:width="640"
scroll="keep">
scroll="keep"
trap-focus
aria-modal
aria-role="dialog">
<div class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_write_text') }}</h2>
@ -248,7 +251,12 @@
:can-cancel="false"
:active.sync="isURLModalActive"
:width="640"
scroll="keep">
scroll="keep"
trap-focus
role="dialog"
tabindex="-1"
aria-modal
aria-role="dialog">
<div class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_insert_url') }}</h2>
@ -1095,7 +1103,8 @@ export default {
this.$console.error(error);
});
}
}
},
trapFocus: true
});
},
@ -1191,7 +1200,8 @@ export default {
this.deleteItem({ itemId: this.itemId, isPermanently: true });
this.$router.push(this.$routerHelper.getCollectionPath(this.form.collectionId))
}
}
},
trapFocus: true
});
},
loadExistingItem() {
@ -1372,7 +1382,8 @@ export default {
onConfirm: () => {
next();
},
}
},
trapFocus: true
});
} else {
next()

View File

@ -115,7 +115,7 @@
<span
v-if="metadatum.required == 'yes'"
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
:title="metadatum.name"
:message="metadatum.description"/>
@ -308,7 +308,8 @@ export default {
onConfirm: () => {
this.$router.push(this.$routerHelper.getCollectionItemsPath(this.collectionId));
}
}
},
trapFocus: true
});
} else if (status == 'trash') {
@ -336,7 +337,8 @@ export default {
this.isTrashingItems = false;
});
}
}
},
trapFocus: true
});
}
},

View File

@ -274,7 +274,8 @@
onConfirm: () => {
next();
}
}
},
trapFocus: true
});
} else if (this.isEditingTerm) {
this.$buefy.modal.open({
@ -287,7 +288,8 @@
onConfirm: () => {
next();
}
}
},
trapFocus: true
});
} else {
next();

View File

@ -5,6 +5,15 @@
@submit.prevent="saveEdition(editForm)">
<div class="tainacan-page-title">
<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>
</div>
@ -181,16 +190,6 @@
{{ $i18n.get('cancel') }}
</button>
</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">
<button
class="button is-success"
@ -443,16 +442,21 @@
animation-duration: 0.5s;
.tainacan-page-title {
margin-bottom: 35px;
margin-bottom: 30px;
display: flex;
flex-wrap: wrap;
align-items: baseline;
h2 {
font-size: 20px;
font-weight: 500;
color: $blue5;
display: inline-block;
margin-right: auto;
}
hr{
hr {
margin: 3px 0px 4px 0px;
width: 100%;
height: 1px;
background-color: $secondary;
}

View File

@ -70,19 +70,19 @@
class="table-creation column-small-width"
@click="openActivityDetailsModal(activity)"
:label="$i18n.get('label_activity_date')"
:aria-label="$i18n.get('label_activity_date') + ': ' + activity.log_date">
:aria-label="$i18n.get('label_activity_date') + ': ' + activity.date">
<p
v-tooltip="{
delay: {
show: 500,
hide: 300,
},
content: activity.log_date,
content: activity.date,
autoHide: false,
classes: ['tooltip', 'repository-tooltip'],
placement: 'auto-start'
}"
v-html="activity.log_date"/>
v-html="activity.date"/>
</td>
<!-- Approbation -->
<!--<td-->
@ -125,9 +125,9 @@
</template>
<script>
import {mapActions} from 'vuex';
import { mapActions } from 'vuex';
import ActivityDetailsModal from '../other/activity/activity-details-modal.vue';
import ActivityDetailsModal from '../other/activity-details-modal.vue';
import ThreeStateToggleButton from '../other/three-state-toggle-button.vue';
export default {
@ -154,9 +154,9 @@
'approve',
'notApprove'
]),
getThis(){
return this;
},
// getThis(){
// return this;
// },
approveActivity(activity) {
this.approve(activity.id)
.then(data => {
@ -172,12 +172,13 @@
parent: this,
component: ActivityDetailsModal,
props: {
activity: activity,
activityId: activity.id,
},
events: {
approveActivity: (activityId) => this.approveActivity(activityId),
notApproveActivity: (activityId) => this.notApproveActivity(activityId)
}
},
trapFocus: true
});
},
},

View File

@ -91,7 +91,8 @@ export default {
title: this.$i18n.get('label_warning'),
message: this.$i18n.get('info_warning_terms_not_saved'),
onConfirm: () => { this.removeTerm(); },
}
},
trapFocus: true
});
} else {
this.removeTerm();
@ -110,8 +111,9 @@ export default {
onConfirm: () => {
// If all checks passed, term can be deleted
this.$termsListBus.onDeleteBasicTermItem(this.term);
},
}
}
},
trapFocus: true
});
},
eventOnEditTerm() {

View File

@ -16,7 +16,8 @@
v-if="$userCaps.hasCapability('delete_tainacan-collections')"
:disabled="!isSelectingCollections"
id="bulk-actions-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-white"
slot="trigger">
@ -54,7 +55,8 @@
<b-dropdown
inline
:style="{ top: cursorPosY + 'px', left: cursorPosX + 'px' }">
:style="{ top: cursorPosY + 'px', left: cursorPosX + 'px' }"
trap-focus>
<b-dropdown-item
@click="openCollection()"
v-if="!isOnTrash">
@ -387,8 +389,8 @@ export default {
// })
});
}
}
},
trapFocus: true
});
this.clearContextMenu();
},
@ -426,8 +428,9 @@ export default {
}
}
this.allCollectionsOnPageSelected = false;
},
}
}
},
trapFocus: true
});
},
openCollection() {
@ -473,48 +476,6 @@ export default {
this.contextMenuCollection = null;
this.contextMenuIndex = null;
}
},
mounted() {
// COLUMN RESIZE
// This feature is not implemented as it would require whitespace
// on table cells to be 'wrap' instead of 'no-wrap'. Once the table
// needs a scroll, the minimum size for the columns would be reached
// text would start to ellipsis, but the column is not resizible anymore.
// (function () {
// var thElm;
// var startOffset;
// Array.prototype.forEach.call(
// document.querySelectorAll("table th"),
// function (th) {
// th.style.position = 'relative';
// var grip = document.createElement('div');
// grip.innerHTML = "&nbsp;";
// grip.style.top = 0;
// grip.style.right = 0;
// grip.style.bottom = 0;
// grip.style.width = '5px';
// grip.style.position = 'absolute';
// grip.style.cursor = 'col-resize';
// grip.addEventListener('mousedown', function (e) {
// thElm = th;
// startOffset = th.offsetWidth - e.pageX;
// });
// th.appendChild(grip);
// });
// document.addEventListener('mousemove', function (e) {
// if (thElm) {
// thElm.style.width = startOffset + e.pageX + 'px';
// }
// });
// document.addEventListener('mouseup', function () {
// thElm = undefined;
// });
// })();
}
}
</script>

View File

@ -96,7 +96,7 @@
<span
v-if="filter.filter_type_object != undefined"
class="label-details">
({{ $i18n.get(filter.filter_type_object.component) }})
({{ filter.filter_type_object.name }})
<span
class="not-saved"
v-if="(editForms[filter.id] != undefined && editForms[filter.id].saved != true) ||filter.status == 'auto-draft'">
@ -117,7 +117,7 @@
@input="onChangeEnable($event, index)"/>
<a
:style="{ visibility: filter.collection_id != collectionId && !isRepositoryLevel? 'hidden' : 'visible' }"
@click.prevent="editFilter(filter)">
@click.prevent="toggleFilterEdition(filter.id)">
<span
v-tooltip="{
content: $i18n.get('edit'),
@ -234,8 +234,15 @@
<b-modal
ref="filterTypeModal"
:width="680"
:active.sync="isSelectingFilterType">
:active.sync="isSelectingFilterType"
trap-focus
aria-modal
aria-role="dialog">
<div
autofocus
role="dialog"
tabindex="-1"
aria-modal
class="tainacan-modal-content"
style="width: auto">
<header class="tainacan-modal-title">
@ -353,6 +360,18 @@ export default {
components: {
FilterEditionForm
},
watch: {
'$route.query': {
handler(newQuery) {
if (newQuery.edit != undefined) {
let existingFilterIndex = this.activeFilterList.findIndex((filter) => filter.id == newQuery.edit);
if (existingFilterIndex >= 0)
this.editFilter(this.activeFilterList[existingFilterIndex])
}
},
immediate: true
}
},
beforeRouteLeave ( to, from, next ) {
let hasUnsavedForms = false;
for (let editForm in this.editForms) {
@ -371,7 +390,8 @@ export default {
this.onEditionCanceled();
next();
},
}
},
trapFocus: true
});
} else {
next()
@ -463,9 +483,9 @@ export default {
// Removes element from filters list
this.activeFilterList.splice(this.newFilterIndex, 1);
},
handleChangeOnMetadata($event) {
handleChangeOnMetadata($event) {
if ($event.removed) {
this.oldMetadatumIndex = $event.removed.oldIndex;
this.oldMetadatumIndex = $event.removed.oldIndex;
}
},
updateFiltersOrder() {
@ -509,7 +529,7 @@ export default {
collectionId: this.collectionId,
metadatumId: this.choosenMetadatum.id,
name: this.choosenMetadatum.name,
filterType: this.selectedFilterType.name,
filterType: this.selectedFilterType.className,
status: 'auto-draft',
isRepositoryLevel: this.isRepositoryLevel,
newIndex: this.newFilterIndex
@ -524,7 +544,7 @@ export default {
this.selectedFilterType = {}
this.allowedFilterTypes = [];
this.editFilter(filter);
this.toggleFilterEdition(filter.id);
})
.catch((error) => {
this.$console.error(error);
@ -559,46 +579,43 @@ export default {
// this.deleteTemporaryFilter(this.newFilterIndex);
this.newFilterIndex = 0;
},
editFilter(filter) {
toggleFilterEdition(filterId) {
// Closing collapse
if (this.openedFilterId == filter.id) {
if (this.openedFilterId == filterId) {
this.openedFilterId = '';
this.$router.push({ query: {}});
// Opening collapse
} else {
if (this.openedFilterId == '' && this.choosenMetadatum.id != undefined) {
this.availableMetadata.push(this.choosenMetadatum);
this.choosenMetadatum = {};
this.allowedFilterTypes = [];
this.selectedFilterType = {};
// this.deleteTemporaryFilter(this.newFilterIndex);
this.newFilterIndex = 0;
}
this.openedFilterId = filter.id;
this.$router.push({ query: { edit: filterId}})
}
},
editFilter(filter) {
this.openedFilterId = filter.id;
// First time opening
if (this.editForms[this.openedFilterId] == undefined) {
this.editForms[this.openedFilterId] = JSON.parse(JSON.stringify(filter));
this.editForms[this.openedFilterId].saved = true;
// Filter inserted now
if (this.editForms[this.openedFilterId].status == 'auto-draft') {
this.editForms[this.openedFilterId].status = 'publish';
this.editForms[this.openedFilterId].saved = false;
}
}
}
// First time opening
if (this.editForms[this.openedFilterId] == undefined) {
this.editForms[this.openedFilterId] = JSON.parse(JSON.stringify(filter));
this.editForms[this.openedFilterId].saved = true;
// Filter inserted now
if (this.editForms[this.openedFilterId].status == 'auto-draft') {
this.editForms[this.openedFilterId].status = 'publish';
this.editForms[this.openedFilterId].saved = false;
}
}
},
onEditionFinished() {
this.formWithErrors = '';
delete this.editForms[this.openedFilterId];
this.openedFilterId = '';
this.$router.push({ query: {}});
},
onEditionCanceled() {
this.formWithErrors = '';
delete this.editForms[this.openedFilterId];
this.openedFilterId = '';
this.$router.push({ query: {}});
},
getProperPreviewMinHeight() {
for (let filterType of this.allowedFilterTypes) {
@ -610,6 +627,55 @@ export default {
}
}
return 190;
},
refreshFilters() {
this.fetchFilters({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: !this.isOnTheme,
includeDisabled: true,
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = true;
// Checks URL as router watcher would not wait for list to load
if (this.$route.query.edit != undefined) {
let existingFilterIndex = this.activeFilterList.findIndex((filter) => filter.id == this.$route.query.edit);
if (existingFilterIndex >= 0)
this.editFilter(this.activeFilterList[existingFilterIndex]);
}
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
// Needs to be done after activeFilterList exists to compare and remove chosen metadata.
this.fetchMetadata({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: true
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = false;
this.updateListOfMetadata();
})
.catch(() => {
this.isLoadingMetadatumTypes = false;
});
// Search Request Token for cancelling
this.metadataSearchCancel = resp.source;
})
.catch(() => this.isLoadingMetadatumTypes = false);
})
.catch(() => this.isLoadingFilters = false);
// Search Request Token for cancelling
this.filtersSearchCancel = resp.source;
})
.catch(() => this.isLoadingFilters = false);
}
},
mounted() {
@ -643,52 +709,8 @@ export default {
if (this.filtersSearchCancel != undefined)
this.filtersSearchCancel.cancel('Filters search Canceled.');
this.fetchFilters({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: !this.isOnTheme,
includeDisabled: true,
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = true;
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
// Needs to be done after activeFilterList exists to compare and remove chosen metadata.
this.fetchMetadata({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: true
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = false;
this.updateListOfMetadata();
})
.catch(() => {
this.isLoadingMetadatumTypes = false;
});
// Search Request Token for cancelling
this.metadataSearchCancel = resp.source;
})
.catch(() => this.isLoadingMetadatumTypes = false);
})
.catch(() => this.isLoadingFilters = false);
// Search Request Token for cancelling
this.filtersSearchCancel = resp.source;
})
.catch(() => this.isLoadingFilters = false);
// On repository level we also fetch collection filters
if (this.isRepositoryLevel) {
this.fetchRepositoryCollectionFilters()
.catch(() => this.isLoadingFilters = false);
}
// Loads Filters
this.refreshFilters();
// Obtains collection name
if (!this.isRepositoryLevel) {
@ -1152,6 +1174,10 @@ export default {
font-size: 1rem;
margin-left: -16px;
}
.field .collapse-handle {
display: flex;
}
input, select, textarea,
.input, .tags, .tag {

View File

@ -31,7 +31,8 @@
v-if="items.length > 0 && items[0].current_user_can_edit"
:disabled="selectedItems.length <= 1"
id="bulk-actions-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-white"
slot="trigger">
@ -85,7 +86,8 @@
<b-dropdown
inline
:style="{ top: cursorPosY + 'px', left: cursorPosX + 'px' }">
:style="{ top: cursorPosY + 'px', left: cursorPosX + 'px' }"
trap-focus>
<b-dropdown-item
@click="openItem()"
v-if="!isOnTrash && !$route.query.iframemode">
@ -1030,6 +1032,7 @@ export default {
collectionID: this.$route.params.collectionId,
},
width: 'calc(100% - 8.333333333%)',
trapFocus: true
});
},
sequenceEditSelectedItems() {
@ -1068,7 +1071,8 @@ export default {
this.$eventBusSearch.loadItems();
}
}
}
},
trapFocus: true
});
this.clearContextMenu();
@ -1099,7 +1103,8 @@ export default {
});
});
}
}
},
trapFocus: true
});
},
deleteOneItem(itemId) {
@ -1121,7 +1126,8 @@ export default {
this.$eventBusSearch.loadItems();
});
}
}
},
trapFocus: true
});
this.clearContextMenu();
},
@ -1151,7 +1157,8 @@ export default {
});
});
}
}
},
trapFocus: true
});
},
deleteSelectedItems() {
@ -1189,7 +1196,8 @@ export default {
}
});
}
}
},
trapFocus: true
});
},
openItem() {

View File

@ -98,19 +98,17 @@
{{ metadatum.name }}
</span>
<span
v-if="metadatum.id != undefined"
v-if="metadatum.id != undefined && metadatum.metadata_type_object"
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.metadata_type_object &&
metadatum.metadata_type_object.core &&
v-if="metadatum.metadata_type_object.core &&
metadatum.metadata_type_object.related_mapped_prop == 'title'">
{{ $i18n.get('label_core_title') }}
</em>
<em
v-if="metadatum.metadata_type_object &&
metadatum.metadata_type_object.core &&
v-if="metadatum.metadata_type_object.core &&
metadatum.metadata_type_object.related_mapped_prop == 'description'">
{{ $i18n.get('label_core_description') }}
</em>
@ -235,7 +233,7 @@
</div>
</b-tab-item>
<!-- Exposer --------------- -->
<!-- Mapping --------------- -->
<b-tab-item :label="$i18n.get('mapping')">
<div>
<section
@ -247,11 +245,10 @@
<i class="tainacan-icon tainacan-icon-36px tainacan-icon-metadata"/>
</span>
</p>
<p>{{ $i18n.get('info_there_is_no_metadatum') }}</p>
<p>{{ $i18n.get('info_create_metadata') }}</p>
<p>{{ $i18n.get('info_there_is_no_metadatum') }}</p>
</div>
</section>
<section>
<section v-else>
<div class="field is-grouped form-submit">
<b-select
id="mappers-options-dropdown"
@ -372,8 +369,15 @@
</section>
<b-modal
@close="onCancelNewMetadataMapperMetadata"
:active.sync="isMapperMetadataCreating">
:active.sync="isMapperMetadataCreating"
trap-focus
aria-modal
aria-role="dialog">
<div
autofocus
role="dialog"
tabindex="-1"
aria-modal
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('instruction_insert_mapper_metadatum_info') }}</h2>
@ -527,7 +531,8 @@ export default {
this.onEditionCanceled();
next();
},
}
},
trapFocus: true
});
} else {
next()
@ -594,7 +599,14 @@ export default {
},
addNewMetadatum(newMetadatum, newIndex) {
this.sendMetadatum({collectionId: this.collectionId, name: newMetadatum.name, metadatumType: newMetadatum.className, status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex})
this.sendMetadatum({
collectionId: this.collectionId,
name: newMetadatum.name,
metadatumType: newMetadatum.className,
status: 'auto-draft',
isRepositoryLevel: this.isRepositoryLevel,
newIndex: newIndex
})
.then((metadatum) => {
if (!this.isRepositoryLevel)
@ -626,8 +638,9 @@ export default {
.catch(() => {
this.$console.log("Error deleting metadatum.")
});
},
}
}
},
trapFocus: true
});
},
toggleMetadatumEdition(metadatumId) {

View File

@ -15,7 +15,8 @@
<b-dropdown
position="is-bottom-left"
:disabled="!isSelecting"
id="bulk-actions-dropdown">
id="bulk-actions-dropdown"
trap-focus>
<button
class="button is-white"
slot="trigger">
@ -389,7 +390,8 @@
// });
});
}
}
},
trapFocus: true
});
},
deleteSelected() {
@ -427,7 +429,8 @@
}
this.allOnPageSelected = false;
}
}
},
trapFocus: true
});
},
getDate(rawDate) {
@ -451,7 +454,8 @@
onConfirm: () => {
this.updateProcess({ id: this.processes[index].ID, status: 'closed' });
},
}
},
trapFocus: true
});
}
},

View File

@ -218,7 +218,8 @@ export default {
title: this.$i18n.get('label_warning'),
message: this.$i18n.get('info_warning_terms_not_saved'),
onConfirm: () => { this.removeTerm(); },
}
},
trapFocus: true
});
} else {
this.removeTerm();
@ -258,8 +259,9 @@ export default {
});
}
}
},
}
}
},
trapFocus: true
});
},
eventOnChildTermDeleted(parentTermId) {

View File

@ -17,7 +17,8 @@
v-if="$userCaps.hasCapability('delete_tainacan-taxonomies')"
:disabled="!isSelecting"
id="bulk-actions-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-white"
slot="trigger">
@ -267,7 +268,8 @@
// });
});
}
}
},
trapFocus: true
});
},
deleteSelected() {
@ -305,7 +307,8 @@
}
this.allOnPageSelected = false;
}
}
},
trapFocus: true
});
},
onClickTaxonomy($event, taxonomyId, index) {

View File

@ -16,7 +16,8 @@
:mobile-modal="true"
:disabled="localTerms.length <= 0 || isLoadingTerms || isEditingTerm"
@input="onChangeOrder(order == 'asc' ? 'desc' : 'asc')"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting_direction')"
class="button is-white"
@ -64,15 +65,15 @@
type="search"
:aria-label="$i18n.get('instruction_search') + ' ' + $i18n.get('terms')"
autocomplete="on"
:value="searchQuery"
@keyup.enter="searchQuery = $event.target.value;searchTerms(0)"
v-model="searchQuery"
@keyup.enter="searchTerms(0)"
:disabled="isEditingTerm">
<span
@click="searchTerms(0)"
class="icon is-right"
:class="{ 'has-text-gray3': isEditingTerm }">
<i class="tainacan-icon tainacan-icon-search" />
</span>
<span
@click="searchTerms(0)"
class="icon is-right"
:class="{ 'has-text-gray3': isEditingTerm }">
<i class="tainacan-icon tainacan-icon-search" />
</span>
</div>
</div>
</div>

View File

@ -61,7 +61,8 @@
ref="advancedSearchShortcut"
class="advanced-search-header-dropdown"
position="is-bottom-left"
aria-role="list">
aria-role="list"
trap-focus>
<a
class="advanced-search-text"
slot="trigger">

View File

@ -130,7 +130,8 @@ export default {
props: {
sourceCollection: this.collectionId,
hideWhenManualCollection: true
}
},
trapFocus: true
});
}
}

View File

@ -0,0 +1,790 @@
<template>
<div
autofocus
role="dialog"
class="tainacan-modal-content"
tabindex="-1"
aria-modal
ref="activityDetailsModal">
<header
v-if="!isLoadingActivity"
class="tainacan-modal-title">
<h2>{{ activity.title ? activity.title : $i18n.get('activity') }}</h2>
<hr>
<p>{{ activityCreationDate + ', ' + $i18n.get('info_by_inner') }} <strong> {{ activity.user_name }}</strong></p>
</header>
<b-loading
:is-full-page="false"
:active.sync="isLoadingActivity"
:can-cancel="false"/>
<div
v-if="!isLoadingActivity"
class="modal-card-body">
<div class="content">
<p v-if="activity.description"><strong>{{ $i18n.get('label_activity_description') }}:</strong> {{ activity.description }}</p>
<p v-if="activity.object">
<strong>{{ $i18n.get('label_related_to') }}: </strong>
<span v-html="relatedToLink" />
</p>
</div>
<!-- LEGACY LOG API RETURN -->
<div v-if="activity.legacy != undefined && activity.legacy == true">
<template v-for="(diff, attributeName, index) in activity.log_diffs">
<div
:key="index"
class="columns">
<!-- OLD -->
<div class="column is-6">
<!-- Thumbnail -->
<div
class="content"
v-if="attributeName == 'thumbnail'">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div>
<picture>
<img
width="150px"
:src="diff.old ? diff.old : placeholderSquareImage"
:alt="attributeName">
</picture>
</div>
</div>
<div
v-if="attributeName == 'attachments'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div
class="tainacan-attachments-in-modal"
v-if="diff.old.length">
<template v-for="(attachment, anotherIndex) in diff.old">
<file-item
:key="anotherIndex"
:modal-on-click="false"
:show-name="true"
:file="{
title: { rendered: attachment.title },
guid: { rendered: attachment.url },
mime_type: attachment.mime_type,
media_type: attachment.mime_type.includes('image') ? 'image' : 'other'
}"/>
</template>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div
class="content"
v-if="!['thumbnail', 'attachments'].includes(attributeName)">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName.replace(/_/g, ' ') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<!-- Is array with length 1 -->
<p
class="tainacan-p-break"
v-if="(diff.old instanceof Array) &&
(diff.old.length == 1) &&
!(diff.old[0] instanceof Object)">
{{ diff.old.toString() }}
</p>
<div
v-else-if="attributeName == 'metadata_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.old"
:key="diffTitle">
{{ diff.old ? `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` : infoEmpty }}
</p>
</div>
<div
v-else-if="attributeName == 'filters_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.old"
:key="diffTitle">
{{ diff.old ? `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` : infoEmpty }}
</p>
</div>
<div
v-else-if="attributeName == 'metadata_type_options'"
class="content">
<p class="tainacan-p-break">
{{ diff.old ?
`Taxonomy ID: ${diff.old.taxonomy_id};
Input type: ${diff.old.input_type};
Allow new terms: ${diff.old.allow_new_terms}` : infoEmpty }}
</p>
</div>
<!-- -->
<p
class="tainacan-p-break"
v-else>
{{ diff.old ? (diff.old instanceof Array && !diff.old.length) ? infoEmpty : diff.old.toString().replace(/,/g, ' ') : infoEmpty }}
</p>
</div>
</div>
<!-- NEW -->
<div class="column is-6">
<!-- Thumbnail -->
<div
class="content"
v-if="attributeName == 'thumbnail'">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div>
<picture>
<img
width="150px"
:src="diff.new ? diff.new : placeholderSquareImage"
:alt="attributeName">
</picture>
</div>
</div>
<div
v-if="attributeName == 'attachments'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div
class="tainacan-attachments-in-modal"
v-if="diff.new.length">
<template v-for="(attachment, index) in diff.new">
<file-item
:key="index"
:modal-on-click="false"
:show-name="true"
:file="{
title: { rendered: attachment.title },
guid: { rendered: attachment.url },
mime_type: attachment.mime_type,
media_type: attachment.mime_type.includes('image') ? 'image' : 'other'
}"/>
</template>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div
class="content"
v-if="!['thumbnail', 'attachments'].includes(attributeName)">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName.replace(/_/g, ' ') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<!-- Is array with length 1 -->
<p
class="tainacan-p-break"
v-if="(diff.new instanceof Array) &&
(diff.new.length == 1) &&
!(diff.new[0] instanceof Object)">
{{ diff.new.toString() }}
</p>
<div
v-else-if="attributeName == 'metadata_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.new"
:key="diffTitle">
{{ `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` }}
</p>
</div>
<div
v-else-if="attributeName == 'filters_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.new"
:key="diffTitle">
{{ `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` }}
</p>
</div>
<div
v-else-if="attributeName == 'metadata_type_options'"
class="content">
<p class="tainacan-p-break">
{{ `Taxonomy ID: ${diff.new.taxonomy_id};
Input type: ${diff.new.input_type};
Allow new terms: ${diff.new.allow_new_terms}` }}
</p>
</div>
<!-- -->
<p
class="tainacan-p-break"
v-else>
{{ diff.new ? (diff.new instanceof Array && !diff.new.length) ? infoEmpty : diff.new.toString().replace(/,/g, ' ') : infoEmpty }}
</p>
</div>
</div>
</div>
</template>
</div>
<!-- NEW LOG API RETURN -->
<div v-else>
<div class="columns">
<!-- OLD -->
<div class="column is-6">
<div
v-if="activity.action == 'update-thumbnail'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ $i18n.get('label_thumbnail') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<p
v-if="activity.old_value && activity.old_value.thumb && activity.old_value.thumb[0]"
class="tainacan-p-break">
<img
style="margin: 12px 0; max-width: 150px;"
:alt="$i18n.get('label_thumbnail')"
:src="activity.old_value.thumb[0]" >
</p>
<p v-else>{{ infoEmpty }}</p>
</div>
<div
v-if="activity.action == 'new-attachment'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ $i18n.get('label_attachment') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div v-if="activity.old_value.url">
<file-item
:modal-on-click="false"
:show-name="true"
:file="{
title: { rendered: activity.old_value.title },
guid: { rendered: activity.old_value.url },
mime_type: activity.old_value.mime_type,
media_type: activity.old_value.mime_type.includes('image') ? 'image' : 'other'
}"/>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div
v-if="activity.action == 'update-document'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ $i18n.get('label_document') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div
:key="index"
v-for="(attributeValue, attributeName, index) of activity.old_value">
<p
v-if="attributeName == 'thumb' && attributeValue[0]"
class="tainacan-p-break">
<img
style="margin: 12px 0; max-width: 150px;"
:alt="$i18n.get('label_document')"
:src="attributeValue[0]" >
</p>
<p
v-else
v-html="`<strong>` + attributeName + `: </strong>` + (attributeValue ? attributeValue : infoEmpty)"
class="tainacan-p-break" />
</div>
</div>
<div
class="content"
v-if="activity.action == 'update-metadata-order' || activity.action == 'update-filters-order'">
<div
:key="index"
v-for="(attributeValue, attributeName, index) in activity.old_value">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in attributeValue"
:key="diffTitle"
v-html="attributeValue ? `ID: ${diffContent.id} <span class='is-italic'>(${diffContent.enabled ? $i18n.get('label_enabled') : $i18n.get('label_disabled')})</span>` : infoEmpty " />
</div>
</div>
</div>
<div
class="content"
v-if="activity.action == 'update'">
<div
:key="index"
v-for="(attributeValue, attributeName, index) in activity.old_value">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<!-- Is array with length 1 -->
<p
class="tainacan-p-break"
v-if="(attributeValue instanceof Array) &&
(attributeValue.length == 1) &&
!(attributeValue[0] instanceof Object)">
{{ attributeValue.toString() }}
</p>
<div
v-else-if="attributeName == 'metadata_type_options'"
class="content">
<p
:key="innerIndex"
v-for="(innerValue, innerName, innerIndex) of attributeValue"
class="tainacan-p-break">
<strong>{{ innerName + ': ' }}</strong>{{ innerValue ? innerValue : infoEmpty }}
<br>
</p>
</div>
<p
class="tainacan-p-break"
v-else
v-html="(!attributeValue || (attributeValue instanceof Array && !attributeValue.length)) ? infoEmpty : (attributeValue instanceof Array ? attributeValue.join(`<span class='multivalue-separator'>|</span>`) : attributeValue)" />
</div>
</div>
<div
class="content"
v-if="activity.action == 'update-metadata-value'">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ activity.metadata && activity.metadata.name ? activity.metadata.name : $i18n.get('metadatum') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<p
class="tainacan-p-break"
v-html="!activity.old_value ? infoEmpty : (activity.old_value instanceof Array ? activity.old_value.join(`<span class='multivalue-separator'>|</span>`) : activity.old_value)" />
</div>
</div>
<!-- NEW -->
<div class="column is-6">
<div
v-if="activity.action == 'update-thumbnail'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ $i18n.get('label_thumbnail') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<p
v-if="activity.new_value && activity.new_value.thumb && activity.new_value.thumb[0]"
class="tainacan-p-break">
<img
style="margin: 12px 0; max-width: 150px;"
:alt="$i18n.get('label_thumbnail')"
:src="activity.new_value.thumb[0]" >
</p>
<p v-else>{{ infoEmpty }}</p>
</div>
<div
v-if="activity.action == 'new-attachment'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ $i18n.get('label_attachment') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div v-if="activity.new_value.url">
<file-item
:modal-on-click="false"
:show-name="true"
:file="{
title: { rendered: activity.new_value.title },
guid: { rendered: activity.new_value.url },
mime_type: activity.new_value.mime_type,
media_type: activity.new_value.mime_type.includes('image') ? 'image' : 'other'
}"/>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div
v-if="activity.action == 'update-document'"
class="content">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ $i18n.get('label_document') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div
:key="index"
v-for="(attributeValue, attributeName, index) of activity.new_value">
<p
v-if="attributeName == 'thumb' && attributeValue[0]"
class="tainacan-p-break">
<img
style="margin: 12px 0; max-width: 150px;"
:alt="$i18n.get('label_document')"
:src="attributeValue[0]" >
</p>
<p
v-else
v-html="`<strong>` + attributeName + `: </strong>` + (attributeValue ? attributeValue : infoEmpty)"
class="tainacan-p-break" />
</div>
</div>
<div
class="content"
v-if="activity.action == 'update-metadata-order' || activity.action == 'update-filters-order'">
<div
:key="index"
v-for="(attributeValue, attributeName, index) in activity.new_value">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in attributeValue"
:key="diffTitle"
v-html="attributeValue ? `ID: ${diffContent.id} <span class='is-italic'>(${diffContent.enabled ? $i18n.get('label_enabled') : $i18n.get('label_disabled')})</span>` : infoEmpty " />
</div>
</div>
</div>
<div
:key="index"
v-for="(attributeValue, attributeName, index) in activity.new_value">
<div
class="content"
v-if="activity.action == 'update'">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ attributeName }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div
v-if="attributeName == 'metadata_type_options'"
class="content">
<p
:key="innerIndex"
v-for="(innerValue, innerName, innerIndex) of attributeValue"
class="tainacan-p-break">
<strong>{{ innerName + ': ' }}</strong>{{ innerValue ? innerValue : infoEmpty }}
<br>
</p>
</div>
<div
v-else-if="attributeName == 'header_image_id'"
class="content">
<p class="tainacan-p-break">
{{ attributeValue ? attributeValue : infoEmpty }}
<br>
<img
style="margin: 12px 0; max-width: 160px;"
v-if="activity.terms && activity.terms.header_image"
:alt="$i18n.get('label_header_image')"
:src="activity.terms.header_image" >
</p>
</div>
<p
class="tainacan-p-break"
v-else
v-html="(!attributeValue || (attributeValue instanceof Array && !attributeValue.length)) ? infoEmpty : (attributeValue instanceof Array ? attributeValue.join(`<span class='multivalue-separator'>|</span>`) : attributeValue)" />
</div>
</div>
<div
class="content"
v-if="activity.action == 'update-metadata-value'">
<p class="is-capitalized has-text-blue5 has-text-weight-bold">
{{ activity.metadata && activity.metadata.name ? activity.metadata.name : $i18n.get('metadatum') }}
<small class="has-text-gray4 has-text-weight-normal"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<p
class="tainacan-p-break"
v-html="!activity.new_value ? infoEmpty : (activity.new_value instanceof Array ? activity.new_value.join(`<span class='multivalue-separator'>|</span>`) : activity.new_value)" />
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="control">
<button
class="button is-outlined"
type="button"
@click="$parent.close()">
{{ $i18n.get('close') }}
</button>
<div class="buttons is-pulled-right">
<!--<button-->
<!--v-if="activity.status != 'publish'"-->
<!--@click="notApproveActivity"-->
<!--type="button"-->
<!--class="button is-danger">-->
<!--<b-icon-->
<!--size="is-small"-->
<!--icon="close"/>-->
<!--<span>{{ $i18n.get('not_approve_item') }}</span>-->
<!--</button>-->
<!--<button-->
<!--v-if="activity.status != 'publish'"-->
<!--@click="approveActivity"-->
<!--type="button"-->
<!--class="button is-secondary">-->
<!--<b-icon-->
<!--size="is-small"-->
<!--icon="check"/>-->
<!--<span>{{ $i18n.get('approve_item') }}</span>-->
<!--</button>-->
<!--<button-->
<!--v-if="activity.status == 'publish'"-->
<!--@click="notApproveActivity"-->
<!--type="button"-->
<!--class="button is-blue5">-->
<!--<b-icon-->
<!--custom-class="mdi-flip-h"-->
<!--size="is-small"-->
<!--icon="share"/>-->
<!--<span>{{ $i18n.get('undo') }}</span>-->
<!--</button>-->
<!-- <button
v-if="activity.status == 'publish'"
@click="$parent.close()"
type="button"
class="button is-secondary">
<span>OK</span>
</button> -->
</div>
</div>
</footer>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
import moment from 'moment';
import FileItem from './file-item.vue';
export default {
name: "ActivityDetailsModal",
props: {
activityId: String
},
data() {
return {
infoEmpty: `[ ${this.$i18n.get('info_empty').toLowerCase()} ]`,
dateFormat: '',
activityCreationDate: '',
placeholderSquareImage: `${tainacan_plugin.base_url}/admin/images/placeholder_square.png`,
isLoadingActivity: false,
adminFullURL: tainacan_plugin.admin_url + 'admin.php?page=tainacan_admin#',
}
},
components: {
FileItem
},
watch: {
'$route' (to, from) {
if (to !== from)
this.$parent.close();
}
},
computed: {
activity() {
return this.getActivity();
},
relatedToLink() {
switch(this.activity.object_type) {
case 'Tainacan\\Entities\\Collection':
return `${ this.$i18n.get('collection') }
<a href="${ this.adminFullURL + this.$routerHelper.getCollectionPath(this.activity.object_id) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-collections"/></span>`;
case 'Tainacan\\Entities\\Taxonomy':
return `${ this.$i18n.get('taxonomy') }
<a href="${ this.adminFullURL + this.$routerHelper.getTaxonomyPath(this.activity.object_id) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-taxonomies"/></span>`;
case 'Tainacan\\Entities\\Metadatum':
return `${ this.$i18n.get('metadatum') }
<a href="${ this.adminFullURL + (this.activity.object.collection_id == 'default' ? this.$routerHelper.getMetadataEditPath(this.activity.object_id) : this.$routerHelper.getCollectionMetadataEditPath(this.activity.object.collection_id, this.activity.object_id)) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-metadata"/></span>`;
case 'Tainacan\\Entities\\Filter':
return `${ this.$i18n.get('filter') }
<a href="${ this.adminFullURL + (this.activity.object.collection_id == 'default' ? this.$routerHelper.getFilterEditPath(this.activity.object_id) : this.$routerHelper.getCollectionFilterEditPath(this.activity.object.collection_id, this.activity.object_id)) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-filters"/></span>`;
case 'Tainacan\\Entities\\Term':
return `${ this.$i18n.get('term') }
<a href="${ this.adminFullURL + this.$routerHelper.getTermEditPath(this.activity.object.taxonomy.replace( /^\D+/g, ''), this.activity.object_id) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-terms"/></span>`;
case 'Tainacan\\Entities\\Item':
return `${ this.$i18n.get('item') }
<a href="${ this.adminFullURL + this.$routerHelper.getItemEditPath(this.activity.object.collection_id, this.activity.object_id) }">${ this.activity.object.title }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-items"/></span>`;
case 'Tainacan\\Entities\\Item_Metadata_Entity':
return `${ this.$i18n.get('item') }
<a href="${ this.adminFullURL + this.$routerHelper.getItemEditPath(this.activity.object.collection_id, this.activity.item.id) }">${ this.activity.item.title }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-items"/></span>`;
}
}
},
created() {
this.loadActivity();
},
mounted() {
if (this.$refs.activityDetailsModal)
this.$refs.activityDetailsModal.focus()
},
methods: {
...mapActions('activity', [
'fetchActivity'
]),
...mapGetters('activity', [
'getActivity'
]),
approveActivity(){
this.$emit('approveActivity', this.activity.id);
},
notApproveActivity(){
this.$emit('notApproveActivity', this.activity.id);
},
loadActivity() {
this.isLoadingActivity = true;
this.fetchActivity(this.activityId)
.then(() => {
this.isLoadingActivity = false;
let locale = navigator.language;
moment.locale(locale);
let localeData = moment.localeData();
this.dateFormat = localeData.longDateFormat('lll');
let logDate = this.activity.log_date;
let date = moment(logDate).format(this.dateFormat);
if (date != 'Invalid date') {
this.activityCreationDate = date;
} else {
this.activityCreationDate = this.$i18n.get('info_unknown_date');
}
})
.catch(() => this.isLoadingActivity = false);
}
}
}
</script>
<style lang="scss" scoped>
@import "../../scss/_variables.scss";
.tainacan-modal-title {
align-self: baseline;
display: flex;
flex-direction: column;
width: 100%;
p {
margin-right: auto;
}
}
.tainacan-modal-content {
width: auto;
min-height: 500px;
p {
font-size: 0.875rem;
}
}
.modal-card-body {
min-height: 300px;
padding: 0;
.columns {
margin: 6px $page-side-padding 0 $page-side-padding;
}
}
.tainacan-attachments-in-modal {
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-content: baseline;
resize: vertical;
overflow-y: auto;
overflow-x: hidden;
height: 200px;
border: 1px solid $gray3;
&>div {
margin: 0.5rem;
}
}
.tainacan-p-overflow {
text-overflow: ellipsis;
white-space: nowrap;
max-width: 150px;
overflow: hidden;
}
p.is-capitalized {
margin-bottom: 0.125rem;
}
.tainacan-p-break {
word-break: break-word;
margin-bottom: 0.5rem;
}
.tainacan-figure {
width: 150px;
height: 150px;
overflow: auto;
}
</style>

View File

@ -1,401 +0,0 @@
<template>
<div class="tainacan-modal-content">
<header class="tainacan-modal-title">
<h2>{{ $i18n.get('activity') }}</h2>
<hr>
</header>
<div class="modal-card-body">
<div class="content">
<p><strong>{{ $i18n.get('label_activity_description') }}:</strong> {{ activity.description }}</p>
<p><strong>{{ $i18n.get('label_activity_creation_date') }}:</strong> {{ activityCreationDate }}</p>
<p><strong>{{ $i18n.get('label_activity_author') }}:</strong> {{ activity.user_name }}</p>
</div>
<div>
<template v-for="(diff, attributeName, index) in activity.log_diffs">
<div
:key="index"
class="columns">
<!-- OLD -->
<div class="column is-6">
<!-- Thumbnail -->
<div
class="content"
v-if="attributeName == 'thumbnail'">
<p class="is-capitalized has-text-blue5">
{{ attributeName }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div>
<picture>
<img
width="150px"
:src="diff.old ? diff.old : placeholderSquareImage"
:alt="attributeName">
</picture>
</div>
</div>
<div
v-if="attributeName == 'attachments'"
class="content">
<p class="is-capitalized has-text-blue5">
{{ attributeName }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<div
class="tainacan-attachments-in-modal"
v-if="diff.old.length">
<template v-for="(attachment, anotherIndex) in diff.old">
<file-item
:key="anotherIndex"
:modal-on-click="false"
:show-name="true"
:file="{
title: { rendered: attachment.title },
guid: { rendered: attachment.url },
mime_type: attachment.mime_type,
media_type: attachment.mime_type.includes('image') ? 'image' : 'other'
}"/>
</template>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div
class="content"
v-if="!['thumbnail', 'attachments'].includes(attributeName)">
<p class="is-capitalized has-text-blue5">
{{ attributeName.replace(/_/g, ' ') }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_before')})` }}</small>
</p>
<!-- Is array with length 1 -->
<p
class="tainacan-p-break"
v-if="(diff.old instanceof Array) &&
(diff.old.length == 1) &&
!(diff.old[0] instanceof Object)">
{{ diff.old.toString() }}
</p>
<div
v-else-if="attributeName == 'metadata_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.old"
:key="diffTitle">
{{ diff.old ? `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` : infoEmpty }}
</p>
</div>
<div
v-else-if="attributeName == 'filters_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.old"
:key="diffTitle">
{{ diff.old ? `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` : infoEmpty }}
</p>
</div>
<div
v-else-if="attributeName == 'metadata_type_options'"
class="content">
<p class="tainacan-p-break">
{{ diff.old ?
`Taxonomy ID: ${diff.old.taxonomy_id};
Input type: ${diff.old.input_type};
Allow new terms: ${diff.old.allow_new_terms}` : infoEmpty }}
</p>
</div>
<!-- -->
<p
class="tainacan-p-break"
v-else>
{{ diff.old ? (diff.old instanceof Array && !diff.old.length) ? infoEmpty : diff.old.toString().replace(/,/g, ' ') : infoEmpty }}
</p>
</div>
</div>
<!-- NEW -->
<div class="column is-6">
<!-- Thumbnail -->
<div
class="content"
v-if="attributeName == 'thumbnail'">
<p class="is-capitalized has-text-blue5">
{{ attributeName }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div>
<picture>
<img
width="150px"
:src="diff.new ? diff.new : placeholderSquareImage"
:alt="attributeName">
</picture>
</div>
</div>
<div
v-if="attributeName == 'attachments'"
class="content">
<p class="is-capitalized has-text-blue5">
{{ attributeName }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<div
class="tainacan-attachments-in-modal"
v-if="diff.new.length">
<template v-for="(attachment, index) in diff.new">
<file-item
:key="index"
:modal-on-click="false"
:show-name="true"
:file="{
title: { rendered: attachment.title },
guid: { rendered: attachment.url },
mime_type: attachment.mime_type,
media_type: attachment.mime_type.includes('image') ? 'image' : 'other'
}"/>
</template>
</div>
<div v-else>
<p>{{ infoEmpty }}</p>
</div>
</div>
<div
class="content"
v-if="!['thumbnail', 'attachments'].includes(attributeName)">
<p class="is-capitalized has-text-blue5">
{{ attributeName.replace(/_/g, ' ') }}
<small class="has-text-gray4"> {{ `(${$i18n.get('info_logs_after')})` }}</small>
</p>
<!-- Is array with length 1 -->
<p
class="tainacan-p-break"
v-if="(diff.new instanceof Array) &&
(diff.new.length == 1) &&
!(diff.new[0] instanceof Object)">
{{ diff.new.toString() }}
</p>
<div
v-else-if="attributeName == 'metadata_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.new"
:key="diffTitle">
{{ `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` }}
</p>
</div>
<div
v-else-if="attributeName == 'filters_order'"
class="content">
<p
class="tainacan-p-break"
v-for="(diffContent, diffTitle) in diff.new"
:key="diffTitle">
{{ `ID: ${diffContent.id} | Enabled: ${diffContent.enabled}` }}
</p>
</div>
<div
v-else-if="attributeName == 'metadata_type_options'"
class="content">
<p class="tainacan-p-break">
{{ `Taxonomy ID: ${diff.new.taxonomy_id};
Input type: ${diff.new.input_type};
Allow new terms: ${diff.new.allow_new_terms}` }}
</p>
</div>
<!-- -->
<p
class="tainacan-p-break"
v-else>
{{ diff.new ? (diff.new instanceof Array && !diff.new.length) ? infoEmpty : diff.new.toString().replace(/,/g, ' ') : infoEmpty }}
</p>
</div>
</div>
</div>
</template>
</div>
</div>
<footer>
<div class="control">
<button
class="button is-outlined"
type="button"
@click="$parent.close()">
{{ $i18n.get('close') }}
</button>
<div class="buttons is-pulled-right">
<!--<button-->
<!--v-if="activity.status != 'publish'"-->
<!--@click="notApproveActivity"-->
<!--type="button"-->
<!--class="button is-danger">-->
<!--<b-icon-->
<!--size="is-small"-->
<!--icon="close"/>-->
<!--<span>{{ $i18n.get('not_approve_item') }}</span>-->
<!--</button>-->
<!--<button-->
<!--v-if="activity.status != 'publish'"-->
<!--@click="approveActivity"-->
<!--type="button"-->
<!--class="button is-secondary">-->
<!--<b-icon-->
<!--size="is-small"-->
<!--icon="check"/>-->
<!--<span>{{ $i18n.get('approve_item') }}</span>-->
<!--</button>-->
<!--<button-->
<!--v-if="activity.status == 'publish'"-->
<!--@click="notApproveActivity"-->
<!--type="button"-->
<!--class="button is-blue5">-->
<!--<b-icon-->
<!--custom-class="mdi-flip-h"-->
<!--size="is-small"-->
<!--icon="share"/>-->
<!--<span>{{ $i18n.get('undo') }}</span>-->
<!--</button>-->
<!-- <button
v-if="activity.status == 'publish'"
@click="$parent.close()"
type="button"
class="button is-secondary">
<span>OK</span>
</button> -->
</div>
</div>
</footer>
</div>
</template>
<script>
import moment from 'moment';
import FileItem from '../file-item.vue';
export default {
name: "ActivityDetailsModal",
props: {
activity: Object
},
data() {
return {
infoEmpty: `[${this.$i18n.get('info_empty').toLowerCase()}]`,
dateFormat: '',
activityCreationDate: '',
placeholderSquareImage: `${tainacan_plugin.base_url}/admin/images/placeholder_square.png`,
}
},
components: {
FileItem
},
created() {
let locale = navigator.language;
moment.locale(locale);
let localeData = moment.localeData();
this.dateFormat = localeData.longDateFormat('lll');
let logDate = this.activity.log_date;
let date = moment(logDate).format(this.dateFormat);
if (date != 'Invalid date') {
this.activityCreationDate = date;
} else {
this.activityCreationDate = this.$i18n.get('info_unknown_date');
}
},
methods: {
approveActivity(){
this.$emit('approveActivity', this.activity.id);
},
notApproveActivity(){
this.$emit('notApproveActivity', this.activity.id);
},
undo(){
}
}
}
</script>
<style lang="scss" scoped>
@import "../../scss/_variables.scss";
.tainacan-modal-title {
align-self: baseline;
display: flex;
flex-direction: column;
width: 100%;
}
.tainacan-modal-content {
width: auto;
min-height: 600px;
}
.modal-card-body {
min-height: 400px;
}
.tainacan-attachments-in-modal {
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-content: baseline;
resize: vertical;
overflow-y: auto;
overflow-x: hidden;
height: 200px;
border: 1px solid $gray3;
&>div {
margin: 0.5rem;
}
}
.tainacan-p-overflow {
text-overflow: ellipsis;
white-space: nowrap;
max-width: 150px;
overflow: hidden;
}
.tainacan-p-break {
word-break: break-word;
}
.tainacan-figure {
width: 150px;
height: 150px;
overflow: auto;
}
</style>

View File

@ -1,5 +1,12 @@
<template>
<form action="">
<form
action=""
autofocus
role="dialog"
class="tainacan-modal-content"
tabindex="-1"
aria-modal
ref="availableExportersModal">
<div
class="tainacan-modal-content"
style="width: auto">
@ -77,6 +84,9 @@
this.$console.log(error);
this.isLoading = false;
});
if (this.$refs.availableExportersModal)
this.$refs.availableExportersModal.focus();
}
}
</script>

View File

@ -1,5 +1,12 @@
<template>
<form action="">
<form
action=""
autofocus
role="dialog"
class="tainacan-modal-content"
tabindex="-1"
aria-modal
ref="availableImportersModal">
<div
class="tainacan-modal-content"
style="width: auto">
@ -79,6 +86,9 @@ export default {
this.$console.log(error);
this.isLoading = false;
});
if (this.$refs.availableImportersModal)
this.$refs.availableImportersModal.focus();
}
}
</script>

View File

@ -1,5 +1,11 @@
<template>
<div class="tainacan-modal-content">
<div
autofocus
role="dialog"
class="tainacan-modal-content"
tabindex="-1"
aria-modal
ref="checkboxRadioModal">
<header class="tainacan-modal-title">
<h2 v-if="isFilter">{{ $i18n.get('filter') }} <em>{{ filter.name }}</em></h2>
<h2 v-else>{{ $i18n.get('metadatum') }} <em>{{ metadatum.name }}</em></h2>
@ -131,7 +137,7 @@
</b-field>
<li v-if="finderColumn.children.length">
<div
v-if="totalRemaining[key].remaining === true || (finderColumn.length < totalRemaining[key].remaining)"
v-if="shouldShowMoreButton(key)"
@click="getMoreOptions(finderColumn, key)"
class="tainacan-show-more">
<span class="icon">
@ -200,7 +206,7 @@
</b-tab-item>
</b-tabs>
<!--<pre>{{ hierarchicalPath }}</pre>-->
<!-- <pre>{{ totalRemaining }}</pre> -->
<!--<pre>{{ totalRemaining }}</pre>-->
<!--<pre>{{ selected }}</pre>-->
<!--<pre>{{ options }}</pre>-->
<!--<pre>{{ searchResults }}</pre>-->
@ -272,11 +278,11 @@
<script>
import qs from 'qs';
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
import { filter_type_mixin } from '../../../classes/filter-types/filter-types-mixin';
import { dynamicFilterTypeMixin } from '../../../classes/filter-types/filter-types-mixin';
export default {
name: 'CheckboxFilterModal',
mixins: [ filter_type_mixin ],
mixins: [ dynamicFilterTypeMixin ],
props: {
isFilter: {
type: Boolean,
@ -286,8 +292,8 @@
parent: Number,
taxonomy_id: Number,
taxonomy: String,
collection_id: Number,
metadatum_id: Number,
collectionId: Number,
metadatumId: Number,
metadatum: Object,
selected: Array,
isTaxonomy: {
@ -295,7 +301,7 @@
default: false,
},
metadatum_type: String,
metadatum_object: Object,
query: Object,
isRepositoryLevel: Boolean,
isCheckbox: {
type: Boolean,
@ -318,7 +324,6 @@
maxNumSearchResultsShow: 20,
maxNumOptionsCheckboxFinderColumns: 100,
checkboxListOffset: 0,
collection: this.collection_id,
isCheckboxListLoading: false,
isSearchingLoading: false,
noMorePage: 0,
@ -345,7 +350,14 @@
this.getOptions(0);
}
},
mounted() {
if (this.$refs.checkboxRadioModal)
this.$refs.checkboxRadioModal.focus()
},
methods: {
shouldShowMoreButton(key) {
return this.totalRemaining[key].remaining === true || (this.finderColumns[key].children.length < this.totalRemaining[key].remaining);
},
fetchSelectedLabels() {
let selected = this.selected instanceof Array ? this.selected : [this.selected];
@ -443,7 +455,7 @@
if ( this.metadatum_type === 'Tainacan\\Metadata_Types\\Relationship' )
promise = this.getValuesRelationship( this.optionName, this.isRepositoryLevel, [], offset, this.maxNumOptionsCheckboxList, true);
else
promise = this.getValuesPlainText( this.metadatum_id, this.optionName, this.isRepositoryLevel, [], offset, this.maxNumOptionsCheckboxList, true);
promise = this.getValuesPlainText( this.metadatumId, this.optionName, this.isRepositoryLevel, [], offset, this.maxNumOptionsCheckboxList, true);
promise.request
.then((data) => {
@ -486,10 +498,10 @@
if (!this.isFilter)
query += '&hideempty=0';
let route = `/collection/${this.collection_id}/facets/${this.metadatum_id}${query}`;
let route = `/collection/${this.collectionId}/facets/${this.metadatumId}${query}`;
if(this.collection_id == 'default' || this.collection_id == 'filter_in_repository'){
route = `/facets/${this.metadatum_id}${query}`
if(this.collectionId == 'default'){
route = `/facets/${this.metadatumId}${query}`
}
axios.get(route)
@ -609,10 +621,10 @@
this.isColumnLoading = true;
let route = `/collection/${this.collection_id}/facets/${this.metadatum_id}${query}`;
let route = `/collection/${this.collectionId}/facets/${this.metadatumId}${query}`;
if(this.collection_id == 'default' || this.collection_id == 'filter_in_repository'){
route = `/facets/${this.metadatum_id}${query}`
if (this.collectionId == 'default'){
route = `/facets/${this.metadatumId}${query}`
}
axios.get(route)
@ -646,10 +658,10 @@
this.isColumnLoading = true;
let route = `/collection/${this.collection_id}/facets/${this.metadatum_id}${query}`;
let route = `/collection/${this.collectionId}/facets/${this.metadatumId}${query}`;
if(this.collection_id == 'default' || this.collection_id == 'filter_in_repository'){
route = `/facets/${this.metadatum_id}${query}`
if (this.collectionId == 'default'){
route = `/facets/${this.metadatumId}${query}`
}
axios.get(route)
@ -674,21 +686,21 @@
applyFilter() {
this.$parent.close();
if(this.isTaxonomy && this.isFilter){
if (this.isTaxonomy && this.isFilter) {
this.$eventBusSearch.$emit('input', {
filter: 'checkbox',
taxonomy: this.taxonomy,
compare: 'IN',
metadatum_id: this.metadatum_id,
collection_id: this.collection_id,
metadatum_id: this.metadatumId ? this.metadatumId : this.filter.metatadum_id,
collection_id: this.collectionId ? this.collectionId : this.filter.collection_id,
terms: this.selected
});
} else if(this.isFilter) {
this.$eventBusSearch.$emit('input', {
filter: 'checkbox',
compare: 'IN',
metadatum_id: this.metadatum_id,
collection_id: this.collection_id ? this.collection_id : this.filter.collection_id,
metadatum_id: this.metadatumId ? this.metadatumId : this.filter.metatadum_id,
collection_id: this.collectionId ? this.collectionId : this.filter.collection_id,
value: this.selected,
});
} else {

View File

@ -1,5 +1,12 @@
<template>
<form action="">
<form
action=""
autofocus
role="dialog"
class="tainacan-modal-content"
tabindex="-1"
aria-modal
ref="collectionsModal">
<div
class="tainacan-modal-content"
style="width: auto">
@ -18,14 +25,20 @@
:key="index"
@click="onSelectCollection(collection)">
<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>
<b-loading
<div
v-if="collections.length <= 0"
class="block">
<p class="has-text-gray">
{{ $i18n.get('info_no_collection_created') }}
</p>
</div>
</div>
<b-loading
:is-full-page="false"
:active.sync="isLoading"
:can-cancel="false"/>
</div>
<footer class="field is-grouped form-submit">
<div class="control">
@ -74,6 +87,9 @@ export default {
this.$console.log(error);
this.isLoading = false;
});
if (this.$refs.collectionsModal)
this.$refs.collectionsModal.focus();
}
}
</script>

View File

@ -1,9 +1,11 @@
<template>
<div
aria-labelledby="alert-dialog-title"
aria-modal="true"
aria-modal
autofocus
role="alertdialog"
class="tainacan-form dialog">
class="tainacan-form dialog"
ref="customDialog">
<div
class="modal-card"
style="width: auto">
@ -87,6 +89,10 @@
changeNeverShowMessageAgain($event) {
this.$userPrefs.set('neverShow' + this.messageKeyForUserPrefs + 'Dialog', $event);
}
},
mounted() {
if (this.$refs.customDialog)
this.$refs.customDialog.focus();
}
}
</script>

View File

@ -11,7 +11,10 @@
<!-- Preview Modal ----------------- -->
<b-modal
:active.sync="isPreviewModalActive"
scroll="keep">
scroll="keep"
trap-focus
aria-modal
aria-role="dialog">
<!-- <div class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2>{{ $i18n.get('label_document') }}</h2>
@ -20,7 +23,11 @@
class="back-link">{{ $i18n.get('exit') }}</a>
<hr>
</div> -->
<div
<div
autofocus
role="dialog"
tabindex="-1"
aria-modal
class="is-flex rendered-content"
v-html="documentHtml" />
<!-- </div> -->
@ -32,9 +39,13 @@
export default {
name: 'DocumentItem',
props: {
documentHtml: String,
isSelected: false,
isPreviewModalActive: false
documentHtml: String
},
data() {
return {
isSelected: false,
isPreviewModalActive: false
}
}
}
</script>

View File

@ -1,10 +1,13 @@
<template>
<div
aria-labelledby="exposers-modal-title"
autofocus
role="dialog"
aria-modal="true"
tabindex="-1"
aria-modal
class="tainacan-modal-content"
style="width: auto">
style="width: auto"
ref="exposersModal">
<header class="tainacan-modal-title">
<h2
id="exposers-modal-title"
@ -469,6 +472,9 @@ export default {
if (this.itemId)
this.shouldRespectFetchOnly = false;
if (this.$refs.exposersModal)
this.$refs.exposersModal.focus()
}
}
</script>

View File

@ -32,8 +32,16 @@
<b-modal
:active.sync="isPreviewModalActive"
:width="1024"
scroll="keep">
<div class="tainacan-modal-content">
scroll="keep"
trap-focus
aria-modal
aria-role="dialog">
<div
autofocus
role="dialog"
tabindex="-1"
aria-modal
class="tainacan-modal-content">
<div class="tainacan-modal-title">
<h2 v-if="file.title != undefined">{{ file.title.rendered }}</h2>
</div>

View File

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

View File

@ -1,9 +1,12 @@
<template>
<div
aria-labelledby="alert-dialog-title"
aria-modal="true"
autofocus
role="alertdialog"
class="tainacan-form dialog">
tabindex="-1"
aria-modal
class="tainacan-form dialog"
ref="itemCopyDialog">
<div
class="modal-card"
style="width: auto">
@ -183,6 +186,10 @@
this.isCreatingBulkEditGroup = false;
this.isCreatingSequenceEditGroup = false;
this.copyCount = 1;
},
mounted() {
if (this.$refs.itemCopyDialog)
this.$refs.itemCopyDialog.focus();
}
}
</script>

View File

@ -18,6 +18,7 @@
</label>
<div
v-if="collections && collections.length"
class="block">
<div
v-for="(collection, key) in collections"
@ -26,11 +27,18 @@
<b-checkbox
v-model="collectionsIdsToFilter"
:native-value="collection.id"
@input="apply_filter">
@input="applyFilter">
{{ collection.name }}
</b-checkbox>
</div>
</div>
<div
v-else
class="block">
<p class="has-text-gray">
{{ $i18n.get('info_no_collection_created') }}
</p>
</div>
</b-collapse>
</b-field>
</template>
@ -60,7 +68,7 @@
Array.isArray(routeQueries.metaquery[0].value)){
this.collectionsIdsToFilter = routeQueries.metaquery[0].value;
this.apply_filter();
this.applyFilter();
}
},
data(){
@ -84,7 +92,7 @@
...mapGetters('collection', [
'getCollections',
]),
apply_filter(){
applyFilter(){
this.$eventBusSearch.$emit( 'input', {
filter: 'checkbox',
metadatum_id: 'collection_id',

View File

@ -1,25 +1,27 @@
<template>
<div
class="is-inline-flex"
v-if="filterTags != undefined && filterTags.length > 0">
<b-tag
v-for="(filterTag, index) of filterTags"
:key="index"
attached
closable
@close="removeMetaQuery(filterTag.filterId, filterTag.value, filterTag.singleValue)">
{{ filterTag.singleValue != undefined ? filterTag.singleValue : filterTag.value }}
</b-tag>
<button
@click="clearAllFilters()"
id="button-clear-all"
class="button is-outlined">
{{ $i18n.get('label_clear_filters') }}
</button>
</div>
<transition name="filter-item">
<div
class="is-inline-flex"
v-if="filterTags != undefined && filterTags.length > 0">
<b-tag
v-for="(filterTag, index) of filterTags"
:key="index"
attached
closable
@close="removeMetaQuery(filterTag)">
{{ filterTag.singleLabel != undefined ? filterTag.singleLabel : filterTag.label }}
</b-tag>
<button
@click="clearAllFilters()"
id="button-clear-all"
class="button is-outlined">
{{ $i18n.get('label_clear_filters') }}
</button>
</div>
</transition>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
import { mapGetters } from 'vuex';
export default {
name: 'FiltersTagsList',
@ -31,9 +33,9 @@
let tags = this.getFilterTags();
let flattenTags = [];
for (let tag of tags) {
if (Array.isArray(tag.value)) {
for (let valueTag of tag.value)
flattenTags.push({filterId: tag.filterId, value: tag, singleValue: valueTag});
if (Array.isArray(tag.label)) {
for (let i = 0; i < tag.label.length; i++)
flattenTags.push({filterId: tag.filterId, label: tag.label, singleLabel: tag.label[i], value: tag.value[i], taxonomy: tag.taxonomy, metadatumId: tag.metadatumId});
} else {
flattenTags.push(tag);
}
@ -43,22 +45,22 @@
},
methods: {
...mapGetters('search',[
'getPostQuery',
'getFilterTags'
]),
...mapActions('metadata',[
'fetchMetadatum'
]),
removeMetaQuery(filterId, value, singleValue) {
if (singleValue != undefined)
this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, singleValue: singleValue });
else
this.$eventBusSearch.removeMetaFromFilterTag({ filterId: filterId, value: value });
removeMetaQuery({ filterId, value, singleLabel, label, taxonomy, metadatumId }) {
this.$eventBusSearch.removeMetaFromFilterTag({
filterId: filterId,
singleLabel: singleLabel,
label: label,
value: value,
taxonomy: taxonomy,
metadatumId: metadatumId
});
},
clearAllFilters() {
// this.$eventBusSearch.clearAllFilters();
for (let tag of this.filterTags) {
this.removeMetaQuery(tag.filterId, tag.value, tag.singleValue);
this.removeMetaQuery(tag);
}
}
}

View File

@ -69,7 +69,8 @@
<b-dropdown
position="is-top-right"
@change="onPageChange"
aria-role="list">
aria-role="list"
trap-focus>
<button
aria-labelledby="go-to-page-dropdown"
class="button is-white"

View File

@ -1,254 +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>
<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,18 +23,20 @@ import FormRelationship from '../../classes/metadata-types/relationship/FormRela
import FormTaxonomy from '../../classes/metadata-types/taxonomy/FormTaxonomy.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 FilterDate from '../../classes/filter-types/date/Date.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
import FilterAutocomplete from '../../classes/filter-types/autocomplete/Autocomplete.vue';
import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.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 FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue';
import FormNumeric from '../../classes/filter-types/numeric/FormNumeric.vue';
import FormNumericInterval from '../../classes/filter-types/numeric-interval/FormNumericInterval.vue';
// import FormDate from '../../classes/filter-types/date/FormDate.vue';
import TainacanFormItem from '../../classes/metadata-types/tainacan-form-item.vue';
@ -50,9 +52,13 @@ import eventBusSearch from '../../js/event-bus-search';
import termsListBus from './terms-list-bus.js';
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin, UserCapabilitiesPlugin, StatusHelperPlugin } from './utilities';
import FilterNumericListInterval from '../../classes/filter-types/numeric-list-interval/NumericListInterval.vue';
import FormNumericListInterval from '../../classes/filter-types/numeric-list-interval/FormNumericListInterval.vue';
// Configure and Register Plugins
Vue.use(Buefy, {
defaultTooltipAnimated: true
defaultTooltipAnimated: true
});
Vue.use(VTooltip);
Vue.use(VueMasonry);
@ -80,7 +86,6 @@ Vue.component('tainacan-form-item', TainacanFormItem);
Vue.component('tainacan-filter-item', TainacanFiltersList);
/* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-numeric', FilterNumeric);
Vue.component('tainacan-filter-date', FilterDate);
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
@ -89,8 +94,14 @@ Vue.component('tainacan-filter-checkbox', FilterCheckbox);
Vue.component('tainacan-filter-taginput', FilterTaginput);
Vue.component('tainacan-filter-taxonomy-checkbox', FilterTaxonomyCheckbox);
Vue.component('tainacan-filter-taxonomy-taginput', FilterTaxonomyTaginput);
Vue.component('tainacan-filter-numeric-interval', FilterNumericInterval);
Vue.component('tainacan-filter-numeric-list-interval', FilterNumericListInterval);
Vue.component('tainacan-filter-date-interval', FilterDateInterval);
/* Filter Metadata Option forms */
Vue.component('tainacan-filter-form-numeric', FormNumeric);
Vue.component('tainacan-filter-form-numeric-interval', FormNumericInterval);
Vue.component('tainacan-filter-form-numeric-list-interval', FormNumericListInterval);
// Vue.component('tainacan-filter-form-date', FormDate);
/* Others */
@ -115,7 +126,7 @@ new Vue({
render: h => h(AdminPage)
});
// Display Icons only once everything is loaded
// Display Icons only once everything is loaded
function listen(evnt, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(evnt,func,false);

View File

@ -5,16 +5,16 @@ import VTooltip from 'v-tooltip';
import VueMasonry from 'vue-masonry-css';
// Custom elements
import FilterCustomInterval from '../../classes/filter-types/custom-interval/CustomInterval.vue';
import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue';
import FilterDate from '../../classes/filter-types/date/Date.vue';
import FilterSelectbox from '../../classes/filter-types/selectbox/Selectbox.vue';
import FilterAutocomplete from '../../classes/filter-types/autocomplete/Autocomplete.vue';
import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue';
import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue';
import FilterNumericInterval from '../../classes/filter-types/numeric-interval/NumericInterval.vue';
import FilterNumericListInterval from '../../classes/filter-types/numeric-list-interval/NumericListInterval.vue';
import TaincanFiltersList from '../../classes/filter-types/tainacan-filter-item.vue';
import ItemsPage from '../pages/lists/items-page.vue';
@ -33,7 +33,7 @@ import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin, StatusH
// Configure and Register Plugins
Vue.use(Buefy, {
defaultTooltipAnimated: true
defaultTooltipAnimated: true
});
Vue.use(VTooltip);
Vue.use(VueMasonry);
@ -43,11 +43,9 @@ Vue.use(RouterHelperPlugin);
Vue.use(StatusHelperPlugin);
Vue.use(ConsolePlugin, {visual: false});
Vue.component('tainacan-filter-item', TaincanFiltersList);
/* Filters */
Vue.component('tainacan-filter-custom-interval', FilterCustomInterval);
Vue.component('tainacan-filter-numeric', FilterNumeric);
Vue.component('tainacan-filter-date', FilterDate);
Vue.component('tainacan-filter-selectbox', FilterSelectbox);
@ -56,6 +54,8 @@ Vue.component('tainacan-filter-checkbox', FilterCheckbox);
Vue.component('tainacan-filter-taginput', FilterTaginput);
Vue.component('tainacan-filter-taxonomy-checkbox', FilterTaxonomyCheckbox);
Vue.component('tainacan-filter-taxonomy-taginput', FilterTaxonomyTaginput);
Vue.component('tainacan-filter-numeric-interval', FilterNumericInterval);
Vue.component('tainacan-filter-numeric-list-interval', FilterNumericListInterval);
/* Others */
Vue.component('items-page', ItemsPage);
@ -76,7 +76,7 @@ import ThemeItemsList from '../theme-items-list.vue';
export const ThemeItemsListing = new Vue({
el: '#tainacan-items-page',
store,
router: routerTheme,
router: routerTheme,
data: {
termId: '',
taxonomy: '',
@ -87,9 +87,9 @@ export const ThemeItemsListing = new Vue({
},
render: h => h(ThemeItemsList),
beforeMount () {
this.collectionId = this.$el.attributes['collection-id'] != undefined ? this.$el.attributes['collection-id'].value : undefined;
if (this.$el.attributes['default-view-mode'] != undefined)
this.defaultViewMode = this.$el.attributes['default-view-mode'].value;
else
@ -104,10 +104,10 @@ export const ThemeItemsListing = new Vue({
this.taxonomy = this.$el.attributes['taxonomy'].value;
}
});
// Display Icons only once everything is loaded
// Display Icons only once everything is loaded
function listen(evnt, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(evnt,func,false);

View File

@ -227,9 +227,6 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getFiltersPath(query) {
return '/filters/?' + qs.stringify(query);
},
getMetadataPath(query) {
return '/metadata/?' + qs.stringify(query);
},
getActivitiesPath(query) {
return '/activities/?' + qs.stringify(query);
},
@ -302,14 +299,23 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getItemEditPath(collectionId, itemId) {
return '/collections/' + collectionId + '/items/' + itemId + '/edit';
},
getFilterEditPath(id) {
return '/filters/' + id + '/edit';
getMetadataEditPath(metadatumId) {
return '/metadata/?edit=' + metadatumId;
},
getFilterEditPath(filterId) {
return '/filters/?edit=' + filterId;
},
getCollectionMetadataEditPath(collectionId, metadatumId) {
return '/collections/' + collectionId + '/metadata/?edit=' + metadatumId;
},
getCollectionFilterEditPath(collectionId, filterId) {
return '/collections/' + collectionId + '/filters/?edit=' + filterId;
},
getTaxonomyEditPath(id, isRecent) {
return isRecent != undefined ? '/taxonomies/' + id + '/edit?recent=true' : '/taxonomies/' + id + '/edit';
},
getTermEditPath(taxonomyId, termId) {
return '/taxonomies/' + taxonomyId + '/terms/' + termId + '/edit';
return '/taxonomies/' + taxonomyId + '/edit?tab=terms';
},
getImporterEditionPath(importerType) {
return '/importers/' + importerType;

View File

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

View File

@ -5,7 +5,7 @@
'repository-level-page': isRepositoryLevel,
'page-container': isRepositoryLevel
}">
<tainacan-title
<tainacan-title
v-if="!isItemLevel"
:bread-crumb-items="[{ path: '', label: this.$i18n.get('activities') }]"/>
<div :class="{ 'above-subheader': isRepositoryLevel }">
@ -14,20 +14,89 @@
v-if="isRepositoryLevel"
class="tabs">
<ul>
<li
<li
@click="onChangeTab('')"
:class="{ 'is-active': tab == undefined || tab == ''}"><a>{{ $i18n.get('activities') }}</a></li>
<li
<li
@click="onChangeTab('processes')"
:class="{ 'is-active': tab == 'processes'}"><a>{{ $i18n.get('processes') }}</a></li>
</ul>
</div>
<b-loading
<b-loading
:is-full-page="false"
:active.sync="isLoading"
:can-cancel="false"/>
<div
v-if="tab != 'processes'"
class="sub-header">
<b-field class="header-item">
<b-datepicker
ref="datepicker"
:placeholder="$i18n.get('instruction_filter_activities_date')"
v-model="searchDates"
range
@input="searchActivities()"
:date-formatter="(date) => dateFormatter(date)"
:date-parser="(date) => dateParser(date)"
size="is-small"
icon="calendar-today"
:years-range="[-50, 3]"
: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')
]"
:month-names="[
$i18n.get('datepicker_month_january'),
$i18n.get('datepicker_month_february'),
$i18n.get('datepicker_month_march'),
$i18n.get('datepicker_month_april'),
$i18n.get('datepicker_month_may'),
$i18n.get('datepicker_month_june'),
$i18n.get('datepicker_month_july'),
$i18n.get('datepicker_month_august'),
$i18n.get('datepicker_month_september'),
$i18n.get('datepicker_month_october'),
$i18n.get('datepicker_month_november'),
$i18n.get('datepicker_month_december')
]"/>
<p
class="control"
v-if="searchDates && searchDates.length != 0">
<button
class="button"
@click="clearSearchDates()">
<span class="icon"><i class="tainacan-icon tainacan-icon-close"/></span>
</button>
</p>
</b-field>
<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('activities')"
autocomplete="on"
v-model="searchQuery"
@keyup.enter="searchActivities()">
<span
@click="searchActivities()"
class="icon is-right">
<i class="tainacan-icon tainacan-icon-search" />
</span>
</div>
</b-field>
</div>
<activities-list
v-if="tab != 'processes'"
:is-loading="isLoading"
@ -149,11 +218,13 @@
<script>
import ActivitiesList from "../../components/lists/activities-list.vue";
import ProcessesList from "../../components/lists/processes-list.vue";
import { dateInter } from "../../../admin/js/mixins";
import { mapActions, mapGetters } from 'vuex';
import moment from 'moment'
export default {
name: 'ActivitiesPage',
mixins: [ dateInter ],
data(){
return {
isLoading: false,
@ -165,6 +236,8 @@
isRepositoryLevel: false,
tab: '',
isItemLevel: false,
searchQuery: '',
searchDates: []
}
},
components: {
@ -237,10 +310,15 @@
loadActivities() {
this.isLoading = true;
let dataInit = this.searchDates && this.searchDates[0] ? moment(this.searchDates[0]).format('YYYY-MM-DD') : null;
let dataEnd = this.searchDates && this.searchDates[1] ? moment(this.searchDates[1]).format('YYYY-MM-DD') : null;
if(this.isRepositoryLevel) {
this.fetchActivities({
'page': this.activitiesPage,
'activitiesPerPage': this.activitiesPerPage
'activitiesPerPage': this.activitiesPerPage,
'search': this.searchQuery,
'searchDates': [dataInit, dataEnd]
})
.then((res) => {
this.isLoading = false;
@ -253,7 +331,9 @@
this.fetchCollectionActivities({
'page': this.activitiesPage,
'activitiesPerPage': this.activitiesPerPage,
'collectionId': this.$route.params.collectionId
'collectionId': this.$route.params.collectionId,
'search': this.searchQuery,
'searchDates': [dataInit, dataEnd]
})
.then((res) => {
this.isLoading = false;
@ -266,7 +346,9 @@
this.fetchItemActivities({
'page': this.activitiesPage,
'activitiesPerPage': this.activitiesPerPage,
'itemId': this.$route.params.itemId
'itemId': this.$route.params.itemId,
'search': this.searchQuery,
'searchDates': [dataInit, dataEnd]
})
.then((res) => {
this.isLoading = false;
@ -300,6 +382,25 @@
getLastProcessesNumber() {
let last = (Number(this.processesPerPage * (this.processesPage - 1)) + Number(this.processesPerPage));
return last > this.total ? this.total : last;
},
searchActivities() {
this.activitiesPage = 1;
this.loadActivities();
},
clearSearchDates() {
this.searchDates = null;
this.searchActivities();
},
dateFormatter(dateObject) {
if (dateObject == null || dateObject.length == 0 || dateObject[0] == null || dateObject[1] == null)
return "";
return moment(dateObject[0], moment.ISO_8601).format(this.dateFormat) + " - " + moment(dateObject[1], moment.ISO_8601).format(this.dateFormat);
},
dateParser(dateString) {
return [
moment(dateString[0], this.dateFormat).toDate(),
moment(dateString[1], this.dateFormat).toDate()
];
}
},
computed: {
@ -357,15 +458,60 @@
@import '../../scss/_variables.scss';
.sub-header {
min-height: $header-height;
min-height: $subheader-height;
height: $header-height;
padding-left: 0;
padding-right: 0;
border-bottom: 1px solid #ddd;
display: inline-flex;
justify-content: space-between;
align-items: center;
width: 100%;
.header-item {
display: inline-block;
padding-right: 8em;
margin-bottom: 0 !important;
&:not(:last-child) {
padding-right: 0.5em;
}
.label {
font-size: 0.875rem;
font-weight: normal;
margin-top: 3px;
margin-bottom: 2px;
cursor: default;
}
.button {
display: flex;
align-items: center;
border-radius: 0 !important;
height: 1.95rem !important;
}
.field {
align-items: center;
}
.gray-icon, .gray-icon .icon {
color: $gray4 !important;
padding-right: 10px;
}
.gray-icon .icon i::before,
.gray-icon i::before {
font-size: 1.3125rem !important;
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) {
@ -373,8 +519,8 @@
margin-top: -0.5em;
padding-top: 0.9em;
.header-item {
padding-right: 0.5em;
.header-item:not(:last-child) {
padding-right: 0.2em;
}
}
}

View File

@ -11,7 +11,8 @@
<div class="header-item">
<b-dropdown
aria-role="list"
id="collection-creation-options-dropdown">
id="collection-creation-options-dropdown"
trap-focus>
<button
class="button is-secondary"
slot="trigger">
@ -62,7 +63,8 @@
:mobile-modal="true"
:disabled="collections.length <= 0 || isLoading"
@input="onChangeOrder(order == 'asc' ? 'desc' : 'asc')"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting_direction')"
class="button is-white"
@ -120,6 +122,25 @@
</option>
</b-select>
</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 class="above-subheader">
@ -139,11 +160,11 @@
</a>
</li>
<li
v-for="(statusOption, index) of $statusHelper.getStatuses()"
v-for="(statusOption, index) of $statusHelper.getStatuses().filter((status) => status.slug != 'draft')"
:key="index"
@click="onChangeTab(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="{
content: $i18n.getWithVariables('info_%s_tab_' + statusOption.slug,[$i18n.get('collections')]),
autoHide: true,
@ -195,7 +216,8 @@
<b-dropdown
:disabled="isLoadingMetadatumMappers"
id="collection-creation-options-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-secondary"
slot="trigger">
@ -307,6 +329,7 @@ export default {
status: '',
order: 'desc',
ordeBy: 'date',
searchQuery: '',
sortingOptions: [
{ label: this.$i18n.get('label_title'), value: 'title' },
{ label: this.$i18n.get('label_creation_date'), value: 'date' },
@ -402,7 +425,8 @@ export default {
status: this.status,
contextEdit: true,
order: this.order,
orderby: this.orderBy
orderby: this.orderBy,
search: this.searchQuery
})
.then((res) => {
this.isLoading = false;
@ -421,9 +445,14 @@ export default {
this.$buefy.modal.open({
parent: this,
component: AvailableImportersModal,
hasModalCard: true
hasModalCard: true,
trapFocus: true
});
}
},
searchCollections() {
this.page = 1;
this.loadCollections();
},
},
created() {
this.collectionsPerPage = this.$userPrefs.get('collections_per_page');
@ -469,18 +498,23 @@ export default {
@import '../../scss/_variables.scss';
.sub-header {
min-height: $subheader-height;
height: $header-height;
min-height: $header-height;
height: auto;
padding-left: 0;
padding-right: 0;
border-bottom: 1px solid #ddd;
display: inline-flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
width: 100%;
.header-item {
margin-bottom: 0 !important;
&:first-child {
margin-right: auto;
}
&:not(:last-child) {
padding-right: 0.5em;
}
@ -493,9 +527,13 @@ export default {
cursor: default;
}
.button {
display: flex;
align-items: center;
&:not(:first-child) {
.button {
display: flex;
align-items: center;
border-radius: 0 !important;
height: 1.95rem !important;
}
}
.field {
@ -511,14 +549,23 @@ export default {
font-size: 1.3125rem !important;
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) {
height: 60px;
height: 120px;
margin-top: -0.5em;
padding-top: 0.9em;
.header-item {
.header-item:not(:last-child) {
padding-right: 0.2em;
}
}

View File

@ -232,7 +232,8 @@
<b-dropdown
:mobile-modal="true"
id="item-creation-options-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-secondary"
slot="trigger">
@ -306,7 +307,8 @@
:mobile-modal="true"
:disabled="totalItems <= 0 || adminViewMode == 'grid'|| adminViewMode == 'cards' || adminViewMode == 'masonry'"
class="show metadata-options-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_displayed_metadata')"
class="button is-white"
@ -348,7 +350,8 @@
<b-dropdown
:mobile-modal="true"
@input="onChangeOrder()"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting_direction')"
class="button is-white"
@ -395,7 +398,8 @@
<b-dropdown
:mobile-modal="true"
@input="onChangeOrderBy($event)"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting')"
class="button is-white"
@ -431,7 +435,8 @@
:mobile-modal="true"
position="is-bottom-left"
:aria-label="$i18n.get('label_view_mode')"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="registeredViewModes[viewMode] != undefined ? registeredViewModes[viewMode].label : $i18n.get('label_visualization')"
class="button is-white"
@ -472,7 +477,8 @@
:mobile-modal="true"
position="is-bottom-left"
:aria-label="$i18n.get('label_view_mode')"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_view_mode')"
class="button is-white"
@ -699,9 +705,6 @@
<div
v-if="(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].skeleton_template != undefined)"
v-html="registeredViewModes[viewMode].skeleton_template"/>
<!-- Admin view modes skeleton -->
<!-- <skeleton-items-list v-if="!isOnTheme"/> -->
</div>
<!-- Alert if custom metada is being used for sorting -->
@ -788,13 +791,20 @@
</p>
<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"
tag="button"
class="button is-secondary"
:to="{ path: $routerHelper.getNewItemPath(collectionId) }">
{{ $i18n.getFrom('items', 'add_new') }}
</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>
</section>
@ -811,12 +821,20 @@
role="region"
aria-labelledby="filters-label-landmark-modal"
id="filters-mobile-modal"
ref="filters-mobile-modal"
class="tainacan-form is-hidden-tablet"
:active.sync="isFilterModalActive"
:width="736"
animation="slide-menu">
<div class="modal-inner-content">
animation="slide-menu"
trap-focus
aria-modal
aria-role="dialog">
<div
ref="filters-mobile-modal"
class="modal-inner-content"
autofocus="true"
tabindex="-1"
aria-modal
role="dialog">
<h3
id="filters-label-landmark-modal"
class="has-text-weight-semibold">
@ -881,7 +899,6 @@
import FiltersTagsList from '../../components/search/filters-tags-list.vue';
import FiltersItemsList from '../../components/search/filters-items-list.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 AvailableImportersModal from '../../components/other/available-importers-modal.vue';
import ExposersModal from '../../components/other/exposers-modal.vue';
@ -1015,7 +1032,6 @@
ItemsList,
FiltersTagsList,
FiltersItemsList,
SkeletonItemsList,
Pagination,
AdvancedSearch,
ExposersModal
@ -1035,6 +1051,14 @@
orderByName() {
if (this.isSortingByCustomMetadata)
this.hasAnOpenAlert = true;
},
isFilterModalActive() {
if (this.isFilterModalActive) {
setTimeout(() => {
if (this.$refs['filters-mobile-modal'])
this.$refs['filters-mobile-modal'].focus();
}, 800);
}
}
},
methods: {
@ -1097,7 +1121,8 @@
props: {
targetCollection: this.collectionId,
hideWhenManualCollection: true
}
},
trapFocus: true
});
},
openExposersModal() {
@ -1108,14 +1133,16 @@
props: {
collectionId: this.collectionId,
totalItems: this.totalItems
}
},
trapFocus: true
})
},
onOpenCollectionsModal() {
this.$buefy.modal.open({
parent: this,
component: CollectionsModal,
hasModalCard: true
hasModalCard: true,
trapFocus: true
});
},
updateSearch() {
@ -1489,7 +1516,8 @@
hideCancel: true,
showNeverShowAgainOption: offerCheckbox && tainacan_plugin.user_caps != undefined && tainacan_plugin.user_caps.length != undefined && tainacan_plugin.user_caps.length > 0,
messageKeyForUserPrefs: 'ItemsHiddenDueSorting'
}
},
trapFocus: true
});
},
adjustSearchControlHeight: _.debounce( function() {
@ -1974,7 +2002,7 @@
.loading-container {
position: relative;
min-height: 200px;
min-height: 50vh;
height: auto;
}
}
@ -2034,10 +2062,9 @@
}
.table-container {
padding-left: 4.166666667%;
padding-right: 4.166666667%;
padding-left: $page-side-padding;
padding-right: $page-side-padding;
min-height: 50vh;
//height: calc(100% - 82px);
}
.pagination-area {

View File

@ -25,7 +25,8 @@
:mobile-modal="true"
:disabled="taxonomies.length <= 0 || isLoading"
@input="onChangeOrder(order == 'asc' ? 'desc' : 'asc')"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting_direction')"
class="button is-white"
@ -83,6 +84,25 @@
</option>
</b-select>
</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 class="above-subheader">
@ -230,6 +250,7 @@
status: '',
order: 'asc',
ordeBy: 'date',
searchQuery: '',
sortingOptions: [
{ label: this.$i18n.get('label_title'), value: 'title' },
{ label: this.$i18n.get('label_creation_date'), value: 'date' },
@ -304,7 +325,8 @@
taxonomiesPerPage: this.taxonomiesPerPage,
status: this.status,
order: this.order,
orderby: this.orderBy
orderby: this.orderBy,
search: this.searchQuery
})
.then((res) => {
this.isLoading = false;
@ -317,6 +339,10 @@
getLastTaxonomyNumber() {
let last = (Number(this.taxonomiesPerPage * (this.page - 1)) + Number(this.taxonomiesPerPage));
return last > this.total ? this.total : last;
},
searchTaxonomies() {
this.page = 1;
this.load();
}
},
computed: {
@ -370,10 +396,15 @@
display: inline-flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
width: 100%;
.header-item {
margin-bottom: 0 !important;
&:first-child {
margin-right: auto;
}
&:not(:last-child) {
padding-right: 0.5em;
}
@ -386,9 +417,13 @@
cursor: default;
}
.button {
display: flex;
align-items: center;
&:not(:first-child) {
.button {
display: flex;
align-items: center;
border-radius: 0 !important;
height: 1.95rem !important;
}
}
.field {
@ -404,10 +439,19 @@
font-size: 1.3125rem !important;
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) {
height: 60px;
height: 160px;
margin-top: -0.5em;
padding-top: 0.9em;

View File

@ -223,7 +223,8 @@
<b-dropdown
:mobile-modal="true"
id="item-creation-options-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-secondary"
slot="trigger">
@ -283,7 +284,8 @@
:mobile-modal="true"
:disabled="totalItems <= 0 || adminViewMode == 'grid'|| adminViewMode == 'cards' || adminViewMode == 'masonry'"
class="show metadata-options-dropdown"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_displayed_metadata')"
class="button is-white"
@ -325,7 +327,8 @@
<b-dropdown
:mobile-modal="true"
@input="onChangeOrder()"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting_direction')"
class="button is-white"
@ -372,7 +375,8 @@
<b-dropdown
:mobile-modal="true"
@input="onChangeOrderBy($event)"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_sorting')"
class="button is-white"
@ -408,7 +412,8 @@
:mobile-modal="true"
position="is-bottom-left"
:aria-label="$i18n.get('label_view_mode')"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-white"
:aria-label="registeredViewModes[viewMode] != undefined ? registeredViewModes[viewMode].label : $i18n.get('label_visualization')"
@ -449,7 +454,8 @@
:mobile-modal="true"
position="is-bottom-left"
:aria-label="$i18n.get('label_view_mode')"
aria-role="list">
aria-role="list"
trap-focus>
<button
class="button is-white"
:aria-label="$i18n.get('label_view_mode')"
@ -675,9 +681,7 @@
<div
v-if="(registeredViewModes[viewMode] != undefined && registeredViewModes[viewMode].skeleton_template != undefined)"
v-html="registeredViewModes[viewMode].skeleton_template"/>
<!-- Admin view modes skeleton -->
<!-- <skeleton-items-list v-if="!isOnTheme"/> -->
</div>
<!-- Alert if custom metada is being used for sorting -->
@ -791,8 +795,16 @@
class="tainacan-form is-hidden-tablet"
:active.sync="isFilterModalActive"
:width="736"
animation="slide-menu">
<div class="modal-inner-content">
animation="slide-menu"
trap-focus
aria-modal
aria-role="dialog">
<div
autofocus="true"
tabindex="-1"
role="dialog"
aria-modal
class="modal-inner-content">
<h3
id="filters-label-landmark-modal"
class="has-text-weight-semibold">
@ -989,6 +1001,14 @@
orderByName() {
if (this.isSortingByCustomMetadata)
this.hasAnOpenAlert = true;
},
isFilterModalActive() {
if (this.isFilterModalActive) {
setTimeout(() => {
if (this.$refs['filters-mobile-modal'])
this.$refs['filters-mobile-modal'].focus();
}, 800);
}
}
},
methods: {
@ -1047,7 +1067,8 @@
props: {
targetCollection: this.collectionId,
hideWhenManualCollection: true
}
},
trapFocus: true
});
},
openExposersModal() {
@ -1058,15 +1079,16 @@
props: {
collectionId: this.collectionId,
totalItems: this.totalItems
}
})
},
trapFocus: true
});
},
updateSearch() {
this.$eventBusSearch.setSearchQuery(this.futureSearchQuery);
},
onChangeOrderBy(metadatum) {
this.$eventBusSearch.setOrderBy(metadatum);
this.showItemsHiddingDueSorting();
this.showItemsHiddingDueSortingDialog();
},
onChangeOrder() {
this.order == 'DESC' ? this.$eventBusSearch.setOrder('ASC') : this.$eventBusSearch.setOrder('DESC');
@ -1419,7 +1441,8 @@
hideCancel: true,
showNeverShowAgainOption: offerCheckbox && tainacan_plugin.user_caps != undefined && tainacan_plugin.user_caps.length != undefined && tainacan_plugin.user_caps.length > 0,
messageKeyForUserPrefs: 'ItemsHiddenDueSorting'
}
},
trapFocus: true
});
},
adjustSearchControlHeight: _.debounce( function() {
@ -1535,7 +1558,7 @@
}
}
this.showItemsHiddingDueSorting();
this.showItemsHiddingDueSortingDialog();
// Watches window resize to adjust filter's top position and compression on mobile
this.adjustSearchControlHeight();
@ -1895,7 +1918,7 @@
.loading-container {
position: relative;
min-height: 200px;
min-height: 50vh;
height: auto;
}
}
@ -1915,8 +1938,8 @@
}
.table-container {
padding-left: 4.166666667%;
padding-right: 4.166666667%;
padding-left: $page-side-padding;
padding-right: $page-side-padding;
min-height: 50vh;
//height: calc(100% - 82px);
}

View File

@ -384,8 +384,9 @@
itemId: this.itemId,
itemURL: this.item.url,
totalItems: 1,
}
})
},
trapFocus: true
});
}
},
created() {

View File

@ -68,7 +68,7 @@
}
}
&.is-mobile-modal {
@media screen and (max-width: 1088px) {
@media screen and (max-width: 768px) {
.dropdown-content {
max-height: 100vh;
}
@ -182,4 +182,167 @@
}
}
}
}
.datepicker {
width: 100%;
.datepicker-content {
height: auto;
input {
height: 30px;
}
}
.dropdown-menu {
background: transparent;
border: none;
.dropdown-item {
background-color: white !important;
}
}
.datepicker-header {
.pagination {
a>span>i:before {
display: inline-block;
font: normal normal normal 20px/1 "TainacanIcons";
font-size: inherit;
text-rendering: auto;
vertical-align: middle;
line-height: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: $secondary;
}
.pagination-previous {
border: none;
flex-grow: 0;
&>span>i:before {
content: 'previous';
font-size: 20px;
}
}
.pagination-next {
border: none;
flex-grow: 0;
&>span>i:before {
content: 'next';
font-size: 20px;
}
}
}
}
.datepicker-table {
margin-bottom: 0px;
.datepicker-cell {
border: none !important;
padding: 0.5rem 0.75rem;
&.is-selectable.is-first-hovered,
&.is-selectable.is-last-hovered {
color: $gray4 !important;
background-color: $gray3 !important;
}
&.is-today,
&.is-today:hover {
color: $gray4 !important;
background-color: $turquoise1;
}
&.is-selected,
&.is-selected:hover {
color: white !important;
background-color: $turquoise5 !important;
}
}
.datepicker-months {
width: auto;
.datepicker-cell {
height: 2rem;
width: 50%;
padding: 0.3rem 0.25rem !important;
text-overflow: ellipsis;
overflow: hidden;
display: block;
}
}
}
@media screen and (min-width: 768px) {
.datepicker-header {
margin-bottom: 0.5rem;
padding-top: 0.15rem;
padding-bottom: 0.5rem;
.pagination {
flex-wrap: wrap;
.pagination-list {
margin-bottom: 0.5rem;
.field.has-addons {
width: 100% !important;
.control {
height: 24px !important;
}
}
}
.pagination-previous {
margin: 0;
height: 24px;
padding: 0;
font-size: 0.75rem;
order: 3;
}
.pagination-next {
margin: 0;
height: 24px;
padding: 0;
font-size: 0.75rem;
}
}
}
.dropdown-item {
padding: 0.8rem !important;
}
.dropdown-menu {
min-width: 100% !important;
}
.datepicker-table {
margin-bottom: 0px;
}
.select {
select {
display: unset;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
.dropdown-content {
border-radius: 2px !important;
padding: 0px;
max-height: inherit !important;
}
}
}

View File

@ -22,7 +22,7 @@
box-shadow: none !important;
text-decoration: none !important;
}
&[disabled] {
&[disabled=disabled] {
background-color: white !important;
}
}

View File

@ -132,8 +132,14 @@
&:focus>option:checked, &:focus>option:hover {
background-color: $turquoise1 !important;
}
}
&[disabled=disabled] {
border: 1px solid $gray1 !important;
}
}
}
.hidden-select-arrow .select::after {
color: transparent !important;
}
.dropdown {
width: 100%;
.dropdown-trigger { width: 100% }
@ -177,13 +183,13 @@
h4 {
font-weight: 600;
color: #298596;
color: $turquoise5;
margin-bottom: 6px;
}
hr {
margin-top: 8px;
height: 1px;
background-color: #298596;
background-color: $turquoise5;
}
}
}

View File

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

View File

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

View File

@ -133,9 +133,11 @@ return apply_filters( 'tainacan-admin-i18n', [
'title_exporter_page' => __( 'Exporter', 'tainacan'),
// Labels (used mainly on Aria Labels and Inputs)
'label' => __( 'Label', 'tainacan' ),
'label_clean' => __( 'Clear', 'tainacan' ),
'label_none' => __( 'None', 'tainacan' ),
'label_clear_filters' => __( 'Clear filters', 'tainacan' ),
'label_and' => __( 'and', 'tainacan' ),
'label_and' => __( 'and', 'tainacan' ),
'label_selected' => __( 'Selected', 'tainacan' ),
'label_relationship_new_search' => __( 'New Search', 'tainacan' ),
'label_relationship_items_found' => __( 'Items found', 'tainacan' ),
@ -434,6 +436,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_day' => __( 'Day', 'tainacan' ),
'label_month' => __( 'Month', 'tainacan' ),
'label_year' => __( 'Year', 'tainacan' ),
'label_related_to' => __( 'Related to', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),
@ -473,15 +476,18 @@ return apply_filters( 'tainacan-admin-i18n', [
'instruction_select_an_exporter_type' => __( 'Select an exporter from the options below:', 'tainacan'),
'instruction_select_a_collection' => __( 'Select a collection', 'tainacan' ),
'instruction_hover_a_filter_type_to_preview' => __( 'Hover a filter type to preview', 'tainacan' ),
'instruction_never_show_message_again' => __( 'Never show me this message again', 'tainacan' ),
'instruction_click_or_drag_filter_create' => __( 'Click or drag and drop to create a new filter', 'tainacan' ),
'instruction_never_show_message_again' => __( 'Never show me this message again', 'tainacan' ),
'instruction_click_or_drag_filter_create' => __( 'Click or drag and drop to create a new filter', 'tainacan' ),
'instruction_click_or_drag_metadatum_create' => __( 'Click or drag and drop to create a new metadatum', 'tainacan' ),
'instruction_drag_and_drop_filter_sort' => __( 'Drag and drop to change filter order', 'tainacan' ),
'instruction_drag_and_drop_filter_sort' => __( 'Drag and drop to change filter order', 'tainacan' ),
'instruction_drag_and_drop_metadatum_sort' => __( 'Drag and drop to change metadatum order', 'tainacan' ),
'instruction_filter_activities_date' => __( 'Range of dates', 'tainacan'),
'instruction_select_a_date' => __( 'Select a date', 'tainacan' ),
'instruction_select_a_month' => __( 'Select a month', 'tainacan' ),
'instruction_type_value_year' => __( 'Type year value', 'tainacan' ),
'instruction_select_the_amount_of_copies' => __( 'Select the amount of copies of the item that you want to create', 'tainacan'),
'instruction_select_a_interval' => __( 'Select an interval', 'tainacan'),
// Info. Other feedback to user.
'info_items_tab_all' => __( 'Every published item, including those visible only to editors.', 'tainacan' ),
@ -527,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_found' => __( 'No term was found here', '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_user_found' => __( 'No user was found with this name.', 'tainacan' ),
'info_no_item_found_filter' => __( 'No item was found here with these filters.', 'tainacan' ),
@ -577,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_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_no_activities' => __( 'No activities', 'tainacan' ),
'info_no_activities' => __( 'No activities yet.', 'tainacan' ),
'info_logs_before' => __( 'Before', 'tainacan' ),
'info_logs_after' => __( 'After', 'tainacan' ),
'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ),
@ -605,11 +611,11 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_updated_at' => __( 'Updated at', 'tainacan' ),
'info_editing_metadata_values' => __( 'Editing metadata values...', 'tainacan' ),
'info_updating_metadata_values' => __( 'Updating metadata values...', 'tainacan' ),
'info_type_to_add_items' => __( 'Add items...', 'tainacan' ),
'info_type_to_add_items' => __( 'Add items to filter...', 'tainacan' ),
'info_type_to_search_items' => __( 'Search items...', 'tainacan' ),
'info_type_to_add_terms' => __( 'Add terms...', 'tainacan' ),
'info_type_to_add_terms' => __( 'Add terms to filter...', 'tainacan' ),
'info_type_to_search_metadata' => __( 'Search metadata...', 'tainacan' ),
'info_type_to_add_metadata' => __( 'Add metadata...', 'tainacan' ),
'info_type_to_add_metadata' => __( 'Add metadata to filter...', 'tainacan' ),
'info_visibility_helper' => __( 'How the item will be available to visualization.', 'tainacan' ),
'info_errors_in_form' => __( 'There are errors in the form', 'tainacan' ),
'info_no_document_to_item' => __( 'No document was uploaded to this item.', 'tainacan' ),
@ -644,7 +650,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_process_status_cancelled' => __('Cancelled', 'tainacan'),
'info_process_status_paused' => __('Paused', 'tainacan'),
'info_process_status_running' => __('Running', 'tainacan'),
'info_warning_process_cancelled' => __( 'Are you sure? This process will be cancelled', 'tainacan' ),
'info_warning_process_cancelled' => __( 'Are you sure? This process will be cancelled', 'tainacan' ),
'info_empty' => __( 'empty', 'tainacan' ),
'info_url_copied' => __( 'URL link copied', 'tainacan' ),
'info_other_options' => __( 'Other options: ', 'tainacan'),
@ -657,28 +663,9 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_await_while_item_copy' => __( 'Please wait while copy is being created...', 'tainacan'),
'info_await_while_item_copies' => __( 'Please wait while copies are being created. This may take a while...', 'tainacan'),
'info_expose_only_displayed_metadata' => __( 'By checking this option, only metatada that are displayed on the current list will be exposed', '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' ),
'info_initial_value' => __( 'Initial value', 'tainacan' ),
'info_final_value' => __( 'Final value', 'tainacan' ),
'info_show_interval_on_tag' => __( 'Show applied interval on tags', 'tainacan' ),
// Datepicker months
'datepicker_month_january' => __( 'January', 'tainacan' ),

View File

@ -153,7 +153,37 @@ export default {
}
}
}
.metadata-alert {
display: flex;
justify-content: space-between;
align-items: center;
margin: 6px $page-side-padding;
border-radius: 3px;
padding: 4px 12px;
color: $yellow2;
background: $yellow1;
animation-name: appear;
animation-duration: 0.5s;
p {
margin: 0 auto;
}
&>div {
display: flex;
.button,
.button:hover,
.button:active,
.button:focus {
background: none;
color:$yellow2;
font-weight: bold;
border: none;
cursor: pointer;
}
}
}
.search-control {
justify-content: flex-start !important;

View File

@ -66,7 +66,7 @@ class REST_Controller extends \WP_REST_Controller {
'name' => 'title',
'title' => 'title',
'id' => 'p',
'authorid' => 'author_id',
'authorid' => 'author',
'authorname' => 'author_name',
'search' => 's',
'searchterm' => 'search',
@ -92,7 +92,8 @@ class REST_Controller extends \WP_REST_Controller {
'metatype' => 'meta_type',
'hierarchical' => 'hierarchical',
'exclude' => 'exclude',
'excludetree' => 'exclude_tree'
'excludetree' => 'exclude_tree',
'include' => 'include'
];
$meta_query = [
@ -164,6 +165,7 @@ class REST_Controller extends \WP_REST_Controller {
$terms = get_terms([
'taxonomy' => $tax_query['taxonomy'],
'fields' => 'ids',
'hide_empty' => isset($args['hide_empty']) ? $args['hide_empty'] : true,
'search' => $tax_query['terms']
]);
@ -178,6 +180,7 @@ class REST_Controller extends \WP_REST_Controller {
$terms = get_terms([
'taxonomy' => $tax_query['taxonomy'],
'fields' => 'ids',
'hide_empty' => isset($args['hide_empty']) ? $args['hide_empty'] : true,
'search' => $tax_query['terms']
]);
if ($terms) {
@ -259,6 +262,23 @@ class REST_Controller extends \WP_REST_Controller {
return false;
}
/**
* Return the fetch_only param
*
* @param string $object_name
*
* @return array|void
*/
public function get_fetch_only_param(){
return [
'fetch_only' => array(
'type' => 'string/array',
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.', 'tainacan' ),
//TODO: explicar o fetch only meta.. cabe aqui?
)
];
}
/**
* Return the common params
@ -267,21 +287,32 @@ class REST_Controller extends \WP_REST_Controller {
*
* @return array|void
*/
public function get_collection_params($object_name = null){
public function get_wp_query_params(){
$query_params['id'] = array(
'description' => __("Limit result to $object_name with specific id."),
'description' => __("Limit result to objects with specific id.", 'tainacan'),
'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(
'description' => __( 'Limit results to those matching a string.' ),
'description' => __( 'Limit results to those matching a string.', 'tainacan' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => 'rest_validate_request_arg',
);
$query_params['authorid'] = array(
'description' => __("Limit result set to $object_name assigned to specific authors by id."),
'description' => __("Limit result set to objects assigned to specific authors by id.", 'tainacan'),
'type' => 'array',
'items' => array(
'type' => 'integer',
@ -289,12 +320,12 @@ class REST_Controller extends \WP_REST_Controller {
);
$query_params['authorname'] = array(
'description' => __("Limit result set to $object_name assigned to specific authors by name"),
'description' => __("Limit result set to objects assigned to specific authors by name", 'tainacan'),
'type' => 'string',
);
$query_params['status'] = array(
'description' => __("Limit result set to $object_name assigned one or more statuses."),
'description' => __("Limit result set to objects assigned one or more statuses.", 'tainacan'),
'type' => 'array',
'items' => array(
'enum' => array_merge(array_keys(get_post_stati()), array('any')),
@ -303,19 +334,19 @@ class REST_Controller extends \WP_REST_Controller {
);
$query_params['offset'] = array(
'description' => __( "Offset the result set by a specific number of $object_name." ),
'description' => __( "Offset the result set by a specific number of objects.", 'tainacan' ),
'type' => 'integer',
);
$query_params['order'] = array(
'description' => __( 'Order sort attribute ascending or descending.' ),
'description' => __( 'Order sort attribute ascending or descending.', 'tainacan' ),
'type' => 'string/array',
'default' => 'desc',
'enum' => array( 'asc', 'desc' ),
'enum' => array( 'asc', 'desc', 'ASC', 'DESC' ),
);
$query_params['orderby'] = array(
'description' => __( "Sort $object_name by object attribute." ),
'description' => __( "Sort objects by object attribute.", 'tainacan' ),
'type' => 'string/array',
'default' => 'date',
'enum' => array(
@ -335,13 +366,13 @@ class REST_Controller extends \WP_REST_Controller {
);
$query_params['perpage'] = array(
'description' => __( "Maximum number of $object_name to be returned in result set." ),
'description' => __( "Maximum number of objects to be returned in result set.", 'tainacan' ),
'type' => 'numeric',
'default' => 10,
);
$query_params['paged'] = array(
'description' => __("Show the $object_name that would normally show up just on page X"),
'description' => __("The results page to be return.", 'tainacan'),
'type' => 'integer',
);
@ -369,8 +400,26 @@ class REST_Controller extends \WP_REST_Controller {
),
'metacompare' => array(
'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' => '=',
'enum' => array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'NOT EXISTS',
'REGEXP',
'NOT REGEXP',
'RLIKE'
)
),
'metaquery' => array(
'description' => __('Limits result set to items that have specific custom metadata'),
@ -388,8 +437,24 @@ class REST_Controller extends \WP_REST_Controller {
),
'compare' => array(
'type' => 'string',
'description' => __('Operator to test. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, EXISTS and NOT EXISTS.'),
'default' => '='
'description' => __('Operator to test.'),
'default' => '=',
'enum' => array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS'
)
),
'relation' => array(
'type' => 'string',
@ -439,8 +504,24 @@ class REST_Controller extends \WP_REST_Controller {
),
'compare' => array(
'type' => 'string',
'description' => __('Operator to test. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, EXISTS and NOT EXISTS.'),
'default' => '='
'description' => __('Operator to test.'),
'default' => '=',
'enum' => array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS'
)
),
'dayofweek' => array('type' => 'array'),
'inclusive' => array(
@ -470,7 +551,14 @@ class REST_Controller extends \WP_REST_Controller {
),
'metadatum' => array(
'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(
'type' => 'int/string/array',
@ -478,13 +566,24 @@ class REST_Controller extends \WP_REST_Controller {
),
'operator' => array(
'type' => 'string',
'description' => __('Operator to test. Possible values are IN, NOT IN, AND, EXISTS and NOT EXISTS'),
'default' => 'IN'
'description' => __('Operator to test.'),
'default' => 'IN',
'enum' => array(
'IN',
'NOT IN',
'AND',
'EXISTS',
'NOT EXISTS'
)
),
'relation' => array(
'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.'),
'default' => 'AND'
'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',
'enum' => array(
'AND',
'OR'
)
),
),
'type' => 'array'
@ -492,6 +591,54 @@ class REST_Controller extends \WP_REST_Controller {
),
);
}
function get_repository_schema( \Tainacan\Repositories\Repository $repository ) {
$schema = [];
$map = $repository->get_map();
foreach ($map as $mapped => $value){
$schema[$mapped] = [
'description' => $value['description'],
'type' => $value['type']
];
}
return $schema;
}
function get_permissions_schema() {
return [
'current_user_can_edit' => [
'description' => esc_html__('Whether current user can edit this object', 'tainacan'),
'type' => 'boolean',
'context' => 'edit'
],
'current_user_can_delete' => [
'description' => esc_html__('Whether current user can delete this object', 'tainacan'),
'type' => 'boolean',
'context' => 'edit'
]
];
}
function get_base_properties_schema() {
return [
'id' => [
'description' => esc_html__( 'Unique identifier for the object.', 'tainacan' ),
'type' => 'integer',
'context' => array( 'view', 'edit' ),
'readonly' => true
]
];
}
}
?>

View File

@ -42,38 +42,48 @@ class REST_Background_Processes_Controller extends REST_Controller {
],
'all_users' => [
'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' => [
'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' => [
'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' => [
'type' => 'integer',
'description' => __( 'Page to retrieve. Default 1', 'tainacan' ),
'description' => __( 'Page to retrieve', 'tainacan' ),
'default' => 1
],
'recent' => [
'type' => 'bool',
'description' => __( 'Returns only processes created or updated recently', 'tainacan' ),
'default' => false
],
],
),
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[0-9]+)', array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'bg_processes_permissions_check'),
),
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[0-9]+)', array(
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item'),
@ -82,27 +92,31 @@ class REST_Background_Processes_Controller extends REST_Controller {
'status' => [
'type' => 'string',
'description' => __( '"open" or "closed" ', 'tainacan' ),
'enum' => array(
'open',
'closed'
)
]
],
),
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[0-9]+)', array(
array(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'bg_processes_permissions_check'),
),
));
}
/**
*
* @param \WP_REST_Request $request
@ -141,7 +155,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$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 = "";
}
}
@ -154,7 +168,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$status_q = "AND done = 1";
}
}
$recent_q = '';
if ( isset($request['recent']) && $request['recent'] !== false ) {
$recent_q = "AND (processed_last >= NOW() - INTERVAL 10 MINUTE OR queued_on >= NOW() - INTERVAL 10 MINUTE)";
@ -180,7 +194,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$rest_response->header('X-WP-Total', (int) $total_items);
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
return $rest_response;
}
@ -314,9 +328,9 @@ class REST_Background_Processes_Controller extends REST_Controller {
public function get_log_url($id, $action, $type = '') {
$suffix = $type ? '-' . $type : '';
$filename = 'bg-' . $action . '-' . $id . $suffix . '.log';
$upload_url = wp_upload_dir();
if (!file_exists( $upload_url['basedir'] . '/tainacan/' . $filename )) {
@ -325,7 +339,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$upload_url = trailingslashit( $upload_url['baseurl'] );
$logs_url = $upload_url . 'tainacan/' . $filename;
return $logs_url;
}

View File

@ -455,9 +455,6 @@ class REST_Bulkedit_Controller extends REST_Controller {
* @return array|void
*/
public function get_create_params($object_name = null) {
$query_params['context']['default'] = 'view';
array_merge($query_params, parent::get_collection_params('item'));
$query_params['title'] = array(
'description' => __('Limits the result set to items with a specific title'),
@ -477,7 +474,11 @@ class REST_Bulkedit_Controller extends REST_Controller {
'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;
}

View File

@ -43,7 +43,7 @@ class REST_Collections_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params(),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
),
array(
'methods' => \WP_REST_Server::CREATABLE,
@ -51,13 +51,15 @@ class REST_Collections_Controller extends REST_Controller {
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
),
'schema' => [$this, 'get_schema'],
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<collection_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),
'args' => $this->get_wp_query_params(),
),
array(
'methods' => \WP_REST_Server::EDITABLE,
@ -71,11 +73,12 @@ class REST_Collections_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'),
'default' => 'false'
'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
'default' => '0',
),
)
),
'schema' => [$this, 'get_schema'],
));
}
@ -474,16 +477,19 @@ class REST_Collections_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
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['name'] = array(
'description' => __('Limits the result set to collections with a specific name'),
'type' => 'string',
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_wp_query_params(),
parent::get_fetch_only_param(),
parent::get_meta_queries_params()
);
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
);
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->collections_repository->get_map();
@ -501,29 +507,30 @@ class REST_Collections_Controller extends REST_Controller {
return $endpoint_args;
}
/**
*
* Return the queries supported when getting a collection of objects
*
* @param null $object_name
*
* @return array
*/
public function get_collection_params($object_name = null) {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_collection_params('collection'));
$query_params['name'] = array(
'description' => __('Limits the result set to collections with a specific name'),
'type' => 'string',
);
$query_params = array_merge($query_params, parent::get_meta_queries_params());
return $query_params;
}
function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'collection',
'type' => 'object'
];
$main_schema = parent::get_repository_schema( $this->collections_repository );
$permissions_schema = parent::get_permissions_schema();
// transformation done in $this->prepare_item_for_response()
$main_schema['moderators'] = $main_schema['moderators_ids'];
$main_schema['moderators']['contex'] = 'edit';
$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
);
return $schema;
}
}
?>

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_collection_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

@ -68,7 +68,7 @@ class REST_Exporters_Controller extends REST_Controller {
],
'options' => [
'type' => 'array/object',
'description' => __( 'The importer options', 'tainacan' ),
'description' => __( 'The exporter options', 'tainacan' ),
]
],
),
@ -121,6 +121,7 @@ class REST_Exporters_Controller extends REST_Controller {
if ($object = $Tainacan_Exporter_Handler->initialize_exporter($slug)) {
$response = $object->_to_Array();
$Tainacan_Exporter_Handler->save_exporter_instance($object);
return new \WP_REST_Response($response, 201);
} else {
return new \WP_REST_Response([
@ -146,13 +147,14 @@ class REST_Exporters_Controller extends REST_Controller {
foreach ($body as $att => $value) {
$attributes[$att] = $value;
}
$importer = $_SESSION['tainacan_exporter'][$session_id];
if($importer) {
global $Tainacan_Exporter_Handler;
$exporter = $Tainacan_Exporter_Handler->get_exporter_instance_by_session_id($session_id);
if($exporter) {
foreach ($body as $att => $value) {
if ($att == 'collection') {
if (is_array($value) && isset($value['id'])) {
$importer->add_collection($value);
$exporter->add_collection($value);
continue;
} else {
return new \WP_REST_Response([
@ -162,17 +164,18 @@ class REST_Exporters_Controller extends REST_Controller {
}
}
$method = 'set_' . $att;
if (method_exists($importer, $method)) {
$importer->$method($value);
if (method_exists($exporter, $method)) {
$exporter->$method($value);
}
}
$response = $importer->_to_Array();
$response = $exporter->_to_Array();
$Tainacan_Exporter_Handler->save_exporter_instance($exporter);
return new \WP_REST_Response( $response, 200 );
}
return new \WP_REST_Response([
'error_message' => __('Importer Session not found', 'tainacan' ),
'error_message' => __('Exporter Session not found', 'tainacan' ),
'session_id' => $session_id
], 400);
}
@ -192,7 +195,8 @@ class REST_Exporters_Controller extends REST_Controller {
*/
public function run($request) {
$session_id = $request['session_id'];
$exporter = $_SESSION['tainacan_exporter'][$session_id];
global $Tainacan_Exporter_Handler;
$exporter = $Tainacan_Exporter_Handler->get_exporter_instance_by_session_id($session_id);
if(!$exporter) {
return new \WP_REST_Response([
@ -212,6 +216,7 @@ class REST_Exporters_Controller extends REST_Controller {
$response = [
'bg_process_id' => $process->ID
];
$Tainacan_Exporter_Handler->delete_exporter_instance($exporter);
return new \WP_REST_Response( $response, 200 );
}

View File

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

View File

@ -44,34 +44,37 @@ class REST_Filters_Controller extends REST_Controller {
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
),
'schema' => [$this, 'get_schema']
));
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $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_collection_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']
));
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_collection_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']
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<filter_id>[\d]+)', array(
array(
@ -80,8 +83,8 @@ class REST_Filters_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'),
'default' => 'false'
'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
'default' => '0'
),
)
),
@ -96,7 +99,8 @@ class REST_Filters_Controller extends REST_Controller {
'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']
));
}
@ -118,13 +122,11 @@ class REST_Filters_Controller extends REST_Controller {
if(empty($received_type)){
throw new \InvalidArgumentException('The type can\'t be empty');
} elseif(!strrchr($received_type, '_')){
$received_type = ucfirst(strtolower($received_type));
$type = ucfirst(strtolower($received_type));
} else {
$received_type = ucwords(strtolower($received_type), '_');
$type = ucwords(strtolower($received_type), '_\\');
}
$type = "Tainacan\Filter_Types\\$received_type";
$filter_type = new $type();
foreach ($filter as $attribute => $value){
@ -148,7 +150,7 @@ class REST_Filters_Controller extends REST_Controller {
$filter_obj->set_metadatum_id($body['metadatum_id']);
} else {
$filter_obj->set_collection_id( 'filter_in_repository' );
$filter_obj->set_collection_id( 'default' );
if(!isset($body['metadatum_id'])){
throw new \InvalidArgumentException('You need provide a metadatum id');
@ -375,7 +377,7 @@ class REST_Filters_Controller extends REST_Controller {
if(!isset($request['collection_id'])) {
$args['meta_query'][] = [
'key' => 'collection_id',
'value' => 'filter_in_repository',
'value' => 'default',
'compare' => '='
];
@ -467,11 +469,10 @@ class REST_Filters_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_wp_query_params()
);
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->filter_repository->get_map();
@ -495,19 +496,45 @@ class REST_Filters_Controller extends REST_Controller {
*
* @return array|void
*/
public function get_collection_params( $object_name = null ) {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_collection_params('filter'));
public function get_wp_query_params() {
$query_params['name'] = array(
'description' => __('Limits the result set to filters with a specific name'),
'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;
}
function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'filter',
'type' => 'object'
];
$main_schema = parent::get_repository_schema( $this->filter_repository );
$permissions_schema = parent::get_permissions_schema();
// $collection_scheme = parent::get_repository_schema( $this->collection_repository );
// $metadatum_scheme = parent::get_repository_schema( $this->metadatum_repository );
$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
// $collection_scheme,
// $metadatum_scheme
);
return $schema;
}
}
?>

View File

@ -165,6 +165,7 @@ class REST_Importers_Controller extends REST_Controller {
if ($object = $Tainacan_Importer_Handler->initialize_importer($slug)) {
$response = $object->_to_Array();
$Tainacan_Importer_Handler->save_importer_instance($object);
return new \WP_REST_Response($response, 201);
} else {
return new \WP_REST_Response([
@ -192,9 +193,10 @@ class REST_Importers_Controller extends REST_Controller {
foreach ($body as $att => $value){
$attributes[$att] = $value;
}
$importer = $_SESSION['tainacan_importer'][$session_id];
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if($importer) {
foreach ($body as $att => $value){
@ -218,6 +220,7 @@ class REST_Importers_Controller extends REST_Controller {
}
$response = $importer->_to_Array();
$Tainacan_Importer_Handler->save_importer_instance($importer);
return new \WP_REST_Response( $response, 200 );
}
@ -237,7 +240,8 @@ class REST_Importers_Controller extends REST_Controller {
public function source_info( $request ) {
$session_id = $request['session_id'];
$importer = $_SESSION['tainacan_importer'][$session_id];
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if(!$importer) {
return new \WP_REST_Response([
@ -263,7 +267,7 @@ class REST_Importers_Controller extends REST_Controller {
if ( method_exists($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 );
}
@ -271,7 +275,8 @@ class REST_Importers_Controller extends REST_Controller {
public function get_saved_mapping( $request ){
$session_id = $request['session_id'];
$collection_id = $request['collection_id'];
$importer = $_SESSION['tainacan_importer'][$session_id];
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
$response = false;
if(!$importer) {
@ -290,7 +295,8 @@ class REST_Importers_Controller extends REST_Controller {
public function get_item( $request ) {
$session_id = $request['session_id'];
$importer = $_SESSION['tainacan_importer'][$session_id];
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if(!$importer) {
return new \WP_REST_Response([
@ -306,7 +312,8 @@ class REST_Importers_Controller extends REST_Controller {
public function add_file( $request ) {
$session_id = $request['session_id'];
$importer = $_SESSION['tainacan_importer'][$session_id];
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if(!$importer) {
return new \WP_REST_Response([
@ -320,6 +327,7 @@ class REST_Importers_Controller extends REST_Controller {
if ( isset($files['file']) && $importer->add_file($files['file']) ) {
$response = $importer->_to_Array();
$Tainacan_Importer_Handler->save_importer_instance($importer);
return new \WP_REST_Response( $response, 200 );
} else {
return new \WP_REST_Response([
@ -335,7 +343,8 @@ class REST_Importers_Controller extends REST_Controller {
public function run($request) {
$session_id = $request['session_id'];
$importer = $_SESSION['tainacan_importer'][$session_id];
global $Tainacan_Importer_Handler;
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if(!$importer) {
return new \WP_REST_Response([
@ -358,6 +367,7 @@ class REST_Importers_Controller extends REST_Controller {
$response = [
'bg_process_id' => $process->ID
];
$Tainacan_Importer_Handler->delete_importer_instance($importer);
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,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_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 ) {
$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'] = [
'type' => 'array/string/object/integer',
'items' => [
@ -289,8 +294,16 @@ class REST_Item_Metadata_Controller extends REST_Controller {
*
* @return array
*/
public function get_collection_params($object_name = null) {
$query_params['context']['default'] = 'view';
public function get_wp_query_params() {
$query_params['context'] = array(
'type' => 'string',
'default' => 'view',
'description' => 'The context in which the request is made.',
'enum' => array(
'view',
'edit'
),
);
return $query_params;
}

View File

@ -49,7 +49,7 @@ class REST_Items_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params(),
'args' => $this->get_wp_query_params(),
),
array(
'methods' => \WP_REST_Server::CREATABLE,
@ -80,8 +80,8 @@ class REST_Items_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection', 'tainacan'),
'default' => 'false'
'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection', 'tainacan'),
'default' => '0'
),
)
),
@ -94,7 +94,7 @@ class REST_Items_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params(),
'args' => $this->get_wp_query_params(),
),
)
);
@ -757,15 +757,18 @@ class REST_Items_Controller extends REST_Controller {
$endpoint_args = [];
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(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
'type' => 'string',
'default' => 'view',
'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) {
$map = $this->items_repository->get_map();
@ -790,17 +793,17 @@ class REST_Items_Controller extends REST_Controller {
*
* @return array|void
*/
public function get_collection_params($object_name = null) {
$query_params['context']['default'] = 'view';
array_merge($query_params, parent::get_collection_params('item'));
public function get_wp_query_params() {
$query_params['title'] = array(
'description' => __('Limits the result set to items with a specific title'),
'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;
}

View File

@ -17,12 +17,7 @@ class REST_Logs_Controller extends REST_Controller {
public function __construct() {
$this->rest_base = 'logs';
parent::__construct();
add_action('init', array($this, 'init_objects'));
}
public function init_objects(){
$this->logs_repository = Repositories\Logs::get_instance();
$this->log = new Entities\Log();
}
public function register_routes() {
@ -32,8 +27,9 @@ class REST_Logs_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params()
)
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<log_id>[\d]+)',
@ -42,17 +38,19 @@ class REST_Logs_Controller extends REST_Controller {
'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 . '/(?P<log_id>[\d]+)/approve',
array(
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'approve_item'),
'permission_callback' => array($this, 'approve_item_permissions_check'),
)
'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']
)
);
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base,
@ -62,7 +60,8 @@ class REST_Logs_Controller extends REST_Controller {
'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)
)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base,
@ -72,7 +71,52 @@ class REST_Logs_Controller extends REST_Controller {
'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)
)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace, '/filter/(?P<filter_id>[\d]+)/' . $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_endpoint_args_for_item_schema( \WP_REST_Server::READABLE)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace, '/metadatum/(?P<metadatum_id>[\d]+)/' . $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_endpoint_args_for_item_schema( \WP_REST_Server::READABLE)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace, '/taxonomy/(?P<taxonomy_id>[\d]+)/' . $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_endpoint_args_for_item_schema( \WP_REST_Server::READABLE)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace, '/term/(?P<term_id>[\d]+)/' . $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_endpoint_args_for_item_schema( \WP_REST_Server::READABLE)
),
'schema' => [$this, 'get_schema']
)
);
}
@ -86,22 +130,127 @@ class REST_Logs_Controller extends REST_Controller {
public function prepare_item_for_response( $item, $request ) {
if(!empty($item)){
if(!isset($request['fetch_only'])) {
$item_array = $item->_toArray();
unset($item_array['value']);
unset($item_array['old_value']);
return $item_array;
// Hanle logs created before 1.0
if ( !empty( get_post_meta($item->get_id(), 'value', true) ) && !empty( get_post_meta($item->get_id(), 'log_diffs', true) ) ) {
return $this->prepare_legacy_item_for_response($item, $request);
}
if ($request['log_id']) {
$item_array = $item->_toArray();
$related_object = true;
if ($item_array['item_id']) {
$item = Repositories\Items::get_instance()->fetch( (int) $item_array['item_id'] );
if ($item instanceof Entities\Item ) {
$item_array['item'] = $item->_toArray();
}
}
if ($item_array['collection_id']) {
$collection = Repositories\Collections::get_instance()->fetch( (int) $item_array['collection_id'] );
if ($collection instanceof Entities\Item ) {
$item_array['collection'] = $collection->_toArray();
}
}
if ( $item_array['object_id'] ) {
if ( $item_array['object_type'] == 'Tainacan\Entities\Term' ) {
$related_entity = Repositories\Terms::get_instance()->fetch( (int) $item_array['object_id'] );
} else {
$related_post = get_post($item_array['object_id']);
$related_entity = Repository::get_entity_by_post( $related_post );
}
if ($related_entity instanceof Entities\Entity ) {
$item_array[ 'object' ] = $related_entity->_toArray();
}
}
if ( $item_array['action'] == 'new-attachment' ) {
if ( isset($item_array['new_value']['id']) ) {
$item_array['new_value']['url'] = wp_get_attachment_url($item_array['new_value']['id']);
$item_array['new_value']['thumb'] = wp_get_attachment_image_src($item_array['new_value']['id'], 'thumbnail');
}
} elseif ( $item_array['action'] == 'update-document' ) {
if ( isset( $item_array['new_value']['document'] ) && is_numeric( $item_array['new_value']['document'] ) ) {
$item_array['new_value']['url'] = wp_get_attachment_url($item_array['new_value']['document']);
$item_array['new_value']['thumb'] = wp_get_attachment_image_src($item_array['new_value']['document'], 'thumbnail');
}
if ( isset( $item_array['old_value']['document'] ) && is_numeric( $item_array['old_value']['document'] ) ) {
$item_array['old_value']['url'] = wp_get_attachment_url($item_array['old_value']['document']);
$item_array['old_value']['thumb'] = wp_get_attachment_image_src($item_array['old_value']['document'], 'thumbnail');
}
} elseif ( $item_array['action'] == 'update-thumbnail' ) {
if ( isset( $item_array['new_value']['_thumbnail_id'] ) ) {
$item_array['new_value']['url'] = wp_get_attachment_url($item_array['new_value']['_thumbnail_id']);
$item_array['new_value']['thumb'] = wp_get_attachment_image_src($item_array['new_value']['_thumbnail_id'], 'thumbnail');
}
if ( isset( $item_array['old_value']['_thumbnail_id'] ) ) {
$item_array['old_value']['url'] = wp_get_attachment_url($item_array['old_value']['_thumbnail_id']);
$item_array['old_value']['thumb'] = wp_get_attachment_image_src($item_array['old_value']['_thumbnail_id'], 'thumbnail');
}
}
// translate
if (isset($related_entity) && $related_entity instanceof Entities\Entity ) {
$map = $related_entity->get_repository()->get_map();
foreach ( $map as $slug => $m ) {
if ( isset($item_array['new_value'][$slug]) ) {
$item_array['new_value'][$m['title']] = $item_array['new_value'][$slug];
unset($item_array['new_value'][$slug]);
}
if ( isset($item_array['old_value'][$slug]) ) {
$item_array['old_value'][$m['title']] = $item_array['old_value'][$slug];
unset($item_array['old_value'][$slug]);
}
}
}
return $item_array;
} else {
if(!isset($request['fetch_only'])) {
$item_array = $item->_toArray();
return $item_array;
}
$attributes_to_filter = $request['fetch_only'];
$attributes_to_filter = $request['fetch_only'];
}
return $this->filter_object_by_attributes($item, $attributes_to_filter);
}
return $item;
}
private function prepare_legacy_item_for_response($item, $request) {
if(!isset($request['fetch_only'])) {
$item_array = $item->_toArray();
unset($item_array['value']);
unset($item_array['old_value']);
$item_array['legacy'] = true;
return $item_array;
}
$attributes_to_filter = $request['fetch_only'];
return $this->filter_object_by_attributes($item, $attributes_to_filter);
}
/**
* @param \WP_REST_Request $request
@ -114,91 +263,28 @@ class REST_Logs_Controller extends REST_Controller {
$args = $this->prepare_filters( $request );
if ($request['item_id']){
$item_id = $request['item_id'];
$item_repository = Repositories\Items::get_instance();
$item = $item_repository->fetch($item_id);
if(!$item){
return new \WP_REST_Response([
'error_message' => __('An item with this ID does not exist', 'tainacan'),
'item_id' => $item
], 400);
}
if($args &&
array_key_exists('meta_query', $args) &&
array_key_exists('relation', $args['meta_query'])){
$metaq = $args['meta_query'];
unset($args['meta_query']);
$args['meta_query'][] = $metaq;
$args['meta_query']['relation'] = 'AND';
} elseif($args &&
array_key_exists('meta_query', $args)){
$args['meta_query']['relation'] = 'AND';
}
$args = array_merge_recursive(array(
'meta_query' => array(
'item_clause' => array(
'key' => 'item_id',
'value' => $item_id,
'compare' => '='
)
)
), $args);
if ($request['item_id']) {
$args['item_id'] = $request['item_id'];
} elseif ($request['collection_id']) {
$args['collection_id'] = $request['collection_id'];
} elseif ($request['filter_id']) {
$args['object_type'] = 'Tainacan\Entities\Filter';
$args['object_id'] = $request['filter_id'];
} elseif ($request['metadatum_id']) {
$args['object_type'] = 'Tainacan\Entities\Metadatum';
$args['object_id'] = $request['metadatum_id'];
} elseif ($request['taxonomy_id']) {
$args['object_type'] = 'Tainacan\Entities\Taxonomy';
$args['object_id'] = $request['taxonomy_id'];
} elseif ($request['term_id']) {
$args['object_type'] = 'Tainacan\Entities\Term';
$args['object_id'] = $request['term_id'];
}
if($request['collection_id']){
$collection_id = $request['collection_id'];
$collection_repository = Repositories\Collections::get_instance();
$collection = $collection_repository->fetch($collection_id);
if(!$collection){
return new \WP_REST_Response([
'error_message' => __('A collection with this ID does not exist', 'tainacan'),
'collection_id' => $collection_id
], 400);
}
if($args &&
array_key_exists('meta_query', $args) &&
array_key_exists('relation', $args['meta_query'])){
$metaq = $args['meta_query'];
unset($args['meta_query']);
$args['meta_query'][] = $metaq;
$args['meta_query']['relation'] = 'AND';
} elseif($args &&
array_key_exists('meta_query', $args)){
$args['meta_query']['relation'] = 'AND';
}
$args = array_merge_recursive(array(
'meta_query' => array(
'collection_clause' => array(
'key' => 'collection_id',
'value' => $collection_id,
'compare' => '='
)
)
), $args);
}
$logs = $this->logs_repository->fetch($args);
$logs = Repositories\Logs::get_instance()->fetch($args);
$response = [];
if($logs->have_posts()){
while ($logs->have_posts()){
$logs->the_post();
@ -228,6 +314,7 @@ class REST_Logs_Controller extends REST_Controller {
* @return bool|\WP_Error
*/
public function get_items_permissions_check( $request ) {
return true;
return current_user_can('read');
}
@ -239,7 +326,7 @@ class REST_Logs_Controller extends REST_Controller {
public function get_item( $request ) {
$log_id = $request['log_id'];
$log = $this->logs_repository->fetch($log_id);
$log = Repositories\Logs::get_instance()->fetch($log_id);
$prepared_log = $this->prepare_item_for_response( $log, $request );
@ -252,7 +339,8 @@ class REST_Logs_Controller extends REST_Controller {
* @return bool|\WP_Error
*/
public function get_item_permissions_check( $request ) {
$log = $this->logs_repository->fetch($request['log_id']);
return true;
$log = Repositories\Logs::get_instance()->fetch($request['log_id']);
if(($log instanceof Entities\Log)) {
if('edit' === $request['context'] && !$log->can_read()) {
@ -264,52 +352,6 @@ class REST_Logs_Controller extends REST_Controller {
return false;
}
/**
* @param \WP_REST_Request $request
*
* @return bool|\WP_Error
*/
public function approve_item_permissions_check( $request ) {
$log = $this->logs_repository->fetch($request['log_id']);
if($log instanceof Entities\Log){
if($log->can_read()) {
$entity = $log->get_value();
if($entity instanceof Entities\Entity) {
if($entity instanceof Entities\Item_Metadata_Entity) {
$item = $entity->get_item();
return $item->can_edit();
} // TODO for other entities types
else {
return $entity->can_edit();
}
}
return new \WP_Error();
}
}
return false;
}
/**
* approve a logged modification
* @param \WP_REST_Request $request
*
* @return \WP_Error|\WP_REST_Response
*/
public function approve_item($request) {
$log = $this->logs_repository->fetch($request['log_id']);
if($log instanceof Entities\Log){
$entity = $log->approve();
$prepared_entity = $this->prepare_item_for_response( $entity, $request );
return new \WP_REST_Response($prepared_entity, 200);
}
}
/**
* @param string $method
@ -319,37 +361,32 @@ class REST_Logs_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view' )
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_wp_query_params()
);
}
return $endpoint_args;
}
/**
*
* Return the queries supported when getting a collection of objects
*
* @param null $object_name
*
* @return array
*/
public function get_collection_params($object_name = null) {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_collection_params('log'));
$query_params['title'] = array(
'description' => __('Limits the result set to a log with a specific title'),
'type' => 'string',
function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'log',
'type' => 'object'
];
$main_schema = parent::get_repository_schema( $this->logs_repository );
$permissions_schema = parent::get_permissions_schema();
$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
);
$query_params = array_merge($query_params, parent::get_meta_queries_params());
return $query_params;
return $schema;
}
}

View File

@ -44,24 +44,34 @@ class REST_Metadata_Controller extends REST_Controller {
public function register_routes() {
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<metadatum_id>[\d]+)',
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(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item'),
'permission_callback' => array($this, 'update_item_permissions_check'),
'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(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
'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']
)
);
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base,
@ -70,7 +80,7 @@ class REST_Metadata_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params(),
'args' => $this->get_wp_query_params(),
),
array(
'methods' => \WP_REST_Server::CREATABLE,
@ -78,31 +88,43 @@ class REST_Metadata_Controller extends REST_Controller {
'permission_callback' => array($this, 'create_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
),
'schema' => [$this, 'get_schema']
)
);
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(),
),
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(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params(),
)
'schema' => [$this, 'get_schema'],
)
);
register_rest_route($this->namespace, '/'. $this->rest_base . '/(?P<metadatum_id>[\d]+)',
array(
// ENDPOINT Z.
array(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check')
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'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(
'methods' => \WP_REST_Server::EDITABLE,
@ -111,11 +133,11 @@ class REST_Metadata_Controller extends REST_Controller {
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
),
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission' => array($this, 'get_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
)
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check')
),
'schema' => [$this, 'get_schema'],
)
);
}
@ -536,10 +558,10 @@ class REST_Metadata_Controller extends REST_Controller {
*
* @return array|void
*/
public function get_collection_params( $object_name = null ) {
public function get_wp_query_params() {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_collection_params('metadatum'));
$query_params = array_merge($query_params, parent::get_wp_query_params());
$query_params['name'] = array(
'description' => __('Limits the result set to metadata with a specific name'),
@ -560,11 +582,10 @@ class REST_Metadata_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_wp_query_params()
);
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->metadatum_repository->get_map();
@ -582,6 +603,32 @@ class REST_Metadata_Controller extends REST_Controller {
return $endpoint_args;
}
function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'metadatum',
'type' => 'object'
];
$main_schema = parent::get_repository_schema( $this->metadatum_repository );
$permissions_schema = parent::get_permissions_schema();
// $item_metadata_scheme = parent::get_repository_schema( $this->item_metadata_repository );
// $item_scheme = parent::get_repository_schema( $this->item_repository );
// $collection_scheme = parent::get_repository_schema( $this->collection_repository );
$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
// $item_metadata_scheme,
// $item_scheme,
// $collection_scheme
);
return $schema;
}
}
?>

View File

@ -36,14 +36,15 @@ class REST_Taxonomies_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_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']
)
);
register_rest_route(
@ -53,7 +54,21 @@ class REST_Taxonomies_Controller extends REST_Controller {
'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)
'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(
'methods' => \WP_REST_Server::DELETABLE,
@ -61,8 +76,8 @@ class REST_Taxonomies_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'),
'default' => 'false',
'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
'default' => '0',
),
)
),
@ -71,7 +86,8 @@ class REST_Taxonomies_Controller extends REST_Controller {
'callback' => array($this, 'update_item'),
'permission_callback' => array($this, 'update_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
)
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route(
@ -82,7 +98,8 @@ class REST_Taxonomies_Controller extends REST_Controller {
'callback' => array($this, 'update_item'),
'permission_callback' => array($this, 'update_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
)
),
'schema' => [$this, 'get_schema']
)
);
}
@ -449,16 +466,11 @@ class REST_Taxonomies_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
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(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_wp_query_params(),
parent::get_fetch_only_param()
);
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->taxonomy_repository->get_map();
@ -485,10 +497,10 @@ class REST_Taxonomies_Controller extends REST_Controller {
*
* @return array
*/
public function get_collection_params($object_name = null) {
public function get_wp_query_params() {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_collection_params('tax'));
$query_params = array_merge($query_params, parent::get_wp_query_params());
$query_params['name'] = array(
'description' => __('Limits the result set to a taxonomy with a specific name.'),
@ -499,6 +511,26 @@ class REST_Taxonomies_Controller extends REST_Controller {
return $query_params;
}
function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'taxonomy',
'type' => 'object'
];
$main_schema = parent::get_repository_schema( $this->taxonomy_repository );
$permissions_schema = parent::get_permissions_schema();
$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
);
return $schema;
}
}
?>

View File

@ -44,8 +44,9 @@ class REST_Terms_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_collection_params()
)
'args' => $this->get_wp_query_params()
),
'schema' => [$this, 'get_schema']
)
);
register_rest_route($this->namespace,'/taxonomy/(?P<taxonomy_id>[\d]+)/'. $this->rest_base . '/(?P<term_id>[\d]+)' ,
@ -55,8 +56,9 @@ class REST_Terms_Controller extends REST_Controller {
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => [
'info' => [
'description' => __('Delete term permanently.')
'permanently' => [
'description' => __('Delete term permanently.'),
'default' => '1'
]
]
),
@ -71,7 +73,8 @@ class REST_Terms_Controller extends REST_Controller {
'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']
)
);
}
@ -418,11 +421,10 @@ class REST_Terms_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
$endpoint_args['context'] = array(
'type' => 'string',
'default' => 'view',
'items' => array( 'view, edit' )
);
$endpoint_args = array_merge(
$endpoint_args,
parent::get_wp_query_params()
);
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->terms_repository->get_map();
@ -449,10 +451,10 @@ class REST_Terms_Controller extends REST_Controller {
*
* @return array
*/
public function get_collection_params($object_name = null) {
public function get_wp_query_params() {
$query_params['context']['default'] = 'view';
$query_params = array_merge($query_params, parent::get_collection_params('term'));
$query_params = array_merge($query_params, parent::get_wp_query_params());
$query_params['name'] = array(
'description' => __('Limits the result set to terms with a specific name'),
@ -463,6 +465,28 @@ class REST_Terms_Controller extends REST_Controller {
return $query_params;
}
function get_schema() {
$schema = [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'term',
'type' => 'object'
];
$main_schema = parent::get_repository_schema( $this->terms_repository );
$permissions_schema = parent::get_permissions_schema();
// $taxonomy_scheme = parent::get_repository_schema( $this->taxonomy_repository );
$schema['properties'] = array_merge(
parent::get_base_properties_schema(),
$main_schema,
$permissions_schema
// $taxonomy_scheme
);
return $schema;
}
}
?>

View File

@ -18,7 +18,6 @@ $rest_exporters_controller = new \Tainacan\API\EndPoints\REST_Exporters_Contr
$rest_background_processes_controller = new \Tainacan\API\EndPoints\REST_Background_Processes_Controller();
$rest_bulkedit_controller = new \Tainacan\API\EndPoints\REST_Bulkedit_Controller();
$rest_exposers_controller = new \Tainacan\API\EndPoints\REST_Exposers_Controller();
new \Tainacan\API\EndPoints\REST_Export_Controller();
new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller();
$rest_facets_controller = new \Tainacan\API\EndPoints\REST_Facets_Controller();
$rest_oaipmh_expose_controller = new \Tainacan\API\EndPoints\REST_Oaipmh_Expose_Controller();

View File

@ -0,0 +1,424 @@
[data-align='full'] .block-control {
width: calc(100% + 14px); }
.block-control {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 5px;
position: relative;
top: -14px;
left: -14px;
width: calc(100% + 28px);
background: #f2f2f2; }
.block-control p {
font-size: 0.875rem !important;
margin: 12px 1.5rem 16px 0;
fill: #555758; }
.block-control p svg {
top: 4px;
margin-right: 0.75rem;
position: relative;
fill: #555758; }
.components-placeholder__fieldset p {
font-size: 0.875rem !important;
margin-top: -2px;
fill: #555758; }
.components-placeholder__fieldset p svg {
margin-right: 1rem;
top: 4px;
position: relative;
fill: #555758; }
.wp-block-tainacan-modal {
width: 50%; }
@media only screen and (max-width: 1024px) {
.wp-block-tainacan-modal {
width: 75%; } }
@media only screen and (max-width: 768px) {
.wp-block-tainacan-modal {
width: 100%; } }
.wp-block-tainacan-modal.dynamic-modal {
width: 90%;
height: 90%;
width: 80vw;
height: 80vh; }
.wp-block-tainacan-modal.dynamic-modal iframe {
width: calc(100% + 32px);
height: calc(100% - 128px);
margin-left: -16px; }
.wp-block-tainacan-modal.dynamic-modal .modal-footer-area {
height: 68px;
width: calc(100% + 32px);
margin-left: -16px !important;
padding: 1.2rem 1.2rem !important;
border-top: 1px solid #cbcbcb; }
.wp-block-tainacan-modal .spinner-container {
min-height: 56px;
padding: 1rem;
display: flex;
justify-content: center;
align-items: center;
color: #555758; }
.wp-block-tainacan-modal .spinner-container .components-spineer {
margin: 8px; }
.wp-block-tainacan-modal .components-modal__header .components-icon-button {
padding-right: 0; }
.wp-block-tainacan-modal hr {
margin: 5px 0.75rem; }
.wp-block-tainacan-modal .modal-search-area {
display: flex;
justify-content: center;
margin-bottom: 14px; }
.wp-block-tainacan-modal .modal-search-area .components-base-control {
width: 60%; }
@media only screen and (max-width: 1024px) {
.wp-block-tainacan-modal .modal-search-area .components-base-control {
width: 95%; } }
.wp-block-tainacan-modal .modal-search-area .components-base-control:nth-child(2) {
flex-shrink: 2; }
.wp-block-tainacan-modal .modal-search-area .components-base-control .components-base-control__field {
flex-wrap: wrap; }
.wp-block-tainacan-modal .modal-search-area .components-base-control label.components-base-control__label {
font-weight: 500;
color: #454647;
font-size: 0.875rem;
text-align: center; }
.wp-block-tainacan-modal .modal-search-area .components-base-control input.components-text-control__input {
padding: 5px 8px;
height: 28px; }
.wp-block-tainacan-modal .modal-radio-area-label {
font-weight: 500;
margin-left: 1.75rem; }
.wp-block-tainacan-modal .modal-checkbox-list,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field {
padding: 0;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fill, 250px);
grid-gap: 0px;
justify-content: space-evenly;
list-style-type: none;
margin: 12px;
max-height: 50vh;
overflow-y: auto;
overflow-x: hidden; }
.wp-block-tainacan-modal .modal-checkbox-list .components-base-control,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .components-base-control {
overflow: hidden; }
.wp-block-tainacan-modal .modal-checkbox-list .modal-checkbox-list-item,
.wp-block-tainacan-modal .modal-checkbox-list .components-radio-control__option,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .modal-checkbox-list-item,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .components-radio-control__option {
display: flex;
justify-content: flex-start; }
.wp-block-tainacan-modal .modal-checkbox-list .modal-checkbox-list-item img,
.wp-block-tainacan-modal .modal-checkbox-list .components-radio-control__option img,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .modal-checkbox-list-item img,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .components-radio-control__option img {
width: 24px;
height: 24px;
margin-right: 10px; }
.wp-block-tainacan-modal .modal-checkbox-list .modal-checkbox-list-item label,
.wp-block-tainacan-modal .modal-checkbox-list .components-radio-control__option label,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .modal-checkbox-list-item label,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .components-radio-control__option label {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: inline-block;
max-width: 85%; }
@media only screen and (max-width: 768px) {
.wp-block-tainacan-modal .modal-checkbox-list .modal-checkbox-list-item label,
.wp-block-tainacan-modal .modal-checkbox-list .components-radio-control__option label,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .modal-checkbox-list-item label,
.wp-block-tainacan-modal .modal-radio-list .components-base-control__field .components-radio-control__option label {
max-width: 80%; } }
.wp-block-tainacan-modal .modal-loadmore-section {
display: flex;
align-items: baseline;
justify-content: center; }
.wp-block-tainacan-modal .modal-loadmore-section p {
color: #555758;
margin-right: 12px;
margin-top: 2px; }
.wp-block-tainacan-modal .modal-footer-area {
border-top: 1px solid #e2e4e7;
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 16px 16px 0 16px;
margin: 0 -16px; }
.wp-block-tainacan-modal .modal-footer-area p {
padding: 0 12px;
color: #454647; }
.components-panel__body .term-carousel-view-modes {
display: flex;
margin: 12px 0 24px 0; }
.components-panel__body .term-carousel-view-modes button {
background: transparent;
border: 1px solid #cbcbcb;
border-radius: 5px;
padding: 2px;
margin: 0;
width: calc(50% - 6px);
flex-shrink: 0;
cursor: pointer;
transition: border ease 0.5s, opacity ease 0.5; }
.components-panel__body .term-carousel-view-modes button.term-carousel-view-mode-grid {
margin-right: 6px; }
.components-panel__body .term-carousel-view-modes button.term-carousel-view-mode-grid div {
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 50% 50%;
grid-column-gap: 2px;
grid-row-gap: 2px;
width: 60px;
height: 40px;
margin: 4px auto 8px auto; }
.components-panel__body .term-carousel-view-modes button.term-carousel-view-mode-grid div > div:first-of-type {
grid-column-start: 1;
grid-column-end: span 2;
grid-row-start: 1;
grid-row-end: span 2;
width: 41px;
height: 42px; }
.components-panel__body .term-carousel-view-modes button.term-carousel-view-mode-grid div > div {
width: 20px;
height: 20px;
background: #555758;
transition: background-color ease 0.5s; }
.components-panel__body .term-carousel-view-modes button.term-carousel-view-mode-thumbnail {
margin-left: 6px; }
.components-panel__body .term-carousel-view-modes button.term-carousel-view-mode-thumbnail div {
display: block;
height: 40px;
width: 40px;
background: #555758;
margin: 4px auto 8px auto;
transition: background-color ease 0.5s; }
.components-panel__body .term-carousel-view-modes button label {
font-size: 0.75rem;
color: #555758; }
.components-panel__body .term-carousel-view-modes button.is-active {
border: 2px solid #298596; }
.components-panel__body .term-carousel-view-modes button.is-active.term-carousel-view-mode-thumbnail div, .components-panel__body .term-carousel-view-modes button.is-active.term-carousel-view-mode-grid div > div {
background-color: #298596; }
.components-panel__body .term-carousel-view-modes button:hover {
opacity: 0.9;
border-width: 2px; }
.components-panel__body .term-carousel-view-modes button:hover button {
background: #f2f2f2; }
.wp-block-tainacan-carousel-terms-list {
margin: 2rem 0px; }
.wp-block-tainacan-carousel-terms-list .spinner-container {
min-height: 56px;
padding: 1rem;
display: flex;
justify-content: center;
align-items: center;
color: #555758; }
@-webkit-keyframes skeleton-animation {
0% {
opacity: 1.0; }
50% {
opacity: 0.2; }
100% {
opacity: 1.0; } }
@-moz-keyframes skeleton-animation {
0% {
opacity: 1.0; }
50% {
opacity: 0.2; }
100% {
opacity: 1.0; } }
@-o-keyframes skeleton-animation {
0% {
opacity: 1.0; }
50% {
opacity: 0.2; }
100% {
opacity: 1.0; } }
@keyframes skeleton-animation {
0% {
opacity: 1.0; }
50% {
opacity: 0.2; }
100% {
opacity: 1.0; } }
.wp-block-tainacan-carousel-terms-list .skeleton {
border-radius: 2px;
background: #f2f2f2;
-webkit-animation: skeleton-animation 1.8s ease infinite;
-moz-animation: skeleton-animation 1.8s ease infinite;
-o-animation: skeleton-animation 1.8s ease infinite;
animation: skeleton-animation 1.8s ease infinite; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel {
position: relative;
width: calc(100% + 40px);
left: -20px; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container {
margin: 0 50px; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container a > span,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container a:hover > span {
color: black;
font-weight: bold;
text-decoration: none;
padding: 8px 16px;
display: block;
line-height: 1.2rem; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container a > img {
width: 100%;
height: auto; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container a:hover {
text-decoration: none; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container .swiper-slide.term-list-item-grid a {
width: 100%;
display: block; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container .swiper-slide.term-list-item-grid .term-items-grid {
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 50% 50%;
width: 100%; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container .swiper-slide.term-list-item-grid .term-items-grid img:first-of-type {
grid-column-start: 1;
grid-column-end: span 2;
grid-row-start: 1;
grid-row-end: span 2; }
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .swiper-container .swiper-slide.term-list-item-grid .term-items-grid img {
width: 100%;
height: auto;
padding: 2px;
margin-bottom: 0px; }
.wp-block-tainacan-carousel-terms-list .preview-warning {
width: 100%;
font-size: 0.875rem;
font-style: italic;
color: #898d8f;
text-align: center;
margin: 4px auto; }
.wp-block-tainacan-carousel-terms-list .swiper-button-prev, .wp-block-tainacan-carousel-terms-list .swiper-button-next {
top: calc(50% - 42px);
bottom: initial;
background: none;
border: none;
width: 42px;
height: 42px;
padding: 0;
margin: 0 -4px; }
.wp-block-tainacan-carousel-terms-list .swiper-button-prev svg, .wp-block-tainacan-carousel-terms-list .swiper-button-next svg {
fill: #298596; }
.wp-block-tainacan-carousel-terms-list .terms-list-edit-container,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel {
position: relative; }
.wp-block-tainacan-carousel-terms-list .terms-list-edit-container .skeleton,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel .skeleton {
min-height: 150px;
max-height: 150px; }
.wp-block-tainacan-carousel-terms-list .terms-list-edit-container.has-arrows-none .swiper-button-prev, .wp-block-tainacan-carousel-terms-list .terms-list-edit-container.has-arrows-none .swiper-button-next,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel.has-arrows-none .swiper-button-prev,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel.has-arrows-none .swiper-button-next {
display: none; }
.wp-block-tainacan-carousel-terms-list .terms-list-edit-container.has-arrows-left .swiper-button-next,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel.has-arrows-left .swiper-button-next {
left: 10px;
right: auto;
top: calc(50% + 12px) !important; }
.wp-block-tainacan-carousel-terms-list .terms-list-edit-container.has-arrows-right .swiper-button-prev,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel.has-arrows-right .swiper-button-prev {
right: 10px;
left: auto; }
.wp-block-tainacan-carousel-terms-list .terms-list-edit-container.has-arrows-right .swiper-button-next,
.wp-block-tainacan-carousel-terms-list .tainacan-carousel.has-arrows-right .swiper-button-next {
top: calc(50% + 12px) !important; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit {
display: flex;
align-items: flex-start;
overflow-x: scroll;
list-style: none;
margin: 0 36px; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item {
position: relative;
display: block;
margin: 16px 32px 16px 0px;
width: calc(16.666% - 32px);
min-width: calc(16.666% - 32px); }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item.term-list-item-grid {
margin: 16px;
width: calc(25% - 16px);
min-width: calc(25% - 16px); }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item a {
color: #454647;
font-weight: bold;
line-height: normal; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item img {
height: auto;
padding: 0px;
margin-bottom: 0.5rem; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item:hover a {
color: #454647;
text-decoration: none; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item button {
position: absolute !important;
background-color: rgba(255, 255, 255, 0.75);
color: #454647;
padding: 2px;
margin-left: 5px;
min-width: 14px;
visibility: hidden;
position: relative;
opacity: 0;
right: -14px;
top: 0px;
justify-content: center;
z-index: 999; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item:hover button {
visibility: visible;
background-color: white !important;
opacity: 1;
right: -8px;
top: -8px;
border: 1px solid #cbcbcb;
border-radius: 12px;
transition: opacity linear 0.15s, right linear 0.15s; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item:hover button:hover {
background-color: white !important;
border: 1px solid #cbcbcb !important; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item .term-items-grid {
display: grid;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 50% 50%; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item .term-items-grid img:first-of-type {
grid-column-start: 1;
grid-column-end: span 2;
grid-row-start: 1;
grid-row-end: span 2; }
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item .term-items-grid img {
padding: 2px;
margin-bottom: 0px; }
@media only screen and (max-width: 1686px) {
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item {
width: calc(20% - 32px);
min-width: calc(20% - 32px); } }
@media only screen and (max-width: 1452px) {
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item {
width: calc(25% - 32px);
min-width: calc(25% - 32px); } }
@media only screen and (max-width: 1118px) {
.wp-block-tainacan-carousel-terms-list ul.terms-edit li.term-list-item {
width: calc(33.333% - 32px);
min-width: calc(33.333% - 32px); } }
@media only screen and (max-width: 854px) {
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item {
width: calc(50% - 32px);
min-width: calc(50% - 32px); } }
@media only screen and (max-width: 584px) {
.wp-block-tainacan-carousel-terms-list ul.terms-list-edit li.term-list-item {
width: calc(100% - 32px);
min-width: calc(100% - 32px); } }
/*# sourceMappingURL=tainacan-gutenberg-block-carousel-terms-list.css.map */

File diff suppressed because one or more lines are too long

View File

@ -12,18 +12,10 @@ namespace Tainacan;
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'WP_Async_Request', false ) ) {
include_once TAINACAN_CLASSES_DIR . '/lib/wp-async-request.php';
}
if ( ! class_exists( 'WP_Background_Process', false ) ) {
include_once TAINACAN_CLASSES_DIR . '/lib/wp-background-process.php';
}
/**
* Tainacan_Background_Process class.
*/
abstract class Background_Process extends \WP_Background_Process {
abstract class Background_Process extends \Tainacan_WP_Background_Process {
/**
* Table name where the queue is stored

View File

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

View File

@ -8,9 +8,11 @@ use Tainacan\Entities;
* Class withe helpful methods to handle media in Tainacan
*/
class Private_Files {
private static $instance = null;
public $dir_separator;
public static function get_instance() {
if(!isset(self::$instance)) {
self::$instance = new self();
@ -18,26 +20,31 @@ class Private_Files {
return self::$instance;
}
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_sideload_prefilter', [$this, 'pre_upload']);
add_filter('wp_handle_upload', [$this, 'post_upload']);
add_action('tainacan-pre-insert-attachment', [$this, 'pre_tainacan_upload'], 10, 3);
add_action('tainacan-post-insert-attachment', [$this, 'post_tainacan_upload'], 10, 3);
add_action('template_redirect', [$this, 'template_redirect']);
add_filter('image_get_intermediate_size', [$this, 'image_get_intermediate_size'], 10, 3);
add_filter('wp_get_attachment_url', [$this, 'wp_get_attachment_url'], 10, 2);
add_action('tainacan-insert', [$this, 'update_item_and_collection'], 10, 3);
add_action('tainacan-insert', [$this, 'update_item_and_collection']);
add_action('tainacan-bulk-edit-set-status', [$this, 'bulk_edit'], 10, 4);
}
function pre_tainacan_upload($blob, $filename, $post_id) {
if (is_numeric($post_id)) {
global $TAINACAN_UPLOADING_ATTACHMENT_TO_POST;
@ -45,33 +52,33 @@ class Private_Files {
add_filter('upload_dir', [$this, 'change_upload_dir']);
}
}
function post_tainacan_upload($attach_id, $attach_data, $post_id) {
remove_filter('upload_dir', [$this, 'change_upload_dir']);
}
/**
* Adds a filter to the upload_dir hook when uploading a new file
*
* Adds a filter to the upload_dir hook when uploading a new file
*
*/
function pre_upload($file){
add_filter('upload_dir', [$this, 'change_upload_dir']);
return $file;
}
/**
* Removes a filter to the upload_dir hook after uploading a new file
*
* Removes a filter to the upload_dir hook after uploading a new file
*
*/
function post_upload($fileinfo){
remove_filter('upload_dir', [$this, 'change_upload_dir']);
return $fileinfo;
}
/**
* Gets the base directory inside the uploads folder where
* attachments and documents for items will be uploaded
*
* Gets the base directory inside the uploads folder where
* attachments and documents for items will be uploaded
*
* @return string The folder name
*/
function get_items_uploads_folder() {
@ -80,11 +87,11 @@ class Private_Files {
}
return 'tainacan-items';
}
/**
* Gets the directory prefix to be added to folders holding
* attachments and documents for private items or collections
*
* attachments and documents for private items or collections
*
* @return string The folder prefix
*/
function get_private_folder_prefix() {
@ -93,140 +100,140 @@ class Private_Files {
}
return '_x_';
}
/**
* Change the upload directory for items attachments and documents
* Change the upload directory for items attachments and documents
*
* It replaces the default WordPress strucutre, which is YYYY/MM/file
* with a path containing the collection id and the item id inside the @see get_items_uploads_folder():
* It replaces the default WordPress strucutre, which is YYYY/MM/file
* with a path containing the collection id and the item id inside the @see get_items_uploads_folder():
* ex: * tainacan-items/$collection_id/$item_id
*
* It also add a prefix in the folder name of private items or collections:
* It also add a prefix in the folder name of private items or collections:
* tainacan-items/$collection_id/_x_$item_id ($item_id is a private item)
*
*
*/
function change_upload_dir($path) {
$post_id = false;
// regular ajax uploads via Admin Panel will send post_id
if ( isset($_REQUEST['post_id']) && $_REQUEST['post_id'] ) {
$post_id = $_REQUEST['post_id'];
}
// API requests to media endpoint will send post
if ( false === $post_id && isset($_REQUEST['post']) && is_numeric($_REQUEST['post']) ) {
$post_id = $_REQUEST['post'];
}
// tainacan internals, scripts and tests, will set this global
// tainacan internals, scripts and tests, will set this global
if (false === $post_id) {
global $TAINACAN_UPLOADING_ATTACHMENT_TO_POST;
if ( isset($TAINACAN_UPLOADING_ATTACHMENT_TO_POST) && is_numeric($TAINACAN_UPLOADING_ATTACHMENT_TO_POST) ) {
$post_id = $TAINACAN_UPLOADING_ATTACHMENT_TO_POST;
}
}
if (false === $post_id) {
return $path;
}
$theme_helper = \Tainacan\Theme_Helper::get_instance();
$post = get_post($post_id);
if ( !$theme_helper->is_post_an_item($post) ) {
return $path;
}
$item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $post_id );
if ($item instanceof \Tainacan\Entities\Item) {
$tainacan_basepath = $this->get_items_uploads_folder();
$col_id_url = $item->get_collection_id();
$col_id = $item->get_collection_id();
$item_id_url = $item->get_id();
$item_id = $item->get_id();
$col_status = get_post_status_object($item->get_collection()->get_status());
$item_status = get_post_status_object($item->get_status());
if ( ! $col_status->public ) {
$col_id = $this->get_private_folder_prefix() . $col_id;
}
if ( ! $item_status->public ) {
$item_id = $this->get_private_folder_prefix() . $item_id;
}
$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['path'] .= DIRECTORY_SEPARATOR . $tainacan_basepath . DIRECTORY_SEPARATOR . $col_id . '/' . $item_id;
$path['subdir'] = DIRECTORY_SEPARATOR . $tainacan_basepath . DIRECTORY_SEPARATOR . $col_id . '/' . $item_id;
$path['url'] = str_replace($path['subdir'], '/' . $tainacan_basepath . '/' . $col_id_url . '/' . $item_id_url, $path['url']);
$path['path'] .= $this->dir_separator . $tainacan_basepath . $this->dir_separator . $col_id . $this->dir_separator . $item_id;
$path['subdir'] = $this->dir_separator . $tainacan_basepath . $this->dir_separator . $col_id . $this->dir_separator . $item_id;
}
return $path;
}
/**
* Handles 404 returns looking for attachments inside the tainacan items uploads folder
* Handles 404 returns looking for attachments inside the tainacan items uploads folder
*
* When looking for a file that does not exists, it checks for relative prefixed folders.
* When looking for a file that does not exists, it checks for relative prefixed folders.
* If it finds the file, it then checks to see if current user have permission to see this file, based on
* the permission he/she have to read the related item.
*
*
*/
function template_redirect() {
if (is_404()) {
$upload_dir = wp_get_upload_dir();
$base_upload_url = preg_replace('/^https?:\/\//', '', $upload_dir['baseurl']);
$requested_uri = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ( strpos($requested_uri, $base_upload_url) === false ) {
// Not uploads
// Not uploads
return;
}
$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;
$existing_file = false;
$file_dirs = explode(DIRECTORY_SEPARATOR, $file);
$file_dirs = explode($this->dir_separator, $file);
$file_dirs_size = sizeof($file_dirs);
$item_id = $file_dirs[$file_dirs_size-2];
$collection_id = $file_dirs[$file_dirs_size-3];
// private item
$prefixed_file = str_replace( DIRECTORY_SEPARATOR . $item_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $item_id . DIRECTORY_SEPARATOR, $file);
// private item
$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 ) ) {
$existing_file = $prefixed_file;
}
// private collection
$prefixed_collection = str_replace( DIRECTORY_SEPARATOR . $collection_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $collection_id . DIRECTORY_SEPARATOR, $file);
// private collection
$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 ) ) {
$existing_file = $prefixed_collection;
}
// 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);
// private both
$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 ) ) {
$existing_file = $prefixed_both;
}
if ($existing_file) {
$item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $item_id, (int) $collection_id );
$mime_type = \Tainacan\Media::get_instance()->get_mime_content_type($existing_file);
if ($item instanceof \Tainacan\Entities\Item && $item->can_read()) {
//header('Content-Description: File Transfer');
//header('Content-Type: application/octet-stream');
@ -237,141 +244,137 @@ class Private_Files {
// header('Pragma: public');
// header('Content-Length: ' . filesize($file));
\readfile($existing_file);
die;
}
}
}
}
/**
* Filters the image_get_intermediate_size hook to strip out the
* Filters the image_get_intermediate_size hook to strip out the
* private uploads folder prefix from the attachments URLs
*/
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']);
return $data;
}
/**
* Filters the wp_get_attachment_url hook to strip out the
* Filters the wp_get_attachment_url hook to strip out the
* private uploads folder prefix from the attachments URLs
*/
function wp_get_attachment_url($url, $post_id) {
$url = str_replace('/' . $this->get_private_folder_prefix(), '/', $url);
return $url;
}
/**
* When an item or collection is saved, it checks if the satus was changed and
* if the items upload directory mus be renamed to add or remove the
* private folder prefix
* When an item or collection is saved, it checks if the satus was changed and
* if the items upload directory mus be renamed to add or remove the
* private folder prefix
*/
function update_item_and_collection($obj, $diffs, $is_update) {
// updating collection or item
if ( $is_update ) {
$folder = DIRECTORY_SEPARATOR;
$check_folder = DIRECTORY_SEPARATOR;
$check = false;
if ( $obj instanceof \Tainacan\Entities\Collection ) {
$status_obj = get_post_status_object($obj->get_status());
$folder .= $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check_folder .= ! $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check = true;
}
if ( $obj instanceof \Tainacan\Entities\Item ) {
$collection = $obj->get_collection();
$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;
$check_folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . DIRECTORY_SEPARATOR;
$folder .= DIRECTORY_SEPARATOR;
$check_folder .= DIRECTORY_SEPARATOR;
$status_obj = get_post_status_object($obj->get_status());
$folder .= $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check_folder .= ! $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check = true;
}
if ($check) {
$upload_dir = wp_get_upload_dir();
$base_dir = $upload_dir['basedir'];
$full_path = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . $folder;
$full_path_check = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . $check_folder;
if (\file_exists($full_path_check)) {
rename($full_path_check, $full_path);
do_action('tainacan-upload-folder-renamed', $full_path_check, $full_path);
}
}
function update_item_and_collection($obj) {
$folder = $this->dir_separator;
$check_folder = $this->dir_separator;
$check = false;
if ( $obj instanceof \Tainacan\Entities\Collection ) {
$status_obj = get_post_status_object($obj->get_status());
$folder .= $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check_folder .= ! $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check = true;
}
if ( $obj instanceof \Tainacan\Entities\Item ) {
$collection = $obj->get_collection();
$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() . $this->dir_separator;
$check_folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . $this->dir_separator;
$folder .= $this->dir_separator;
$check_folder .= $this->dir_separator;
$status_obj = get_post_status_object($obj->get_status());
$folder .= $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check_folder .= ! $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check = true;
}
if ($check) {
$upload_dir = wp_get_upload_dir();
$base_dir = $upload_dir['basedir'];
$full_path = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $folder;
$full_path_check = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $check_folder;
if (\file_exists($full_path_check)) {
rename($full_path_check, $full_path);
do_action('tainacan-upload-folder-renamed', $full_path_check, $full_path);
}
}
}
/**
* Rename all folders from items after a bulk edit operation move their statuses
* Rename all folders from items after a bulk edit operation move their statuses
*
* TODO: In the upcoming bulk edit refactor this must be handled as there are performance issues
*
*
*/
function bulk_edit($status, $group, $select_query, $query) {
global $wpdb;
$ids = $wpdb->get_col($select_query);
$status_obj = get_post_status_object($status);
$prefix = $status_obj->public ? $this->get_private_folder_prefix() : '';
$upload_dir = wp_get_upload_dir();
$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) {
$folder = $full_path . $id;
$found = glob($folder);
if (sizeof($found) == 1 && isset($found[0])) {
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 {
$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);
do_action('tainacan-upload-folder-renamed', $found[0], $target);
}
if (\file_exists($folder)) {
}
}
}
}
}

View File

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

View File

@ -152,7 +152,7 @@ class Filter extends Entity {
}
$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;
}
@ -171,6 +171,10 @@ class Filter extends Entity {
* @return array Configurations for the filter type object
*/
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');
}
@ -275,6 +279,21 @@ class Filter extends Entity {
if (false === $is_valid)
return false;
$status = $this->get_status();
$status_obj = get_post_status_object($status);
if ($status_obj->public) {
$metadatum = $this->get_metadatum();
if ($metadatum) {
$metadatum_status_obj = get_post_status_object($metadatum->get_status());
if ( ! $metadatum_status_obj->public ) {
$this->add_error('status', __('Filter can not be public because the related metadatum is private', 'tainacan'));
return false;
}
}
}
$fto = $this->get_filter_type_object();
if (is_object($fto)) {
$is_valid = $fto->validate_options( $this );

View File

@ -444,25 +444,29 @@ class Item_Metadata_Entity extends Entity {
}
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;
}
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;
}
$this->set_as_valid();
return true;
} 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;
}
} else {
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;
}
@ -476,11 +480,12 @@ class Item_Metadata_Entity extends Entity {
'value' => $value
],
],
'post__not_in' => [$item->get_id()]
'post__not_in' => [$item->get_id()]
], $item->get_collection());
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;
}
}

View File

@ -93,10 +93,10 @@ class Item extends Entity {
}
$attachments_query = [
'post_type' => 'attachment',
'post_per_page' => -1,
'post_parent' => $item_id,
'exclude' => $to_exclude,
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $item_id,
'exclude' => $to_exclude,
];
$attachments = get_posts( $attachments_query );

View File

@ -12,14 +12,17 @@ class Log extends Entity {
protected
$title,
$order,
$parent,
$description,
$blog_id,
$user_id,
$log_date,
$date,
$user_name,
$collection_id,
$item_id;
$item_id,
$object_type,
$object_id,
$old_value,
$new_value;
static $post_type = 'tainacan-log';
/**
@ -34,7 +37,6 @@ class Log extends Entity {
if ( is_int( $which ) && $which == 0 ) {
$this->set_user_id();
$this->set_blog_id();
}
}
@ -89,27 +91,19 @@ class Log extends Entity {
*
* @return mixed|null
*/
function get_log_date() {
return $this->get_mapped_property( 'log_date' );
function get_date() {
return $this->get_mapped_property( 'date' );
}
/**
* Return the log order type
* Return the log slug
*
* @return string
* @return mixed|null
*/
function get_order() {
return $this->get_mapped_property( 'order' );
function get_slug() {
return $this->get_mapped_property( 'slug' );
}
/**
* Retun the parent ID
*
* @return integer
*/
function get_parent() {
return $this->get_mapped_property( 'parent' );
}
/**
* Return the Log description
@ -120,15 +114,6 @@ class Log extends Entity {
return $this->get_mapped_property( 'description' );
}
/**
* Return the ID of blog
*
* @return integer
*/
function get_blog_id() {
return $this->get_mapped_property( 'blog_id' );
}
/**
* Return User Id of who make the action
*
@ -138,27 +123,28 @@ class Log extends Entity {
return $this->get_mapped_property( 'user_id' );
}
/**
* Get value of log entry
* Get old value of log entry object
*
* @param mixed $value
*
* @return void
*/
public function get_value() {
return maybe_unserialize( base64_decode( $this->get_mapped_property( 'value' ) ) );
public function get_old_value() {
return $this->get_mapped_property( 'old_value' );
}
// /**
// * Get old value of log entry object
// *
// * @param mixed $value
// *
// * @return void
// */
// public function get_old_value() {
// return maybe_unserialize( base64_decode( $this->get_mapped_property( 'old_value' ) ) );
// }
/**
* Get new value of log entry object
*
* @param mixed $value
*
* @return void
*/
public function get_new_value() {
return $this->get_mapped_property( 'new_value' );
}
/**
* Set log tittle
@ -167,30 +153,8 @@ class Log extends Entity {
*
* @return void
*/
function set_title( $value ) {
$this->set_mapped_property( 'title', $value );
}
/**
* Define the order type
*
* @param [string] $value
*
* @return void
*/
function set_order( $value ) {
$this->set_mapped_property( 'order', $value );
}
/**
* Define the parent ID
*
* @param [integer] $value
*
* @return void
*/
function set_parent( $value ) {
$this->set_mapped_property( 'parent', $value );
public function set_title( $value ) {
$this->set_mapped_property( 'title', apply_filters('tainacan-log-set-title', $value) );
}
/**
@ -200,7 +164,7 @@ class Log extends Entity {
*
* @return void
*/
function set_description( $value ) {
public function set_description( $value ) {
$this->set_mapped_property( 'description', $value );
}
@ -211,7 +175,7 @@ class Log extends Entity {
*
* @return void
*/
protected function set_user_id( $value = 0 ) {
public function set_user_id( $value = 0 ) {
if ( 0 == $value ) {
$value = get_current_user_id();
}
@ -219,46 +183,25 @@ class Log extends Entity {
}
/**
* Define the blog ID of log entry
*
* @param [integer] $value
*
* @return void
*/
protected function set_blog_id( $value = 0 ) {
if ( 0 == $value ) {
$value = get_current_blog_id();
}
$this->set_mapped_property( 'blog_id', $value );
}
/**
* Define the value of log entry
* Set old value of log entry
*
* @param [mixed] $value
*
* @return void
*/
protected function set_value( $value = null ) {
$this->set_mapped_property( 'value', base64_encode( maybe_serialize( $value ) ) );
public function set_old_value( $value ) {
$this->set_mapped_property( 'old_value', $value );
}
// /**
// * Set old value of log entry
// *
// * @param [mixed] $value
// *
// * @return void
// */
// protected function set_old_value( $value = null ) {
// $this->set_mapped_property( 'old_value', base64_encode( maybe_serialize( $value ) ) );
// }
/**
* @param $diffs
* Set new value of log entry
*
* @param [mixed] $value
*
* @return void
*/
public function set_log_diffs($diffs){
$this->set_mapped_property( 'log_diffs', $diffs );
public function set_new_value( $value ) {
$this->set_mapped_property( 'new_value', $value );
}
/**
@ -268,55 +211,20 @@ class Log extends Entity {
return $this->get_mapped_property('log_diffs');
}
/**
*
* @param bool $message
* @param string $desc
* @param null $value
* @param array $diffs
* @param string $status 'publish', 'private', 'pending', 'processing' or 'error'
* @param int $parent
*
* @return \Tainacan\Entities\Log | bool
* @throws \Exception
*/
public static function create( $message = false, $desc = '', $value = null, $diffs = [], $status = 'publish', $parent = 0 ) {
public function get_object_type() {
return $this->get_mapped_property('object_type');
}
$log = new Log();
public function set_object_type($value) {
$this->set_mapped_property('object_type', $value);
}
$log->set_title( $message );
$log->set_description( $desc );
$log->set_status( $status );
$log->set_log_diffs( $diffs );
public function get_object_id() {
return $this->get_mapped_property('object_id');
}
if($parent > 0) {
$log->set_parent($parent);
}
if(is_object($value) || is_string($value)) {
if(array_search( 'Tainacan\Traits\Entity_Collection_Relation', class_uses($value))) {
$log->set_collection_id( $value->get_collection_id() );
} elseif($value instanceof Collection){
$log->set_collection_id( $value->get_id());
} elseif($value instanceof Item_Metadata_Entity){
$log->set_item_id($value->get_item()->get_id());
$log->set_collection_id($value->get_item()->get_collection_id());
}
}
if ( ! is_null( $value ) ) {
$log->set_value( $value );
} elseif ( $message === false ) {
throw new \Exception( 'Message or value is needed to log' );
}
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
if ( $log->validate() ) {
return $Tainacan_Logs->insert( $log );
} else {
throw new \Exception( 'Invalid log' );
}
public function set_object_id($value) {
$this->set_mapped_property('object_id', $value);
}
/**
@ -333,6 +241,14 @@ class Log extends Entity {
return $this->get_mapped_property('item_id');
}
public function get_action() {
return $this->get_mapped_property('action');
}
public function set_action($value) {
$this->set_mapped_property('action', $value);
}
/**
* {@inheritDoc}
* @see \Tainacan\Repositories\Logs::approve
@ -342,4 +258,4 @@ class Log extends Entity {
return $repository->approve( $this );
}
}
}

View File

@ -178,7 +178,7 @@ class Metadatum extends Entity {
}
$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;
}
@ -197,7 +197,11 @@ class Metadatum extends Entity {
* @return array Configurations for the metadatum type object
*/
function get_metadata_type_options(){
return $this->get_mapped_property('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');
}
/**

View File

@ -22,28 +22,28 @@ class Taxonomy extends Entity {
* @var string
*/
static $post_type = 'tainacan-taxonomy';
/**
* {@inheritDoc}
* @see \Tainacan\Entities\Entity::capability_type
* @var string
*/
protected static $capability_type = ['tainacan-taxonomy', 'tainacan-taxonomies'];
/**
* {@inheritDoc}
* @see \Tainacan\Entities\Entity::repository
* @var string
*/
protected $repository = 'Taxonomies';
/**
* Prefix used to create the db_identifier
*
* @var string
*/
static $db_identifier_prefix = 'tnc_tax_';
public function __toString(){
return apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this);
}
@ -67,7 +67,7 @@ class Taxonomy extends Entity {
'new_item_name' => __( 'New Genre term', 'tainacan' ),
'menu_name' => $this->get_name(),
);
$enabled_post_types = $this->get_enabled_post_types();
$enabled_post_types = sizeof($enabled_post_types) ? $enabled_post_types : null;
$show_ui = is_array($enabled_post_types) ? true : false;
@ -80,21 +80,22 @@ class Taxonomy extends Entity {
'show_admin_column' => false,
'rewrite' => [
'slug' => $this->get_slug()
],
],
'update_count_callback' => '_update_generic_term_count'
);
if (taxonomy_exists($this->get_db_identifier())){
unregister_taxonomy($this->get_db_identifier());
}
register_taxonomy(
$this->get_db_identifier(),
$enabled_post_types,
$args
register_taxonomy(
$this->get_db_identifier(),
$enabled_post_types,
$args
);
return true;
}
@ -135,7 +136,7 @@ class Taxonomy extends Entity {
function get_slug() {
return $this->get_mapped_property('slug');
}
/**
* Return the enabled post types
*
@ -144,7 +145,7 @@ class Taxonomy extends Entity {
function get_enabled_post_types() {
return $this->get_mapped_property('enabled_post_types');
}
// special Getters
/**
@ -194,7 +195,7 @@ class Taxonomy extends Entity {
function set_allow_insert($value) {
$this->set_mapped_property('allow_insert', $value);
}
/**
* Sets enabled post types
*
@ -221,19 +222,19 @@ class Taxonomy extends Entity {
return parent::validate();
}
/**
* Check if a term already exists
* Check if a term already exists
*
* @param string $term_name The term name
* @param int|null $parent The ID of the parent term to look for children or null to look for terms in any hierarchical position. Default is null
* @param bool $return_term wether to return the term object if it exists. default is to false
*
* @return bool|WP_Term return boolean indicating if term exists. If $return_term is true and term exists, return WP_Term object
* @param string $term_name The term name
* @param int|null $parent The ID of the parent term to look for children or null to look for terms in any hierarchical position. Default is null
* @param bool $return_term wether to return the term object if it exists. default is to false
*
* @return bool|WP_Term return boolean indicating if term exists. If $return_term is true and term exists, return WP_Term object
*/
function term_exists($term_name, $parent = null, $return_term = false) {
$repo = $this->get_repository();
return $repo->term_exists($this, $term_name, $parent, $return_term);
}
}
}

View File

@ -145,6 +145,16 @@ class Term extends Entity {
return wp_get_attachment_url( $this->get_header_image_id() );
}
/**
* @return false|string
*/
function get_url(){
$url = get_term_link( $this->get_id() );
if (is_wp_error($url))
return "";
return $url;
}
// Setters
/**

View File

@ -3,15 +3,15 @@
<b-autocomplete
icon="magnify"
size="is-small"
:aria-labelledby="labelId"
:aria-labelledby="'filter-label-id-' + filter.id"
v-model="selected"
:data="options"
expanded
:loading="isLoadingOptions"
@input="search"
field="label"
@select="option => setResults(option) "
:placeholder="(type == 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_search_items') : $i18n.get('info_type_to_search_metadata')">
@select="onSelect"
:placeholder="(metadatumType === 'Tainacan\\Metadata_Types\\Relationship') ? $i18n.get('info_type_to_search_items') : $i18n.get('info_type_to_search_metadata')">
<template slot-scope="props">
<div class="media">
<div
@ -41,83 +41,54 @@
<script>
import { tainacan as axios, isCancel } from '../../../js/axios/axios'
import { filter_type_mixin } from '../filter-types-mixin'
// import qs from 'qs';
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
export default {
created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
const vm = this;
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/metadata/'+ this.metadatum;
}
axios.get(in_route)
.then( res => {
let result = res.data;
if( result && result.metadata_type ){
vm.metadatum_object = result;
vm.type = result.metadata_type;
vm.selectedValues();
}
})
.catch(error => {
this.$console.log(error);
});
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
data(){
return {
results:'',
selected:'',
options: [],
type: '',
collection: '',
metadatum: '',
metadatum_object: {},
label: ''
}
},
props: {
isRepositoryLevel: Boolean,
labelId: String
watch: {
'query.metaquery'() {
this.updateSelectedValues();
},
},
mounted() {
this.updateSelectedValues();
},
mixins: [filter_type_mixin],
methods: {
setResults(option){
onSelect(option){
if(!option)
return;
this.results = option.value;
this.selected = option.value;
this.label = option.label;
this.onSelect()
},
onSelect(){
this.$emit('input', {
filter: 'autocomplete',
metadatum_id: this.metadatum,
collection_id: this.collection,
value: this.results
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: this.selected
});
this.selectedValues();
this.updateSelectedValues();
},
search: _.debounce( function(query) {
if (query != '') {
let promise = null;
this.options = [];
// Cancels previous Request
if (this.getOptionsValuesCancel != undefined)
this.getOptionsValuesCancel.cancel('Facet search Canceled.');
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' )
if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' )
promise = this.getValuesRelationship( query, this.isRepositoryLevel );
else
promise = this.getValuesPlainText( this.metadatum, query, this.isRepositoryLevel );
promise = this.getValuesPlainText( this.metadatumId, query, this.isRepositoryLevel );
promise.request.catch( error => {
if (isCancel(error))
@ -130,71 +101,51 @@
this.getOptionsValuesCancel = promise.source;
} else {
this.cleanSearch();
this.label = '';
this.selected = '';
this.$emit('input', {
filter: 'autocomplete',
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: this.selected
});
}
}, 500),
selectedValues(){
const instance = this;
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
updateSelectedValues(){
if (!this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ))
return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
if ( index >= 0){
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId);
if (index >= 0) {
let metadata = this.query.metaquery[ index ];
// let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
// this.metadatum_object.metadata_type_options.collection_id : this.collection_id;
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' ) {
// let query = qs.stringify({ postin: metadata.value });
axios.get('/items/' + metadata.value)
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') {
let endpoint = '/items/' + metadata.value + '?fetch_only=title,thumbnail';
axios.get(endpoint)
.then( res => {
let item = res.data;
instance.results = item.title;
instance.label = item.title;
instance.selected = item.title;
this.label = item.title;
this.selected = item.title;
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: instance.filter.id,
value: instance.label
});
this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected });
})
.catch(error => {
this.$console.log(error);
});
} else {
instance.results = metadata.value;
instance.label = metadata.value;
instance.selected = metadata.value;
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: instance.filter.id,
value: metadata.value
});
this.label = metadata.value;
this.selected = metadata.value;
this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected });
}
} else {
return false;
this.label = '';
this.selected = '';
}
},
cleanSearchFromTags(filterTag) {
if (filterTag.filterId == this.filter.id)
this.cleanSearch();
},
cleanSearch(){
this.results = '';
this.label = '';
this.selected = '';
this.$emit('input', {
filter: 'autocomplete',
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: ''
});
},
},
beforeDestroy() {
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
}
</script>

View File

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

View File

@ -3,12 +3,6 @@
:style="{ 'height': isLoadingOptions ? (Number(filter.max_options)*28) + 'px' : 'auto' }"
:class="{ 'skeleton': isLoadingOptions }"
class="block">
<!-- <span
v-if="isLoadingOptions"
style="width: 100%; position: absolute;"
class="icon has-text-centered loading-icon">
<div class="control has-icons-right is-loading is-clearfix" />
</span> -->
<div
v-for="(option, index) in options.slice(0, filter.max_options)"
v-if="!isLoadingOptions"
@ -29,15 +23,6 @@
class="has-text-gray">&nbsp;{{ "(" + option.total_items + ")" }}</span>
</span>
</label>
<!-- <b-checkbox
v-if="index <= filter.max_options - 1"
v-model="selected"
:native-value="option.value">
<span class="checkbox-label-text">{{ option.label }}</span>
<span
v-if="option.total_items != undefined"
class="has-text-gray">{{ "(" + option.total_items + ")" }}</span>
</b-checkbox> -->
<button
class="view-all-button link-style"
v-if="option.showViewAllButton && index == options.slice(0, filter.max_options).length - 1"
@ -54,96 +39,61 @@
</template>
<script>
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
import { filter_type_mixin } from '../filter-types-mixin';
import { isCancel } from '../../../js/axios/axios';
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
export default {
created(){
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
let route = '/collection/' + this.collection + '/metadata/' + this.metadatum +'?nopaging=1';
if (this.isRepositoryLevel || this.collection == 'filter_in_repository')
route = '/metadata?nopaging=1';
axios.get(route)
.then( res => {
let result = res.data;
if ( result && result.metadata_type ){
this.metadatum_object = result;
this.type = result.metadata_type;
if (!this.isUsingElasticSearch)
this.loadOptions();
}
})
.catch(error => {
this.$console.log(error);
});
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
if (this.isUsingElasticSearch) {
this.isLoadingOptions = false;
this.$eventBusSearch.$on('isLoadingItems', this.updatesIsLoading);
}
},
props: {
isRepositoryLevel: Boolean,
},
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
data(){
return {
options: [],
type: '',
collection: '',
metadatum: '',
selected: [],
metadatum_object: {}
selected: []
}
},
mixins: [filter_type_mixin],
watch: {
selected: function(){
//this.selected = val;
this.onSelect();
selected(newVal, oldVal) {
const isEqual = (newVal.length == oldVal.length) && newVal.every((element, index) => {
return element === oldVal[index];
});
if (!isEqual)
this.onSelect();
},
'query.metaquery'() {
if (!this.isUsingElasticSearch)
this.loadOptions();
}
},
mounted() {
if (!this.isUsingElasticSearch)
this.loadOptions();
},
methods: {
loadOptions(skipSelected) {
loadOptions() {
let promise = null;
// Cancels previous Request
if (this.getOptionsValuesCancel != undefined)
this.getOptionsValuesCancel.cancel('Facet search Canceled.');
if ( this.type === 'Tainacan\\Metadata_Types\\Relationship' )
if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' )
promise = this.getValuesRelationship( null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1');
else
promise = this.getValuesPlainText( this.metadatum, 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' );
promise.request
.then(() => {
this.updateSelectedValues();
})
.catch( (error) => {
if (isCancel(error)) {
this.$console.log('Request canceled: ' + error.message);
this.updateSelectedValues();
} else
this.$console.error( error );
});
if (skipSelected != undefined && skipSelected == true) {
promise.request
.then(() => {
if (this.options.length > this.filter.max_options)
this.options.splice(this.filter.max_options);
}).catch((error) => {
this.$console.error(error);
});
} else {
promise.request
.then(() => {
this.selectedValues();
})
.catch( (error) => {
if (isCancel(error)) {
this.$console.log('Request canceled: ' + error.message);
}else
this.$console.error( error );
});
}
// Search Request Token for cancelling
this.getOptionsValuesCancel = promise.source;
},
@ -151,41 +101,36 @@
this.$emit('input', {
filter: 'checkbox',
compare: 'IN',
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: this.selected
});
},
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 query = this.query.metaquery.slice();
this.selected = query[ index ].value;
} else {
this.selected = [];
}
let onlyLabels = [];
if(!isNaN(this.selected[0])){
if (!isNaN(this.selected[0])){
for (let aSelected of this.selected) {
let valueIndex = this.options.findIndex(option => option.value == aSelected);
if (valueIndex >= 0) {
onlyLabels.push(this.options[valueIndex].label);
}
}
}
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: this.filter.id,
value: onlyLabels.length ? onlyLabels : this.selected,
});
},
selectedValues() {
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
if ( index >= 0){
let query = this.query.metaquery.slice();
this.selected = query[ index ].value;
} else {
this.selected = [];
return false;
}
this.$emit( 'sendValuesToTags', { label: onlyLabels.length ? onlyLabels : this.selected, value: this.selected });
},
openCheckboxModal() {
this.$buefy.modal.open({
@ -196,11 +141,10 @@
filter: this.filter,
//taxonomy_id: this.taxonomy_id,
selected: this.selected,
metadatum_id: this.metadatum,
metadatumId: this.metadatumId,
//taxonomy: this.taxonomy,
collection_id: this.collection,
metadatum_type: this.type,
metadatum_object: this.metadatum_object,
collectionId: this.collectionId,
metadatum_type: this.metadatumType,
isRepositoryLevel: this.isRepositoryLevel,
query: this.query
},
@ -208,50 +152,13 @@
appliedCheckBoxModal: () => {
this.loadOptions();
}
}
},
trapFocus: true
});
},
cleanSearchFromTags(filterTag) {
if (filterTag.filterId == this.filter.id) {
let selectedIndex = this.selected.findIndex(option => option == filterTag.singleValue);
let optionIndex = this.options.findIndex(option => option.label == filterTag.singleValue);
let alternativeIndex;
if (optionIndex >= 0) {
alternativeIndex = this.selected.findIndex(option => this.options[optionIndex].value == option);
}
if (selectedIndex >= 0 || alternativeIndex >= 0) {
selectedIndex >= 0 ? this.selected.splice(selectedIndex, 1) : this.selected.splice(alternativeIndex, 1);
this.$emit('input', {
filter: 'checkbox',
compare: 'IN',
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: this.selected
});
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: this.filter.id,
value: this.selected
});
this.selectedValues();
}
}
},
updatesIsLoading(isLoading) {
this.isLoadingOptions = isLoading;
updatesIsLoading(isLoadingOptions) {
this.isLoadingOptions = isLoadingOptions;
}
},
beforeDestroy() {
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
if (this.isUsingElasticSearch)
this.$eventBusSearch.$off('isLoadingItems', this.updatesIsLoading);
}
}
</script>

View File

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

View File

@ -1,330 +0,0 @@
<template>
<div>
<!-- Date -->
<div v-if="type === 'date'">
<b-datepicker
:aria-labelledby="labelId"
: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="labelId"
: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-numberinput
:aria-labelledby="labelId"
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-numberinput
:aria-labelledby="labelId"
size="is-small"
step="any"
@input="validate_values()"
@focus="isTouched = true"
v-model="value_end"/>
</div>
</div>
</template>
<script>
import { tainacan as axios } from '../../../js/axios/axios';
import { wpAjax, dateInter } from "../../../admin/js/mixins";
import moment from 'moment';
export default {
mixins: [ wpAjax, dateInter ],
created() {
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : this.filter.metadatum.metadatum_id;
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
if(this.isRepositoryLevel || this.collection == 'filter_in_repository'){
in_route = '/metadata/'+ this.metadatum;
}
axios.get(in_route)
.then( res => {
let result = res.data;
if( result && result.metadata_type ){
this.metadatum_object = result;
this.type = ( result.metadata_type === 'Tainacan\\Metadata_Types\\Date') ? 'date' : 'numeric';
this.selectedValues();
}
})
.catch(error => {
this.$console.log(error);
});
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
data(){
return {
value_init: null,
value_end: null,
date_init: undefined,
date_end: undefined,
isTouched: false,
isValid: false,
clear: false,
type: 'numeric',
collection: '',
metadatum: '',
metadatum_object: {}
}
},
props: {
filter: {
type: Object // concentrate all attributes metadatum id and type
},
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
labelId: '',
query: Object,
isRepositoryLevel: Boolean,
},
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();
this.isTouched = val;
}
},
methods: {
// only validate if the first value is higher than first
validate_values: _.debounce( function (){
if( this.type === '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 ) {
let result = this.date_init;
result.setDate(result.getDate() + 1);
this.date_end = result;
result.setDate(result.getDate() - 1);
this.date_init = result;
//this.error_message();
}
} else {
if ( parseFloat( this.value_init ) > parseFloat( this.value_end )) {
//this.value_end = parseFloat( this.value_init ) + 1;
//this.error_message();
return;
}
}
this.emit();
}, 1000),
// 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.metadatum );
if ( index >= 0){
let metadata = this.query.metaquery[ index ];
if( metadata.value && metadata.value.length > 0 && this.type === 'numeric'){
this.value_init = metadata.value[0];
this.value_end = 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.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: this.filter.id,
value: this.parseDateToNavigatorLanguage(metadata.value[0]) + ' - ' + this.parseDateToNavigatorLanguage(metadata.value[1])
});
}
} else {
return false;
}
},
showSearch(){
if( this.type === 'date' ){
if( this.date_init === null || this.date_end === null ){
this.clear = true;
return '';
}
return this.date_init.toLocaleString().split(' ')[0] + ' - ' + this.date_end.toLocaleString().split(' ')[0];
}
// else {
// return this.value_init + ' - ' +this.value_end;
// }
},
cleanSearchFromTags(filterTag) {
if (filterTag.filterId == this.filter.id)
this.clearSearch();
},
clearSearch(){
this.clear = true;
this.$emit('input', {
filter: 'range',
compare: 'BETWEEN',
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: ''
});
if( this.type === 'date' ){
this.date_init = null;
this.date_end = null;
this.isTouched = false;
} else {
this.value_end = null;
this.value_init = null;
this.isTouched = false;
}
},
// emit the operation for listeners
emit() {
let values = [];
let type = '';
if( this.type === 'date' ){
if( this.date_init === null && this.date_end === null ){
values = [];
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 ];
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)) {
type = 'DECIMAL';
} else if(this.value_init !== this.value_end &&
this.value_init % 1 !== 0 &&
this.value_end % 1 !== 0) {
type = '';
} else if(this.value_init !== this.value_end &&
!(this.value_init % 1 == 0 && this.value_end % 1 !== 0)){
type = 'DECIMAL';
} else {
type = '';
}
//this.isValid = true;
//this.clear = false;
}
}
this.$emit('input', {
filter: 'range',
type: type,
compare: 'BETWEEN',
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: values
});
if (values[0] != undefined && values[1] != undefined) {
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: this.filter.id,
value: this.parseDateToNavigatorLanguage(values[0]) + ' - ' + this.parseDateToNavigatorLanguage(values[1])
});
}
}
},
beforeDestroy() {
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
</script>
<style scoped>
.field {
margin-bottom: 0.125rem !important;
}
p.is-size-7 {
margin-bottom: 0.125rem !important;
}
</style>

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

@ -3,7 +3,8 @@
<b-dropdown
:mobile-modal="true"
@input="onChangeComparator($event)"
aria-role="list">
aria-role="list"
trap-focus>
<button
:aria-label="$i18n.get('label_comparator')"
class="button is-white"
@ -59,16 +60,16 @@
</b-dropdown-item>
</b-dropdown>
<!-- <b-numberinput
v-if="options.type == 'year'"
v-if="filterTypeOptions.type == 'year'"
:placeholder="$i18n.get('instruction_type_value_year')"
:aria-labelledby="labelId"
:aria-labelledby="'filter-label-id-' + filter.id"
size="is-small"
step="1"
@input="emitOnlyYear($event)"
v-model="yearsOnlyValue"/> -->
<b-datepicker
position="is-bottom-left"
:aria-labelledby="labelId"
:aria-labelledby="'filter-label-id-' + filter.id"
:placeholder="$i18n.get('instruction_select_a_date')"
v-model="value"
@input="emit()"
@ -77,6 +78,7 @@
:date-parser="(date) => dateParser(date)"
size="is-small"
icon="calendar-today"
:years-range="[-200, 50]"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
@ -100,67 +102,38 @@
$i18n.get('datepicker_month_november'),
$i18n.get('datepicker_month_december')
]"/>
<!-- OPTIONS FOR TYPE
<!-- filterTypeOptions FOR TYPE
v-else
:type="options.type == 'month' ? 'month' : null"
:placeholder="options.type == 'month' ? $i18n.get('instruction_select_a_date') : $i18n.get('instruction_select_a_month')"
:type="filterTypeOptions.type == 'month' ? 'month' : null"
:placeholder="filterTypeOptions.type == 'month' ? $i18n.get('instruction_select_a_date') : $i18n.get('instruction_select_a_month')"
-->
</div>
</template>
<script>
import { tainacan as axios } from '../../../js/axios/axios';
import { wpAjax, dateInter } from "../../../admin/js/mixins";
import { filterTypeMixin } from '../filter-types-mixin';
import moment from 'moment';
export default {
mixins: [ wpAjax, dateInter ],
created() {
this.collection = ( this.collection_id ) ? this.collection_id : this.filter.collection_id;
this.metadatum = ( this.metadatum_id ) ? this.metadatum_id : (typeof this.filter.metadatum.metadatum_id == 'object' ? this.filter.metadatum.metadatum_id.metadatum_id : this.filter.metadatum.metadatum_id);
this.options = this.filter.filter_type_options;
let in_route = '/collection/' + this.collection + '/metadata/' + this.metadatum;
if (this.isRepositoryLevel || this.collection == 'filter_in_repository')
in_route = '/metadata/'+ this.metadatum;
axios.get(in_route)
.then( res => {
let result = res.data;
if ( result && result.metadata_type ){
this.metadatum_object = result;
this.selectedValues();
}
})
.catch(error => {
this.$console.log(error);
});
this.$eventBusSearch.$on('removeFromFilterTag', this.cleanSearchFromTags);
},
mixins: [
wpAjax,
dateInter,
filterTypeMixin
],
mounted() {
this.selectedValues();
this.updateSelectedValues();
},
data(){
return {
value: null,
clear: false,
options: [],
collection: '',
metadatum: '',
metadatum_object: {},
comparator: '=', // =, !=, >, >=, <, <=
}
},
props: {
filter: {
type: Object // concentrate all attributes metadatum id and type
},
metadatum_id: [Number], // not required, but overrides the filter metadatum id if is set
collection_id: [Number], // not required, but overrides the filter metadatum id if is set
labelId: '',
query: Object,
isRepositoryLevel: Boolean,
watch: {
'query.metaquery'() {
this.updateSelectedValues();
}
},
computed: {
yearsOnlyValue() {
@ -179,12 +152,12 @@
}
},
methods: {
selectedValues(){
updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key === this.metadatum );
let index = this.query.metaquery.findIndex(newMetadatum => newMetadatum.key == this.metadatumId );
if ( index >= 0){
let metadata = this.query.metaquery[ index ];
@ -199,35 +172,15 @@
this.value = new Date(textValue);
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: this.filter.id,
value: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat)
this.$emit('sendValuesToTags', {
label: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat),
value: textValue
});
}
} else {
return false;
this.value = null;
}
},
cleanSearchFromTags(filterTag) {
if (filterTag.filterId == this.filter.id)
this.clearSearch();
},
clearSearch(){
this.clear = true;
this.$emit('input', {
filter: 'date',
type: 'DATE',
compare: this.comparator,
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
value: ''
});
this.value = null;
},
dateFormatter(dateObject) {
return moment(dateObject, moment.ISO_8601).format(this.dateFormat);
@ -260,13 +213,13 @@
filter: 'date',
type: 'DATE',
compare: this.comparator,
metadatum_id: this.metadatum,
collection_id: ( this.collection_id ) ? this.collection_id : this.filter.collection_id,
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
value: valueQuery
});
this.$eventBusSearch.$emit( 'sendValuesToTags', {
filterId: this.filter.id,
value: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat)
this.$emit('sendValuesToTags', {
label: this.comparator + ' ' + moment(this.value, moment.ISO_8601).format(this.dateFormat),
value: valueQuery
});
},
@ -274,9 +227,6 @@
this.comparator = newComparator;
this.emit();
}
},
beforeDestroy() {
this.$eventBusSearch.$off('removeFromFilterTag', this.cleanSearchFromTags);
}
}
</script>

View File

@ -27,7 +27,6 @@
type: Object
},
value: [String, Number, Array],
id: '',
disabled: false,
},
data() {
@ -39,9 +38,6 @@
onUpdateType(type) {
this.$emit('input', { type: type });
},
},
created() {
this.type = this.type && this.value.type ? this.value.type : 'day';
}
}
</script>

View File

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

View File

@ -24,6 +24,12 @@ abstract class Filter_Type {
*/
private $default_options = [];
/**
* The name of the filter type that will be rendered on labels
* @var string
*/
private $name;
/**
* The name of the web component used by this filter type
* @var string
@ -56,6 +62,20 @@ abstract class Filter_Type {
}
/**
* @param string $name for the filter type
*/
public function set_name($name){
$this->name = $name;
}
/**
* @return string
*/
public function get_name() {
return $this->name;
}
/**
* @return array Supported types by the filter
*/
@ -103,6 +123,7 @@ abstract class Filter_Type {
$attributes = [];
$attributes['className'] = get_class($this);
$attributes['name'] = $this->get_name();
$attributes['component'] = $this->get_component();
$attributes['options'] = $this->get_options();
$attributes['supported_types'] = $this->get_supported_types();
@ -207,4 +228,8 @@ abstract class Filter_Type {
public function set_form_component($form_component){
$this->form_component = $form_component;
}
public function get_filter_type() {
return str_replace( 'Tainacan\Filter_Types\\', '', get_class($this) );
}
}

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