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.

526 lines
23 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='/_assets/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-p3s(icon, outlined, color='grey', href='https://docs.requarks.io/navigation', target='_blank')
  12. v-icon mdi-help-circle
  13. v-btn.mx-3.animated.fadeInDown.wait-p2s.mr-3(icon, outlined, color='grey', @click='refresh')
  14. v-icon mdi-refresh
  15. v-btn.animated.fadeInDown(color='success', depressed, @click='save', large)
  16. v-icon(left) mdi-check
  17. span {{$t('common:actions.apply')}}
  18. v-container.pa-0.mt-3(fluid, grid-list-lg)
  19. v-row(dense)
  20. v-col(cols='3')
  21. v-card.animated.fadeInUp
  22. v-toolbar(color='teal', dark, dense, flat, height='56')
  23. v-toolbar-title.subtitle-1 {{$t('admin:navigation.mode')}}
  24. v-list(nav, two-line)
  25. v-list-item-group(v-model='config.mode', mandatory, :color='$vuetify.theme.dark ? `teal lighten-3` : `teal`')
  26. v-list-item(value='TREE')
  27. v-list-item-avatar
  28. img(src='/_assets/svg/icon-tree-structure-dotted.svg', alt='Site Tree')
  29. v-list-item-content
  30. v-list-item-title {{$t('admin:navigation.modeSiteTree.title')}}
  31. v-list-item-subtitle {{$t('admin:navigation.modeSiteTree.description')}}
  32. v-list-item-avatar
  33. v-icon(v-if='$vuetify.theme.dark', :color='config.mode === `TREE` ? `teal lighten-3` : `grey darken-2`') mdi-check-circle
  34. v-icon(v-else, :color='config.mode === `TREE` ? `teal` : `grey lighten-3`') mdi-check-circle
  35. v-list-item(value='STATIC')
  36. v-list-item-avatar
  37. img(src='/_assets/svg/icon-features-list.svg', alt='Static Navigation')
  38. v-list-item-content
  39. v-list-item-title {{$t('admin:navigation.modeStatic.title')}}
  40. v-list-item-subtitle {{$t('admin:navigation.modeStatic.description')}}
  41. v-list-item-avatar
  42. v-icon(v-if='$vuetify.theme.dark', :color='config.mode === `STATIC` ? `teal lighten-3` : `grey darken-2`') mdi-check-circle
  43. v-icon(v-else, :color='config.mode === `STATIC` ? `teal` : `grey lighten-3`') mdi-check-circle
  44. v-list-item(value='MIXED')
  45. v-list-item-avatar
  46. img(src='/_assets/svg/icon-user-menu-male-dotted.svg', alt='Custom Navigation')
  47. v-list-item-content
  48. v-list-item-title {{$t('admin:navigation.modeCustom.title')}}
  49. v-list-item-subtitle {{$t('admin:navigation.modeCustom.description')}}
  50. v-list-item-avatar
  51. v-icon(v-if='$vuetify.theme.dark', :color='config.mode === `MIXED` ? `teal lighten-3` : `grey darken-2`') mdi-check-circle
  52. v-icon(v-else, :color='config.mode === `MIXED` ? `teal` : `grey lighten-3`') mdi-check-circle
  53. v-list-item(value='NONE')
  54. v-list-item-avatar
  55. img(src='/_assets/svg/icon-cancel-dotted.svg', alt='None')
  56. v-list-item-content
  57. v-list-item-title {{$t('admin:navigation.modeNone.title')}}
  58. v-list-item-subtitle {{$t('admin:navigation.modeNone.description')}}
  59. v-list-item-avatar
  60. v-icon(v-if='$vuetify.theme.dark', :color='config.mode === `none` ? `teal lighten-3` : `grey darken-2`') mdi-check-circle
  61. v-icon(v-else, :color='config.mode === `none` ? `teal` : `grey lighten-3`') mdi-check-circle
  62. v-col(cols='9', v-if='config.mode === `MIXED` || config.mode === `STATIC`')
  63. v-card.animated.fadeInUp.wait-p2s
  64. v-row(no-gutters, align='stretch')
  65. v-col(style='flex: 0 0 350px;')
  66. v-card.grey(flat, style='height: 100%; border-radius: 4px 0 0 4px;', :class='$vuetify.theme.dark ? `darken-4-l5` : `lighten-3`')
  67. .teal.lighten-1.pa-2.d-flex(style='margin-bottom: 1px; height:56px;')
  68. v-select(
  69. :disabled='locales.length < 2'
  70. label='Locale'
  71. hide-details
  72. solo
  73. flat
  74. background-color='teal darken-2'
  75. dark
  76. dense
  77. v-model='currentLang'
  78. :items='locales'
  79. item-text='nativeName'
  80. item-value='code'
  81. )
  82. v-tooltip(top)
  83. template(v-slot:activator='{ on }')
  84. v-btn.ml-2(icon, tile, color='white', v-on='on', @click='copyFromLocaleDialogIsShown = true')
  85. v-icon mdi-arrange-send-backward
  86. span {{$t('admin:navigation.copyFromLocale')}}
  87. v-list.py-2(dense, nav, dark, class='blue darken-2', style='border-radius: 0;')
  88. v-list-item(v-if='currentTree.length < 1')
  89. v-list-item-avatar(size='24'): v-icon(color='blue lighten-3') mdi-alert
  90. v-list-item-content
  91. em.caption.blue--text.text--lighten-4 {{$t('navigation.emptyList')}}
  92. draggable(v-model='currentTree')
  93. template(v-for='navItem in currentTree')
  94. v-list-item(
  95. v-if='navItem.kind === "link"'
  96. :key='navItem.id'
  97. :class='(navItem === current) ? "blue" : ""'
  98. @click='selectItem(navItem)'
  99. )
  100. v-list-item-avatar(size='24', tile)
  101. v-icon(v-if='navItem.icon.match(/fa[a-z] fa-/)', size='19') {{ navItem.icon }}
  102. v-icon(v-else) {{ navItem.icon }}
  103. v-list-item-title {{navItem.label}}
  104. .py-2.clickable(
  105. v-else-if='navItem.kind === "divider"'
  106. :key='navItem.id'
  107. :class='(navItem === current) ? "blue" : ""'
  108. @click='selectItem(navItem)'
  109. )
  110. v-divider
  111. v-subheader.pl-4.clickable(
  112. v-else-if='navItem.kind === "header"'
  113. :key='navItem.id'
  114. :class='(navItem === current) ? "blue" : ""'
  115. @click='selectItem(navItem)'
  116. ) {{navItem.label}}
  117. v-card-chin
  118. v-menu(offset-y, bottom, min-width='200px', style='flex: 1 1;')
  119. template(v-slot:activator='{ on }')
  120. v-btn(v-on='on', color='primary', depressed, block)
  121. v-icon(left) mdi-plus
  122. span {{$t('common:actions.add')}}
  123. v-list
  124. v-list-item(@click='addItem("link")')
  125. v-list-item-avatar(size='24'): v-icon mdi-link
  126. v-list-item-title {{$t('navigation.link')}}
  127. v-list-item(@click='addItem("header")')
  128. v-list-item-avatar(size='24'): v-icon mdi-format-title
  129. v-list-item-title {{$t('navigation.header')}}
  130. v-list-item(@click='addItem("divider")')
  131. v-list-item-avatar(size='24'): v-icon mdi-minus
  132. v-list-item-title {{$t('navigation.divider')}}
  133. v-col
  134. v-card(flat, style='border-radius: 0 4px 4px 0;')
  135. template(v-if='current.kind === "link"')
  136. v-toolbar(height='56', color='teal lighten-1', flat, dark)
  137. .subtitle-1 {{$t('navigation.edit', { kind: $t('navigation.link') })}}
  138. v-spacer
  139. v-btn.px-5(color='white', outlined, @click='deleteItem(current)')
  140. v-icon(left) mdi-delete
  141. span {{$t('navigation.delete', { kind: $t('navigation.link') })}}
  142. v-card-text
  143. v-text-field(
  144. outlined
  145. :label='$t("navigation.label")'
  146. prepend-icon='mdi-format-title'
  147. v-model='current.label'
  148. counter='255'
  149. )
  150. v-text-field(
  151. outlined
  152. :label='$t("navigation.icon")'
  153. prepend-icon='mdi-dice-5'
  154. v-model='current.icon'
  155. hide-details
  156. )
  157. .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.
  158. .caption.pt-3.pl-5: strong Material Design Icons
  159. .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]
  160. .caption.pt-3.pl-5: strong Font Awesome 5
  161. .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]).
  162. .caption.pt-3.pl-5: strong Font Awesome 4
  163. .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]
  164. v-divider
  165. v-card-text
  166. v-select(
  167. outlined
  168. :label='$t("navigation.targetType")'
  169. prepend-icon='mdi-near-me'
  170. :items='navTypes'
  171. v-model='current.targetType'
  172. hide-details
  173. )
  174. v-text-field.mt-4(
  175. v-if='current.targetType === `external` || current.targetType === `externalblank`'
  176. outlined
  177. :label='$t("navigation.target")'
  178. prepend-icon='mdi-near-me'
  179. v-model='current.target'
  180. hide-details
  181. )
  182. .d-flex.align-center.mt-4(v-else-if='current.targetType === "page"')
  183. v-btn.ml-8(
  184. color='primary'
  185. dark
  186. @click='selectPage'
  187. )
  188. v-icon(left) mdi-magnify
  189. span {{$t('admin:navigation.selectPageButton')}}
  190. .caption.ml-4.primary--text {{current.target}}
  191. v-text-field(
  192. v-else-if='current.targetType === `search`'
  193. outlined
  194. :label='$t("navigation.navType.searchQuery")'
  195. prepend-icon='search'
  196. v-model='current.target'
  197. )
  198. v-divider
  199. template(v-else-if='current.kind === "header"')
  200. v-toolbar(height='56', color='teal lighten-1', flat, dark)
  201. .subtitle-1 {{$t('navigation.edit', { kind: $t('navigation.header') })}}
  202. v-spacer
  203. v-btn.px-5(color='white', outlined, @click='deleteItem(current)')
  204. v-icon(left) mdi-delete
  205. span {{$t('navigation.delete', { kind: $t('navigation.header') })}}
  206. v-card-text
  207. v-text-field(
  208. outlined
  209. :label='$t("navigation.label")'
  210. prepend-icon='mdi-format-title'
  211. v-model='current.label'
  212. )
  213. v-divider
  214. div(v-else-if='current.kind === "divider"')
  215. v-toolbar(height='56', color='teal lighten-1', flat, dark)
  216. .subtitle-1 {{$t('navigation.edit', { kind: $t('navigation.divider') })}}
  217. v-spacer
  218. v-btn.px-5(color='white', outlined, @click='deleteItem(current)')
  219. v-icon(left) mdi-delete
  220. span {{$t('navigation.delete', { kind: $t('navigation.divider') })}}
  221. v-card-text(v-if='current.kind')
  222. v-radio-group.pl-8(v-model='current.visibilityMode', mandatory, hide-details)
  223. v-radio(:label='$t("admin:navigation.visibilityMode.all")', value='all', color='primary')
  224. v-radio.mt-3(:label='$t("admin:navigation.visibilityMode.restricted")', value='restricted', color='primary')
  225. .pl-8
  226. v-select.pl-8.mt-3(
  227. item-text='name'
  228. item-value='id'
  229. outlined
  230. prepend-icon='mdi-account-group'
  231. label='Groups'
  232. :disabled='current.visibilityMode !== `restricted`'
  233. v-model='current.visibilityGroups'
  234. :items='groups'
  235. persistent-hint
  236. clearable
  237. multiple
  238. )
  239. template(v-else)
  240. v-toolbar(height='56', color='teal lighten-1', flat, dark)
  241. v-card-text.grey--text(v-if='currentTree.length > 0') {{$t('navigation.noSelectionText')}}
  242. v-card-text.grey--text(v-else) {{$t('navigation.noItemsText')}}
  243. v-dialog(v-model='copyFromLocaleDialogIsShown', max-width='650', persistent)
  244. v-card
  245. .dialog-header.is-short.is-teal
  246. v-icon.mr-3(color='white') mdi-arrange-send-backward
  247. span {{$t('admin:navigation.copyFromLocale')}}
  248. v-card-text.pt-5
  249. .body-2 {{$t('admin:navigation.copyFromLocaleInfoText')}}
  250. v-select.mt-3(
  251. :items='locales'
  252. item-text='nativeName'
  253. item-value='code'
  254. outlined
  255. prepend-icon='mdi-web'
  256. v-model='copyFromLocaleCode'
  257. :label='$t(`admin:navigation.sourceLocale`)'
  258. :hint='$t(`admin:navigation.sourceLocaleHint`)'
  259. persistent-hint
  260. )
  261. v-card-chin
  262. v-spacer
  263. v-btn(text, @click='copyFromLocaleDialogIsShown = false') {{$t('common:actions.cancel')}}
  264. v-btn.px-3(depressed, color='primary', @click='copyFromLocale')
  265. v-icon(left) mdi-chevron-right
  266. span {{$t('common:actions.copy')}}
  267. page-selector(mode='select', v-model='selectPageModal', :open-handler='selectPageHandle', path='home', :locale='currentLang')
  268. </template>
  269. <script>
  270. import _ from 'lodash'
  271. import gql from 'graphql-tag'
  272. import { v4 as uuid } from 'uuid'
  273. import groupsQuery from 'gql/admin/users/users-query-groups.gql'
  274. import draggable from 'vuedraggable'
  275. /* global siteConfig, siteLangs */
  276. export default {
  277. components: {
  278. draggable
  279. },
  280. data() {
  281. return {
  282. selectPageModal: false,
  283. trees: [],
  284. current: {},
  285. currentLang: siteConfig.lang,
  286. groups: [],
  287. copyFromLocaleDialogIsShown: false,
  288. config: {
  289. mode: 'NONE'
  290. },
  291. allLocales: [],
  292. copyFromLocaleCode: 'en'
  293. }
  294. },
  295. computed: {
  296. navTypes () {
  297. return [
  298. { text: this.$t('navigation.navType.external'), value: 'external' },
  299. { text: this.$t('navigation.navType.externalblank'), value: 'externalblank' },
  300. { text: this.$t('navigation.navType.home'), value: 'home' },
  301. { text: this.$t('navigation.navType.page'), value: 'page' }
  302. // { text: this.$t('navigation.navType.searchQuery'), value: 'search' }
  303. ]
  304. },
  305. locales () {
  306. return _.intersectionBy(this.allLocales, _.unionBy(siteLangs, [{ code: 'en' }, { code: siteConfig.lang }], 'code'), 'code')
  307. },
  308. currentTree: {
  309. get () {
  310. return _.get(_.find(this.trees, ['locale', this.currentLang]), 'items', null) || []
  311. },
  312. set (val) {
  313. const tree = _.find(this.trees, ['locale', this.currentLang])
  314. if (tree) {
  315. tree.items = val
  316. } else {
  317. this.trees = [...this.trees, {
  318. locale: this.currentLang,
  319. items: val
  320. }]
  321. }
  322. }
  323. }
  324. },
  325. watch: {
  326. currentLang (newValue, oldValue) {
  327. this.$nextTick(() => {
  328. if (this.currentTree.length > 0) {
  329. this.current = this.currentTree[0]
  330. } else {
  331. this.current = {}
  332. }
  333. })
  334. }
  335. },
  336. methods: {
  337. addItem(kind) {
  338. let newItem = {
  339. id: uuid(),
  340. kind,
  341. visibilityMode: 'all',
  342. visibilityGroups: []
  343. }
  344. switch (kind) {
  345. case 'link':
  346. newItem = {
  347. ...newItem,
  348. label: this.$t('navigation.untitled', { kind: this.$t(`navigation.link`) }),
  349. icon: 'mdi-chevron-right',
  350. targetType: 'home',
  351. target: ''
  352. }
  353. break
  354. case 'header':
  355. newItem.label = this.$t('navigation.untitled', { kind: this.$t(`navigation.header`) })
  356. break
  357. }
  358. this.currentTree = [...this.currentTree, newItem]
  359. this.current = newItem
  360. },
  361. deleteItem(item) {
  362. this.currentTree = _.pull(this.currentTree, item)
  363. this.current = {}
  364. },
  365. selectItem(item) {
  366. this.current = item
  367. },
  368. selectPage() {
  369. this.selectPageModal = true
  370. },
  371. selectPageHandle ({ path, locale }) {
  372. this.current.target = `/${locale}/${path}`
  373. },
  374. copyFromLocale () {
  375. this.copyFromLocaleDialogIsShown = false
  376. this.currentTree = [...this.currentTree, ..._.get(_.find(this.trees, ['locale', this.copyFromLocaleCode]), 'items', null) || []]
  377. },
  378. async save() {
  379. this.$store.commit(`loadingStart`, 'admin-navigation-save')
  380. try {
  381. const resp = await this.$apollo.mutate({
  382. mutation: gql`
  383. mutation ($tree: [NavigationTreeInput]!, $mode: NavigationMode!) {
  384. navigation{
  385. updateTree(tree: $tree) {
  386. responseResult {
  387. succeeded
  388. errorCode
  389. slug
  390. message
  391. }
  392. },
  393. updateConfig(mode: $mode) {
  394. responseResult {
  395. succeeded
  396. errorCode
  397. slug
  398. message
  399. }
  400. }
  401. }
  402. }
  403. `,
  404. variables: {
  405. tree: this.trees,
  406. mode: this.config.mode
  407. }
  408. })
  409. if (_.get(resp, 'data.navigation.updateTree.responseResult.succeeded', false) && _.get(resp, 'data.navigation.updateConfig.responseResult.succeeded', false)) {
  410. this.$store.commit('showNotification', {
  411. message: this.$t('navigation.saveSuccess'),
  412. style: 'success',
  413. icon: 'check'
  414. })
  415. } else {
  416. throw new Error(_.get(resp, 'data.navigation.updateTree.responseResult.message', 'An unexpected error occurred.'))
  417. }
  418. } catch (err) {
  419. this.$store.commit('pushGraphError', err)
  420. }
  421. this.$store.commit(`loadingStop`, 'admin-navigation-save')
  422. },
  423. async refresh() {
  424. await this.$apollo.queries.trees.refetch()
  425. this.current = {}
  426. this.$store.commit('showNotification', {
  427. message: 'Navigation has been refreshed.',
  428. style: 'success',
  429. icon: 'cached'
  430. })
  431. }
  432. },
  433. apollo: {
  434. config: {
  435. query: gql`
  436. {
  437. navigation {
  438. config {
  439. mode
  440. }
  441. }
  442. }
  443. `,
  444. fetchPolicy: 'network-only',
  445. update: (data) => _.cloneDeep(data.navigation.config),
  446. watchLoading (isLoading) {
  447. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-navigation-config')
  448. }
  449. },
  450. trees: {
  451. query: gql`
  452. {
  453. navigation {
  454. tree {
  455. locale
  456. items {
  457. id
  458. kind
  459. label
  460. icon
  461. targetType
  462. target
  463. visibilityMode
  464. visibilityGroups
  465. }
  466. }
  467. }
  468. }
  469. `,
  470. fetchPolicy: 'network-only',
  471. update: (data) => _.cloneDeep(data.navigation.tree),
  472. watchLoading (isLoading) {
  473. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-navigation-tree')
  474. }
  475. },
  476. groups: {
  477. query: groupsQuery,
  478. fetchPolicy: 'network-only',
  479. update: (data) => data.groups.list,
  480. watchLoading (isLoading) {
  481. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-navigation-groups')
  482. }
  483. },
  484. allLocales: {
  485. query: gql`
  486. {
  487. localization {
  488. locales {
  489. code
  490. name
  491. nativeName
  492. }
  493. }
  494. }
  495. `,
  496. fetchPolicy: 'network-only',
  497. update: (data) => data.localization.locales,
  498. watchLoading (isLoading) {
  499. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-navigation-locales')
  500. }
  501. }
  502. }
  503. }
  504. </script>
  505. <style lang='scss' scoped>
  506. .clickable {
  507. cursor: pointer;
  508. &:hover {
  509. background-color: rgba(mc('blue', '500'), .25);
  510. }
  511. }
  512. </style>