First usage of summary endpoints #483.
This commit is contained in:
parent
87174e3f8c
commit
0a52fd416e
|
@ -19,3 +19,24 @@ export const fetchReports = ({ commit }, {} ) => {
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchSummary = ({ commit }, { collectionId } ) => {
|
||||||
|
|
||||||
|
let endpoint = '/reports';
|
||||||
|
|
||||||
|
if (collectionId && collectionId != 'default')
|
||||||
|
endpoint += '/collection/' + collectionId + '/summary';
|
||||||
|
else
|
||||||
|
endpoint += '/repository/summary';
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
axios.tainacan.get(endpoint)
|
||||||
|
.then(res => {
|
||||||
|
let summary = res.data;
|
||||||
|
|
||||||
|
commit('setSummary', summary);
|
||||||
|
resolve(summary);
|
||||||
|
})
|
||||||
|
.catch(error => reject(error));
|
||||||
|
});
|
||||||
|
};
|
|
@ -1,3 +1,7 @@
|
||||||
export const getReports = state => {
|
export const getReports = state => {
|
||||||
return state.reports;
|
return state.reports;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getSummary = state => {
|
||||||
|
return state.summary;
|
||||||
|
};
|
||||||
|
|
|
@ -644,7 +644,8 @@ const state = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
summary: {}
|
||||||
};
|
};
|
||||||
function generateData (count, yrange) {
|
function generateData (count, yrange) {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
export const setReports = (state, reports) => {
|
export const setReports = (state, reports) => {
|
||||||
state.reports = reports;
|
state.reports = reports;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setSummary = (state, summary) => {
|
||||||
|
state.summary = summary;
|
||||||
|
};
|
|
@ -33,38 +33,19 @@
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
sourceCollection: String,
|
sourceCollection: String,
|
||||||
entityType: String
|
entityType: String,
|
||||||
|
summary: Object
|
||||||
},
|
},
|
||||||
data() {
|
computed: {
|
||||||
|
total() {
|
||||||
|
return this.summary.totals[this.entityType].total;
|
||||||
|
},
|
||||||
|
totalByStatus() {
|
||||||
return {
|
return {
|
||||||
total: 0,
|
'publish': this.summary.totals[this.entityType].publish,
|
||||||
totalByStatus: {}
|
'private': this.summary.totals[this.entityType].private,
|
||||||
}
|
'draft': this.summary.totals[this.entityType].draft,
|
||||||
},
|
'trash': this.summary.totals[this.entityType].trash
|
||||||
mounted() {
|
|
||||||
// Fake data until we fetch and load this from store
|
|
||||||
if (this.entityType === 'items') {
|
|
||||||
this.total = 2344;
|
|
||||||
this.totalByStatus = {
|
|
||||||
'publish': 2326,
|
|
||||||
'private': 8,
|
|
||||||
'draft': 9,
|
|
||||||
'trash': 1
|
|
||||||
}
|
|
||||||
} else if (this.entityType === 'collections') {
|
|
||||||
this.total = 23;
|
|
||||||
this.totalByStatus = {
|
|
||||||
'publish': 18,
|
|
||||||
'private': 2,
|
|
||||||
'trash': 3
|
|
||||||
}
|
|
||||||
} else if (this.entityType === 'taxonomies') {
|
|
||||||
this.total = 8;
|
|
||||||
this.totalByStatus = {
|
|
||||||
'publish': 5,
|
|
||||||
'private': 0,
|
|
||||||
'draft': 1,
|
|
||||||
'trash': 1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,6 @@ import NumberBlock from '../components/number-block.vue';
|
||||||
|
|
||||||
Vue.use(VueApexCharts)
|
Vue.use(VueApexCharts)
|
||||||
|
|
||||||
// Apex.theme = {
|
|
||||||
// monochrome: {
|
|
||||||
// enabled: true,
|
|
||||||
// color: '#298596',
|
|
||||||
// shadeTo: 'light',
|
|
||||||
// shadeIntensity: 0.65
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
Apex.colors = [
|
Apex.colors = [
|
||||||
'#298596', // Tainacan Turquoise
|
'#298596', // Tainacan Turquoise
|
||||||
'#01295c', // Tainacan Blue
|
'#01295c', // Tainacan Blue
|
||||||
|
@ -37,7 +29,6 @@ Apex.colors = [
|
||||||
'#ed4f63' // Tainacan Pink
|
'#ed4f63' // Tainacan Pink
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
Vue.use(I18NPlugin);
|
Vue.use(I18NPlugin);
|
||||||
Vue.use(UserCapabilitiesPlugin);
|
Vue.use(UserCapabilitiesPlugin);
|
||||||
Vue.use(StatusHelperPlugin);
|
Vue.use(StatusHelperPlugin);
|
||||||
|
|
|
@ -17,22 +17,32 @@
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="columns is-multiline">
|
<div class="columns is-multiline">
|
||||||
<div class="column is-full is-one-third-tablet has-text-centered">
|
<div
|
||||||
|
v-if="!selectedCollection || selectedCollection == 'default'"
|
||||||
|
class="column is-full is-one-third-tablet has-text-centered">
|
||||||
<number-block
|
<number-block
|
||||||
|
v-if="!isFetchingSummary && summary && summary.totals"
|
||||||
class="postbox"
|
class="postbox"
|
||||||
:source-collection="selectedCollection"
|
:source-collection="selectedCollection"
|
||||||
|
:summary="summary"
|
||||||
entity-type="collections"/>
|
entity-type="collections"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-full is-one-third-tablet has-text-centered">
|
<div class="column is-full is-one-third-tablet has-text-centered">
|
||||||
<number-block
|
<number-block
|
||||||
|
v-if="!isFetchingSummary && summary && summary.totals"
|
||||||
class="postbox"
|
class="postbox"
|
||||||
:source-collection="selectedCollection"
|
:source-collection="selectedCollection"
|
||||||
|
:summary="summary"
|
||||||
entity-type="items"/>
|
entity-type="items"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-full is-one-third-tablet has-text-centered">
|
<div
|
||||||
|
v-if="!selectedCollection || selectedCollection == 'default'"
|
||||||
|
class="column is-full is-one-third-tablet has-text-centered">
|
||||||
<number-block
|
<number-block
|
||||||
|
v-if="!isFetchingSummary && summary && summary.totals"
|
||||||
class="postbox"
|
class="postbox"
|
||||||
:source-collection="selectedCollection"
|
:source-collection="selectedCollection"
|
||||||
|
:summary="summary"
|
||||||
entity-type="taxonomies"/>
|
entity-type="taxonomies"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-half is-one-quarter-widescreen">
|
<div class="column is-half is-one-quarter-widescreen">
|
||||||
|
@ -83,7 +93,8 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectedCollection: 'default',
|
selectedCollection: 'default',
|
||||||
isLoadingCollections: false,
|
isFetchingCollections: false,
|
||||||
|
isFetchingSummary: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -92,11 +103,13 @@ export default {
|
||||||
}),
|
}),
|
||||||
...mapGetters('report', {
|
...mapGetters('report', {
|
||||||
reports: 'getReports',
|
reports: 'getReports',
|
||||||
}),
|
summary: 'getSummary'
|
||||||
|
})
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'$route.query' (to) {
|
'$route.query' (to) {
|
||||||
this.selectedCollection = to['collection'] ? to['collection'] : 'default';
|
this.selectedCollection = to['collection'] ? to['collection'] : 'default';
|
||||||
|
this.loadSummary();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -104,15 +117,27 @@ export default {
|
||||||
this.selectedCollection = this.$route.query['collection'] ? this.$route.query['collection'] : 'default';
|
this.selectedCollection = this.$route.query['collection'] ? this.$route.query['collection'] : 'default';
|
||||||
|
|
||||||
// Loads collection for the select input
|
// Loads collection for the select input
|
||||||
this.isLoadingCollections = true;
|
this.isFetchingCollections = true;
|
||||||
this.fetchAllCollectionNames()
|
this.fetchAllCollectionNames()
|
||||||
.then(() => this.isLoadingCollections = false)
|
.then(() => {
|
||||||
.catch(() => this.isLoadingCollections = false);
|
this.loadSummary();
|
||||||
|
this.isFetchingCollections = false;
|
||||||
|
})
|
||||||
|
.catch(() => this.isFetchingCollections = false);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('collection', [
|
...mapActions('collection', [
|
||||||
'fetchAllCollectionNames'
|
'fetchAllCollectionNames'
|
||||||
])
|
]),
|
||||||
|
...mapActions('report', [
|
||||||
|
'fetchSummary',
|
||||||
|
]),
|
||||||
|
loadSummary() {
|
||||||
|
this.isFetchingSummary = true;
|
||||||
|
this.fetchSummary({ collectionId: this.selectedCollection })
|
||||||
|
.then(() => this.isFetchingSummary = false)
|
||||||
|
.catch(() => this.isFetchingSummary = false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue