Browse Source

Set visibility to the side bar according to the project role

pull/341/head
Hironsan 5 years ago
parent
commit
ce6ff2336f
4 changed files with 31 additions and 17 deletions
  1. 31
      frontend/components/organisms/layout/TheSideBar.vue
  2. 7
      frontend/layouts/annotation.vue
  3. 7
      frontend/layouts/project.vue
  4. 3
      frontend/store/projects.js

31
frontend/components/organisms/layout/TheSideBar.vue

@ -11,14 +11,8 @@
Start annotation Start annotation
</v-btn> </v-btn>
<template v-for="(item, i) in items"> <template v-for="(item, i) in items">
<v-divider
v-if="item.divider"
:key="i"
dark
class="my-4"
/>
<v-list-item <v-list-item
v-else
v-if="isVisible(item)"
:key="i" :key="i"
@click="$router.push('/projects/' + $route.params.id + '/' + item.link)" @click="$router.push('/projects/' + $route.params.id + '/' + item.link)"
> >
@ -44,18 +38,23 @@ export default {
type: String, type: String,
default: '', default: '',
required: true required: true
},
role: {
type: Object,
default: () => {},
required: true
} }
}, },
data() { data() {
return { return {
items: [ items: [
{ icon: 'mdi-home', text: 'Home', link: '' },
{ icon: 'mdi-database', text: 'Dataset', link: 'dataset' },
{ icon: 'label', text: 'Labels', link: 'labels' },
{ icon: 'person', text: 'Members', link: 'members' },
{ icon: 'mdi-book-open-outline', text: 'Guideline', link: 'guideline' },
{ icon: 'mdi-chart-bar', text: 'Statistics', link: 'statistics' }
{ icon: 'mdi-home', text: 'Home', link: '', adminOnly: false },
{ icon: 'mdi-database', text: 'Dataset', link: 'dataset', adminOnly: true },
{ icon: 'label', text: 'Labels', link: 'labels', adminOnly: true },
{ icon: 'person', text: 'Members', link: 'members', adminOnly: true },
{ icon: 'mdi-book-open-outline', text: 'Guideline', link: 'guideline', adminOnly: true },
{ icon: 'mdi-chart-bar', text: 'Statistics', link: 'statistics', adminOnly: true }
] ]
} }
}, },
@ -64,6 +63,12 @@ export default {
to() { to() {
return `/projects/${this.$route.params.id}/${this.link}` return `/projects/${this.$route.params.id}/${this.link}`
} }
},
methods: {
isVisible(item) {
return !item.adminOnly || this.role.is_project_admin
}
} }
} }
</script> </script>

7
frontend/layouts/annotation.vue

@ -12,7 +12,10 @@
clipped clipped
color="" color=""
> >
<the-side-bar :link="getLink" />
<the-side-bar
:link="getLink"
:role="getCurrentUserRole"
/>
</v-navigation-drawer> </v-navigation-drawer>
<nuxt /> <nuxt />
@ -36,7 +39,7 @@ export default {
}, },
computed: { computed: {
...mapGetters('projects', ['getLink'])
...mapGetters('projects', ['getLink', 'getCurrentUserRole'])
}, },
created() { created() {

7
frontend/layouts/project.vue

@ -12,7 +12,10 @@
clipped clipped
color="" color=""
> >
<the-side-bar :link="getLink" />
<the-side-bar
:link="getLink"
:role="getCurrentUserRole"
/>
</v-navigation-drawer> </v-navigation-drawer>
<v-content> <v-content>
@ -50,7 +53,7 @@ export default {
}, },
computed: { computed: {
...mapGetters('projects', ['getLink'])
...mapGetters('projects', ['getLink', 'getCurrentUserRole'])
}, },
created() { created() {

3
frontend/store/projects.js

@ -14,6 +14,9 @@ export const getters = {
currentProject(state) { currentProject(state) {
return state.current return state.current
}, },
getCurrentUserRole(state) {
return state.current.current_users_role || {}
},
getFilterOption(state) { getFilterOption(state) {
if (state.current.project_type === 'DocumentClassification') { if (state.current.project_type === 'DocumentClassification') {
return 'doc_annotations__isnull' return 'doc_annotations__isnull'

Loading…
Cancel
Save