Hides collection filters bty default in repository level lists and adds option to enable them #824.

This commit is contained in:
mateuswetah 2023-11-10 19:10:58 -03:00
parent e6d64ac122
commit f56fb61fd4
6 changed files with 74 additions and 35 deletions

View File

@ -19,7 +19,8 @@ class Filter extends Entity {
$max_options, $max_options,
$filter_type, $filter_type,
$filter_type_options, $filter_type_options,
$begin_with_filter_collapsed; $begin_with_filter_collapsed,
$display_in_repository_level_lists;
static $post_type = 'tainacan-filter'; static $post_type = 'tainacan-filter';
public $enabled_for_collection = true; public $enabled_for_collection = true;
@ -179,6 +180,15 @@ class Filter extends Entity {
return $this->get_mapped_property('begin_with_filter_collapsed'); return $this->get_mapped_property('begin_with_filter_collapsed');
} }
/**
* Return 'yes' or 'no' to the option of display in repository level lists
*
* @return string
*/
public function get_display_in_repository_level_lists() {
return $this->get_mapped_property('display_in_repository_level_lists');
}
/** /**
* Define the filter name * Define the filter name
@ -252,6 +262,15 @@ class Filter extends Entity {
$this->set_mapped_property('begin_with_filter_collapsed', $begin_with_filter_collapsed); $this->set_mapped_property('begin_with_filter_collapsed', $begin_with_filter_collapsed);
} }
/**
* Tells if filter should appear in repository level lists, even belonging to a collection
*
* @param string $display_in_repository_level_lists
*/
public function set_display_in_repository_level_lists($display_in_repository_level_lists) {
$this->set_mapped_property('display_in_repository_level_lists', $display_in_repository_level_lists);
}
/** /**
* Transient property used to store the status of the filter for a particular collection * Transient property used to store the status of the filter for a particular collection
* *

View File

@ -79,6 +79,16 @@ class Filters extends Repository {
'enum' => [ 'yes', 'no' ], 'enum' => [ 'yes', 'no' ],
'default' => 'no' 'default' => 'no'
], ],
'display_in_repository_level_lists' => [
'map' => 'meta',
'title' => __( 'Display in repository level lists', 'tainacan' ),
'type' => 'string',
'description' => __( 'With this option enabled, the filter will appear even in repository level items lists, such as the complete items list and the term items list.', 'tainacan' ),
'on_error' => __( 'Please set the "Display in repository level lists" value as "yes" or "no"', 'tainacan' ),
'validation' => v::stringType()->in( [ 'yes', 'no' ] ), // yes or no
'enum' => [ 'yes', 'no' ],
'default' => 'no'
],
'collection_id' => [ 'collection_id' => [
'map' => 'meta', 'map' => 'meta',
'title' => __( 'Collection', 'tainacan' ), 'title' => __( 'Collection', 'tainacan' ),

View File

@ -173,6 +173,28 @@
</b-switch> </b-switch>
</b-field> </b-field>
<b-field
v-if="form.collection_id && form.collection_id !== 'default'"
:addons="false"
:label="$i18n.getHelperTitle('filters', 'display_in_repository_level_lists')"
:type="formErrors['display_in_repository_level_lists'] != undefined ? 'is-danger' : ''"
:message="formErrors['display_in_repository_level_lists'] != undefined ? formErrors['display_in_repository_level_lists'] : ''">
&nbsp;
<b-switch
size="is-small"
@input="clearErrors('display_in_repository_level_lists')"
v-model="form.display_in_repository_level_lists"
:true-value="'yes'"
:false-value="'no'"
:native-value="form.display_in_repository_level_lists == 'yes' ? 'yes' : 'no'"
name="display_in_repository_level_lists">
<help-button
:title="$i18n.getHelperTitle('filters', 'display_in_repository_level_lists')"
:message="$i18n.getHelperMessage('filters', 'display_in_repository_level_lists')"
:extra-classes="isRepositoryLevel ? 'tainacan-repository-tooltip' : ''" />
</b-switch>
</b-field>
<component <component
:errors="formErrors['filter_type_options']" :errors="formErrors['filter_type_options']"
v-if="(form.filter_type_object && form.filter_type_object.form_component) || form.edit_form == ''" v-if="(form.filter_type_object && form.filter_type_object.form_component) || form.edit_form == ''"
@ -273,11 +295,13 @@ export default {
this.isLoading = true; this.isLoading = true;
for (let [key, value] of Object.entries(this.form)) { for (let [key, value] of Object.entries(this.form)) {
if (key === 'begin_with_filter_collapsed') if (key === 'begin_with_filter_collapsed' || key === 'display_in_repository_level_lists')
this.form[key] = (value == 'yes' || value == true) ? 'yes' : 'no'; this.form[key] = (value == 'yes' || value == true) ? 'yes' : 'no';
} }
if (this.form['begin_with_filter_collapsed'] === undefined) if (this.form['begin_with_filter_collapsed'] === undefined)
this.form['begin_with_filter_collapsed'] = 'no'; this.form['begin_with_filter_collapsed'] = 'no';
if (this.form['display_in_repository_level_lists'] === undefined)
this.form['display_in_repository_level_lists'] = 'no';
this.updateFilter({ filterId: filter.id, index: this.index, options: this.form }) this.updateFilter({ filterId: filter.id, index: this.index, options: this.form })
.then(() => { .then(() => {
@ -306,13 +330,15 @@ export default {
let formObj = {}; let formObj = {};
for (let [key, value] of formData.entries()) { for (let [key, value] of formData.entries()) {
if (key === 'begin_with_filter_collapsed') if (key === 'begin_with_filter_collapsed' || key === 'display_in_repository_level_lists')
formObj[key] = (value == 'yes' || value == true) ? 'yes' : 'no'; formObj[key] = (value == 'yes' || value == true) ? 'yes' : 'no';
else else
formObj[key] = value; formObj[key] = value;
} }
if (formObj['begin_with_filter_collapsed'] === undefined) if (formObj['begin_with_filter_collapsed'] === undefined)
formObj['begin_with_filter_collapsed'] = 'no'; formObj['begin_with_filter_collapsed'] = 'no';
if (formObj['display_in_repository_level_lists'] === undefined)
formObj['display_in_repository_level_lists'] = 'no';
this.fillExtraFormData(formObj); this.fillExtraFormData(formObj);
this.isLoading = true; this.isLoading = true;

View File

@ -90,12 +90,6 @@
:filters-as-modal="filtersAsModal" :filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen"/> :is-mobile-screen="isMobileScreen"/>
</template> </template>
<!-- <p
class="has-text-gray"
style="font-size: 0.75em;"
v-if="taxonomyFilter.length <= 0">
{{ $i18n.get('info_there_is_no_filter') }}
</p> -->
<hr v-if="taxonomyFilter.length > 1"> <hr v-if="taxonomyFilter.length > 1">
</div> </div>
</template> </template>
@ -140,12 +134,6 @@
:filters-as-modal="filtersAsModal" :filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen" /> :is-mobile-screen="isMobileScreen" />
</template> </template>
<!-- <p
class="has-text-gray"
style="font-size: 0.75em;"
v-if="taxonomyFilter.length <= 0">
{{ $i18n.get('info_there_is_no_filter') }}
</p> -->
<hr v-if="taxonomyFilter.length > 1"> <hr v-if="taxonomyFilter.length > 1">
</div> </div>
</template> </template>
@ -194,12 +182,6 @@
:filters-as-modal="filtersAsModal" :filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen" /> :is-mobile-screen="isMobileScreen" />
</template> </template>
<!-- <p
class="has-text-gray"
style="font-size: 0.75em;"
v-if="taxonomyFilter.length <= 0">
{{ $i18n.get('info_there_is_no_filter') }}
</p> -->
<hr v-if="repositoryCollectionFilters.length > 1"> <hr v-if="repositoryCollectionFilters.length > 1">
</div> </div>
</template> </template>
@ -244,12 +226,6 @@
:filters-as-modal="filtersAsModal" :filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen" /> :is-mobile-screen="isMobileScreen" />
</template> </template>
<!-- <p
class="has-text-gray"
style="font-size: 0.75em;"
v-if="taxonomyFilter.length <= 0">
{{ $i18n.get('info_there_is_no_filter') }}
</p> -->
<hr v-if="repositoryCollectionFilters.length > 1"> <hr v-if="repositoryCollectionFilters.length > 1">
</div> </div>
</template> </template>
@ -271,8 +247,11 @@
</template> </template>
</div> </div>
<section <section
v-if="!isLoadingFilters && v-if="!isLoadingFilters && (
!((filters.length >= 0 && isRepositoryLevel) || filters.length > 0)" ( taxonomy && taxonomyFilters && Object.keys(taxonomyFilters).length <= 0 ) ||
( isRepositoryLevel && !taxonomy && repositoryCollectionFilters && Object.keys(repositoryCollectionFilters).length <= 0 ) ||
( !isRepositoryLevel && !taxonomy && filters && filters.length <= 0 )
)"
class="is-grouped-centered"> class="is-grouped-centered">
<div class="content has-text-gray has-text-centered"> <div class="content has-text-gray has-text-centered">
<p> <p>
@ -281,6 +260,7 @@
</span> </span>
</p> </p>
<p>{{ $i18n.get('info_there_is_no_filter' ) }}</p> <p>{{ $i18n.get('info_there_is_no_filter' ) }}</p>
<p v-if="isRepositoryLevel && $route.name != null">{{ $i18n.get('info_collection_filter_on_repository_level') }}</p>
<router-link <router-link
v-if="!$adminOptions.hideItemsListFilterCreationButton && $route.name != null && ((isRepositoryLevel && $userCaps.hasCapability('tnc_rep_edit_filters')) || (!isRepositoryLevel && collection && collection.current_user_can_edit_filters))" v-if="!$adminOptions.hideItemsListFilterCreationButton && $route.name != null && ((isRepositoryLevel && $userCaps.hasCapability('tnc_rep_edit_filters')) || (!isRepositoryLevel && collection && collection.current_user_can_edit_filters))"
id="button-create-filter" id="button-create-filter"

View File

@ -188,7 +188,7 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
// Then we add collection level filters // Then we add collection level filters
collections.forEach(collection => { collections.forEach(collection => {
promises.push( promises.push(
axios.tainacan.get('/collection/' + collection.id + '/filters/?include_control_metadata_types=true&nopaging=1&include_disabled=false&metaquery[0][key]=collection_id&metaquery[0][value]=default&metaquery[0][compare]=!=') axios.tainacan.get('/collection/' + collection.id + '/filters/?include_control_metadata_types=true&nopaging=1&include_disabled=false&metaquery[0][key]=collection_id&metaquery[0][value]=default&metaquery[0][compare]=!=&metaquery[1][key]=display_in_repository_level_lists&metaquery[1][value]=no&metaquery[1][compare]=!=')
.then((resp) => { return { filters: resp.data, collectionId: collection.id } }) .then((resp) => { return { filters: resp.data, collectionId: collection.id } })
.catch((error) => { .catch((error) => {
reject(error); reject(error);
@ -201,8 +201,10 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
.then((results) => { .then((results) => {
let futureRepositoryCollectionFilters = {}; let futureRepositoryCollectionFilters = {};
for (let resp of results) for (let resp of results) {
if (resp.filters.length > 0)
futureRepositoryCollectionFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = resp.filters; futureRepositoryCollectionFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = resp.filters;
}
commit('setRepositoryCollectionFilters', futureRepositoryCollectionFilters); commit('setRepositoryCollectionFilters', futureRepositoryCollectionFilters);
@ -251,7 +253,7 @@ export const fetchTaxonomyFilters = ({ dispatch, commit }, { taxonomyId, collect
const collectionsToSearch = collectionsIds.length ? collectionsIds : taxonomy.collections_ids const collectionsToSearch = collectionsIds.length ? collectionsIds : taxonomy.collections_ids
collectionsToSearch.forEach(collectionId => { collectionsToSearch.forEach(collectionId => {
promises.push( promises.push(
axios.tainacan.get('/collection/' + collectionId + '/filters/?include_control_metadata_types=true&nopaging=1&include_disabled=false&metaquery[0][key]=collection_id&metaquery[0][value]=default&metaquery[0][compare]=!=') axios.tainacan.get('/collection/' + collectionId + '/filters/?include_control_metadata_types=true&nopaging=1&include_disabled=false&metaquery[0][key]=collection_id&metaquery[0][value]=default&metaquery[0][compare]=!=&metaquery[1][key]=display_in_repository_level_lists&metaquery[1][value]=no&metaquery[1][compare]=!=')
.then((resp) => { return { filters: resp.data, collectionId: collectionId } }) .then((resp) => { return { filters: resp.data, collectionId: collectionId } })
.catch((error) => { .catch((error) => {
reject(error); reject(error);
@ -268,6 +270,7 @@ export const fetchTaxonomyFilters = ({ dispatch, commit }, { taxonomyId, collect
let taxonomyFilters = resp.filters.filter((filter) => { let taxonomyFilters = resp.filters.filter((filter) => {
return filter.metadatum.metadata_type_object.options.taxonomy_id != taxonomyId return filter.metadatum.metadata_type_object.options.taxonomy_id != taxonomyId
}); });
if (taxonomyFilters.length > 0)
futureTaxonomyFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = taxonomyFilters; futureTaxonomyFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = taxonomyFilters;
} }

View File

@ -906,6 +906,7 @@ return apply_filters( 'tainacan-i18n', [
'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ), 'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ),
'info_there_is_no_metadata_section' => __( 'There is no metadata section here yet.', 'tainacan' ), 'info_there_is_no_metadata_section' => __( 'There is no metadata section here yet.', 'tainacan' ),
'info_there_is_no_filter' => __( 'There is no filter here yet.', 'tainacan' ), 'info_there_is_no_filter' => __( 'There is no filter here yet.', 'tainacan' ),
'info_collection_filter_on_repository_level' => __( 'If there are filters set in the collections, you can also set them to be displayed at repository level.', 'tainacan' ),
'info_changes' => __( 'Changes', 'tainacan' ), 'info_changes' => __( 'Changes', 'tainacan' ),
'info_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, YouTube, etc.', 'tainacan' ), 'info_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, YouTube, etc.', 'tainacan' ),
'info_help_term_name' => __( 'The term name', 'tainacan' ), 'info_help_term_name' => __( 'The term name', 'tainacan' ),