admin-navigation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/svg/icon-triangle-arrow.svg', alt='Navigation', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{$t('navigation.title')}}
  9. .subheading.grey--text.animated.fadeInLeft.wait-p4s {{$t('navigation.subtitle')}}
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p2s(outline, color='grey', @click='refresh', large)
  12. v-icon refresh
  13. v-btn.animated.fadeInDown(color='success', depressed, @click='save', large)
  14. v-icon(left) check
  15. span {{$t('common:actions.apply')}}
  16. v-container.pa-0.mt-3(fluid, grid-list-lg)
  17. v-layout(row)
  18. v-flex(style='flex: 0 0 350px;')
  19. v-card.animated.fadeInUp
  20. v-list.py-2(dense, dark, :class='navTree.length < 1 ? "grey lighten-4" : "primary"')
  21. v-list-tile(v-if='navTree.length < 1')
  22. v-list-tile-avatar: v-icon(color='grey') explore_off
  23. v-list-tile-content
  24. .caption.grey--text {{$t('navigation.emptyList')}}
  25. draggable(v-model='navTree')
  26. template(v-for='navItem in navTree')
  27. v-list-tile(
  28. v-if='navItem.kind === "link"'
  29. :key='navItem.id'
  30. :class='(navItem === current) ? "blue" : ""'
  31. @click='selectItem(navItem)'
  32. )
  33. v-list-tile-avatar: v-icon {{navItem.icon}}
  34. v-list-tile-title {{navItem.label}}
  35. .py-2.clickable(
  36. v-else-if='navItem.kind === "divider"'
  37. :key='navItem.id'
  38. :class='(navItem === current) ? "blue" : ""'
  39. @click='selectItem(navItem)'
  40. )
  41. v-divider
  42. v-subheader.pl-4.clickable(
  43. v-else-if='navItem.kind === "header"'
  44. :key='navItem.id'
  45. :class='(navItem === current) ? "blue" : ""'
  46. @click='selectItem(navItem)'
  47. ) {{navItem.label}}
  48. v-card-chin
  49. v-menu(offset-y, bottom, min-width='200px', style='flex: 1 1;')
  50. v-btn(slot='activator', color='primary', depressed, block)
  51. v-icon(left) add
  52. span {{$t('common:actions.add')}}
  53. v-list
  54. v-list-tile(@click='addItem("link")')
  55. v-list-tile-avatar: v-icon link
  56. v-list-tile-title {{$t('navigation.link')}}
  57. v-list-tile(@click='addItem("header")')
  58. v-list-tile-avatar: v-icon title
  59. v-list-tile-title {{$t('navigation.header')}}
  60. v-list-tile(@click='addItem("divider")')
  61. v-list-tile-avatar: v-icon power_input
  62. v-list-tile-title {{$t('navigation.divider')}}
  63. v-flex.animated.fadeInUp.wait-p2s
  64. v-card.wiki-form(v-if='current.kind === "link"')
  65. v-toolbar(dense, color='blue', flat, dark)
  66. .subheading {{$t('navigation.edit', { kind: $t('navigation.link') })}}
  67. v-card-text
  68. v-text-field(
  69. outline
  70. :label='$t("navigation.label")'
  71. prepend-icon='title'
  72. v-model='current.label'
  73. )
  74. v-text-field(
  75. outline
  76. :label='$t("navigation.icon")'
  77. prepend-icon='casino'
  78. v-model='current.icon'
  79. hide-details
  80. )
  81. .caption.pt-3.pl-5 The default icon set is #[strong Material Icons]. In order to use another icon set, you must first select it in the Theme administration section.
  82. .caption.pt-3.pl-5 #[strong Material Icons] #[em (default)]
  83. .caption.pl-5 Refer to the #[a(href='https://material.io/tools/icons/?style=baseline', target='_blank') Material Icons Reference] for the list of all possible values.
  84. .caption.pt-3.pl-5: strong Material Design Icons
  85. .caption.pl-5 Refer to the #[a(href='https://cdn.materialdesignicons.com/3.7.95/', target='_blank') Material Design Icons Reference] for the list of all possible values. You must prefix all values with #[code mdi-], e.g. #[code mdi-home]
  86. .caption.pt-3.pl-5: strong Font Awesome 5
  87. .caption.pl-5 Refer to the #[a(href='https://fontawesome.com/icons?d=gallery&m=free', target='_blank') Font Awesome 5 Reference] for the list of all possible values. You must prefix all values with #[code fas fa-], e.g. #[code fas fa-home]
  88. .caption.pt-3.pl-5: strong Font Awesome 4
  89. .caption.pl-5 Refer to the #[a(href='https://fontawesome.com/v4.7.0/icons/', target='_blank') Font Awesome 4 Reference] for the list of all possible values. You must prefix all values with #[code fa fa-], e.g. #[code fa fa-home]
  90. v-select.mt-4(
  91. outline
  92. :label='$t("navigation.targetType")'
  93. prepend-icon='near_me'
  94. :items='navTypes'
  95. v-model='current.targetType'
  96. )
  97. v-text-field(
  98. v-if='current.targetType === `external`'
  99. outline
  100. :label='$t("navigation.target")'
  101. prepend-icon='near_me'
  102. v-model='current.target'
  103. )
  104. v-btn(
  105. v-else-if='current.targetType === "page"'
  106. color='indigo'
  107. :dark='false'
  108. disabled
  109. @click='selectPage'
  110. )
  111. v-icon(left) search
  112. span Select Page...
  113. v-text-field(
  114. v-else-if='current.targetType === `search`'
  115. outline
  116. :label='$t("navigation.navType.searchQuery")'
  117. prepend-icon='search'
  118. v-model='current.target'
  119. )
  120. v-card-chin
  121. v-spacer
  122. v-btn(color='red', outline, @click='deleteItem(current)')
  123. v-icon(left) delete
  124. span {{$t('navigation.delete', { kind: $t('navigation.link') })}}
  125. v-card(v-else-if='current.kind === "header"')
  126. v-toolbar(dense, color='blue', flat, dark)
  127. .subheading {{$t('navigation.edit', { kind: $t('navigation.header') })}}
  128. v-card-text
  129. v-text-field(
  130. outline
  131. background-color='grey lighten-2'
  132. :label='$t("navigation.label")'
  133. prepend-icon='title'
  134. v-model='current.label'
  135. )
  136. v-card-chin
  137. v-spacer
  138. v-btn(color='red', outline, @click='deleteItem(current)')
  139. v-icon(left) delete
  140. span {{$t('navigation.delete', { kind: $t('navigation.header') })}}
  141. div(v-else-if='current.kind === "divider"')
  142. v-btn.mt-0(color='red', outline, @click='deleteItem(current)')
  143. v-icon(left) delete
  144. span {{$t('navigation.delete', { kind: $t('navigation.divider') })}}
  145. v-card(v-else)
  146. v-card-text.grey--text(v-if='navTree.length > 0') {{$t('navigation.noSelectionText')}}
  147. v-card-text.grey--text(v-else) {{$t('navigation.noItemsText')}}
  148. </template>
  149. <script>
  150. import _ from 'lodash'
  151. import uuid from 'uuid/v4'
  152. import treeSaveMutation from 'gql/admin/navigation/navigation-mutation-save-tree.gql'
  153. import treeQuery from 'gql/admin/navigation/navigation-query-tree.gql'
  154. import draggable from 'vuedraggable'
  155. export default {
  156. components: {
  157. draggable
  158. },
  159. data() {
  160. return {
  161. navTree: [],
  162. current: {}
  163. }
  164. },
  165. computed: {
  166. navTypes() {
  167. return [
  168. // { text: this.$t('navigation.navType.external'), value: 'external' },
  169. { text: this.$t('navigation.navType.home'), value: 'home' },
  170. { text: 'Internal Path / External Link', value: 'external' },
  171. // { text: this.$t('navigation.navType.page'), value: 'page' }
  172. // { text: this.$t('navigation.navType.searchQuery'), value: 'search' }
  173. ]
  174. }
  175. },
  176. methods: {
  177. addItem(kind) {
  178. let newItem = {
  179. id: uuid(),
  180. kind
  181. }
  182. switch (kind) {
  183. case 'link':
  184. newItem = {
  185. ...newItem,
  186. label: this.$t('navigation.untitled', { kind: this.$t(`navigation.link`) }),
  187. icon: 'chevron_right',
  188. targetType: 'home',
  189. target: '/'
  190. }
  191. break
  192. case 'header':
  193. newItem.label = this.$t('navigation.untitled', { kind: this.$t(`navigation.header`) })
  194. break
  195. }
  196. this.navTree.push(newItem)
  197. this.current = newItem
  198. },
  199. deleteItem(item) {
  200. this.navTree = _.pull(this.navTree, item)
  201. this.current = {}
  202. },
  203. selectItem(item) {
  204. this.current = item
  205. },
  206. selectPage() {
  207. window.alert(`Coming soon. Use External Link for now (you can still specify internal links).`)
  208. },
  209. async save() {
  210. this.$store.commit(`loadingStart`, 'admin-navigation-save')
  211. try {
  212. const resp = await this.$apollo.mutate({
  213. mutation: treeSaveMutation,
  214. variables: {
  215. tree: this.navTree
  216. }
  217. })
  218. if (_.get(resp, 'data.navigation.updateTree.responseResult.succeeded', false)) {
  219. this.$store.commit('showNotification', {
  220. message: this.$t('navigation.saveSuccess'),
  221. style: 'success',
  222. icon: 'check'
  223. })
  224. } else {
  225. throw new Error(_.get(resp, 'data.navigation.updateTree.responseResult.message', 'An unexpected error occured.'))
  226. }
  227. } catch (err) {
  228. this.$store.commit('pushGraphError', err)
  229. }
  230. this.$store.commit(`loadingStop`, 'admin-navigation-save')
  231. },
  232. async refresh() {
  233. await this.$apollo.queries.navTree.refetch()
  234. this.current = {}
  235. this.$store.commit('showNotification', {
  236. message: 'Navigation has been refreshed.',
  237. style: 'success',
  238. icon: 'cached'
  239. })
  240. }
  241. },
  242. apollo: {
  243. navTree: {
  244. query: treeQuery,
  245. fetchPolicy: 'network-only',
  246. update: (data) => _.cloneDeep(data.navigation.tree),
  247. watchLoading (isLoading) {
  248. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-navigation-tree')
  249. }
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang='scss' scoped>
  255. .clickable {
  256. cursor: pointer;
  257. &:hover {
  258. background-color: rgba(mc('blue', '500'), .25);
  259. }
  260. }
  261. </style>