2018-09-23 04:14:01 +00:00
|
|
|
<template lang='pug'>
|
2018-09-30 03:30:20 +00:00
|
|
|
v-container(fluid, grid-list-lg)
|
2018-09-23 04:14:01 +00:00
|
|
|
v-layout(row wrap)
|
|
|
|
v-flex(xs12)
|
2018-09-30 03:30:20 +00:00
|
|
|
.admin-header
|
|
|
|
v-icon(size='80', color='grey lighten-2') near_me
|
|
|
|
.admin-header-title
|
|
|
|
.headline.primary--text {{$t('navigation.title')}}
|
|
|
|
.subheading.grey--text {{$t('navigation.subtitle')}}
|
|
|
|
v-spacer
|
|
|
|
v-btn(color='success', depressed, @click='save', large)
|
|
|
|
v-icon(left) check
|
|
|
|
span {{$t('common:actions.apply')}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-container.pa-0.mt-3(fluid, grid-list-lg)
|
|
|
|
v-layout(row)
|
|
|
|
v-flex(style='flex: 0 0 350px;')
|
|
|
|
v-card
|
2018-09-30 03:30:20 +00:00
|
|
|
v-list.py-2(dense, dark, :class='navTree.length < 1 ? "grey lighten-4" : "primary"')
|
|
|
|
v-list-tile(v-if='navTree.length < 1')
|
|
|
|
v-list-tile-avatar: v-icon(color='grey') explore_off
|
|
|
|
v-list-tile-content
|
|
|
|
.caption.grey--text {{$t('navigation.emptyList')}}
|
2018-09-29 19:39:09 +00:00
|
|
|
draggable(v-model='navTree')
|
2018-09-23 04:14:01 +00:00
|
|
|
template(v-for='navItem in navTree')
|
2018-09-29 19:39:09 +00:00
|
|
|
v-list-tile(
|
|
|
|
v-if='navItem.kind === "link"'
|
|
|
|
:key='navItem.id'
|
|
|
|
:class='(navItem === current) ? "blue" : ""'
|
|
|
|
@click='selectItem(navItem)'
|
|
|
|
)
|
2018-09-23 04:14:01 +00:00
|
|
|
v-list-tile-avatar: v-icon {{navItem.icon}}
|
|
|
|
v-list-tile-title {{navItem.label}}
|
2018-09-29 19:39:09 +00:00
|
|
|
.py-2.clickable(
|
|
|
|
v-else-if='navItem.kind === "divider"'
|
|
|
|
:key='navItem.id'
|
|
|
|
:class='(navItem === current) ? "blue" : ""'
|
|
|
|
@click='selectItem(navItem)'
|
|
|
|
)
|
2018-09-23 04:14:01 +00:00
|
|
|
v-divider
|
2018-09-29 19:39:09 +00:00
|
|
|
v-subheader.pl-4.clickable(
|
|
|
|
v-else-if='navItem.kind === "header"'
|
|
|
|
:key='navItem.id'
|
|
|
|
:class='(navItem === current) ? "blue" : ""'
|
|
|
|
@click='selectItem(navItem)'
|
|
|
|
) {{navItem.label}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-card-chin
|
2018-09-29 19:39:09 +00:00
|
|
|
v-menu(offset-y, bottom, min-width='200px', style='flex: 1 1;')
|
|
|
|
v-btn(slot='activator', color='primary', depressed, block)
|
2018-09-23 04:14:01 +00:00
|
|
|
v-icon(left) add
|
2018-09-29 19:39:09 +00:00
|
|
|
span {{$t('common:actions.add')}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-list
|
|
|
|
v-list-tile(@click='addItem("link")')
|
|
|
|
v-list-tile-avatar: v-icon link
|
2018-09-29 19:39:09 +00:00
|
|
|
v-list-tile-title {{$t('navigation.link')}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-list-tile(@click='addItem("header")')
|
|
|
|
v-list-tile-avatar: v-icon title
|
2018-09-29 19:39:09 +00:00
|
|
|
v-list-tile-title {{$t('navigation.header')}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-list-tile(@click='addItem("divider")')
|
|
|
|
v-list-tile-avatar: v-icon power_input
|
2018-09-29 19:39:09 +00:00
|
|
|
v-list-tile-title {{$t('navigation.divider')}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-flex
|
|
|
|
v-card(v-if='current.kind === "link"')
|
|
|
|
v-toolbar(dense, color='blue', flat, dark)
|
2018-09-29 19:39:09 +00:00
|
|
|
.subheading {{$t('navigation.edit', { kind: $t('navigation.link') })}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-card-text
|
|
|
|
v-text-field(
|
|
|
|
outline
|
|
|
|
background-color='grey lighten-2'
|
2018-09-29 19:39:09 +00:00
|
|
|
:label='$t("navigation.label")'
|
2018-09-23 04:14:01 +00:00
|
|
|
prepend-icon='title'
|
|
|
|
v-model='current.label'
|
|
|
|
)
|
|
|
|
v-text-field(
|
|
|
|
outline
|
|
|
|
background-color='grey lighten-2'
|
2018-09-29 19:39:09 +00:00
|
|
|
:label='$t("navigation.icon")'
|
2018-09-23 04:14:01 +00:00
|
|
|
prepend-icon='casino'
|
|
|
|
v-model='current.icon'
|
|
|
|
)
|
|
|
|
v-select(
|
|
|
|
outline
|
|
|
|
background-color='grey lighten-2'
|
2018-09-29 19:39:09 +00:00
|
|
|
:label='$t("navigation.targetType")'
|
2018-09-23 04:14:01 +00:00
|
|
|
prepend-icon='near_me'
|
|
|
|
:items='navTypes'
|
|
|
|
v-model='current.targetType'
|
|
|
|
)
|
|
|
|
v-text-field(
|
|
|
|
v-if='current.targetType === "external"'
|
|
|
|
outline
|
|
|
|
background-color='grey lighten-2'
|
2018-09-29 19:39:09 +00:00
|
|
|
:label='$t("navigation.target")'
|
2018-09-23 04:14:01 +00:00
|
|
|
prepend-icon='near_me'
|
|
|
|
v-model='current.target'
|
|
|
|
)
|
|
|
|
v-card-chin
|
|
|
|
v-spacer
|
2018-09-29 19:39:09 +00:00
|
|
|
v-btn(color='red', outline, @click='deleteItem(current)')
|
2018-09-23 04:14:01 +00:00
|
|
|
v-icon(left) delete
|
2018-09-29 19:39:09 +00:00
|
|
|
span {{$t('navigation.delete', { kind: $t('navigation.link') })}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-card(v-else-if='current.kind === "header"')
|
|
|
|
v-toolbar(dense, color='blue', flat, dark)
|
2018-09-29 19:39:09 +00:00
|
|
|
.subheading {{$t('navigation.edit', { kind: $t('navigation.header') })}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-card-text
|
|
|
|
v-text-field(
|
|
|
|
outline
|
|
|
|
background-color='grey lighten-2'
|
2018-09-29 19:39:09 +00:00
|
|
|
:label='$t("navigation.label")'
|
2018-09-23 04:14:01 +00:00
|
|
|
prepend-icon='title'
|
|
|
|
v-model='current.label'
|
|
|
|
)
|
|
|
|
v-card-chin
|
|
|
|
v-spacer
|
2018-09-29 19:39:09 +00:00
|
|
|
v-btn(color='red', outline, @click='deleteItem(current)')
|
2018-09-23 04:14:01 +00:00
|
|
|
v-icon(left) delete
|
2018-09-29 19:39:09 +00:00
|
|
|
span {{$t('navigation.delete', { kind: $t('navigation.header') })}}
|
2018-09-23 04:14:01 +00:00
|
|
|
div(v-else-if='current.kind === "divider"')
|
2018-09-29 19:39:09 +00:00
|
|
|
v-btn.mt-0(color='red', outline, @click='deleteItem(current)')
|
2018-09-23 04:14:01 +00:00
|
|
|
v-icon(left) delete
|
2018-09-29 19:39:09 +00:00
|
|
|
span {{$t('navigation.delete', { kind: $t('navigation.divider') })}}
|
2018-09-23 04:14:01 +00:00
|
|
|
v-card(v-else)
|
2018-09-30 03:30:20 +00:00
|
|
|
v-card-text.grey--text(v-if='navTree.length > 0') {{$t('navigation.noSelectionText')}}
|
|
|
|
v-card-text.grey--text(v-else) {{$t('navigation.noItemsText')}}
|
2018-09-23 04:14:01 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-09-29 19:39:09 +00:00
|
|
|
import _ from 'lodash'
|
|
|
|
import uuid from 'uuid/v4'
|
|
|
|
|
|
|
|
import treeSaveMutation from 'gql/admin/navigation/navigation-mutation-save-tree.gql'
|
|
|
|
import treeQuery from 'gql/admin/navigation/navigation-query-tree.gql'
|
|
|
|
|
2018-09-23 04:14:01 +00:00
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
draggable
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2018-09-29 19:39:09 +00:00
|
|
|
navTree: [],
|
2018-09-23 04:14:01 +00:00
|
|
|
current: {}
|
|
|
|
}
|
|
|
|
},
|
2018-09-29 19:39:09 +00:00
|
|
|
computed: {
|
|
|
|
navTypes() {
|
|
|
|
return [
|
|
|
|
{ text: this.$t('navigation.navType.external'), value: 'external' },
|
|
|
|
{ text: this.$t('navigation.navType.home'), value: 'home' },
|
|
|
|
{ text: this.$t('navigation.navType.page'), value: 'page' },
|
|
|
|
{ text: this.$t('navigation.navType.searchQuery'), value: 'search' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2018-09-23 04:14:01 +00:00
|
|
|
methods: {
|
|
|
|
addItem(kind) {
|
|
|
|
let newItem = {
|
2018-09-29 19:39:09 +00:00
|
|
|
id: uuid(),
|
2018-09-23 04:14:01 +00:00
|
|
|
kind
|
|
|
|
}
|
|
|
|
switch (kind) {
|
|
|
|
case 'link':
|
|
|
|
newItem = {
|
|
|
|
...newItem,
|
2018-09-29 19:39:09 +00:00
|
|
|
label: this.$t('navigation.untitled', { kind: this.$t(`navigation.link`) }),
|
2018-09-23 04:14:01 +00:00
|
|
|
icon: 'chevron_right',
|
|
|
|
targetType: 'home',
|
|
|
|
target: '/'
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case 'header':
|
2018-09-29 19:39:09 +00:00
|
|
|
newItem.label = this.$t('navigation.untitled', { kind: this.$t(`navigation.header`) })
|
2018-09-23 04:14:01 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
this.navTree.push(newItem)
|
|
|
|
this.current = newItem
|
|
|
|
},
|
2018-09-29 19:39:09 +00:00
|
|
|
deleteItem(item) {
|
|
|
|
this.navTree = _.pull(this.navTree, item)
|
|
|
|
this.current = {}
|
|
|
|
},
|
2018-09-23 04:14:01 +00:00
|
|
|
selectItem(item) {
|
|
|
|
this.current = item
|
2018-09-29 19:39:09 +00:00
|
|
|
},
|
|
|
|
async save() {
|
|
|
|
this.$store.commit(`loadingStart`, 'admin-navigation-save')
|
|
|
|
try {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: treeSaveMutation,
|
|
|
|
variables: {
|
|
|
|
tree: this.navTree
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
this.$store.commit('showNotification', {
|
|
|
|
message: this.$t('navigation.saveSuccess'),
|
|
|
|
style: 'success',
|
|
|
|
icon: 'check'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.$store.commit(`loadingStop`, 'admin-navigation-save')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
navTree: {
|
|
|
|
query: treeQuery,
|
|
|
|
fetchPolicy: 'network-only',
|
|
|
|
update: (data) => _.cloneDeep(data.navigation.tree),
|
|
|
|
watchLoading (isLoading) {
|
|
|
|
this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-navigation-tree')
|
|
|
|
}
|
2018-09-23 04:14:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang='scss' scoped>
|
|
|
|
|
|
|
|
.clickable {
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background-color: rgba(mc('blue', '500'), .25);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|