Show reports count in Sidebar

This commit is contained in:
Angelina Filippova 2020-07-14 02:51:51 +03:00
parent 1899450dc1
commit 08bd5dae40
3 changed files with 36 additions and 6 deletions

View file

@ -3,6 +3,10 @@ export default {
name: 'MenuItem', name: 'MenuItem',
functional: true, functional: true,
props: { props: {
count: {
type: String,
default: null
},
icon: { icon: {
type: String, type: String,
default: '' default: ''
@ -13,7 +17,7 @@ export default {
} }
}, },
render(h, context) { render(h, context) {
const { icon, title } = context.props const { count, icon, title } = context.props
const vnodes = [] const vnodes = []
if (icon) { if (icon) {
@ -21,7 +25,11 @@ export default {
} }
if (title) { if (title) {
vnodes.push(<span slot='title'>{(title)}</span>) vnodes.push(<span slot='title'>{(title)} </span>)
}
if (count) {
vnodes.push(<span slot='title'>({(count)})</span>)
} }
return vnodes return vnodes
} }

View file

@ -4,14 +4,21 @@
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> <template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
<app-link :to="resolvePath(onlyOneChild.path)"> <app-link :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}"> <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon||item.meta.icon" :title="generateTitle(onlyOneChild.meta.title)" /> <item
v-if="onlyOneChild.meta"
:count="showCount(item) ? normalizedReportsCount : null"
:icon="onlyOneChild.meta.icon||item.meta.icon"
:title="generateTitle(onlyOneChild.meta.title)" />
</el-menu-item> </el-menu-item>
</app-link> </app-link>
</template> </template>
<el-submenu v-else ref="subMenu" :index="resolvePath(item.path)"> <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)">
<template slot="title"> <template slot="title">
<item v-if="item.meta" :icon="item.meta.icon" :title="generateTitle(item.meta.title)" /> <item
v-if="item.meta"
:count="showCount(item) ? normalizedReportsCount : null"
:icon="item.meta.icon"
:title="generateTitle(item.meta.title)" />
</template> </template>
<template v-for="child in item.children"> <template v-for="child in item.children">
@ -26,7 +33,11 @@
<app-link v-else :to="resolvePath(child.path)" :key="child.name"> <app-link v-else :to="resolvePath(child.path)" :key="child.name">
<el-menu-item :index="resolvePath(child.path)"> <el-menu-item :index="resolvePath(child.path)">
<item v-if="child.meta" :icon="child.meta.icon" :title="generateTitle(child.meta.title)" /> <item
v-if="child.meta"
:count="showCount(item) ? normalizedReportsCount : null"
:icon="child.meta.icon"
:title="generateTitle(child.meta.title)" />
</el-menu-item> </el-menu-item>
</app-link> </app-link>
</template> </template>
@ -43,6 +54,7 @@ import { isExternal } from '@/utils'
import Item from './Item' import Item from './Item'
import AppLink from './Link' import AppLink from './Link'
import FixiOSBug from './FixiOSBug' import FixiOSBug from './FixiOSBug'
import numeral from 'numeral'
export default { export default {
name: 'SidebarItem', name: 'SidebarItem',
@ -71,6 +83,9 @@ export default {
computed: { computed: {
invitesEnabled() { invitesEnabled() {
return this.basePath === '/invites' ? this.$store.state.app.invitesEnabled : true return this.basePath === '/invites' ? this.$store.state.app.invitesEnabled : true
},
normalizedReportsCount() {
return numeral(this.$store.state.reports.totalReportsCount).format('0a')
} }
}, },
methods: { methods: {
@ -104,6 +119,9 @@ export default {
} }
return path.resolve(this.basePath, routePath) return path.resolve(this.basePath, routePath)
}, },
showCount(item) {
return item.path === '/reports'
},
isExternalLink(routePath) { isExternalLink(routePath) {
return isExternal(routePath) return isExternal(routePath)
}, },

View file

@ -31,6 +31,10 @@ export default {
isCollapse() { isCollapse() {
return !this.sidebar.opened return !this.sidebar.opened
} }
},
mounted() {
this.$store.dispatch('SetReportsFilter', 'open')
this.$store.dispatch('FetchReports', 1)
} }
} }
</script> </script>