Adds validation to terms. Impovements in field item validation and sorting actions.
This commit is contained in:
parent
5d618064ff
commit
333a12001b
|
@ -26,18 +26,17 @@
|
||||||
v-for="(column, index) in tableFields"
|
v-for="(column, index) in tableFields"
|
||||||
:key="index"
|
:key="index"
|
||||||
:custom-key="column.slug"
|
:custom-key="column.slug"
|
||||||
:label="column.label"
|
:label="column.name"
|
||||||
:visible="column.visible"
|
:visible="column.visible"
|
||||||
:width="column.field == 'row_actions' ? 78 : column.field == 'featured_image' ? 55 : undefined ">
|
:width="column.field == 'row_actions' ? 78 : column.field == 'featured_image' ? 55 : undefined ">
|
||||||
|
|
||||||
<router-link
|
<template>
|
||||||
tag="span"
|
<span
|
||||||
class="clickable-row"
|
class="clickable-row"
|
||||||
:to="{path: $routerHelper.getItemPath(collectionId, props.row.id)}">
|
@click.prevent="goToItemPage(props.row.id)"
|
||||||
<template v-if="column.field != 'featured_image' && column.field != 'row_actions'">
|
v-if="column.field != 'featured_image' && column.field != 'row_actions'"
|
||||||
{{ showValue( props.row.metadata[column.slug] ) }}
|
v-html="renderMetadata( props.row.metadata[column.slug] )" />
|
||||||
</template>
|
</template>
|
||||||
</router-link>
|
|
||||||
|
|
||||||
<template v-if="column.field == 'featured_image'">
|
<template v-if="column.field == 'featured_image'">
|
||||||
<router-link
|
<router-link
|
||||||
|
@ -85,7 +84,7 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
</b-table>
|
</b-table>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -179,20 +178,14 @@ export default {
|
||||||
goToItemEditPage(itemId) {
|
goToItemEditPage(itemId) {
|
||||||
this.$router.push(this.$routerHelper.getItemEditPath(this.collectionId, 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 '';
|
return '';
|
||||||
|
else if (metadata)
|
||||||
if( metadata.value instanceof Array ){
|
return metadata.value_as_html;
|
||||||
let result = [];
|
else
|
||||||
for( let val of metadata.value ){
|
return metadata.value_as_html;
|
||||||
result.push( ( val.name ) ? val.name : val )
|
|
||||||
}
|
|
||||||
return result.join(', ');
|
|
||||||
} else {
|
|
||||||
return metadata.value.name ? metadata.value.name : metadata.value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
class="control"
|
class="control"
|
||||||
custom>
|
custom>
|
||||||
<b-checkbox
|
<b-checkbox
|
||||||
@input="onChangeTableFields(column)"
|
|
||||||
v-model="column.visible"
|
v-model="column.visible"
|
||||||
:native-value="column.field">
|
:native-value="column.field">
|
||||||
{{ column.label }}
|
{{ column.label }}
|
||||||
|
@ -29,10 +28,10 @@
|
||||||
:placeholder="$i18n.get('label_sorting')">
|
:placeholder="$i18n.get('label_sorting')">
|
||||||
<option
|
<option
|
||||||
v-for="(field, index) in tableFields"
|
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"
|
:value="field"
|
||||||
:key="index">
|
:key="index">
|
||||||
{{ field.label }}
|
{{ field.name }}
|
||||||
</option>
|
</option>
|
||||||
</b-select>
|
</b-select>
|
||||||
<button
|
<button
|
||||||
|
@ -46,7 +45,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions, mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
import { eventSearchBus } from '../../../js/event-search-bus';
|
import { eventSearchBus } from '../../../js/event-search-bus';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -74,21 +73,6 @@ export default {
|
||||||
'getOrderBy',
|
'getOrderBy',
|
||||||
'getOrder'
|
'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) {
|
onChangeOrderBy(field) {
|
||||||
eventSearchBus.setOrderBy(field);
|
eventSearchBus.setOrderBy(field);
|
||||||
},
|
},
|
||||||
|
|
|
@ -87,14 +87,12 @@ export default {
|
||||||
|
|
||||||
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then((res) => {
|
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then((res) => {
|
||||||
let rawFields = 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) {
|
for (let field of rawFields) {
|
||||||
this.tableFields.push(
|
this.tableFields.push(field);
|
||||||
{ label: field.name, field: field.description, slug: field.slug, field_type: field.field_type, id: field.id, visible: true }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
this.tableFields.push({ label: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
|
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.prefTableFields = this.tableFields;
|
||||||
// this.$userPrefs.get('table_columns_' + this.collectionId)
|
// this.$userPrefs.get('table_columns_' + this.collectionId)
|
||||||
// .then((value) => {
|
// .then((value) => {
|
||||||
// this.prefTableFields = value;
|
// this.prefTableFields = value;
|
||||||
|
|
|
@ -368,6 +368,10 @@ class Item extends Entity {
|
||||||
|
|
||||||
$is_valid = true;
|
$is_valid = true;
|
||||||
|
|
||||||
|
if ( parent::validate() === false ) {
|
||||||
|
$is_valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
$arrayItemMetadata = $this->get_fields();
|
$arrayItemMetadata = $this->get_fields();
|
||||||
if ( $arrayItemMetadata ) {
|
if ( $arrayItemMetadata ) {
|
||||||
foreach ( $arrayItemMetadata as $itemMetadata ) {
|
foreach ( $arrayItemMetadata as $itemMetadata ) {
|
||||||
|
|
|
@ -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() {
|
public function __toHtml() {
|
||||||
|
|
||||||
$return = '';
|
$return = '';
|
||||||
|
|
|
@ -41,8 +41,8 @@ export const setOrderBy = ({ commit }, orderBy ) => {
|
||||||
});
|
});
|
||||||
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
|
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
|
||||||
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } );
|
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } );
|
||||||
} else if (orderBy.field_type == 'Tainacan\\Field_Types\\Core_Title') {
|
} else if (orderBy.field_type == orderBy.field_type_object.core) {
|
||||||
commit('setPostQueryAttribute', { attr: 'orderby', value: 'title' } );
|
commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.field_type_object.related_mapped_prop } );
|
||||||
} else {
|
} else {
|
||||||
commit('addMetaQuery', {
|
commit('addMetaQuery', {
|
||||||
field_id: orderBy.id
|
field_id: orderBy.id
|
||||||
|
|
Loading…
Reference in New Issue