Merge pull request #826 from tainacan/feature/824

Adds option to show collection filters in repository level lists. #824
This commit is contained in:
Mateus Machado Luna 2023-11-13 16:53:50 -03:00 committed by GitHub
commit 8b8ff69b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 145 additions and 102 deletions

View File

@ -19,7 +19,8 @@ class Filter extends Entity {
$max_options,
$filter_type,
$filter_type_options,
$begin_with_filter_collapsed;
$begin_with_filter_collapsed,
$display_in_repository_level_lists;
static $post_type = 'tainacan-filter';
public $enabled_for_collection = true;
@ -179,6 +180,15 @@ class Filter extends Entity {
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
@ -252,6 +262,15 @@ class Filter extends Entity {
$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
*

View File

@ -79,6 +79,16 @@ class Filters extends Repository {
'enum' => [ 'yes', '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' => [
'map' => 'meta',
'title' => __( 'Collection', 'tainacan' ),

View File

@ -173,6 +173,28 @@
</b-switch>
</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
:errors="formErrors['filter_type_options']"
v-if="(form.filter_type_object && form.filter_type_object.form_component) || form.edit_form == ''"
@ -273,11 +295,13 @@ export default {
this.isLoading = true;
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';
}
if (this.form['begin_with_filter_collapsed'] === undefined)
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 })
.then(() => {
@ -306,13 +330,15 @@ export default {
let formObj = {};
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';
else
formObj[key] = value;
}
if (formObj['begin_with_filter_collapsed'] === undefined)
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.isLoading = true;

View File

@ -2,7 +2,6 @@
<aside
aria-labelledby="filters-label-landmark"
:aria-busy="isLoadingFilters">
<b-loading
:is-full-page="false"
:active.sync="isLoadingFilters"/>
@ -90,12 +89,6 @@
:filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen"/>
</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">
</div>
</template>
@ -140,12 +133,6 @@
:filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen" />
</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">
</div>
</template>
@ -194,12 +181,6 @@
:filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen" />
</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">
</div>
</template>
@ -244,12 +225,6 @@
:filters-as-modal="filtersAsModal"
:is-mobile-screen="isMobileScreen" />
</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">
</div>
</template>
@ -271,8 +246,11 @@
</template>
</div>
<section
v-if="!isLoadingFilters &&
!((filters.length >= 0 && isRepositoryLevel) || filters.length > 0)"
v-if="!isLoadingFilters && (
( 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">
<div class="content has-text-gray has-text-centered">
<p>
@ -281,6 +259,7 @@
</span>
</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
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"
@ -431,7 +410,7 @@
this.isLoadingFilters = true;
// Normal filter loading, only collection ones
if (!this.taxonomy) {
if ( !this.taxonomy && !this.isRepositoryLevel ) {
this.fetchFilters({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
@ -449,7 +428,7 @@
.catch(() => this.isLoadingFilters = false);
// Custom filter loading, get's from collections that have items with that taxonomy
} else {
} else if ( this.taxonomy ) {
let collectionsIds = [];
@ -466,20 +445,24 @@
this.fetchTaxonomyFilters({ taxonomyId: taxonomyId[taxonomyId.length - 1], collectionsIds: collectionsIds })
.catch(() => this.isLoadingFilters = false);
}
// On repository level we also fetch collection filters
if ( !this.taxonomy && this.isRepositoryLevel ) {
} else if ( this.isRepositoryLevel && !this.taxonomy ) {
// Cancels previous Request
if (this.repositoryFiltersSearchCancel != undefined)
this.repositoryFiltersSearchCancel.cancel('Repository Collection Filters search Canceled.');
this.fetchRepositoryCollectionFilters()
.then((source) => {
this.repositoryFiltersSearchCancel = source;
});
.then((anotherResp) => {
anotherResp.request
.then(() => this.isLoadingFilters = false)
.catch(() => this.isLoadingFilters = false);
this.repositoryFiltersSearchCancel = anotherResp.source;
})
.catch(() => this.isLoadingFilters = false);
}
},
updateIsLoadingItems(isLoadingItems) {
this.$emit('updateIsLoadingItemsState', isLoadingItems);

View File

@ -165,7 +165,10 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
commit('clearRepositoryCollectionFilters');
return new Promise((resolve, reject) => {
const source = axios.CancelToken.source();
return Object({
request: new Promise((resolve, reject) => {
dispatch('collection/fetchAllCollectionNames', { } ,{ root: true })
.then((resp) => {
@ -188,7 +191,7 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
// Then we add collection level filters
collections.forEach(collection => {
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 } })
.catch((error) => {
reject(error);
@ -201,9 +204,10 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
.then((results) => {
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;
}
commit('setRepositoryCollectionFilters', futureRepositoryCollectionFilters);
resolve();
@ -217,10 +221,9 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
.catch(() => {
reject();
});
// Search Request Token for cancelling
resolve(resp.source);
});
}),
source: source
});
};
@ -251,7 +254,7 @@ export const fetchTaxonomyFilters = ({ dispatch, commit }, { taxonomyId, collect
const collectionsToSearch = collectionsIds.length ? collectionsIds : taxonomy.collections_ids
collectionsToSearch.forEach(collectionId => {
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 } })
.catch((error) => {
reject(error);
@ -268,6 +271,7 @@ export const fetchTaxonomyFilters = ({ dispatch, commit }, { taxonomyId, collect
let taxonomyFilters = resp.filters.filter((filter) => {
return filter.metadatum.metadata_type_object.options.taxonomy_id != taxonomyId
});
if (taxonomyFilters.length > 0)
futureTaxonomyFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = taxonomyFilters;
}

View File

@ -127,7 +127,7 @@ class Admin {
global $TAINACAN_BASE_URL;
wp_enqueue_style( 'tainacan-fonts', $TAINACAN_BASE_URL . '/assets/css/tainacanicons.css', [], TAINACAN_VERSION );
wp_enqueue_style( 'roboto-fonts', 'https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700,700i', [], TAINACAN_VERSION );
wp_enqueue_style( 'roboto-fonts', 'https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700,700i', [] );
wp_enqueue_script('underscore');
}

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_metadata_section' => __( 'There is no metadata section 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_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, YouTube, etc.', 'tainacan' ),
'info_help_term_name' => __( 'The term name', 'tainacan' ),