Adds validation to terms. Impovements in field item validation and sorting actions.

This commit is contained in:
Mateus Machado Luna 2018-04-09 18:39:35 -03:00
parent 5d618064ff
commit 333a12001b
6 changed files with 79 additions and 49 deletions

View File

@ -26,18 +26,17 @@
v-for="(column, index) in tableFields"
:key="index"
:custom-key="column.slug"
:label="column.label"
:label="column.name"
:visible="column.visible"
:width="column.field == 'row_actions' ? 78 : column.field == 'featured_image' ? 55 : undefined ">
<router-link
tag="span"
class="clickable-row"
:to="{path: $routerHelper.getItemPath(collectionId, props.row.id)}">
<template v-if="column.field != 'featured_image' && column.field != 'row_actions'">
{{ showValue( props.row.metadata[column.slug] ) }}
</template>
</router-link>
<template>
<span
class="clickable-row"
@click.prevent="goToItemPage(props.row.id)"
v-if="column.field != 'featured_image' && column.field != 'row_actions'"
v-html="renderMetadata( props.row.metadata[column.slug] )" />
</template>
<template v-if="column.field == 'featured_image'">
<router-link
@ -179,20 +178,14 @@ export default {
goToItemEditPage(itemId) {
this.$router.push(this.$routerHelper.getItemEditPath(this.collectionId, itemId));
},
showValue( metadata ){
renderMetadata( metadata ){
if( ! metadata || metadata.value === false || metadata.value == undefined || metadata.value == '' )
if( ! metadata || metadata.value === false || metadata.value == undefined )
return '';
if( metadata.value instanceof Array ){
let result = [];
for( let val of metadata.value ){
result.push( ( val.name ) ? val.name : val )
}
return result.join(', ');
} else {
return metadata.value.name ? metadata.value.name : metadata.value
}
else if (metadata)
return metadata.value_as_html;
else
return metadata.value_as_html;
}
}
}

View File

@ -14,7 +14,6 @@
class="control"
custom>
<b-checkbox
@input="onChangeTableFields(column)"
v-model="column.visible"
:native-value="column.field">
{{ column.label }}
@ -29,10 +28,10 @@
:placeholder="$i18n.get('label_sorting')">
<option
v-for="(field, index) in tableFields"
v-if="field.id != undefined"
v-if="field.id != undefined && field.field_type != 'Tainacan\Field_Types\Core_Description'"
:value="field"
:key="index">
{{ field.label }}
{{ field.name }}
</option>
</b-select>
<button
@ -46,7 +45,7 @@
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
import { mapGetters } from 'vuex';
import { eventSearchBus } from '../../../js/event-search-bus';
export default {
@ -74,21 +73,6 @@ export default {
'getOrderBy',
'getOrder'
]),
onChangeTableFields(field) {
// let prevValue = this.prefTableFields;
// let index = this.prefTableFields.findIndex(alteredField => alteredField.slug === field.slug);
// if (index >= 0) {
// prevValue[index].visible = this.prefTableFields[index].visible ? false : true;
// }
// for (let currentField of this.prefTableFields)
// this.$console.log(currentField.slug, currentField.visible);
// for (let oldField of prevValue)
// this.$console.log(oldField.slug, oldField.visible);
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, prevValue);
},
onChangeOrderBy(field) {
eventSearchBus.setOrderBy(field);
},

View File

@ -87,14 +87,12 @@ export default {
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then((res) => {
let rawFields = res;
this.tableFields.push({ label: this.$i18n.get('label_thumbnail'), field: 'featured_image', field_type: undefined, slug: 'featured_image', id: undefined, visible: true });
this.tableFields.push({ name: this.$i18n.get('label_thumbnail'), field: 'featured_image', field_type: undefined, slug: 'featured_image', id: undefined, visible: true });
for (let field of rawFields) {
this.tableFields.push(
{ label: field.name, field: field.description, slug: field.slug, field_type: field.field_type, id: field.id, visible: true }
);
this.tableFields.push(field);
}
this.tableFields.push({ label: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
this.prefTableFields = this.tableFields;
this.tableFields.push({ name: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
//this.prefTableFields = this.tableFields;
// this.$userPrefs.get('table_columns_' + this.collectionId)
// .then((value) => {
// this.prefTableFields = value;

View File

@ -368,6 +368,10 @@ class Item extends Entity {
$is_valid = true;
if ( parent::validate() === false ) {
$is_valid = false;
}
$arrayItemMetadata = $this->get_fields();
if ( $arrayItemMetadata ) {
foreach ( $arrayItemMetadata as $itemMetadata ) {

View File

@ -174,6 +174,57 @@ class Term extends Entity {
}
/**
*
* {@inheritDoc}
* @see \Tainacan\Entities\Entity::validate()
*/
function validate() {
if (!parent::validate())
return false;
$parent = $this->get_parent();
$name = $this->get_name();
$taxonomy = $this->get_taxonomy();
/**
* Code from WordPress Core, taxonomy.php#2070
*/
/*
* Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy,
* unless a unique slug has been explicitly provided.
*/
$name_matches = get_terms( $taxonomy, array(
'name' => $name,
'hide_empty' => false,
'parent' => $parent,
) );
/*
* The `name` match in `get_terms()` doesn't differentiate accented characters,
* so we do a stricter comparison here.
*/
$name_match = null;
if ( $name_matches ) {
foreach ( $name_matches as $_match ) {
if ( strtolower( $name ) === strtolower( $_match->name ) ) {
$name_match = $_match;
break;
}
}
}
if ($name_match) {
$this->add_error( 'repeated', __('You can not have two terms with the same name at the same level', 'tainacan') );
return false;
}
return true;
}
public function __toHtml() {
$return = '';

View File

@ -41,8 +41,8 @@ export const setOrderBy = ({ commit }, orderBy ) => {
});
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } );
} else if (orderBy.field_type == 'Tainacan\\Field_Types\\Core_Title') {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'title' } );
} else if (orderBy.field_type == orderBy.field_type_object.core) {
commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.field_type_object.related_mapped_prop } );
} else {
commit('addMetaQuery', {
field_id: orderBy.id