Merge pull request #826 from tainacan/feature/824
Adds option to show collection filters in repository level lists. #824
This commit is contained in:
commit
8b8ff69b03
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
} else if ( this.isRepositoryLevel && !this.taxonomy ) {
|
||||
|
||||
// Cancels previous Request
|
||||
if (this.repositoryFiltersSearchCancel != undefined)
|
||||
this.repositoryFiltersSearchCancel.cancel('Repository Collection Filters search Canceled.');
|
||||
|
||||
this.fetchRepositoryCollectionFilters()
|
||||
.then((anotherResp) => {
|
||||
anotherResp.request
|
||||
.then(() => this.isLoadingFilters = false)
|
||||
.catch(() => this.isLoadingFilters = false);
|
||||
|
||||
this.repositoryFiltersSearchCancel = anotherResp.source;
|
||||
})
|
||||
.catch(() => this.isLoadingFilters = false);
|
||||
|
||||
}
|
||||
|
||||
// On repository level we also fetch collection filters
|
||||
if ( !this.taxonomy && this.isRepositoryLevel ) {
|
||||
|
||||
// Cancels previous Request
|
||||
if (this.repositoryFiltersSearchCancel != undefined)
|
||||
this.repositoryFiltersSearchCancel.cancel('Repository Collection Filters search Canceled.');
|
||||
|
||||
this.fetchRepositoryCollectionFilters()
|
||||
.then((source) => {
|
||||
this.repositoryFiltersSearchCancel = source;
|
||||
});
|
||||
}
|
||||
},
|
||||
updateIsLoadingItems(isLoadingItems) {
|
||||
this.$emit('updateIsLoadingItemsState', isLoadingItems);
|
||||
|
|
|
@ -144,15 +144,15 @@ export const updateCollectionFiltersOrder = ({ commit }, { collectionId, filters
|
|||
export const fetchFilterTypes = ({ commit} ) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.tainacan.get('/filter-types')
|
||||
.then((res) => {
|
||||
let filterTypes = res.data;
|
||||
commit('setFilterTypes', filterTypes);
|
||||
resolve (filterTypes);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
});
|
||||
.then((res) => {
|
||||
let filterTypes = res.data;
|
||||
commit('setFilterTypes', filterTypes);
|
||||
resolve (filterTypes);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -165,62 +165,65 @@ export const fetchRepositoryCollectionFilters = ({ dispatch, commit } ) => {
|
|||
|
||||
commit('clearRepositoryCollectionFilters');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const source = axios.CancelToken.source();
|
||||
|
||||
dispatch('collection/fetchAllCollectionNames', { } ,{ root: true })
|
||||
.then((resp) => {
|
||||
resp.request
|
||||
.then((res) => {
|
||||
let collections = res;
|
||||
if (collections != undefined && collections.length != undefined) {
|
||||
return Object({
|
||||
request: new Promise((resolve, reject) => {
|
||||
|
||||
let promises = [];
|
||||
dispatch('collection/fetchAllCollectionNames', { } ,{ root: true })
|
||||
.then((resp) => {
|
||||
resp.request
|
||||
.then((res) => {
|
||||
let collections = res;
|
||||
if (collections != undefined && collections.length != undefined) {
|
||||
|
||||
// First, we add repository level filters
|
||||
promises.push(
|
||||
axios.tainacan.get('/filters/?include_control_metadata_types=true&nopaging=1&include_disabled=false')
|
||||
.then((resp) => { return { filters: resp.data, collectionId: 'default' } })
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
})
|
||||
);
|
||||
let promises = [];
|
||||
|
||||
// Then we add collection level filters
|
||||
collections.forEach(collection => {
|
||||
// First, we add repository level filters
|
||||
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]=!=')
|
||||
.then((resp) => { return { filters: resp.data, collectionId: collection.id } })
|
||||
axios.tainacan.get('/filters/?include_control_metadata_types=true&nopaging=1&include_disabled=false')
|
||||
.then((resp) => { return { filters: resp.data, collectionId: 'default' } })
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Process it all
|
||||
axios.all(promises)
|
||||
.then((results) => {
|
||||
let futureRepositoryCollectionFilters = {};
|
||||
|
||||
for (let resp of results)
|
||||
futureRepositoryCollectionFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = resp.filters;
|
||||
|
||||
commit('setRepositoryCollectionFilters', futureRepositoryCollectionFilters);
|
||||
// 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]=!=&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);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Process it all
|
||||
axios.all(promises)
|
||||
.then((results) => {
|
||||
let futureRepositoryCollectionFilters = {};
|
||||
|
||||
for (let resp of results) {
|
||||
if (resp.filters.length > 0)
|
||||
futureRepositoryCollectionFilters[resp.collectionId != 'default' ? resp.collectionId : 'repository-filters'] = resp.filters;
|
||||
}
|
||||
commit('setRepositoryCollectionFilters', futureRepositoryCollectionFilters);
|
||||
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
reject();
|
||||
});
|
||||
|
||||
// Search Request Token for cancelling
|
||||
resolve(resp.source);
|
||||
});
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}),
|
||||
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,7 +271,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);
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -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