Number of items with a certain metadata value. #483

This commit is contained in:
mateuswetah 2021-03-08 16:57:43 -03:00
parent 270e0d50cc
commit 702ffaa0d9
6 changed files with 127 additions and 6 deletions

View File

@ -28,7 +28,7 @@ export const fetchMetadata = ({ commit }, { collectionId } ) => {
if (collectionId && collectionId != 'default') if (collectionId && collectionId != 'default')
endpoint += '/collection/' + collectionId + '/metadata'; endpoint += '/collection/' + collectionId + '/metadata';
else else
endpoint += '/repository/metadata'; endpoint += '/metadata';
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.tainacan.get(endpoint) axios.tainacan.get(endpoint)
@ -42,6 +42,27 @@ export const fetchMetadata = ({ commit }, { collectionId } ) => {
}); });
}; };
export const fetchMetadataList = ({ commit }, { collectionId, metadatumId } ) => {
let endpoint = '/reports';
if (collectionId && collectionId != 'default')
endpoint += '/collection/' + collectionId + '/metadata/' + metadatumId;
else
endpoint += '/metadata/' + metadatumId;
return new Promise((resolve, reject) => {
axios.tainacan.get(endpoint)
.then(res => {
let metadataList = res.data.list;
commit('setMetadataList', metadataList);
resolve(metadataList);
})
.catch(error => reject(error));
});
};
export const fetchCollectionsList = ({ commit }) => { export const fetchCollectionsList = ({ commit }) => {
let endpoint = '/reports/collection' let endpoint = '/reports/collection'

View File

@ -6,6 +6,10 @@ export const getMetadata = state => {
return state.metadata; return state.metadata;
}; };
export const getMetadataList = state => {
return state.metadataList;
};
export const getCollectionsList = state => { export const getCollectionsList = state => {
return state.collectionsList; return state.collectionsList;
}; };

View File

@ -8,6 +8,7 @@ const state = {
colletionsList: {}, colletionsList: {},
taxonomyTerms: {}, taxonomyTerms: {},
metadata: {}, metadata: {},
metadataList: {},
stackedBarChartOptions: { stackedBarChartOptions: {
chart: { chart: {
type: 'bar', type: 'bar',

View File

@ -6,6 +6,10 @@ export const setMetadata = (state, metadata) => {
state.metadata = metadata; state.metadata = metadata;
}; };
export const setMetadataList = (state, metadataList) => {
state.metadataList = metadataList;
};
export const setCollectionsList = (state, collectionsList) => { export const setCollectionsList = (state, collectionsList) => {
state.collectionsList = collectionsList; state.collectionsList = collectionsList;
}; };

View File

@ -101,7 +101,7 @@
</option> </option>
</select> </select>
<apexchart <apexchart
v-if="!isFetchingTaxonomiesList && selectedTaxonomy" v-if="!isFetchingTaxonomiesList && !isFetchingTaxonomyTerms && selectedTaxonomy"
height="380px" height="380px"
class="postbox" class="postbox"
:series="taxonomyTermsChartSeries" :series="taxonomyTermsChartSeries"
@ -143,6 +143,33 @@
style="min-height=740px" style="min-height=740px"
class="skeleton postbox" /> class="skeleton postbox" />
</div> </div>
<div
v-if="metadataList != undefined"
class="column is-full">
<select
v-if="!isFetchingMetadata"
name="select_metadata"
id="select_metadata"
:placeholder="$i18n.get('label_select_a_metadata')"
v-model="selectedMetadatum">
<option
v-for="(metadatum, index) of metadataListArray"
:key="index"
:value="metadatum.id">
{{ metadatum.name }}
</option>
</select>
<apexchart
v-if="!isFetchingMetadataList && !isFetchingMetadata && selectedMetadatum"
height="380px"
class="postbox"
:series="metadataListChartSeries"
:options="metadataListChartOptions" />
<div
v-else
style="min-height=380px"
class="skeleton postbox" />
</div>
</div> </div>
</div> </div>
</template> </template>
@ -156,16 +183,20 @@ export default {
return { return {
selectedCollection: 'default', selectedCollection: 'default',
selectedTaxonomy: '', selectedTaxonomy: '',
selectedMetadatum: '',
isFetchingCollections: false, isFetchingCollections: false,
isFetchingSummary: false, isFetchingSummary: false,
isFetchingCollectionsList: false, isFetchingCollectionsList: false,
isFetchingTaxonomiesList: false, isFetchingTaxonomiesList: false,
isFetchingTaxonomyTerms: false, isFetchingTaxonomyTerms: false,
isFetchingMetadata: false, isFetchingMetadata: false,
isFetchingMetadataList: false,
collectionsListChartSeries: [], collectionsListChartSeries: [],
collectionsListChartOptions: {}, collectionsListChartOptions: {},
taxonomiesListChartSeries: [], taxonomiesListChartSeries: [],
taxonomiesListChartOptions: {}, taxonomiesListChartOptions: {},
metadataListChartSeries: [],
metadataListChartOptions: {},
taxonomyTermsChartSeries: [], taxonomyTermsChartSeries: [],
taxonomyTermsChartOptions: {}, taxonomyTermsChartOptions: {},
metadataTypeChartSeries: [], metadataTypeChartSeries: [],
@ -182,6 +213,7 @@ export default {
...mapGetters('report', { ...mapGetters('report', {
summary: 'getSummary', summary: 'getSummary',
metadata: 'getMetadata', metadata: 'getMetadata',
metadataList: 'getMetadataList',
taxonomyTerms: 'getTaxonomyTerms', taxonomyTerms: 'getTaxonomyTerms',
taxonomiesList: 'getTaxonomiesList', taxonomiesList: 'getTaxonomiesList',
collectionsList: 'getCollectionsList', collectionsList: 'getCollectionsList',
@ -191,6 +223,9 @@ export default {
}), }),
taxonomiesListArray() { taxonomiesListArray() {
return this.taxonomiesList && this.taxonomiesList != undefined ? Object.values(this.taxonomiesList) : []; return this.taxonomiesList && this.taxonomiesList != undefined ? Object.values(this.taxonomiesList) : [];
},
metadataListArray() {
return this.metadata && this.metadata != undefined && this.metadata.distribution ? Object.values(this.metadata.distribution) : [];
} }
}, },
watch: { watch: {
@ -198,10 +233,9 @@ export default {
handler(to) { handler(to) {
this.selectedCollection = to['collection'] ? to['collection'] : 'default'; this.selectedCollection = to['collection'] ? to['collection'] : 'default';
this.loadSummary(); this.loadSummary();
if (this.selectedCollection && this.selectedCollection != 'default')
this.loadMetadata(); this.loadMetadata();
else {
if (!this.selectedCollection || this.selectedCollection == 'default') {
this.loadCollectionsList(); this.loadCollectionsList();
this.loadTaxonomiesList(); this.loadTaxonomiesList();
} }
@ -212,6 +246,10 @@ export default {
selectedTaxonomy() { selectedTaxonomy() {
if (this.selectedTaxonomy && this.selectedTaxonomy != '') if (this.selectedTaxonomy && this.selectedTaxonomy != '')
this.loadTaxonomyTerms(); this.loadTaxonomyTerms();
},
selectedMetadatum() {
if (this.selectedMetadatum && this.selectedMetadatum != '')
this.loadMetadataList();
} }
}, },
created() { created() {
@ -230,7 +268,8 @@ export default {
'fetchCollectionsList', 'fetchCollectionsList',
'fetchTaxonomiesList', 'fetchTaxonomiesList',
'fetchTaxonomyTerms', 'fetchTaxonomyTerms',
'fetchMetadata' 'fetchMetadata',
'fetchMetadataList'
]), ]),
loadCollections() { loadCollections() {
this.isFetchingCollections = true; this.isFetchingCollections = true;
@ -272,6 +311,7 @@ export default {
} }
if (this.metadata.distribution) { if (this.metadata.distribution) {
// Building Metadata Distribution Bar chart // Building Metadata Distribution Bar chart
const orderedMetadataDistributions = Object.values(this.metadata.distribution).sort((a, b) => b.fill_percentage - a.fill_percentage); const orderedMetadataDistributions = Object.values(this.metadata.distribution).sort((a, b) => b.fill_percentage - a.fill_percentage);
let metadataDistributionValues = []; let metadataDistributionValues = [];
@ -285,6 +325,10 @@ export default {
metadataDistributionLabels.push(metadataDistribution.name); metadataDistributionLabels.push(metadataDistribution.name);
}) })
// Sets first metadatum as the selected one
if (orderedMetadataDistributions.length)
this.selectedMetadatum = orderedMetadataDistributions[0].id;
this.metadataDistributionChartSeries = [ this.metadataDistributionChartSeries = [
{ {
name: this.$i18n.get('label_filled'), name: this.$i18n.get('label_filled'),
@ -489,6 +533,51 @@ export default {
}) })
.catch(() => this.isFetchingTaxonomyTerms = false); .catch(() => this.isFetchingTaxonomyTerms = false);
},
loadMetadataList() {
this.isFetchingMetadataList = true;
this.fetchMetadataList({ collectionId: this.collectionId, metadatumId: this.selectedMetadatum })
.then(() => {
// Building Taxonomy term usage chart
const orderedMetadata = Object.values(this.metadataList).sort((a, b) => a.total_items - b.total_items);
let metadataItemValues = [];
let metadataItemLabels = [];
orderedMetadata.forEach(metadataItem => {
metadataItemValues.push(metadataItem.total_items);
metadataItemLabels.push(metadataItem.label);
});
this.metadataListChartSeries = [
{
name: this.$i18n.get('label_items_with_this_metadum_value'),
data: metadataItemValues
}
];
this.metadataListChartOptions = {
...this.stackedBarChartOptions,
...{
title: {
text: this.$i18n.get('label_amount_of_items_per_metadatum_value')
},
xaxis: {
type: 'category',
tickPlacement: 'on',
categories: metadataItemLabels,
},
yaxis: {
title: {
text: this.$i18n.get('label_number_of_items')
}
}
}
}
this.isFetchingMetadataList = false;
})
.catch(() => this.isFetchingMetadataList = false);
} }
} }
} }

View File

@ -508,6 +508,8 @@ return apply_filters( 'tainacan-admin-i18n', [
/* translators: To be displayed with the number of Taxonomies used in the colllection */ /* translators: To be displayed with the number of Taxonomies used in the colllection */
'label_used' => __( 'Used', 'tainacan' ), 'label_used' => __( 'Used', 'tainacan' ),
'label_select_a_taxonomy' => __( 'Select a taxonomy', 'tainacan' ), 'label_select_a_taxonomy' => __( 'Select a taxonomy', 'tainacan' ),
'label_items_with_this_metadum_value' => __( 'Items with this metadatum value', 'tainacan' ),
'label_amount_of_items_per_metadatum_value' => __( 'Amount of items per metadatum value', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders // Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),