Hides collection filters bty default in repository level lists and adds option to enable them #824.
This commit is contained in:
parent
e6d64ac122
commit
f56fb61fd4
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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' ),
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
</div>
|
||||
</b-field>
|
||||
|
||||
<b-field
|
||||
<b-field
|
||||
:addons="false"
|
||||
:label="$i18n.getHelperTitle('filters', 'begin_with_filter_collapsed')"
|
||||
:type="formErrors['begin_with_filter_collapsed'] != undefined ? 'is-danger' : ''"
|
||||
|
@ -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'] : ''">
|
||||
|
||||
<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;
|
||||
|
|
|
@ -90,12 +90,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 +134,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 +182,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 +226,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 +247,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 +260,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"
|
||||
|
|
|
@ -188,7 +188,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,8 +201,10 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
|
|||
.then((results) => {
|
||||
let futureRepositoryCollectionFilters = {};
|
||||
|
||||
for (let resp of results)
|
||||
futureRepositoryCollectionFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = resp.filters;
|
||||
for (let resp of results) {
|
||||
if (resp.filters.length > 0)
|
||||
futureRepositoryCollectionFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = resp.filters;
|
||||
}
|
||||
|
||||
commit('setRepositoryCollectionFilters', futureRepositoryCollectionFilters);
|
||||
|
||||
|
@ -251,7 +253,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,7 +270,8 @@ export const fetchTaxonomyFilters = ({ dispatch, commit }, { taxonomyId, collect
|
|||
let taxonomyFilters = resp.filters.filter((filter) => {
|
||||
return filter.metadatum.metadata_type_object.options.taxonomy_id != taxonomyId
|
||||
});
|
||||
futureTaxonomyFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = taxonomyFilters;
|
||||
if (taxonomyFilters.length > 0)
|
||||
futureTaxonomyFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = taxonomyFilters;
|
||||
}
|
||||
|
||||
commit('setTaxonomyFilters', futureTaxonomyFilters);
|
||||
|
|
|
@ -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' ),
|
||||
|
|
Loading…
Reference in New Issue