diff --git a/src/views/admin/components/filter-types/taginput/Taginput.vue b/src/views/admin/components/filter-types/taginput/Taginput.vue index 138b38bcd..b8b862d0c 100644 --- a/src/views/admin/components/filter-types/taginput/Taginput.vue +++ b/src/views/admin/components/filter-types/taginput/Taginput.vue @@ -68,7 +68,7 @@ getInputPlaceholder() { if (this.metadatumType == 'Tainacan\\Metadata_Types\\Relationship') return this.$i18n.get('info_type_to_add_items'); - else if (this.metadatumType == 'Tainacan\\Metadata_Types\\Core_Author') + else if (this.metadatumType == 'Tainacan\\Metadata_Types\\User') return this.$i18n.get('info_type_to_add_users'); else return this.$i18n.get('info_type_to_add_metadata'); @@ -125,7 +125,7 @@ if (this.getOptionsValuesCancel != undefined) this.getOptionsValuesCancel.cancel('Facet search Canceled.'); - if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' || this.metadatumType === 'Tainacan\\Metadata_Types\\Core_Author' ) + if ( this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship' || this.metadatumType === 'Tainacan\\Metadata_Types\\User' ) promise = this.getValuesRelationship( this.searchQuery, this.isRepositoryLevel, valuesToIgnore, this.searchOffset, this.searchNumber ); else promise = this.getValuesPlainText( this.metadatumId, this.searchQuery, this.isRepositoryLevel, valuesToIgnore, this.searchOffset, this.searchNumber ); @@ -189,7 +189,7 @@ .catch(error => { this.$console.log(error); }); - } else if (this.metadatumType === 'Tainacan\\Metadata_Types\\Core_Author') { + } else if (this.metadatumType === 'Tainacan\\Metadata_Types\\User') { let query = qs.stringify({ include: metadata.value }); let endpoint = '/users/'; diff --git a/src/views/admin/components/metadata-types/numeric/Numeric.vue b/src/views/admin/components/metadata-types/numeric/Numeric.vue index 9b58a8514..7efd51ee2 100644 --- a/src/views/admin/components/metadata-types/numeric/Numeric.vue +++ b/src/views/admin/components/metadata-types/numeric/Numeric.vue @@ -9,7 +9,7 @@ lang="en" :step="getStep"/> -itemMetadatum + diff --git a/src/views/admin/components/metadata-types/user/class-tainacan-user.php b/src/views/admin/components/metadata-types/user/class-tainacan-user.php index 0d6b3ea2d..f1ad14309 100644 --- a/src/views/admin/components/metadata-types/user/class-tainacan-user.php +++ b/src/views/admin/components/metadata-types/user/class-tainacan-user.php @@ -17,8 +17,9 @@ class User extends Metadata_Type { parent::__construct(); $this->set_primitive_type('user'); $this->set_component('tainacan-user'); + $this->set_form_component('tainacan-form-user'); $this->set_name( __('User', 'tainacan') ); - $this->set_description( __('A registered user on wordpress', 'tainacan') ); + $this->set_description( __('A registered user on WordPress', 'tainacan') ); $this->set_preview_template('
@@ -28,24 +29,17 @@ class User extends Metadata_Type { '); } - /** - * generate the metadata for this metadatum type - */ - public function form() { - - } - function user_exists($user) { // if( !is_int($user) ) // return username_exists($user) !== false; - global $wpdb; - // Check cache: - if (wp_cache_get($user, 'users')) return true; - // Check database: - if ($wpdb->get_var($wpdb->prepare("SELECT EXISTS (SELECT 1 FROM $wpdb->users WHERE ID = %d)", $user))) - return true; - return false; + global $wpdb; + // Check cache: + if (wp_cache_get($user, 'users')) return true; + // Check database: + if ($wpdb->get_var($wpdb->prepare("SELECT EXISTS (SELECT 1 FROM $wpdb->users WHERE ID = %d)", $user))) + return true; + return false; } /** @@ -73,6 +67,18 @@ class User extends Metadata_Type { return true; } + /** + * @inheritdoc + */ + public function get_form_labels(){ + return [ + 'default_author' => [ + 'title' => __( 'Defaults to author user', 'tainacan' ), + 'description' => __( 'This sets the default value of this metadata as the current item author.', 'tainacan' ), + ] + ]; + } + public function validate_options( Metadatum $metadatum ) { if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) ) { return true; diff --git a/src/views/admin/components/modals/bulk-edition-modal.vue b/src/views/admin/components/modals/bulk-edition-modal.vue index e2c2110d8..64f5fe0ee 100644 --- a/src/views/admin/components/modals/bulk-edition-modal.vue +++ b/src/views/admin/components/modals/bulk-edition-modal.vue @@ -537,12 +537,7 @@ let validEditionActions = {}; for (let [actionKey, action] of Object.entries(isMultiple ? this.editionActionsForMultiple : this.editionActionsForNotMultiple)) { - if ( (metadatumID != 'status' && - metadatumID != 'comments' && - (this.getMetadataByID(metadatumID) && this.getMetadataByID(metadatumID).metadata_type_object && this.getMetadataByID(metadatumID).metadata_type_object.component !== 'tainacan-author') - ) || - actionKey != 'clear' - ) + if ((metadatumID != 'status' && metadatumID != 'comments') || actionKey != 'clear') validEditionActions[actionKey] = action; } diff --git a/src/views/admin/js/main.js b/src/views/admin/js/main.js index 9386edf94..8b225df4a 100644 --- a/src/views/admin/js/main.js +++ b/src/views/admin/js/main.js @@ -26,6 +26,7 @@ import FormRelationship from '../components/metadata-types/relationship/FormRela import FormTaxonomy from '../components/metadata-types/taxonomy/FormTaxonomy.vue'; import FormSelectbox from '../components/metadata-types/selectbox/FormSelectbox.vue'; import FormNumeric from '../components/metadata-types/numeric/FormNumeric.vue'; +import FormUser from '../components/metadata-types/user/FormUser.vue'; import FilterNumeric from '../components/filter-types/numeric/Numeric.vue'; import FilterDate from '../components/filter-types/date/Date.vue'; @@ -102,6 +103,7 @@ Vue.component('tainacan-form-relationship', FormRelationship); Vue.component('tainacan-form-taxonomy', FormTaxonomy); Vue.component('tainacan-form-selectbox', FormSelectbox); Vue.component('tainacan-form-numeric', FormNumeric); +Vue.component('tainacan-form-user', FormUser); /* Filters */ Vue.component('tainacan-filter-numeric', FilterNumeric); diff --git a/src/views/admin/js/store/modules/search/actions.js b/src/views/admin/js/store/modules/search/actions.js index 8bd1802e2..7b56b6862 100644 --- a/src/views/admin/js/store/modules/search/actions.js +++ b/src/views/admin/js/store/modules/search/actions.js @@ -107,7 +107,7 @@ export const setOrderBy = ({ state, commit }, orderBy ) => { commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } ); commit('setPostQueryAttribute', { attr: 'metatype', value: 'DATETIME' } ); } else if (orderBy.metadata_type_object.core) { - commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.metadata_type_object.related_mapped_prop == 'author_id' ? 'author' : orderBy.metadata_type_object.related_mapped_prop } ); + commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.metadata_type_object.related_mapped_prop } ); commit('removePostQueryAttribute', 'metakey'); commit('removePostQueryAttribute', 'metatype'); } else { diff --git a/src/views/admin/pages/lists/items-page.vue b/src/views/admin/pages/lists/items-page.vue index 680b32e66..ec1d9bbe4 100644 --- a/src/views/admin/pages/lists/items-page.vue +++ b/src/views/admin/pages/lists/items-page.vue @@ -704,7 +704,7 @@ if ( ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug == 'creation_date' && (!metadatum.metadata_type_object || !metadatum.metadata_type_object.core)) && this.orderBy == 'date') || - ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug != 'creation_date' && (metadatum.metadata_type_object != undefined && metadatum.metadata_type_object.core)) && this.orderBy == (metadatum.metadata_type_object.related_mapped_prop == 'author_id' ? 'author' : metadatum.metadata_type_object.related_mapped_prop)) || + ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug != 'creation_date' && (metadatum.metadata_type_object != undefined && metadatum.metadata_type_object.core)) && this.orderBy == metadatum.metadata_type_object.related_mapped_prop) || ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug != 'creation_date' && (!metadatum.metadata_type_object || !metadatum.metadata_type_object.core)) && this.orderBy == metadatum.slug) || ((this.orderBy == 'meta_value' || this.orderBy == 'meta_value_num') && this.getMetaKey() == metadatum.id) ) @@ -1002,15 +1002,6 @@ id: undefined, display: true }); - metadata.push({ - name: this.$i18n.get('label_author'), - metadatum: 'row_author', - metadata_type_object: {core: true, related_mapped_prop: 'author_id'}, - metadata_type: undefined, - slug: 'author', - id: undefined, - display: true - }); } let fetchOnlyMetadatumIds = []; diff --git a/src/views/admin/pages/lists/metadata-page.vue b/src/views/admin/pages/lists/metadata-page.vue index e36f94ab3..5f6f875b9 100644 --- a/src/views/admin/pages/lists/metadata-page.vue +++ b/src/views/admin/pages/lists/metadata-page.vue @@ -96,24 +96,10 @@ + class="label-details" + :class="{ 'has-text-weight-bold': metadatum.metadata_type_object.core }"> ({{ metadatum.metadata_type_object.name }}) {{ $i18n.get('label_inherited') }} - - {{ $i18n.get('label_core_title') }} - - - {{ $i18n.get('label_core_description') }} - - - {{ $i18n.get('label_core_author') }} - diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index 5c729ce9e..976c9af07 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -231,7 +231,6 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_inherited' => __( 'Inherited', 'tainacan' ), 'label_core_title' => __( 'Core Title', 'tainacan' ), 'label_core_description' => __( 'Core Description', 'tainacan' ), - 'label_core_author' => __( 'Core Author', 'tainacan' ), 'label_sorting' => __( 'Sorting', 'tainacan' ), 'label_sorting_direction' => __( 'Sorting direction', 'tainacan' ), 'label_sort' => __( 'Sort', 'tainacan' ), @@ -460,6 +459,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_associated_roles' => __( 'Associated roles', 'tainacan' ), 'label_inherited_roles' => __( 'Inherited roles', 'tainacan' ), 'label_editing_capabilitiy' => __( 'Editing capabilitiy', 'tainacan' ), + 'label_default_author_user' => __( 'Set the item author as default value', 'tainacan' ), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), diff --git a/src/views/theme-search/pages/theme-items-page.vue b/src/views/theme-search/pages/theme-items-page.vue index f9143d70d..7b9c03c90 100644 --- a/src/views/theme-search/pages/theme-items-page.vue +++ b/src/views/theme-search/pages/theme-items-page.vue @@ -629,7 +629,7 @@ for (let metadatum of this.sortingMetadata) { if ( ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug == 'creation_date' && (!metadatum.metadata_type_object || !metadatum.metadata_type_object.core)) && this.orderBy == 'date') || - ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug != 'creation_date' && (metadatum.metadata_type_object != undefined && metadatum.metadata_type_object.core)) && this.orderBy == (metadatum.metadata_type_object.related_mapped_prop == 'author_id' ? 'author' : metadatum.metadata_type_object.related_mapped_prop)) || + ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug != 'creation_date' && (metadatum.metadata_type_object != undefined && metadatum.metadata_type_object.core)) && this.orderBy == metadatum.metadata_type_object.related_mapped_prop) || ((this.orderBy != 'meta_value' && this.orderBy != 'meta_value_num' && metadatum.slug != 'creation_date' && (!metadatum.metadata_type_object || !metadatum.metadata_type_object.core)) && this.orderBy == metadatum.slug) || ((this.orderBy == 'meta_value' || this.orderBy == 'meta_value_num') && this.getMetaKey() == metadatum.id) ) @@ -903,15 +903,6 @@ id: undefined, display: true }); - metadata.push({ - name: this.$i18n.get('label_author'), - metadatum: 'row_author', - metadata_type_object: {core: true, related_mapped_prop: 'author_id'}, - metadata_type: undefined, - slug: 'author', - id: undefined, - display: true - }); } let fetchOnlyMetadatumIds = [];