Solving small merge conflicts from develop.

This commit is contained in:
Mateus Machado Luna 2019-11-07 14:40:34 -03:00
commit 8fac7ae028
41 changed files with 1095 additions and 741 deletions

View File

@ -97,8 +97,6 @@
:maxtags="1" :maxtags="1"
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}" :class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
:disabled="bulkEditionProcedures[criterion].isDone" :disabled="bulkEditionProcedures[criterion].isDone"
:id="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component +
'-' + getMetadataByID(bulkEditionProcedures[criterion].metadatumID).slug"
:is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component" :is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component"
:metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}" :metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}"
class="tainacan-bulk-edition-field" class="tainacan-bulk-edition-field"
@ -152,8 +150,6 @@
:maxtags="1" :maxtags="1"
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}" :class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
:disabled="bulkEditionProcedures[criterion].isDone || bulkEditionProcedures[criterion].isExecuting" :disabled="bulkEditionProcedures[criterion].isDone || bulkEditionProcedures[criterion].isExecuting"
:id="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component +
'-' + getMetadataByID(bulkEditionProcedures[criterion].metadatumID).slug"
:is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component" :is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component"
:metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}" :metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}"
class="tainacan-bulk-edition-field tainacan-bulk-edition-field-last" class="tainacan-bulk-edition-field tainacan-bulk-edition-field-last"

View File

@ -132,8 +132,6 @@
:metadatum="{ metadatum: metadatum }" :metadatum="{ metadatum: metadatum }"
:value="itemMetadata[index].value" :value="itemMetadata[index].value"
@input="clearErrorMessage(metadatum.id); bulkEdit($event, metadatum)"/> @input="clearErrorMessage(metadatum.id); bulkEdit($event, metadatum)"/>
<!-- :class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
:disabled="bulkEditionProcedures[criterion].isDone || bulkEditionProcedures[criterion].isExecuting" -->
</div> </div>
</transition> </transition>
</b-field> </b-field>

View File

@ -150,7 +150,7 @@
</b-field> </b-field>
<b-field :addons="false"> <b-field :addons="false">
<label class="label is-inline-block">{{ $i18n.get('label_options') }}</label> <label class="label is-inline-block">{{ $i18n.get('label_insert_options') }}</label>
<b-field <b-field
:type="formErrors['required'] != undefined ? 'is-danger' : ''" :type="formErrors['required'] != undefined ? 'is-danger' : ''"
:message="formErrors['required'] != undefined ? formErrors['required'] : ''"> :message="formErrors['required'] != undefined ? formErrors['required'] : ''">

View File

@ -144,7 +144,7 @@
:message="$i18n.get('info_help_parent_term')"/> :message="$i18n.get('info_help_parent_term')"/>
</label> </label>
<b-autocomplete <b-autocomplete
id="tainacan-text-cover-page" id="tainacan-add-parent-field"
:placeholder="$i18n.get('instruction_parent_term')" :placeholder="$i18n.get('instruction_parent_term')"
:data="parentTerms" :data="parentTerms"
field="name" field="name"
@ -155,7 +155,18 @@
@focus="clearErrors('parent');" @focus="clearErrors('parent');"
:disabled="!hasParent"> :disabled="!hasParent">
<template slot-scope="props"> <template slot-scope="props">
{{ props.option.name }} <div class="media">
<div
v-if="props.option.header_image"
class="media-left">
<img
width="28"
:src="props.option.header_image">
</div>
<div class="media-content">
{{ props.option.name }}
</div>
</div>
</template> </template>
<template slot="empty">{{ $i18n.get('info_no_parent_term_found') }}</template> <template slot="empty">{{ $i18n.get('info_no_parent_term_found') }}</template>
</b-autocomplete> </b-autocomplete>

View File

@ -363,35 +363,35 @@
let selected = this.selected instanceof Array ? this.selected : [this.selected]; let selected = this.selected instanceof Array ? this.selected : [this.selected];
if (this.taxonomy_id && selected.length) { if (this.taxonomy_id && selected.length) {
for (const term of selected) {
this.isSelectedTermsLoading = true; this.isSelectedTermsLoading = true;
axios.get(`/taxonomy/${this.taxonomy_id}/terms/${term}`) axios.get(`/taxonomy/${this.taxonomy_id}/terms/?${qs.stringify({ hideempty: 0, include: selected})}`)
.then((res) => { .then((res) => {
this.saveSelectedTagName(res.data.id, res.data.name); for (const term of res.data)
this.isSelectedTermsLoading = false; this.saveSelectedTagName(term.id, term.name);
})
.catch((error) => { this.isSelectedTermsLoading = false;
this.$console.log(error); })
this.isSelectedTermsLoading = false; .catch((error) => {
}); this.$console.log(error);
} this.isSelectedTermsLoading = false;
});
} else if (this.metadatum_type === 'Tainacan\\Metadata_Types\\Relationship' && selected.length) { } else if (this.metadatum_type === 'Tainacan\\Metadata_Types\\Relationship' && selected.length) {
this.isSelectedTermsLoading = true; this.isSelectedTermsLoading = true;
for (const item of selected) { axios.get(`/items/?${qs.stringify({ fetch_only: 'title', postin: selected})}`)
.then((res) => {
for (const item of res.data)
this.saveSelectedTagName(item.id, item.title);
axios.get('/items/' + item + '?fetch_only=title') this.isSelectedTermsLoading = false;
.then((res) => { })
this.saveSelectedTagName(res.data.id, res.data.title); .catch((error) => {
this.isSelectedTermsLoading = false; this.$console.log(error);
}) this.isSelectedTermsLoading = false;
.catch((error) => { });
this.$console.log(error);
this.isSelectedTermsLoading = false;
});
}
} }
}, },
saveSelectedTagName(value, label){ saveSelectedTagName(value, label){

View File

@ -22,6 +22,7 @@ import Taxonomy from '../../classes/metadata-types/taxonomy/Taxonomy.vue';
import FormRelationship from '../../classes/metadata-types/relationship/FormRelationship.vue'; import FormRelationship from '../../classes/metadata-types/relationship/FormRelationship.vue';
import FormTaxonomy from '../../classes/metadata-types/taxonomy/FormTaxonomy.vue'; import FormTaxonomy from '../../classes/metadata-types/taxonomy/FormTaxonomy.vue';
import FormSelectbox from '../../classes/metadata-types/selectbox/FormSelectbox.vue'; import FormSelectbox from '../../classes/metadata-types/selectbox/FormSelectbox.vue';
import FormNumeric from '../../classes/metadata-types/numeric/FormNumeric.vue';
import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue'; import FilterNumeric from '../../classes/filter-types/numeric/Numeric.vue';
import FilterDate from '../../classes/filter-types/date/Date.vue'; import FilterDate from '../../classes/filter-types/date/Date.vue';
@ -31,12 +32,13 @@ import FilterCheckbox from '../../classes/filter-types/checkbox/Checkbox.vue';
import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue'; import FilterTaginput from '../../classes/filter-types/taginput/Taginput.vue';
import FilterNumericInterval from '../../classes/filter-types/numeric-interval/NumericInterval.vue'; import FilterNumericInterval from '../../classes/filter-types/numeric-interval/NumericInterval.vue';
import FilterDateInterval from '../../classes/filter-types/date-interval/DateInterval.vue'; import FilterDateInterval from '../../classes/filter-types/date-interval/DateInterval.vue';
import FilterNumericListInterval from '../../classes/filter-types/numeric-list-interval/NumericListInterval.vue';
import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue'; import FilterTaxonomyCheckbox from '../../classes/filter-types/taxonomy/Checkbox.vue';
import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue'; import FilterTaxonomyTaginput from '../../classes/filter-types/taxonomy/Taginput.vue';
import FormNumeric from '../../classes/filter-types/numeric/FormNumeric.vue'; import FormFilterNumeric from '../../classes/filter-types/numeric/FormNumeric.vue';
import FormNumericInterval from '../../classes/filter-types/numeric-interval/FormNumericInterval.vue'; import FormFilterNumericInterval from '../../classes/filter-types/numeric-interval/FormNumericInterval.vue';
import FormFilterNumericListInterval from '../../classes/filter-types/numeric-list-interval/FormNumericListInterval.vue';
// import FormDate from '../../classes/filter-types/date/FormDate.vue'; // import FormDate from '../../classes/filter-types/date/FormDate.vue';
import TainacanFormItem from '../../classes/metadata-types/tainacan-form-item.vue'; import TainacanFormItem from '../../classes/metadata-types/tainacan-form-item.vue';
@ -52,10 +54,6 @@ import eventBusSearch from '../../js/event-bus-search';
import termsListBus from './terms-list-bus.js'; import termsListBus from './terms-list-bus.js';
import { I18NPlugin, UserPrefsPlugin, RouterHelperPlugin, ConsolePlugin, UserCapabilitiesPlugin, StatusHelperPlugin } from './utilities'; 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 // Configure and Register Plugins
Vue.use(Buefy, { Vue.use(Buefy, {
defaultTooltipAnimated: true defaultTooltipAnimated: true
@ -78,10 +76,12 @@ Vue.component('tainacan-numeric', Numeric);
Vue.component('tainacan-date', Date); Vue.component('tainacan-date', Date);
Vue.component('tainacan-relationship', Relationship); Vue.component('tainacan-relationship', Relationship);
Vue.component('tainacan-taxonomy', Taxonomy); Vue.component('tainacan-taxonomy', Taxonomy);
/* Metadata Option forms */ /* Metadata Option forms */
Vue.component('tainacan-form-relationship', FormRelationship); Vue.component('tainacan-form-relationship', FormRelationship);
Vue.component('tainacan-form-taxonomy', FormTaxonomy); Vue.component('tainacan-form-taxonomy', FormTaxonomy);
Vue.component('tainacan-form-selectbox', FormSelectbox); Vue.component('tainacan-form-selectbox', FormSelectbox);
Vue.component('tainacan-form-numeric', FormNumeric);
Vue.component('tainacan-form-item', TainacanFormItem); Vue.component('tainacan-form-item', TainacanFormItem);
Vue.component('tainacan-filter-item', TainacanFiltersList); Vue.component('tainacan-filter-item', TainacanFiltersList);
@ -99,9 +99,9 @@ Vue.component('tainacan-filter-numeric-list-interval', FilterNumericListInterval
Vue.component('tainacan-filter-date-interval', FilterDateInterval); Vue.component('tainacan-filter-date-interval', FilterDateInterval);
/* Filter Metadata Option forms */ /* Filter Metadata Option forms */
Vue.component('tainacan-filter-form-numeric', FormNumeric); Vue.component('tainacan-filter-form-numeric', FormFilterNumeric);
Vue.component('tainacan-filter-form-numeric-interval', FormNumericInterval); Vue.component('tainacan-filter-form-numeric-interval', FormFilterNumericInterval);
Vue.component('tainacan-filter-form-numeric-list-interval', FormNumericListInterval); Vue.component('tainacan-filter-form-numeric-list-interval', FormFilterNumericListInterval);
// Vue.component('tainacan-filter-form-date', FormDate); // Vue.component('tainacan-filter-form-date', FormDate);
/* Others */ /* Others */

View File

@ -78,6 +78,39 @@
</p> </p>
</b-field> </b-field>
<b-field
style="margin-left: auto"
class="header-item">
<div class="control has-icons-right is-small is-clearfix">
<b-autocomplete
:data="users"
:placeholder="$i18n.get('instruction_type_search_users_filter')"
:keep-first="keepFirst"
:open-on-focus="openOnFocus"
@typing="fetchUsersForFiltering"
@select="filterActivitiesByUser"
:loading="isFetchingUsers"
field="name"
icon="account">
<template slot-scope="props">
<div class="media">
<div
v-if="props.option.avatar_urls && props.option.avatar_urls['24']"
class="media-left">
<img
width="24"
:src="props.option.avatar_urls['24']">
</div>
<div class="media-content">
{{ props.option.name }}
</div>
</div>
</template>
<template slot="empty">{{ $i18n.get('info_no_user_found') }}</template>
</b-autocomplete>
</div>
</b-field>
<b-field class="header-item"> <b-field class="header-item">
<div class="control has-icons-right is-small is-clearfix"> <div class="control has-icons-right is-small is-clearfix">
<input <input
@ -237,7 +270,10 @@
tab: '', tab: '',
isItemLevel: false, isItemLevel: false,
searchQuery: '', searchQuery: '',
searchDates: [] searchDates: [],
users: [],
isFetchingUsers: false,
userIdForFiltering: null
} }
}, },
components: { components: {
@ -248,7 +284,8 @@
...mapActions('activity', [ ...mapActions('activity', [
'fetchActivities', 'fetchActivities',
'fetchCollectionActivities', 'fetchCollectionActivities',
'fetchItemActivities' 'fetchItemActivities',
'fetchUsers'
]), ]),
...mapGetters('activity', [ ...mapGetters('activity', [
'getActivities' 'getActivities'
@ -315,10 +352,11 @@
if(this.isRepositoryLevel) { if(this.isRepositoryLevel) {
this.fetchActivities({ this.fetchActivities({
'page': this.activitiesPage, page: this.activitiesPage,
'activitiesPerPage': this.activitiesPerPage, activitiesPerPage: this.activitiesPerPage,
'search': this.searchQuery, search: this.searchQuery,
'searchDates': [dataInit, dataEnd] searchDates: [dataInit, dataEnd],
authorId: this.userIdForFiltering
}) })
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
@ -329,11 +367,12 @@
}); });
} else if (!this.isRepositoryLevel && !this.isItemLevel) { } else if (!this.isRepositoryLevel && !this.isItemLevel) {
this.fetchCollectionActivities({ this.fetchCollectionActivities({
'page': this.activitiesPage, page: this.activitiesPage,
'activitiesPerPage': this.activitiesPerPage, activitiesPerPage: this.activitiesPerPage,
'collectionId': this.$route.params.collectionId, collectionId: this.$route.params.collectionId,
'search': this.searchQuery, search: this.searchQuery,
'searchDates': [dataInit, dataEnd] searchDates: [dataInit, dataEnd],
authorId: this.userIdForFiltering
}) })
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
@ -344,11 +383,12 @@
}); });
} else { } else {
this.fetchItemActivities({ this.fetchItemActivities({
'page': this.activitiesPage, page: this.activitiesPage,
'activitiesPerPage': this.activitiesPerPage, activitiesPerPage: this.activitiesPerPage,
'itemId': this.$route.params.itemId, itemId: this.$route.params.itemId,
'search': this.searchQuery, search: this.searchQuery,
'searchDates': [dataInit, dataEnd] searchDates: [dataInit, dataEnd],
authorId: this.userIdForFiltering
}) })
.then((res) => { .then((res) => {
this.isLoading = false; this.isLoading = false;
@ -391,6 +431,10 @@
this.searchDates = null; this.searchDates = null;
this.searchActivities(); this.searchActivities();
}, },
filterActivitiesByUser(user) {
this.userIdForFiltering = user != null && user.id != undefined ? user.id : null;
this.loadActivities();
},
dateFormatter(dateObject) { dateFormatter(dateObject) {
if (dateObject == null || dateObject.length == 0 || dateObject[0] == null || dateObject[1] == null) if (dateObject == null || dateObject.length == 0 || dateObject[0] == null || dateObject[1] == null)
return ""; return "";
@ -401,7 +445,20 @@
moment(dateString[0], this.dateFormat).toDate(), moment(dateString[0], this.dateFormat).toDate(),
moment(dateString[1], this.dateFormat).toDate() moment(dateString[1], this.dateFormat).toDate()
]; ];
} },
fetchUsersForFiltering: _.debounce(function (search) {
this.isFetchingUsers = true;
this.fetchUsers({ search: search })
.then((users) => {
this.users = users;
this.isFetchingUsers = false;
})
.catch((error) => {
this.$console.error(error);
this.isFetchingPages = false;
});
}, 500)
}, },
computed: { computed: {
activities(){ activities(){

View File

@ -26,6 +26,7 @@
border-radius: 0px; border-radius: 0px;
min-width: 6rem; min-width: 6rem;
border: none; border: none;
z-index: 99;
.dropdown-content { .dropdown-content {
padding: 0px; padding: 0px;
@ -50,18 +51,22 @@
.is-small { color: $gray4; } .is-small { color: $gray4; }
&.is-active { background-color: $turquoise2; } &.is-active { background-color: $turquoise2; }
.media-left { .media {
margin-right: 0.5rem; align-items: center;
}
.media-content { .media-left {
display: flex; margin-right: 0.5rem;
width: 80%; }
.media-content {
display: flex;
width: 80%;
.ellipsed-text { .ellipsed-text {
overflow-x: hidden; overflow-x: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
margin-right: 3px; margin-right: 3px;
}
} }
} }
} }

View File

@ -51,6 +51,7 @@
} }
.b-numberinput { .b-numberinput {
height: 30px; height: 30px;
padding: 0 !important;
.control { .control {
margin-right: 0 !important; margin-right: 0 !important;
@ -62,6 +63,7 @@
button, button,
input { input {
height: 30px !important; height: 30px !important;
text-align: start;
} }
button.is-primary, button.is-primary,
button.is-primary:hover, button.is-primary:hover,

View File

@ -121,7 +121,7 @@ $subheader-height: 42px;
$side-menu-width: 160px; $side-menu-width: 160px;
$filter-menu-width: 16.666666667%; $filter-menu-width: 16.666666667%;
$filter-menu-width-theme: 20.833333333%; $filter-menu-width-theme: 20.833333333%;
$page-height: calc(100% - 94px); $page-height: calc(100vh - 94px);
// Overall Pages padding: // Overall Pages padding:
$page-side-padding: 4.166666667%;//82px; $page-side-padding: 4.166666667%;//82px;

View File

@ -98,6 +98,7 @@ a:hover {
.add-link { .add-link {
display: inline; display: inline;
font-size: 0.75rem; font-size: 0.75rem;
margin: 3px 0 6px 0;
&.disabled { &.disabled {
pointer-events: none; pointer-events: none;
cursor: default; cursor: default;

View File

@ -200,7 +200,9 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_select_taxonomy_input_type' => __( 'Input type', 'tainacan' ), 'label_select_taxonomy_input_type' => __( 'Input type', 'tainacan' ),
'label_taxonomy_allow_new_terms' => __( 'Allow new terms', 'tainacan' ), 'label_taxonomy_allow_new_terms' => __( 'Allow new terms', 'tainacan' ),
'label_selectbox_init' => __( 'Select', 'tainacan' ), 'label_selectbox_init' => __( 'Select', 'tainacan' ),
'label_options' => __( 'Insert options', 'tainacan' ), 'label_insert_options' => __( 'Insert options', 'tainacan'),
'label_available_terms' => __( 'Available terms', 'tainacan' ),
'label_some_available_terms' => __( 'Some available terms', 'tainacan' ),
'label_attachments' => __( 'Attachments', 'tainacan' ), 'label_attachments' => __( 'Attachments', 'tainacan' ),
'label_attachment' => __( 'Attachment', 'tainacan' ), 'label_attachment' => __( 'Attachment', 'tainacan' ),
'label_enabled' => __( 'Enabled', 'tainacan' ), 'label_enabled' => __( 'Enabled', 'tainacan' ),
@ -213,6 +215,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_parent_term' => __( 'Parent Term', 'tainacan' ), 'label_parent_term' => __( 'Parent Term', 'tainacan' ),
'label_children_terms' => __( 'children terms', 'tainacan' ), 'label_children_terms' => __( 'children terms', 'tainacan' ),
'label_new_term' => __( 'Create New Term', 'tainacan' ), 'label_new_term' => __( 'Create New Term', 'tainacan' ),
'label_create_and_select' => __( 'Create and Select', 'tainacan' ),
'label_new_child' => __( 'New Child', 'tainacan' ), 'label_new_child' => __( 'New Child', 'tainacan' ),
'label_taxonomy_terms' => __( 'Taxonomy Terms', 'tainacan' ), 'label_taxonomy_terms' => __( 'Taxonomy Terms', 'tainacan' ),
'label_no_parent_term' => __( 'No parent term', 'tainacan' ), 'label_no_parent_term' => __( 'No parent term', 'tainacan' ),
@ -348,6 +351,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_show_metadata' => __( 'Show metadata', 'tainacan' ), 'label_show_metadata' => __( 'Show metadata', 'tainacan' ),
'label_all_terms' => __( 'All terms', 'tainacan' ), 'label_all_terms' => __( 'All terms', 'tainacan' ),
'label_selected_terms' => __( 'Selected terms', 'tainacan' ), 'label_selected_terms' => __( 'Selected terms', 'tainacan' ),
'label_selected_term' => __( 'Selected term', 'tainacan' ),
'label_all_metadatum_values' => __( 'All metadatum values', 'tainacan' ), 'label_all_metadatum_values' => __( 'All metadatum values', 'tainacan' ),
'label_selected_metadatum_values' => __( 'Selected metadatum values', 'tainacan' ), 'label_selected_metadatum_values' => __( 'Selected metadatum values', 'tainacan' ),
'label_editing_item_number' => __( 'Editing item n.', 'tainacan' ), 'label_editing_item_number' => __( 'Editing item n.', 'tainacan' ),
@ -450,10 +454,12 @@ return apply_filters( 'tainacan-admin-i18n', [
'instruction_image_upload_box' => __( 'Drop an image here or click to upload.', 'tainacan' ), 'instruction_image_upload_box' => __( 'Drop an image here or click to upload.', 'tainacan' ),
'instruction_select_a_status' => __( 'Select a status:', 'tainacan' ), 'instruction_select_a_status' => __( 'Select a status:', 'tainacan' ),
'instruction_select_a_status2' => __( 'Select a status', 'tainacan' ), 'instruction_select_a_status2' => __( 'Select a status', 'tainacan' ),
'instruction_click_to_select_a_filter_type' => __( 'Click to select a filter type:', 'tainacan' ), 'instruction_click_to_select_a_filter_type' => __( 'Click to select a filter type:', 'tainacan' ),
'instruction_select_a_parent_term' => __( 'Select a parent term:', 'tainacan' ), 'instruction_select_a_parent_term' => __( 'Select a parent term:', 'tainacan' ),
'instruction_select_a_metadatum' => __( 'Select a metadatum', 'tainacan' ), 'instruction_select_a_metadatum' => __( 'Select a metadatum', 'tainacan' ),
'instruction_cover_page' => __( 'Type to search a Page to choose.', 'tainacan' ), 'instruction_cover_page' => __( 'Type to search a Page to choose.', 'tainacan' ),
'instruction_moderators' => __( 'Type to search a User to add.', 'tainacan' ),
'instruction_type_search_users_filter' => __( 'Type to search users to filter...', 'tainacan' ),
'instruction_select_a_parent_collection' => __( 'Select a parent collection.', 'tainacan' ), 'instruction_select_a_parent_collection' => __( 'Select a parent collection.', 'tainacan' ),
'instruction_select_collection_thumbnail' => __( 'Select a thumbnail image for collection', 'tainacan' ), 'instruction_select_collection_thumbnail' => __( 'Select a thumbnail image for collection', 'tainacan' ),
'instruction_select_item_thumbnail' => __( 'Select a thumbnail image for item', 'tainacan' ), 'instruction_select_item_thumbnail' => __( 'Select a thumbnail image for item', 'tainacan' ),
@ -578,6 +584,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_no_role_associated_capability' => __( 'No role associated to this capability', 'tainacan' ), 'info_no_role_associated_capability' => __( 'No role associated to this capability', 'tainacan' ),
'info_associated_roles' => __( 'These are the roles that have this capability set. You may add or remove the capability to customize the role.', 'tainacan' ), 'info_associated_roles' => __( 'These are the roles that have this capability set. You may add or remove the capability to customize the role.', 'tainacan' ),
'info_inherited_roles' => __( 'These are the roles that have greater capabilities, which inherit this one. You can not edit this as it will not have precendece over the greater capability.', 'tainacan' ), 'info_inherited_roles' => __( 'These are the roles that have greater capabilities, which inherit this one. You can not edit this as it will not have precendece over the greater capability.', 'tainacan' ),
'info_showing_terms' => __( 'Showing terms ', 'tainacan' ),
'info_warning_remove_from_trash_first' => __( 'Remove this item from trash first' ), 'info_warning_remove_from_trash_first' => __( 'Remove this item from trash first' ),
'info_to' => __( ' to ', 'tainacan' ), 'info_to' => __( ' to ', 'tainacan' ),
'info_of' => __( ' of ', 'tainacan' ), 'info_of' => __( ' of ', 'tainacan' ),

View File

@ -81,9 +81,9 @@ class Elastic_Press {
if ($item instanceof Entities\Item) { if ($item instanceof Entities\Item) {
$ids_meta = array_keys ($post_args['meta']); $ids_meta = array_keys ($post_args['meta']);
\array_filter(function($n) { \array_filter($ids_meta, function($n) {
if (is_numeric($n)) return intval($n); if (is_numeric($n)) return intval($n);
}, $ids_meta); });
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();

View File

@ -20,7 +20,7 @@
<img <img
:alt="$i18n.get('label_thumbnail')" :alt="$i18n.get('label_thumbnail')"
width="24" width="24"
:src="`${props.option.img}`"> :src="props.option.img">
</div> </div>
<div class="media-content"> <div class="media-content">
<span class="ellipsed-text">{{ props.option.label }}</span> <span class="ellipsed-text">{{ props.option.label }}</span>
@ -148,15 +148,4 @@
} }
} }
} }
</script> </script>
<style scoped>
#profileImage {
width: 32px;
height: 32px;
font-size: 2.1875rem;
color: #fff;
text-align: center;
line-height: 9.375rem;
margin: 20px 0;
}
</style>

View File

@ -276,13 +276,14 @@ export const dynamicFilterTypeMixin = {
sResults.push({ sResults.push({
label: item.label, label: item.label,
value: item.value, value: item.value,
img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''),
total_items: item.total_items total_items: item.total_items
}); });
} else if (indexToIgnore < 0) { } else if (indexToIgnore < 0) {
opts.push({ opts.push({
label: item.label, label: item.label,
value: item.value, value: item.value,
img: (item.img ? item.img : this.thumbPlaceholderPath), img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''),
total_items: item.total_items total_items: item.total_items
}); });
} }
@ -291,14 +292,14 @@ export const dynamicFilterTypeMixin = {
sResults.push({ sResults.push({
label: item.label, label: item.label,
value: item.value, value: item.value,
img: (item.img ? item.img : this.thumbPlaceholderPath), img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''),
total_items: item.total_items total_items: item.total_items
}); });
} else { } else {
opts.push({ opts.push({
label: item.label, label: item.label,
value: item.value, value: item.value,
img: (item.img ? item.img : this.thumbPlaceholderPath), img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : (item.img ? item.img : ''),
total_items: item.total_items total_items: item.total_items
}); });
} }

View File

@ -74,9 +74,7 @@
export default { export default {
props: { props: {
filter: Object, value: [String, Number, Array]
value: [String, Number, Array],
disabled: false,
}, },
data() { data() {
return { return {

View File

@ -157,7 +157,8 @@
let params = { let params = {
'include': metadata.terms, 'include': metadata.terms,
'order': 'asc' 'order': 'asc',
'fetchonly': 0
}; };
return axios.get('/taxonomy/' + this.taxonomyId + '/terms/?' + qs.stringify(params) ) return axios.get('/taxonomy/' + this.taxonomyId + '/terms/?' + qs.stringify(params) )

View File

@ -1,41 +1,34 @@
<template> <template>
<div> <div>
<div <b-input
:class="{'has-content': dateValue !== undefined && dateValue !== ''}" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
class="control is-inline"> :disabled="disabled"
<input class="input"
:disabled="disabled" :class="{'is-danger': isInvalidDate && dateValue}"
class="input" type="text"
:class="{'is-danger': isInvalidDate && dateValue}" v-mask="dateMask"
type="text" v-model="dateValue"
v-mask="dateMask" @input.native="onInput"
v-model="dateValue" :placeholder="dateFormat.toLowerCase()" />
@blur="onBlur" <p
@input="onInput" v-if="isInvalidDate && dateValue"
:placeholder="dateFormat.toLowerCase()"> class="has-text-danger is-italic is-size-7">{{ $i18n.get('info_error_invalid_date') }}</p>
<p <!--<b-collapse-->
v-if="isInvalidDate && dateValue" <!--position="is-bottom-right">-->
class="has-text-danger is-italic is-size-7">{{ $i18n.get('info_error_invalid_date') }}</p> <!--<span class="icon"-->
<!--<b-collapse--> <!--icon="calendar-today"-->
<!--position="is-bottom-right">--> <!--size="is-small"-->
<!--<span class="icon"--> <!--slot="trigger" />-->
<!--icon="calendar-today"-->
<!--size="is-small"-->
<!--slot="trigger" />-->
<!--<div class="field">--> <!--<div class="field">-->
<!--<b-datepicker--> <!--<b-datepicker-->
<!--:class="{'has-content': dateValue !== undefined && dateValue !== ''}"--> <!--v-model="dateValue"-->
<!--:id="id"--> <!--:readonly="false"-->
<!--v-model="dateValue"--> <!--inline-->
<!--@blur="onBlur"--> <!--@input="onInput($event)"-->
<!--:readonly="false"--> <!--:placeholder="datePlaceHolder"/>-->
<!--inline--> <!--</div>-->
<!--@input="onInput($event)"--> <!--</b-collapse>-->
<!--:placeholder="datePlaceHolder"/>-->
<!--</div>-->
<!--</b-collapse>-->
</div>
</div> </div>
</template> </template>
@ -56,17 +49,11 @@
} }
}, },
props: { props: {
id: '', metadatum: Object,
metadatum: {
type: Object
},
value: [String, Number, Array], value: [String, Number, Array],
disabled: false, disabled: false,
}, },
methods: { methods: {
onBlur() {
this.$emit('blur');
},
onInput: _.debounce(function ($event) { onInput: _.debounce(function ($event) {
// Emty dates don't need to be validated, they remove the metadata // Emty dates don't need to be validated, they remove the metadata
if ($event.target.value != '') { if ($event.target.value != '') {
@ -89,8 +76,14 @@
} else { } else {
this.$emit('input', [null]); this.$emit('input', [null]);
} }
this.$emit('blur');
}, 300) }, 300)
} }
} }
</script> </script>
<style scoped lang="scss">
.control {
padding-left: 0 !important;
padding-right: 0 !important;
}
</style>

View File

@ -0,0 +1,99 @@
<template>
<section>
<b-field :addons="false">
<label class="label is-inline">
{{ $i18n.getHelperTitle('tainacan-numeric', 'step') }}<span>&nbsp;*&nbsp;</span>
<help-button
:title="$i18n.getHelperTitle('tainacan-numeric', 'step')"
:message="$i18n.getHelperMessage('tainacan-numeric', 'step')"/>
</label>
<div
v-if="!showEditStepOptions"
class="is-flex">
<b-select
name="step_options"
v-model="step"
@input="onUpdateStep">
<option value="0.001">0.001</option>
<option value="0.01">0.01</option>
<option value="0.1">0.1</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="100">100</option>
<option value="1000">1000</option>
<option
v-if="step && ![0.001,0.01,0.1,1,2,5,10,100,1000].find( (element) => element == step )"
:value="step">
{{ step }}</option>
</b-select>
<button
class="button is-white is-pulled-right"
:aria-label="$i18n.get('edit')"
@click.prevent="showEditStepOptions = true">
<span
v-tooltip="{
content: $i18n.get('edit'),
autoHide: true,
placement: 'bottom'
}"
class="icon">
<i class="tainacan-icon tainacan-icon-18px tainacan-icon-edit has-text-secondary"/>
</span>
</button>
</div>
<div
v-if="showEditStepOptions"
class="is-flex">
<b-input
name="max_options"
v-model="step"
@input="onUpdateStep"
type="number"
step="1" />
<button
@click.prevent="showEditStepOptions = false"
class="button is-white is-pulled-right">
<span
v-tooltip="{
content: $i18n.get('close'),
autoHide: true,
placement: 'bottom'
}"
class="icon">
<i class="tainacan-icon tainacan-icon-18px tainacan-icon-close has-text-secondary"/>
</span>
</button>
</div>
</b-field>
</section>
</template>
<script>
export default {
props: {
value: [ String, Object, Array ]
},
data() {
return {
step: [Number, String],
showEditStepOptions: false
}
},
methods: {
onUpdateStep(value) {
this.$emit('input', { step: value });
}
},
created() {
this.step = this.value && this.value.step ? this.value.step : 0.01;
}
}
</script>
<style scoped>
section{
margin-bottom: 10px;
}
</style>

View File

@ -1,44 +1,32 @@
<template> <template>
<b-input <b-input
:disabled="disabled" :disabled="disabled"
:class="{'has-content': inputValue !== undefined && inputValue !== ''}" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
:id="id" :value="value"
lang="en" @input="onInput($event)"
type="number" type="number"
:value="inputValue" lang="en"
step="0.01" :step="getStep"/>
@blur="onBlur"
@change="onBlur"
@input="onInput($event)"/>
</template> </template>
<script> <script>
export default { export default {
created(){
if( this.value ){
this.inputValue = this.value
}
},
data() {
return {
inputValue: ''
}
},
props: { props: {
id: '', metadatum: Object,
metadatum: {
type: Object
},
value: [String, Number, Array], value: [String, Number, Array],
disabled: false, disabled: false,
}, },
computed: {
getStep() {
if (this.metadatum && this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.step)
return this.metadatum.metadatum.metadata_type_options.step;
else
return 0.01;
}
},
methods: { methods: {
onBlur() { onInput(value) {
this.$emit('blur'); this.$emit('input', value);
},
onInput($event) {
this.inputValue = $event;
this.$emit('input', this.inputValue);
} }
} }
} }

View File

@ -12,9 +12,10 @@ class Numeric extends Metadata_Type {
function __construct(){ function __construct(){
// call metadatum type constructor // call metadatum type constructor
parent::__construct(); parent::__construct();
$this->set_name( __('Numeric', 'tainacan') );
$this->set_primitive_type('float'); $this->set_primitive_type('float');
$this->set_component('tainacan-numeric'); $this->set_component('tainacan-numeric');
$this->set_name( __('Numeric', 'tainacan') ); $this->set_form_component('tainacan-form-numeric');
$this->set_description( __('A numeric value, integer or float', 'tainacan') ); $this->set_description( __('A numeric value, integer or float', 'tainacan') );
$this->set_preview_template(' $this->set_preview_template('
<div> <div>
@ -25,6 +26,18 @@ class Numeric extends Metadata_Type {
'); ');
} }
/**
* @inheritdoc
*/
public function get_form_labels(){
return [
'step' => [
'title' => __( 'Step', 'tainacan' ),
'description' => __( 'The amount to be increased or decreased when clicking on filter control buttons.', 'tainacan' ),
]
];
}
/** /**
* @param $itemMetadata \Tainacan\Entities\Item_Metadata_Entity The instace of the entity itemMetadata * @param $itemMetadata \Tainacan\Entities\Item_Metadata_Entity The instace of the entity itemMetadata
* @return string * @return string

View File

@ -3,17 +3,41 @@
<b-taginput <b-taginput
expanded expanded
:disabled="disabled" :disabled="disabled"
:id="id" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
v-model="selected" :value="selected"
size="is-small"
icon="magnify"
@input="onInput"
:data="options" :data="options"
:maxtags="maxtags != undefined ? maxtags : (metadatum.metadatum.multiple == 'yes' || allowNew === true ? 100 : 1)" :maxtags="maxtags != undefined ? maxtags : (metadatum.metadatum.multiple == 'yes' || allowNew === true ? 100 : 1)"
autocomplete autocomplete
attached attached
:loading="loading" :placeholder="$i18n.get('instruction_type_existing_term')"
:loading="isLoading"
:aria-close-label="$i18n.get('remove_value')" :aria-close-label="$i18n.get('remove_value')"
:class="{'has-selected': selected != undefined && selected != []}" :class="{'has-selected': selected != undefined && selected != []}"
field="label" field="label"
@typing="search"/> @typing="(query) => { options = []; search(query); }">
<template slot-scope="props">
<div class="media">
<div
v-if="props.option.img"
class="media-left">
<img
width="28"
:src="props.option.img">
</div>
<div class="media-content">
{{ props.option.label }}
</div>
</div>
</template>
<template
v-if="!isLoading"
slot="empty">
{{ $i18n.get('info_no_item_found') }}
</template>
</b-taginput>
</div> </div>
</template> </template>
@ -22,17 +46,20 @@
import qs from 'qs'; import qs from 'qs';
export default { export default {
created(){ created() {
let collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : this.collection_id; this.collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : '';
if ( this.metadatum.value && (Array.isArray( this.metadatum.value ) ? this.metadatum.value.length > 0 : true )){ if (this.metadatum.value && (Array.isArray( this.metadatum.value ) ? this.metadatum.value.length > 0 : true )) {
let query = qs.stringify({ postin: ( Array.isArray( this.metadatum.value ) ) ? this.metadatum.value : [ this.metadatum.value ] }); let query = qs.stringify({ postin: ( Array.isArray( this.metadatum.value ) ) ? this.metadatum.value : [ this.metadatum.value ] });
query += this.metadatum.metadatum.metadata_type_options.search ? '&fetch_only_meta=' + this.metadatum.metadatum.metadata_type_options.search : ''; query += this.metadatum.metadatum.metadata_type_options.search ? '&fetch_only_meta=' + this.metadatum.metadatum.metadata_type_options.search : '';
axios.get('/collection/'+collectionId+'/items?' + query + '&nopaging=1&fetch_only=title,thumbnail') axios.get('/collection/' + this.collectionId + '/items?' + query + '&nopaging=1&fetch_only=title,thumbnail')
.then( res => { .then( res => {
if (res.data.items) { if (res.data.items) {
for (let item of res.data.items) { for (let item of res.data.items)
this.selected.push({ label: this.getItemLabel(item), value: item.id, img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : '' }); this.selected.push({
} label: this.getItemLabel(item),
value: item.id,
img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : ''
});
} }
}) })
.catch(error => { .catch(error => {
@ -40,100 +67,78 @@
}); });
} }
}, },
data(){ data() {
return { return {
results:'', results:'',
selected:[], selected:[],
options: [], options: [],
loading: false, isLoading: false,
collectionId: 0, collectionId: '',
inputValue: null, inputValue: null,
queryObject: {}, queryObject: {},
itemsFound: [] itemsFound: []
} }
}, },
props: { props: {
metadatum: { metadatum: Object,
type: Object
},
collection_id: {
type: Number
},
id: '',
maxtags: undefined, maxtags: undefined,
disabled: false, disabled: false,
allowNew: true, allowNew: true,
}, },
watch: {
selected( value ){
this.selected = value;
let values = [];
if( this.selected.length > 0 ){
for(let val of this.selected){
values.push( val.value );
}
}
this.onInput( values );
}
},
methods: { methods: {
setResults(option){ setResults(option){
if(!option) if(!option)
return; return;
this.results = option.value; this.results = option.value;
}, },
onInput( $event ) { onInput(newSelected) {
this.$emit('input', $event); this.selected = newSelected;
this.$emit('blur'); this.$emit('input', newSelected.map((item) => item.value));
}, },
search: _.debounce(function(query) { search: _.debounce(function(query) {
if ( this.selected.length > 0 && this.metadatum.metadatum.multiple === 'no') if ( this.selected.length > 0 && this.metadatum.metadatum.multiple === 'no')
return ''; return '';
if (query !== '') { if (query !== '') {
this.loading = true; this.isLoading = true;
this.options = [];
let metaquery = this.mountQuery( query );
let collectionId = ( this.metadatum && this.metadatum.metadatum.metadata_type_options.collection_id ) ? this.metadatum.metadatum.metadata_type_options.collection_id : this.collection_id;
axios.get('/collection/'+collectionId+'/items?' + qs.stringify( metaquery ))
.then( res => {
this.loading = false;
this.options = [];
let result = res.data;
if (result.items) { axios.get('/collection/' + this.collectionId + '/items?' + this.getQueryString(query))
for (let item of result.items) { .then( res => {
this.options.push({ label: this.getItemLabel(item), value: item.id }) this.isLoading = false;
} this.options = [];
if (res.data.items) {
for (let item of res.data.items)
this.options.push({
label: this.getItemLabel(item),
value: item.id,
img: item.thumbnail && item.thumbnail['tainacan-small'] && item.thumbnail['tainacan-small'][0] ? item.thumbnail['tainacan-small'][0] : ''
})
} }
}) })
.catch(error => { .catch(error => {
this.$console.log(error); this.$console.log(error);
}); });
} else {
this.options = [];
} }
}, 500), }, 500),
getItemLabel(item) { getItemLabel(item) {
let label = ''; let label = '';
for (let m in item.metadata) { for (let m in item.metadata) {
if (item.metadata[m].id == this.metadatum.metadatum.metadata_type_options.search) { if (item.metadata[m].id == this.metadatum.metadatum.metadata_type_options.search)
label = item.metadata[m].value_as_string; label = item.metadata[m].value_as_string;
}
} }
if (label != '' && label != item.title && item.title != '') { if (label != '' && label != item.title && item.title != '')
label += ' (' + item.title + ')'; label += ' (' + item.title + ')';
} else if (label == '') { else if (label == '')
label = item.title; label = item.title;
}
return label; return label;
}, },
mountQuery( search ) { getQueryString( search ) {
let query = []; let query = [];
if ( this.metadatum.metadatum.metadata_type_options && if (this.metadatum.metadatum.metadata_type_options &&
this.metadatum.metadatum.metadata_type_options.search) this.metadatum.metadatum.metadata_type_options.search)
{ {
query['metaquery'] = []; query['metaquery'] = [];
@ -150,7 +155,7 @@
query['fetch_only'] = 'title,thumbnail'; query['fetch_only'] = 'title,thumbnail';
query['fetch_only_meta'] = this.metadatum.metadatum.metadata_type_options.search; query['fetch_only_meta'] = this.metadatum.metadatum.metadata_type_options.search;
return query; return qs.stringify(query);
} }
} }
} }

View File

@ -1,44 +1,33 @@
<template> <template>
<div> <b-select
<b-select expanded
expanded :disabled="disabled"
:disabled="disabled" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
:id = "id" :placeholder="$i18n.get('label_selectbox_init')"
:placeholder="$i18n.get('label_selectbox_init')" :value="value"
:value="value" @input="onSelected($event)">
:class="{'is-empty': value == undefined || value == ''}" <option value="">{{ $i18n.get('label_selectbox_init') }}...</option>
@blur="$emit('blur')" <option
@input="onChecked($event)"> v-for="(option, index) in getOptions"
<option :key="index"
v-for="(option, index) in getOptions" :label="option"
:key="index" :value="option">
:label="option" {{ option }}
:value="option" </option>
border>{{ option }}</option> </b-select>
</b-select>
</div>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
metadatum: { metadatum: Object,
type: Object
},
options: {
type: String
},
value: [String, Number, Array], value: [String, Number, Array],
id: '',
disabled: false, disabled: false,
}, },
computed: { computed: {
getOptions(){ getOptions(){
if ( this.options && this.options !== '' ){ if (this.metadatum && this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.options ) {
return this.options.split("\n");
}
else if ( this.metadatum && this.metadatum.metadatum.metadata_type_options.options ) {
const metadata = this.metadatum.metadatum.metadata_type_options.options; const metadata = this.metadatum.metadatum.metadata_type_options.options;
return ( metadata ) ? metadata.split("\n") : []; return ( metadata ) ? metadata.split("\n") : [];
} }
@ -46,7 +35,7 @@
} }
}, },
methods: { methods: {
onChecked(value) { onSelected(value) {
this.$emit('input', value); this.$emit('input', value);
}, },
} }

View File

@ -27,8 +27,12 @@
<span <span
v-if="metadatum.metadatum.required == 'yes'" v-if="metadatum.metadatum.required == 'yes'"
class="required-metadatum-asterisk" class="required-metadatum-asterisk"
:class="metadatumTypeMessage">*</span> :class="metadatumTypeMessage">
<span class="metadata-type">({{ metadatum.metadatum.metadata_type_object.name }})</span> *
</span>
<span class="metadata-type">
({{ metadatum.metadatum.metadata_type_object.name }})
</span>
<help-button <help-button
:title="metadatum.metadatum.name" :title="metadatum.metadatum.name"
:message="metadatum.metadatum.description"/> :message="metadatum.metadatum.description"/>
@ -38,43 +42,45 @@
v-show="isCollapsed || metadatumTypeMessage == 'is-danger'" v-show="isCollapsed || metadatumTypeMessage == 'is-danger'"
v-if="isTextInputComponent( metadatum.metadatum.metadata_type_object.component )"> v-if="isTextInputComponent( metadatum.metadatum.metadata_type_object.component )">
<component <component
:id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
:is="metadatum.metadatum.metadata_type_object.component" :is="metadatum.metadatum.metadata_type_object.component"
v-model="inputs[0]" v-model="inputs[0]"
:metadatum="metadatum" :metadatum="metadatum"
@input="emitIsChangingValue()"/> @input="changeValue()"/>
<div v-if="metadatum.metadatum.multiple == 'yes'"> <template v-if="metadatum.metadatum.multiple == 'yes'">
<div <transition-group
v-if="index > 0" name="filter-item"
v-for="(input, index) in inputs"
:key="index"
class="multiple-inputs"> class="multiple-inputs">
<component <template
:id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug" v-if="index > 0"
:is="metadatum.metadatum.metadata_type_object.component" v-for="(input, index) in inputs">
v-model="inputs[index]" <component
:metadatum="metadatum" :key="index"
@input="emitIsChangingValue()"/> :is="metadatum.metadatum.metadata_type_object.component"
<a v-model="inputs[index]"
v-if="index > 0" :metadatum="metadatum"
@click="removeInput(index)" @input="changeValue()"/>
class="is-inline add-link"> <a
<b-icon v-if="index > 0"
icon="minus-circle" @click="removeInput(index)"
size="is-small" class="is-inline add-link"
type="is-secondary"/> :key="index">
&nbsp;{{ $i18n.get('label_remove_value') }}</a> <b-icon
</div> icon="minus-circle"
size="is-small"
type="is-secondary"/>
&nbsp;{{ $i18n.get('label_remove_value') }}
</a>
</template>
</transition-group>
<a <a
@click="addInput" @click="addInput"
class="is-inline add-link"> class="is-block add-link">
<span class="icon is-small"> <span class="icon is-small">
<i class="tainacan-icon has-text-secondary tainacan-icon-add"/> <i class="tainacan-icon has-text-secondary tainacan-icon-add"/>
</span> </span>
&nbsp;{{ $i18n.get('label_add_value') }} &nbsp;{{ $i18n.get('label_add_value') }}
</a> </a>
</div> </template>
</div> </div>
</transition> </transition>
<transition name="filter-item"> <transition name="filter-item">
@ -82,11 +88,10 @@
v-show="isCollapsed" v-show="isCollapsed"
v-if="!isTextInputComponent( metadatum.metadatum.metadata_type_object.component )"> v-if="!isTextInputComponent( metadatum.metadatum.metadata_type_object.component )">
<component <component
:id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
:is="metadatum.metadatum.metadata_type_object.component" :is="metadatum.metadatum.metadata_type_object.component"
v-model="inputs" v-model="inputs"
:metadatum="metadatum" :metadatum="metadatum"
@input="emitIsChangingValue()"/> @input="changeValue()"/>
</div> </div>
</transition> </transition>
</b-field> </b-field>
@ -103,8 +108,7 @@
}, },
data(){ data(){
return { return {
inputs: [], inputs: []
metadatumTypeMessage: ''
} }
}, },
computed: { computed: {
@ -113,79 +117,70 @@
let errors = eventBus.getErrors(this.metadatum.metadatum.id); let errors = eventBus.getErrors(this.metadatum.metadatum.id);
if (errors) { if (errors) {
this.setMetadatumTypeMessage('is-danger');
for (let error of errors) { for (let error of errors) {
for (let index of Object.keys(error)) { for (let index of Object.keys(error))
// this.$console.log(index);
errorMessage += error[index] + '\n'; errorMessage += error[index] + '\n';
}
} }
} else {
this.setMetadatumTypeMessage('');
} }
return errorMessage; return errorMessage;
},
metadatumTypeMessage() {
return this.getErrorMessage ? 'is-danger' : ''
} }
}, },
created(){ created(){
this.getValue(); this.createInputs();
}, },
methods: { methods: {
emitIsChangingValue() {
this.changeValue();
},
changeValue: _.debounce(function() { changeValue: _.debounce(function() {
if (this.metadatum.value != this.inputs) {
if (this.inputs.length > 0 && this.inputs[0].value) { if (this.inputs.length > 0 && this.inputs[0] && this.inputs[0].value) {
let terms = this.inputs.map(term => term.value) let terms = this.inputs.map(term => term.value)
if (this.metadatum.value instanceof Array){ if (this.metadatum.value instanceof Array){
let equal = [];
for (let meta of terms) {
let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
if (foundIndex >= 0)
equal.push(this.metadatum.value[foundIndex]);
}
if (equal.length == terms.length && this.metadatum.value.length <= equal.length)
return;
}
} else if (this.metadatum.value.constructor.name == 'Object') {
if (this.metadatum.value.id == this.inputs)
return;
} else if (this.metadatum.value instanceof Array) {
let equal = []; let equal = [];
for (let meta of this.inputs) { for (let meta of terms) {
let foundIndex = this.metadatum.value.findIndex(element => meta == element.id); let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
if (foundIndex >= 0) if (foundIndex >= 0)
equal.push(this.metadatum.value[foundIndex]); equal.push(this.metadatum.value[foundIndex]);
} }
if (equal.length == this.inputs.length && this.metadatum.value.length <= equal.length) if (equal.length == terms.length && this.metadatum.value.length <= equal.length)
return; return;
}
eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } ); }
} } else if (this.metadatum.value.constructor.name == 'Object') {
}, 1000),
getValue(){ if (this.metadatum.value.id == this.inputs)
if (this.metadatum.value instanceof Array) { return;
} else if (this.metadatum.value instanceof Array) {
let equal = [];
for (let meta of this.inputs) {
let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
if (foundIndex >= 0)
equal.push(this.metadatum.value[foundIndex]);
}
if (equal.length == this.inputs.length && this.metadatum.value.length <= equal.length)
return;
}
eventBus.$emit('input', {
itemId: this.metadatum.item.id,
metadatumId: this.metadatum.metadatum.id,
values: this.inputs
} );
}, 900),
createInputs(){
if (this.metadatum.value instanceof Array)
this.inputs = this.metadatum.value.slice(0); this.inputs = this.metadatum.value.slice(0);
else
if (this.inputs.length === 0) this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs = [] : this.inputs.push(this.metadatum.value);
this.inputs.push('');
} else {
this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value);
}
}, },
addInput(){ addInput(){
this.inputs.push(''); this.inputs.push('');
@ -195,12 +190,9 @@
this.inputs.splice(index, 1); this.inputs.splice(index, 1);
this.changeValue(); this.changeValue();
}, },
isTextInputComponent(component){ isTextInputComponent(component) {
let array = ['tainacan-relationship','tainacan-taxonomy']; const array = ['tainacan-relationship','tainacan-taxonomy'];
return !( array.indexOf( component ) >= 0 ); return !(array.indexOf(component) >= 0 );
},
setMetadatumTypeMessage(message){
this.metadatumTypeMessage = message;
} }
} }
} }

View File

@ -1,5 +1,5 @@
<template> <template>
<div> <div class="add-new-term">
<span v-if="!showForm"> <span v-if="!showForm">
<a <a
@click="toggleForm()" @click="toggleForm()"
@ -10,10 +10,10 @@
&nbsp;{{ $i18n.get('label_new_term') }} &nbsp;{{ $i18n.get('label_new_term') }}
</a> </a>
</span> </span>
<transition name="appear"> <transition name="filter-item">
<section <section
v-if="showForm" v-if="showForm"
style="padding-left: 0px; margin-top: 12px; margin-bottom: -12px;"> class="add-new-term-form">
<b-field <b-field
:addons="false" :addons="false"
:type="((formErrors.name !== '' || formErrors.repeated !== '') && (formErrors.name !== undefined || formErrors.repeated !== undefined )) ? 'is-danger' : ''" :type="((formErrors.name !== '' || formErrors.repeated !== '') && (formErrors.name !== undefined || formErrors.repeated !== undefined )) ? 'is-danger' : ''"
@ -25,26 +25,12 @@
:title="$i18n.get('label_name')" :title="$i18n.get('label_name')"
:message="$i18n.get('info_help_term_name')"/> :message="$i18n.get('info_help_term_name')"/>
</label> </label>
<b-input <b-input
:class="{'has-content': name != undefined && name != ''}" :placeholder="$i18n.get('label_term_without_name')"
v-model="name" v-model="name"
@focus="clearErrors({ name: 'name', repeated: 'repeated' })"/> @focus="clearErrors({ name: 'name', repeated: 'repeated' })"/>
</b-field> </b-field>
<!-- <b-field :label="$i18n.get('label_parent_term')">
<b-select
v-model="parent">
<option
:value="0"
selected> ---{{ $i18n.get('label_parent_term') }}--- </option>
<option
v-for="(option,index) in options"
:key="index"
:value="option.id"
v-html="setSpaces( option.level ) + option.name"/>
</b-select>
</b-field> -->
<!-- Parent -------------- --> <!-- Parent -------------- -->
<b-field <b-field
:addons="false" :addons="false"
@ -62,7 +48,7 @@
:message="$i18n.get('info_help_parent_term')"/> :message="$i18n.get('info_help_parent_term')"/>
</label> </label>
<b-autocomplete <b-autocomplete
id="tainacan-text-cover-page" id="tainacan-add-parent-field"
:placeholder="$i18n.get('instruction_parent_term')" :placeholder="$i18n.get('instruction_parent_term')"
:data="parentTerms" :data="parentTerms"
field="name" field="name"
@ -85,22 +71,22 @@
</p> </p>
</transition> </transition>
</b-field> </b-field>
<div class="field is-grouped form-submit">
<button <button
:class="{ 'is-loading': isAddingNewTerm }" :class="{ 'is-loading': isAddingNewTerm }"
class="button is-outlined" class="button is-outlined"
@click="toggleForm()" @click="toggleForm()"
type="button"> type="button">
{{ $i18n.get('cancel') }} {{ $i18n.get('cancel') }}
</button> </button>
<button
<button :class="{ 'is-loading': isAddingNewTerm }"
:class="{ 'is-loading': isAddingNewTerm }" class="button is-secondary"
class="button is-secondary" @click="save"
@click="save" type="button">
type="button"> {{ $i18n.get('label_create_and_select') }}
{{ $i18n.get('save') }} </button>
</button> </div>
</section> </section>
</transition> </transition>
@ -122,19 +108,15 @@
parentTermName: '', parentTermName: '',
isAddingNewTerm: false, isAddingNewTerm: false,
isFetchingParentTerms: false, isFetchingParentTerms: false,
metadatum_id: this.metadatum.metadatum.id, metadatumId: this.metadatum.metadatum.id,
itemId: this.metadatum.item.id,
formErrors: {} formErrors: {}
} }
}, },
props: { props: {
id: String,
item_id: [Number,String],
metadatum: [Number,String], metadatum: [Number,String],
taxonomy_id: [Number,String], taxonomyId: [Number,String],
value:[ Array, Boolean, Number ], value: [ Array, Boolean, Number ],
options: {
type: Array
},
componentType: '' componentType: ''
}, },
methods: { methods: {
@ -153,20 +135,11 @@
this.formErrors = {}; this.formErrors = {};
this.showForm = !this.showForm; this.showForm = !this.showForm;
}, },
setSpaces( level ){
let result = '';
let space = '&nbsp;&nbsp;'
for(let i = 0;i < level; i++)
result += space;
return result;
},
fecthParentTerms(search) { fecthParentTerms(search) {
this.isFetchingParentTerms = true; this.isFetchingParentTerms = true;
this.fetchPossibleParentTerms({ this.fetchPossibleParentTerms({
taxonomyId: this.taxonomy_id, taxonomyId: this.taxonomyId,
termId: 'new', termId: 'new',
search: search }) search: search })
.then((parentTerms) => { .then((parentTerms) => {
@ -187,16 +160,15 @@
this.parentTermName = selectedParentTerm.name; this.parentTermName = selectedParentTerm.name;
}, },
clearErrors(attributes) { clearErrors(attributes) {
if(attributes instanceof Object){ if (attributes instanceof Object) {
for(let attribute in attributes){ for(let attribute in attributes)
this.formErrors[attribute] = undefined; this.formErrors[attribute] = undefined;
}
} else { } else {
this.formErrors[attributes] = undefined; this.formErrors[attributes] = undefined;
} }
}, },
save(){ save() {
if( this.name.trim() === ''){ if ( this.name.trim() === '') {
this.$buefy.toast.open({ this.$buefy.toast.open({
duration: 2000, duration: 2000,
message: this.$i18n.get('info_name_is_required'), message: this.$i18n.get('info_name_is_required'),
@ -206,32 +178,32 @@
} else { } else {
this.isAddingNewTerm = true; this.isAddingNewTerm = true;
axios.post(`/taxonomy/${this.taxonomy_id}/terms?hideempty=0&order=asc`, { axios.post(`/taxonomy/${this.taxonomyId}/terms?hideempty=0&order=asc`, {
name: this.name, name: this.name,
parent: this.parent parent: this.parent
}) })
.then( res => { .then(res => {
this.isAddingNewTerm = false; this.isAddingNewTerm = false;
if( res.data && res.data.id || res.id ){ if (res.data && res.data.id || res.id) {
let id = ( res.id ) ? res.id : res.data.id; let id = res.id ? res.id : res.data.id;
let val = this.value; let val = this.value;
if( !Array.isArray( val ) && this.metadatum.metadatum.multiple === 'no' ){ if (!Array.isArray(val) && this.metadatum.metadatum.multiple === 'no') {
axios.patch(`/item/${this.item_id}/metadata/${this.metadatum_id}`, { axios.patch(`/item/${this.itemId}/metadata/${this.metadatumId}`, {
values: id, values: id,
}).then(() => { }).then(() => {
this.$emit('newTerm', { values: id, taxonomyId: this.taxonomy_id, metadatumId: this.metadatum_id }); this.$emit('newTerm', { values: id, taxonomyId: this.taxonomyId, metadatumId: this.metadatumId });
this.toggleForm(); this.toggleForm();
}) })
} else { } else {
val = ( val ) ? val : []; val = val ? val : [];
val.push( this.componentType == ('tainacan-taxonomy-checkbox' || 'tainacan-taxonomy-radio') ? id : {'label': this.name, 'value': id} ); val.push( this.componentType == ('tainacan-taxonomy-checkbox' || 'tainacan-taxonomy-radio') ? id : {'label': this.name, 'value': id} );
axios.patch(`/item/${this.item_id}/metadata/${this.metadatum_id}`, { axios.patch(`/item/${this.itemId}/metadata/${this.metadatumId}`, {
values: val, values: val,
}).then(() => { }).then(() => {
this.$emit('newTerm', { values: val, taxonomyId: this.taxonomy_id, metadatumId: this.metadatum_id }); this.$emit('newTerm', { values: val, taxonomyId: this.taxonomyId, metadatumId: this.metadatumId });
this.toggleForm(); this.toggleForm();
}) })
} }
@ -256,5 +228,17 @@
} }
} }
</script> </script>
<style scoped> <style scoped>
.add-new-term {
margin-top: 15px;
margin-bottom: 25px;
font-size: 0.75rem;
}
.add-new-term-form {
padding: 14px 24px;
margin-top: 12px;
margin-bottom: -12px;
border: 1px solid #cbcbcb;
}
</style> </style>

View File

@ -7,53 +7,33 @@
v-model="valueComponent" v-model="valueComponent"
:allow-select-to-create="allowSelectToCreate" :allow-select-to-create="allowSelectToCreate"
:allow-new="allowNew" :allow-new="allowNew"
:terms="terms" :taxonomy-id="taxonomyId"
:taxonomy-id="taxonomy_id" :metadatum="metadatum.metadatum"/>
:options="getOptions(0)"/>
<a
class="add-new-term"
v-if="(getComponent == 'tainacan-taxonomy-checkbox' || getComponent == 'tainacan-taxonomy-radio') &&
terms.length < totalTerms"
@click="openCheckboxModal()">
{{ $i18n.get('label_view_all') }}
</a>
<add-new-term <add-new-term
class="add-new-term"
v-if="allowNew" v-if="allowNew"
:component-type="getComponent" :component-type="getComponent"
:taxonomy_id="taxonomy_id" :taxonomy-id="taxonomyId"
:metadatum="metadatum" :metadatum="metadatum"
:item_id="metadatum.item.id"
:value="valueComponent" :value="valueComponent"
:options="getOptions(0)"
@newTerm="reload"/> @newTerm="reload"/>
</div> </div>
</template> </template>
<script> <script>
import { tainacan as axios } from '../../../js/axios/axios'
import TainacanTaxonomyRadio from './TaxonomyRadio.vue' import TainacanTaxonomyRadio from './TaxonomyRadio.vue'
import TainacanTaxonomyCheckbox from './TaxonomyCheckbox.vue' import TainacanTaxonomyCheckbox from './TaxonomyCheckbox.vue'
import TainacanTaxonomyTagInput from './TaxonomyTaginput.vue' import TainacanTaxonomyTagInput from './TaxonomyTaginput.vue'
import AddNewTerm from './AddNewTerm.vue' import AddNewTerm from './AddNewTerm.vue'
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue'
export default { export default {
created(){ created(){
let metadata_type_options = this.metadatum.metadatum.metadata_type_options; const metadata_type_options = this.metadatum.metadatum.metadata_type_options;
this.component = ( metadata_type_options && metadata_type_options.input_type )
? this.metadatum.metadatum.metadata_type_options.input_type : this.componentAttribute;
this.collectionId = this.metadatum.metadatum.collection_id; this.taxonomyId = metadata_type_options.taxonomy_id;
this.taxonomy_id = metadata_type_options.taxonomy_id;
this.taxonomy = metadata_type_options.taxonomy; this.taxonomy = metadata_type_options.taxonomy;
if (metadata_type_options && metadata_type_options.allow_new_terms && this.metadatum.item) if (metadata_type_options && metadata_type_options.allow_new_terms && this.metadatum.item)
this.allowNew = metadata_type_options.allow_new_terms == 'yes'; this.allowNew = metadata_type_options.allow_new_terms == 'yes';
// This condition is temporary, used by bulk edition modal
if (this.component != 'tainacan-taxonomy-tag-input' || this.forcedComponentType != 'tainacan-taxonomy-tag-input')
this.getTermsFromTaxonomy();
this.getTermsId(); this.getTermsId();
}, },
components: { components: {
@ -65,32 +45,20 @@
data(){ data(){
return { return {
valueComponent: null, valueComponent: null,
component: '', taxonomyId: '',
collectionId: '',
taxonomy_id: '',
taxonomy: '', taxonomy: '',
terms:[], // object with names terms:[],
totalTerms: 0, allowNew: false
allowNew: false,
offset: 0,
termsNumber: 12
} }
}, },
watch: { watch: {
valueComponent( val ){ valueComponent( val ){
this.$emit('input', val); this.$emit('input', val);
this.$emit('blur');
} }
}, },
props: { props: {
metadatum: { metadatum: Object,
type: Object
},
componentAttribute: {
type: String
},
value: [ Number, String, Array, Object ], value: [ Number, String, Array, Object ],
id: '',
disabled: false, disabled: false,
forcedComponentType: '', forcedComponentType: '',
maxtags: '', maxtags: '',
@ -98,123 +66,36 @@
}, },
computed: { computed: {
getComponent() { getComponent() {
if (this.forcedComponentType){ if (this.forcedComponentType)
return this.forcedComponentType; return this.forcedComponentType;
} else if( this.metadatum.metadatum else if(this.metadatum.metadatum &&
&& this.metadatum.metadatum.metadata_type_options && this.metadatum.metadatum.metadata_type_options.input_type ){ this.metadatum.metadatum.metadata_type_options &&
this.metadatum.metadatum.metadata_type_options.input_type
)
return this.metadatum.metadatum.metadata_type_options.input_type; return this.metadatum.metadatum.metadata_type_options.input_type;
}
} }
}, },
methods: { methods: {
openCheckboxModal(){ getTermsId() {
this.$buefy.modal.open({ let values = [];
parent: this, if (this.value && this.metadatum.metadatum && this.getComponent != 'tainacan-taxonomy-tag-input') {
component: CheckboxRadioModal, values = this.value.map(term => term.id)
props: { this.valueComponent = (values.length >= 0 && this.metadatum.metadatum && this.metadatum.metadatum.multiple === 'no') ? values[0] : values;
isFilter: false, } else if (this.value && this.metadatum.metadatum && this.getComponent == 'tainacan-taxonomy-tag-input') {
parent: 0, values = this.value.map((term) => { return { label: term.name, value: term.id } });
taxonomy_id: this.taxonomy_id,
selected: !this.valueComponent ? [] : this.valueComponent,
metadatumId: this.metadatum.metadatum.id,
taxonomy: this.taxonomy,
collectionId: this.collectionId,
isTaxonomy: true,
query: '',
metadatum: this.metadatum.metadatum,
isCheckbox: this.getComponent == 'tainacan-taxonomy-checkbox'
},
events: {
input: (selected) => {
this.valueComponent = selected;
}
},
width: 'calc(100% - 8.333333333%)',
trapFocus: true
});
},
getTermsFromTaxonomy(){
let endpoint = '/taxonomy/' + this.taxonomy_id + '/terms?hideempty=0&order=asc';
if (this.getComponent == 'tainacan-taxonomy-checkbox' || this.getComponent == 'tainacan-taxonomy-radio')
endpoint = endpoint + '&number=' + this.termsNumber + '&offset=' + this.offset;
axios.get(endpoint)
.then( res => {
if (this.getComponent == 'tainacan-taxonomy-checkbox' || this.getComponent == 'tainacan-taxonomy-radio') {
this.totalTerms = Number(res.headers['x-wp-total']);
this.offset += this.termsNumber;
}
for (let item of res.data) {
this.terms.push( item );
}
})
.catch(error => {
this.$console.log(error);
});
},
getOptions( parent, level = 0 ){ // retrieve only ids
let result = [];
if ( this.terms ){
for( let term of this.terms ){
if( term.parent == parent ){
term['level'] = level;
result.push( term );
const levelTerm = level + 1;
const children = this.getOptions( term.id, levelTerm);
result = result.concat( children );
}
}
}
return result;
},
getTermsId(){
let values = [];
if( this.value && this.value.length > 0){
for( let term of this.value ){
if( term && term.id)
values.push(term.id);
}
}
if( values.length > 0 && this.metadatum.metadatum && this.component != 'tainacan-taxonomy-tag-input'){
this.valueComponent = ( this.metadatum.metadatum && this.metadatum.metadatum.multiple === 'no' ) ? values[0] : values;
} else if(values.length > 0 && this.metadatum.metadatum && this.component == 'tainacan-taxonomy-tag-input') {
let values = [];
for(let term of this.value){
values.push({label: term.name, value: term.id});
}
this.valueComponent = values; this.valueComponent = values;
} }
}, },
onInput($event) { onInput($event) {
this.inputValue = $event;
this.valueComponent = $event; this.valueComponent = $event;
this.$emit('input', this.inputValue); this.$emit('input', this.valueComponent);
this.$emit('blur');
}, },
reload( $event ) { reload($event) {
if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatum.metadatum.id) { if ($event.taxonomyId == this.taxonomyId && $event.metadatumId == this.metadatum.metadatum.id) {
this.valueComponent = $event.values; this.valueComponent = $event.values;
this.terms = []; this.$emit('update-taxonomy-inputs', $event)
this.offset = 0;
this.getTermsFromTaxonomy();
this.getTermsId();
} }
} }
} }
} }
</script> </script>
<style scoped>
.add-new-term{
margin-top: 15px;
margin-bottom: 30px;
font-size: 0.75rem;
}
</style>

View File

@ -3,7 +3,7 @@
<p <p
v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')" v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')"
class="has-text-gray"> class="has-text-gray">
{{ $i18n.get('label_selected_terms') + ' :' }} {{ $i18n.get('label_selected_terms') + ':' }}
</p> </p>
<b-field <b-field
v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')" v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')"
@ -24,97 +24,187 @@
v-if="isSelectedTermsLoading" v-if="isSelectedTermsLoading"
class="control has-icons-right is-loading is-clearfix" /> class="control has-icons-right is-loading is-clearfix" />
</b-field> </b-field>
<p
<div style="margin-top: 10px;"
v-for="(option, index) in options" class="has-text-gray">
:key="index"> {{ (isShowingAllTerms ? $i18n.get('label_available_terms') : $i18n.get('label_some_available_terms')) + ':' }}
<b-checkbox </p>
:disabled="disabled" <div
:id="id" class="metadata-taxonomy-list"
:style="{ paddingLeft: (option.level * 30) + 'px' }" :id="metadatum.metadata_type_object.component + '-' + metadatum.slug">
:key="index" <template v-for="(option, index) in options">
v-model="checked" <b-checkbox
@input="onChecked(option)" :key="index"
:native-value="option.id" :disabled="disabled"
border> :style="{ paddingLeft: (option.level * 30) + 'px' }"
{{ option.name }} v-model="checked"
</b-checkbox> @input="onChecked(option)"
<br> :native-value="option.id"
border>
{{ option.name }}
</b-checkbox>
<br :key="index">
</template>
</div>
<div
v-if="!isShowingAllTerms"
class="view-all">
<span>
{{
$i18n.get('info_showing_terms') + 1 +
$i18n.get('info_to') + options.length +
$i18n.get('info_of') + totalTerms + '. '
}}
</span>
<a @click="openCheckboxModal()">
{{ $i18n.get('label_view_all') + ' ' + totalTerms + '.' }}
</a>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { tainacan as axios } from '../../../js/axios/axios'; import { tainacan as axios } from '../../../js/axios/axios';
import qs from 'qs';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue'
export default { export default {
created(){ created() {
if( this.value && this.value.length > 0) if (this.value && this.value.length > 0)
this.checked = this.value; this.checked = this.value;
this.getTermsFromTaxonomy();
this.$parent.$on('update-taxonomy-inputs', ($event) => {
if ($event.taxonomyId == this.taxonomyId && $event.metadatumId == this.metadatum.metadatum.id) {
this.offset = 0;
this.getTermsFromTaxonomy();
}
});
}, },
data(){ data() {
return { return {
checked: [], checked: [],
selectedTagsName: {}, selectedTagsName: {},
isSelectedTermsLoading: false, isSelectedTermsLoading: false,
options: [],
terms: [],
termsNumber: 12,
offset: 0,
totalTerms: 0
} }
}, },
watch: { watch: {
value( val ){ value(val){
this.checked = val; this.checked = val;
this.fetchSelectedLabels(); this.fetchSelectedLabels();
} }
}, },
computed: {
isShowingAllTerms() {
return this.terms.length >= this.totalTerms;
}
},
props: { props: {
options: {
type: Array
},
value: [ Number, String, Array ], value: [ Number, String, Array ],
disabled: false, disabled: false,
taxonomyId: Number taxonomyId: Number,
metadatum: Object
}, },
methods: { methods: {
onChecked() { onChecked() {
this.$emit('blur');
this.onInput(this.checked); this.onInput(this.checked);
}, },
onInput($event) { onInput($event) {
this.inputValue = $event; this.value = $event;
this.$emit('input', this.inputValue); this.$emit('input', this.value);
}, },
fetchSelectedLabels() { fetchSelectedLabels() {
if (this.value != null && this.value != undefined) { if (this.value != null && this.value != undefined) {
this.isSelectedTermsLoading = true; const selected = this.value instanceof Array ? this.value : [this.value];
let selected = this.value instanceof Array ? this.value : [this.value];
if (this.taxonomyId && selected.length > 0) { if (this.taxonomyId) {
for (const term of selected) { this.isSelectedTermsLoading = true;
if(!this.isSelectedTermsLoading){ axios.get(`/taxonomy/${this.taxonomyId}/terms/?${qs.stringify({ hideempty: 0, include: selected })}`)
this.isSelectedTermsLoading = true; .then((res) => {
} let terms = res.data;
axios.get(`/taxonomy/${this.taxonomyId}/terms/${term}`) for (let term of terms) {
.then((res) => { if (!this.selectedTagsName[term.id])
this.saveSelectedTagName(res.data.id, res.data.name); this.$set(this.selectedTagsName, term.id, term.name);
this.isSelectedTermsLoading = false; }
})
.catch((error) => { this.isSelectedTermsLoading = false;
this.$console.log(error); })
this.isSelectedTermsLoading = false; .catch((error) => {
}); this.$console.log(error);
} this.isSelectedTermsLoading = false;
} else { });
this.isSelectedTermsLoading = false;
} }
} }
}, },
saveSelectedTagName(value, label){ getTermsFromTaxonomy() {
if(!this.selectedTagsName[value]) { this.terms = [];
this.$set(this.selectedTagsName, `${value}`, label);
const endpoint = '/taxonomy/' + this.taxonomyId + '/terms?hideempty=0&order=asc&number=' + this.termsNumber + '&offset=' + this.offset;
axios.get(endpoint)
.then( res => {
this.totalTerms = Number(res.headers['x-wp-total']);
this.offset += this.termsNumber;
for (let item of res.data)
this.terms.push( item );
this.options = this.getOptions(0);
})
.catch(error => {
this.$console.log(error);
});
},
getOptions(parent, level = 0) { // retrieve only ids
let result = [];
if (this.terms) {
for (let term of this.terms){
if (term.parent == parent){
term['level'] = level;
result.push(term);
const levelTerm = level + 1;
const children = this.getOptions( term.id, levelTerm);
result = result.concat(children);
}
}
} }
return result;
},
openCheckboxModal() {
this.$buefy.modal.open({
parent: this,
component: CheckboxRadioModal,
props: {
isFilter: false,
parent: 0,
taxonomy_id: this.taxonomyId,
selected: !this.value ? [] : this.value,
metadatumId: this.metadatum.id,
taxonomy: this.taxonomy,
collectionId: this.metadatum.collection_id,
isTaxonomy: true,
query: '',
metadatum: this.metadatum,
isCheckbox: true
},
events: {
input: (selected) => {
this.value = selected;
this.$emit('input', this.value);
}
},
width: 'calc(100% - 8.333333333%)',
trapFocus: true
});
} }
}, },
mounted() { mounted() {
@ -123,7 +213,7 @@
} }
</script> </script>
<style> <style scoped lang="scss">
.selected-tags { .selected-tags {
margin-top: 0.75rem; margin-top: 0.75rem;
font-size: 0.75rem; font-size: 0.75rem;
@ -138,4 +228,18 @@
border-right-color: #dbdbdb !important; border-right-color: #dbdbdb !important;
border-top-color: #dbdbdb !important; border-top-color: #dbdbdb !important;
} }
.metadata-taxonomy-list {
column-count: 2;
margin: 10px;
label {
break-inside: avoid;
padding-right: 10px;
}
}
.view-all {
color: #898d8f;
margin-bottom: 20px;
font-size: 0.75rem;
}
</style> </style>

View File

@ -3,7 +3,7 @@
<p <p
v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')" v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')"
class="has-text-gray"> class="has-text-gray">
{{ $i18n.get('label_selected_terms') + ' :' }} {{ $i18n.get('label_selected_term') + ':' }}
</p> </p>
<b-field <b-field
v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')" v-if="value instanceof Array ? value.length > 0 : (value != undefined && value != '')"
@ -24,43 +24,79 @@
v-if="isSelectedTermsLoading" v-if="isSelectedTermsLoading"
class="control has-icons-right is-loading is-clearfix" /> class="control has-icons-right is-loading is-clearfix" />
</b-field> </b-field>
<b-radio <p
:disabled="disabled" style="margin-top: 10px;"
:id="id" class="has-text-gray">
v-model="checked" {{ (isShowingAllTerms ? $i18n.get('label_available_terms') : $i18n.get('label_some_available_terms')) + ':' }}
@input="onChecked()" </p>
:native-value="''" <div class="metadata-taxonomy-list">
border>
{{ $i18n.get('clear_radio') }}
</b-radio>
<div
v-for="(option, index) in options"
:key="index">
<b-radio <b-radio
:disabled="disabled" :disabled="disabled"
:id="id" :id="metadatum.metadata_type_object.component + '-' + metadatum.slug"
:style="{ paddingLeft: (option.level * 30) + 'px' }"
:key="index"
v-model="checked" v-model="checked"
@input="onChecked(option)" @input="onChecked()"
:native-value="option.id" :native-value="''"
border> border>
{{ option.name }} {{ $i18n.get('clear_radio') }}
</b-radio> </b-radio>
<br> <template
:id="metadatum.metadata_type_object.component + '-' + metadatum.slug"
v-for="(option, index) in options">
<b-radio
:disabled="disabled"
:style="{ marginLeft: 0, paddingLeft: (option.level * 30) + 'px' }"
:key="index"
v-model="checked"
@input="onChecked(option)"
:native-value="option.id"
border>
{{ option.name }}
</b-radio>
<br :key="index">
</template>
</div>
<div
v-if="!isShowingAllTerms"
class="view-all">
<span>
{{
$i18n.get('info_showing_terms') + 1 +
$i18n.get('info_to') + options.length +
$i18n.get('info_of') + totalTerms + '. '
}}
</span>
<a @click="openCheckboxModal()">
{{ $i18n.get('label_view_all') + ' ' + totalTerms + '.' }}
</a>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { tainacan as axios } from '../../../js/axios/axios'; import { tainacan as axios } from '../../../js/axios/axios';
import qs from 'qs';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue'
export default { export default {
data(){ created() {
this.getTermsFromTaxonomy();
this.$parent.$on('update-taxonomy-inputs', ($event) => {
if ($event.taxonomyId == this.taxonomyId && $event.metadatumId == this.metadatum.metadatum.id) {
this.offset = 0;
this.getTermsFromTaxonomy();
}
});
},
data() {
return { return {
checked: ( this.value ) ? this.value : '', checked: this.value ? this.value : '',
selectedTagsName: {}, selectedTagsName: {},
isSelectedTermsLoading: false, isSelectedTermsLoading: false,
options: [],
terms: [],
termsNumber: 12,
offset: 0,
totalTerms: 0
} }
}, },
watch: { watch: {
@ -69,60 +105,147 @@
this.fetchSelectedLabels(); this.fetchSelectedLabels();
} }
}, },
computed: {
isShowingAllTerms() {
return this.terms.length >= this.totalTerms;
}
},
props: { props: {
options: {
type: Array
},
value: [ Number, String, Array ], value: [ Number, String, Array ],
disabled: false, disabled: false,
taxonomyId: Number taxonomyId: Number,
metadatum: Object
}, },
methods: { methods: {
onChecked() { onChecked() {
this.$emit('blur');
this.onInput(this.checked) this.onInput(this.checked)
}, },
onInput($event) { onInput($event) {
this.inputValue = $event; this.value = $event;
this.$emit('input', this.inputValue); this.$emit('input', this.value);
}, },
fetchSelectedLabels() { fetchSelectedLabels() {
if (this.value != null && this.value != undefined) { if (this.value != null && this.value != undefined) {
this.isSelectedTermsLoading = true; const selected = this.value instanceof Array ? this.value : [this.value];
let selected = this.value instanceof Array ? this.value : [this.value];
if (this.taxonomyId && selected.length > 0) { if (this.taxonomyId && selected.length > 0) {
for (const term of selected) { this.isSelectedTermsLoading = true;
if(!this.isSelectedTermsLoading){ axios.get(`/taxonomy/${this.taxonomyId}/terms/?${qs.stringify({ hideempty: 0, include: selected })}`)
this.isSelectedTermsLoading = true; .then((res) => {
} let terms = res.data;
axios.get(`/taxonomy/${this.taxonomyId}/terms/${term}`) for (let term of terms) {
.then((res) => { if (!this.selectedTagsName[term.id])
this.saveSelectedTagName(res.data.id, res.data.name); this.$set(this.selectedTagsName, term.id, term.name);
this.isSelectedTermsLoading = false; }
})
.catch((error) => { this.isSelectedTermsLoading = false;
this.$console.log(error); })
this.isSelectedTermsLoading = false; .catch((error) => {
}); this.$console.log(error);
} this.isSelectedTermsLoading = false;
} else { });
this.isSelectedTermsLoading = false;
} }
} }
}, },
saveSelectedTagName(value, label){ getTermsFromTaxonomy() {
if(!this.selectedTagsName[value]) { this.terms = [];
this.$set(this.selectedTagsName, `${value}`, label);
const endpoint = '/taxonomy/' + this.taxonomyId + '/terms?hideempty=0&order=asc&number=' + this.termsNumber + '&offset=' + this.offset;
axios.get(endpoint)
.then( res => {
this.totalTerms = Number(res.headers['x-wp-total']);
this.offset += this.termsNumber;
for (let item of res.data)
this.terms.push( item );
this.options = this.getOptions(0);
})
.catch(error => {
this.$console.log(error);
});
},
getOptions(parent, level = 0) { // retrieve only ids
let result = [];
if (this.terms) {
for (let term of this.terms){
if (term.parent == parent){
term['level'] = level;
result.push(term);
const levelTerm = level + 1;
const children = this.getOptions( term.id, levelTerm);
result = result.concat(children);
}
}
} }
return result;
},
openCheckboxModal() {
this.$buefy.modal.open({
parent: this,
component: CheckboxRadioModal,
props: {
isFilter: false,
parent: 0,
taxonomy_id: this.taxonomyId,
selected: !this.value ? [] : this.value,
metadatumId: this.metadatum.metadatum.id,
taxonomy: this.taxonomy,
collectionId: this.metadatum.collection_id,
isTaxonomy: true,
query: '',
metadatum: this.metadatum.metadatum,
isCheckbox: false
},
events: {
input: (selected) => {
this.value = selected;
this.$emit('input', this.value);
}
},
width: 'calc(100% - 8.333333333%)',
trapFocus: true
});
} }
}, },
mounted() { mounted() {
this.fetchSelectedLabels(); this.fetchSelectedLabels();
} }
} }
</script> </script>
<style lang="scss" scoped>
.selected-tags {
margin-top: 0.75rem;
font-size: 0.75rem;
position: relative;
}
.selected-tags .is-loading {
margin-left: 2rem;
margin-top: -0.4rem;
}
.selected-tags .is-loading::after {
border: 2px solid #555758 !important;
border-right-color: #dbdbdb !important;
border-top-color: #dbdbdb !important;
}
.metadata-taxonomy-list {
column-count: 2;
margin: 10px;
label {
break-inside: avoid;
padding-right: 10px;
}
}
.view-all {
color: #898d8f;
margin-bottom: 20px;
font-size: 0.75rem;
}
</style>

View File

@ -1,6 +1,7 @@
<template> <template>
<div class="block"> <div class="block">
<b-taginput <b-taginput
:id="metadatumComponentId"
:disabled="disabled" :disabled="disabled"
size="is-small" size="is-small"
icon="magnify" icon="magnify"
@ -36,16 +37,14 @@
}, },
watch: { watch: {
selected(){ selected(){
if(this.allowSelectToCreate && this.selected[0]){ if (this.allowSelectToCreate && this.selected[0]) {
this.selected[0].label.includes(`(${this.$i18n.get('select_to_create')})`); this.selected[0].label.includes(`(${this.$i18n.get('select_to_create')})`);
this.selected[0].label = this.selected[0].label.split('(')[0]; this.selected[0].label = this.selected[0].label.split('(')[0];
} }
} }
}, },
props: { props: {
options: { metadatumComponentId: '',
type: Array
},
value: [ Number, String, Array ], value: [ Number, String, Array ],
allowNew: true, allowNew: true,
taxonomyId: Number, taxonomyId: Number,
@ -54,7 +53,7 @@
maxtags: '', maxtags: '',
}, },
created(){ created(){
if(this.value && this.value.length > 0){ if (this.value && this.value.length > 0){
this.selected = this.value; this.selected = this.value;
} }
}, },
@ -85,13 +84,11 @@
}).then((res) => { }).then((res) => {
this.termList = res.terms; this.termList = res.terms;
for(let term of this.termList){ for (let term of this.termList)
this.labels.push({label: term.name, value: term.id}); this.labels.push({label: term.name, value: term.id});
}
if(this.termList.length <= 0 && this.allowSelectToCreate){ if (this.termList.length <= 0 && this.allowSelectToCreate)
this.labels.push({label: `${value} (${this.$i18n.get('select_to_create')})`, value: value}) this.labels.push({label: `${value} (${this.$i18n.get('select_to_create')})`, value: value})
}
this.isFetching = false; this.isFetching = false;
}).catch((error) => { }).catch((error) => {
@ -102,9 +99,8 @@
updateSelectedValues(){ updateSelectedValues(){
let selected = []; let selected = [];
for( let term of this.value){ for( let term of this.value)
selected.push({label: term.label, value: term.value}) selected.push({label: term.label, value: term.value})
}
this.selected = selected; this.selected = selected;
}, },
@ -117,7 +113,6 @@
results.push( term.value ); results.push( term.value );
this.$emit('input', results); this.$emit('input', results);
this.$emit('blur');
} }
}, },
emitRemove(){ emitRemove(){
@ -128,7 +123,6 @@
results.push(term.value); results.push(term.value);
this.$emit('input', results); this.$emit('input', results);
this.$emit('blur');
} }
} }
} }

View File

@ -184,6 +184,7 @@ class Taxonomy extends Metadata_Type {
// TODO term_exists is not fully reliable. Use $terms_repository->term_exists. see issue #159 // TODO term_exists is not fully reliable. Use $terms_repository->term_exists. see issue #159
if (!term_exists($term)) { if (!term_exists($term)) {
$valid = false; $valid = false;
$this->add_error(__('term not found.', 'tainacan'));
break; break;
} }
} }

View File

@ -1,21 +1,16 @@
<template> <template>
<b-input <b-input
:disabled="disabled" :disabled="disabled"
:class="{'has-content': value !== undefined && value !== ''}" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
:id="id"
:value="value" :value="value"
@blur="$emit('blur')"
@input="onInput($event)"/> @input="onInput($event)"/>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
metadatum: { metadatum: Object,
type: Object
},
value: [String, Number, Array], value: [String, Number, Array],
id: '',
disabled: false disabled: false
}, },
methods: { methods: {

View File

@ -1,42 +1,22 @@
<template> <template>
<b-input <b-input
:disabled="disabled" :disabled="disabled"
:class="{'has-content': inputValue !== undefined && inputValue !== ''}" :id="metadatum.metadatum.metadata_type_object.component + '-' + metadatum.metadatum.slug"
:id="id" :value="value"
size="is-small" @input="onInput($event)"
type="textarea" type="textarea" />
:value="inputValue"
@blur="onBlur"
@input="onInput($event)"/>
</template> </template>
<script> <script>
export default { export default {
created(){
if( this.value ){
this.inputValue = this.value
}
},
data() {
return {
inputValue: ''
}
},
props: { props: {
id: '', metadatum: Object,
metadatum: {
type: Object
},
value: [String, Number, Array], value: [String, Number, Array],
disabled: false disabled: false
}, },
methods: { methods: {
onBlur() { onInput(value) {
this.$emit('blur'); this.$emit('input', value);
},
onInput($event) {
this.inputValue = $event;
this.$emit('input', this.inputValue);
} }
} }
} }

View File

@ -283,7 +283,10 @@ class Terms extends Repository {
* @return bool|WP_Term return boolean indicating if term exists. If $return_term is true and term exists, return WP_Term object * @return bool|WP_Term return boolean indicating if term exists. If $return_term is true and term exists, return WP_Term object
*/ */
public function term_exists($searched_term, $taxonomy, $parent = null, $return_term = false) { public function term_exists($searched_term, $taxonomy, $parent = null, $return_term = false) {
if ($searched_term == "") {
return false;
}
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
if ( is_numeric( $taxonomy ) ) { if ( is_numeric( $taxonomy ) ) {

View File

@ -240,7 +240,7 @@ export default {
this.termsRequestSource = axios.CancelToken.source(); this.termsRequestSource = axios.CancelToken.source();
let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ include: this.selectedTerms }) + '&fetch_only=id,name,url,header_image'; let endpoint = '/taxonomy/' + this.taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: this.selectedTerms }) + '&fetch_only=id,name,url,header_image';
this.tainacanAxios.get(endpoint, { cancelToken: this.termsRequestSource.token }) this.tainacanAxios.get(endpoint, { cancelToken: this.termsRequestSource.token })
.then(response => { .then(response => {

View File

@ -210,7 +210,7 @@ registerBlockType('tainacan/carousel-terms-list', {
terms = []; terms = [];
let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ include: selectedTerms }) + '&fetch_only=id,name,url,header_image'; let endpoint = '/taxonomy/' + taxonomyId + '/terms/?'+ qs.stringify({ hideempty: 0, include: selectedTerms }) + '&fetch_only=id,name,url,header_image';
tainacan.get(endpoint, { cancelToken: itemsRequestSource.token }) tainacan.get(endpoint, { cancelToken: itemsRequestSource.token })
.then(response => { .then(response => {

View File

@ -15,51 +15,46 @@ export const eventBus = new Vue({
} }
}, },
methods : { methods : {
updateValue(data){ updateValue({ itemId, metadatumId, values}){
this.$emit('isUpdatingValue', true); this.$emit('isUpdatingValue', true);
if (data.item_id) { if (itemId) {
if (data.values.length > 0 && data.values[0].value) { if (values.length > 0 && values[0].value) {
let val = []; let onlyValues = values.map((aValueObject) => aValueObject.value);
for (let i of data.values) values = onlyValues;
val.push(i.value); }
data.values = val;
}
let values = ( Array.isArray( data.values[0] ) ) ? data.values[0] : data.values ;
this.$store.dispatch('item/updateMetadata', { this.$store.dispatch('item/updateMetadata', {
item_id: data.item_id, item_id: itemId,
metadatum_id: data.metadatum_id, metadatum_id: metadatumId,
values: values values: Array.isArray(values[0]) ? values[0] : values
}) })
.then(() => { .then(() => {
this.$emit('isUpdatingValue', false); this.$emit('isUpdatingValue', false);
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id ); let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId );
if ( index >= 0) if (index >= 0)
this.errors.splice( index, 1); this.errors.splice( index, 1);
}) })
.catch((error) => { .catch((error) => {
this.$emit('isUpdatingValue', false); this.$emit('isUpdatingValue', false);
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == data.metadatum_id ); let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId );
let messages = []; let messages = [];
for (let index in error) for (let index in error)
messages.push(error[index]); messages.push(error[index]);
if ( index >= 0) if ( index >= 0)
Vue.set( this.errors, index, { metadatum_id: data.metadatum_id, errors: messages }); Vue.set( this.errors, index, { metadatum_id: metadatumId, errors: messages });
else else
this.errors.push( { metadatum_id: data.metadatum_id, errors: messages } ); this.errors.push( { metadatum_id: metadatumId, errors: messages } );
}); });
} }
}, },
getErrors(metadatum_id) { getErrors(metadatum_id) {
let error = this.errors.find( errorItem => errorItem.metadatum_id == metadatum_id ); let error = this.errors.find(errorItem => errorItem.metadatum_id == metadatum_id);
return ( error ) ? error.errors : false return error ? error.errors : false
}, },
clearAllErrors() { clearAllErrors() {
this.errors = []; this.errors = [];

View File

@ -1,7 +1,7 @@
import axios from '../../../axios/axios'; import axios from '../../../axios/axios';
import qs from 'qs'; import qs from 'qs';
export const fetchActivities = ({ commit }, { page, activitiesPerPage, search, searchDates} ) => { export const fetchActivities = ({ commit }, { page, activitiesPerPage, search, searchDates, authorId} ) => {
let endpoint = `/logs?paged=${page}&perpage=${activitiesPerPage}&context=edit&orderby=id&order=desc`; let endpoint = `/logs?paged=${page}&perpage=${activitiesPerPage}&context=edit&orderby=id&order=desc`;
@ -21,6 +21,19 @@ export const fetchActivities = ({ commit }, { page, activitiesPerPage, search, s
endpoint += '&' + qs.stringify(dateQuery); endpoint += '&' + qs.stringify(dateQuery);
} }
if (authorId != undefined && authorId != null) {
let metaQuery = {
metaquery: [
{
value: authorId,
key: 'user_id',
compare: '='
}
]
};
endpoint += '&' + qs.stringify(metaQuery);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.get(endpoint) axios.tainacan.get(endpoint)
.then(res => { .then(res => {
@ -37,7 +50,7 @@ export const fetchActivities = ({ commit }, { page, activitiesPerPage, search, s
}); });
}; };
export const fetchCollectionActivities = ({ commit }, { page, activitiesPerPage, collectionId, search, searchDates }) => { export const fetchCollectionActivities = ({ commit }, { page, activitiesPerPage, collectionId, search, searchDates, authorId }) => {
let endpoint = `/collection/${collectionId}/logs?paged=${page}&perpage=${activitiesPerPage}&context=edit&orderby=id&order=desc`; let endpoint = `/collection/${collectionId}/logs?paged=${page}&perpage=${activitiesPerPage}&context=edit&orderby=id&order=desc`;
@ -57,6 +70,19 @@ export const fetchCollectionActivities = ({ commit }, { page, activitiesPerPage,
endpoint += '&' + qs.stringify(dateQuery); endpoint += '&' + qs.stringify(dateQuery);
} }
if (authorId != undefined && authorId != null) {
let metaQuery = {
metaquery: [
{
value: authorId,
key: 'user_id',
compare: '='
}
]
};
endpoint += '&' + qs.stringify(metaQuery);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.get(endpoint) axios.tainacan.get(endpoint)
.then(res => { .then(res => {
@ -73,13 +99,26 @@ export const fetchCollectionActivities = ({ commit }, { page, activitiesPerPage,
}); });
}; };
export const fetchItemActivities = ({ commit }, { page, activitiesPerPage, itemId, search, searchDates }) => { export const fetchItemActivities = ({ commit }, { page, activitiesPerPage, itemId, search, searchDates, authorId }) => {
let endpoint = `/item/${itemId}/logs?paged=${page}&perpage=${activitiesPerPage}&context=edit&orderby=id&order=desc`; let endpoint = `/item/${itemId}/logs?paged=${page}&perpage=${activitiesPerPage}&context=edit&orderby=id&order=desc`;
if (search != undefined && search != '') if (search != undefined && search != '')
endpoint += `&search=${search}`; endpoint += `&search=${search}`;
if (authorId != undefined && authorId != null) {
let metaQuery = {
metaquery: [
{
value: authorId,
key: 'user_id',
compare: '='
}
]
};
endpoint += '&' + qs.stringify(metaQuery);
}
if (searchDates && searchDates[0] != null && searchDates[1] != null) { if (searchDates && searchDates[0] != null && searchDates[1] != null) {
let dateQuery = { let dateQuery = {
datequery: [ datequery: [
@ -154,4 +193,17 @@ export const approve = ({commit}, activityId) => {
export const notApprove = ({commit}, activityId) => { export const notApprove = ({commit}, activityId) => {
};
// Users for filtering
export const fetchUsers = ({ commit }, { search }) => {
return new Promise((resolve, reject) => {
axios.wp.get('/users?search=' + search)
.then(res => {
resolve(res.data);
})
.catch(error => {
reject(error);
});
});
}; };

View File

@ -296,7 +296,7 @@ export const clearTerms = ({ commit }) => {
// Used only on Term Edition form, for autocomplete searhc for parents // Used only on Term Edition form, for autocomplete searhc for parents
export const fetchPossibleParentTerms = ({ commit }, { taxonomyId, termId, search } ) => { export const fetchPossibleParentTerms = ({ commit }, { taxonomyId, termId, search } ) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms?searchterm=' + search + '&hierarchical=1&exclude_tree=' + termId + "&hideempty=0&offset=0&number=20") axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms?searchterm=' + search + '&hierarchical=1&exclude_tree=' + termId + "&hideempty=0&offset=0&number=20&order=asc")
.then(res => { .then(res => {
let parentTerms = res.data; let parentTerms = res.data;
resolve( parentTerms ); resolve( parentTerms );

View File

@ -8,11 +8,11 @@ Stable tag: 0.13
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html License URI: http://www.gnu.org/licenses/gpl-3.0.html
Tainacan is a powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. Tainacan is an open source, powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform.
== Description == == Description ==
Tainacan is a powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform. [Tainacan](https://tainacan.org/) is an open source, powerful and flexible repository platform for WordPress. Manage and publish your digital collections just as easily as you post to your blog, having all the tools of a professional repository platform.
= Features = = Features =
@ -76,6 +76,11 @@ Upload the files to the plugins directory and activate it. You can also install
If you have Imagick installed in your server, Tainacan will be able to automatically generate a thumbnail from your PDF files. This is desired but not required. If you have Imagick installed in your server, Tainacan will be able to automatically generate a thumbnail from your PDF files. This is desired but not required.
== Find out more ==
* Visit our oficial website: [https://tainacan.org/](https://tainacan.org/)
* Check our documentation Wiki: [https://wiki.tainacan.org/](https://wiki.tainacan.org/)
== Screenshots == == Screenshots ==
1. Manage your repository 1. Manage your repository

View File

@ -2,7 +2,7 @@
/* /*
Plugin Name: Tainacan Plugin Name: Tainacan
Plugin URI: https://tainacan.org/ Plugin URI: https://tainacan.org/
Description: powerfull and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional respository platform. Description: Open source, powerfull and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional respository platform.
Author: Tainacan.org Author: Tainacan.org
Version: 0.13 Version: 0.13
Text Domain: tainacan Text Domain: tainacan

View File

@ -575,6 +575,98 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
} }
public function test_update_taxonomy_metadata() {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'test_col',
'status' => 'publish'
),
true
);
$tax = $this->tainacan_entity_factory->create_entity(
'taxonomy',
array(
'name' => 'tax_test',
'collections' => [$collection],
'status' => 'publish'
),
true
);
$this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $tax->get_db_identifier(),
'name' => 'Rock',
'user' => 56
),
true
);
$this->tainacan_entity_factory->create_entity(
'term',
array(
'taxonomy' => $tax->get_db_identifier(),
'name' => 'Samba',
'user' => 56
),
true
);
$metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'tax',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Taxonomy',
'metadata_type_options' => [
'taxonomy_id' => $tax->get_id(),
]
),
true
);
$i1 = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'item teste',
'description' => 'adasdasdsa',
'collection' => $collection
),
true
);
$itemMeta1 = new \Tainacan\Entities\Item_Metadata_Entity($i1, $metadatum);
$itemMeta1->set_value('Rock');
$itemMeta1->validate();
$Tainacan_Item_Metadata->insert($itemMeta1);
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/item/' . $i1->get_id() . '/metadata/' . $metadatum->get_id()
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals(false, empty($data['value']));
$request = new \WP_REST_Request(
'PATCH',
$this->namespace . '/item/' . $i1->get_id() . '/metadata/' . $metadatum->get_id()
);
$attributes = json_encode(['values' => '']);
$request->set_body($attributes);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals(true, empty($data['value']));
}
} }
?> ?>