You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
11 KiB

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