Skip to content

Commit

Permalink
fix(webui): metrics pie charts show library name in tooltip
Browse files Browse the repository at this point in the history
Closes: #1159
  • Loading branch information
gotson committed Jul 13, 2023
1 parent 36a35b5 commit 318a444
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions komga-webui/src/views/Metrics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export default Vue.extend({
this.loadData()
},
methods: {
getLibraryNameById(id: string): string {
return this.$store.getters.getLibraryById(id).name
},
async loadData() {
this.$komgaMetrics.getMetric('komga.tasks.execution')
.then(m => {
Expand All @@ -144,7 +147,7 @@ export default Vue.extend({
this.$komgaMetrics.getMetric('komga.series')
.then(m => {
this.series = m
this.getStatisticForEachTagValue(m, 'library')
this.getStatisticForEachTagValue(m, 'library', 'VALUE', this.getLibraryNameById)
.then(v => this.seriesAllTags = v)
},
)
Expand All @@ -154,7 +157,7 @@ export default Vue.extend({
this.$komgaMetrics.getMetric('komga.books')
.then(m => {
this.books = m
this.getStatisticForEachTagValue(m, 'library')
this.getStatisticForEachTagValue(m, 'library', 'VALUE', this.getLibraryNameById)
.then(v => this.booksAllTags = v)
},
)
Expand All @@ -164,7 +167,7 @@ export default Vue.extend({
this.$komgaMetrics.getMetric('komga.books.filesize')
.then(m => {
this.booksFileSize = m
this.getStatisticForEachTagValue(m, 'library')
this.getStatisticForEachTagValue(m, 'library', 'VALUE', this.getLibraryNameById)
.then(v => this.fileSizeAllTags = v)
},
)
Expand All @@ -174,7 +177,7 @@ export default Vue.extend({
this.$komgaMetrics.getMetric('komga.sidecars')
.then(m => {
this.sidecars = m
this.getStatisticForEachTagValue(m, 'library')
this.getStatisticForEachTagValue(m, 'library', 'VALUE', this.getLibraryNameById)
.then(v => this.sidecarsAllTags = v)
},
)
Expand All @@ -191,7 +194,7 @@ export default Vue.extend({
.catch(() => {
})
},
async getStatisticForEachTagValue(metric: MetricDto, tag: string, statistic: string = 'VALUE'): Promise<{
async getStatisticForEachTagValue(metric: MetricDto, tag: string, statistic: string = 'VALUE', tagTransform: (t: string) => string = x => x): Promise<{
[key: string]: number | undefined
} | undefined> {
const tagDto = metric.availableTags.find(x => x.tag === tag)
Expand All @@ -202,7 +205,7 @@ export default Vue.extend({
}, {} as { [key: string]: number | undefined })
for (let tagKey in tagToStatistic) {
tagToStatistic[tagKey] = (await this.$komgaMetrics.getMetric(metric.name, [{
tagToStatistic[tagTransform(tagKey)] = (await this.$komgaMetrics.getMetric(metric.name, [{
key: tag,
value: tagKey,
}])).measurements.find(x => x.statistic === statistic)?.value
Expand Down

0 comments on commit 318a444

Please sign in to comment.