nav-header.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template lang='pug'>
  2. v-app-bar.nav-header(color='black', dark, app, :clipped-left='!$vuetify.rtl', :clipped-right='$vuetify.rtl', fixed, flat, :extended='searchIsShown && $vuetify.breakpoint.smAndDown')
  3. v-toolbar(color='deep-purple', flat, slot='extension', v-if='searchIsShown && $vuetify.breakpoint.smAndDown')
  4. v-text-field(
  5. ref='searchFieldMobile'
  6. v-model='search'
  7. clearable
  8. background-color='deep-purple'
  9. color='white'
  10. :label='$t(`common:header.search`)'
  11. single-line
  12. solo
  13. flat
  14. hide-details
  15. prepend-inner-icon='mdi-magnify'
  16. :loading='searchIsLoading'
  17. @keyup.enter='searchEnter'
  18. autocomplete='off'
  19. )
  20. v-layout(row)
  21. v-flex(xs5, md4)
  22. v-toolbar.nav-header-inner(color='black', dark, flat, :class='$vuetify.rtl ? `pr-3` : `pl-3`')
  23. v-avatar(tile, size='34', @click='goHome')
  24. v-img.org-logo(:src='logoUrl')
  25. //- v-menu(open-on-hover, offset-y, bottom, left, min-width='250', transition='slide-y-transition')
  26. //- template(v-slot:activator='{ on }')
  27. //- v-app-bar-nav-icon.btn-animate-app(v-on='on', :class='$vuetify.rtl ? `mx-0` : ``')
  28. //- v-icon mdi-menu
  29. //- v-list(nav, :light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark', :class='$vuetify.theme.dark ? `grey darken-4` : ``')
  30. //- v-list-item.pl-4(href='/')
  31. //- v-list-item-avatar(size='24'): v-icon(color='blue') mdi-home
  32. //- v-list-item-title.body-2 {{$t('common:header.home')}}
  33. //- v-list-item.pl-4(@click='')
  34. //- v-list-item-avatar(size='24'): v-icon(color='grey lighten-2') mdi-file-tree
  35. //- v-list-item-content
  36. //- v-list-item-title.body-2.grey--text.text--ligten-2 {{$t('common:header.siteMap')}}
  37. //- v-list-item-subtitle.overline.grey--text.text--lighten-2 Coming soon
  38. //- v-list-item.pl-4(href='/t')
  39. //- v-list-item-avatar(size='24'): v-icon(color='teal') mdi-tag-multiple
  40. //- v-list-item-title.body-2 {{$t('common:header.browseTags')}}
  41. //- v-list-item.pl-4(@click='assets')
  42. //- v-list-item-avatar(size='24'): v-icon(color='grey lighten-2') mdi-folder-multiple-image
  43. //- v-list-item-content
  44. //- v-list-item-title.body-2.grey--text.text--ligten-2 {{$t('common:header.imagesFiles')}}
  45. //- v-list-item-subtitle.overline.grey--text.text--lighten-2 Coming soon
  46. v-toolbar-title(:class='{ "mx-3": $vuetify.breakpoint.mdAndUp, "mx-1": $vuetify.breakpoint.smAndDown }')
  47. span.subheading {{title}}
  48. v-flex(md4, v-if='$vuetify.breakpoint.mdAndUp')
  49. v-toolbar.nav-header-inner(color='black', dark, flat)
  50. slot(name='mid')
  51. transition(name='navHeaderSearch', v-if='searchIsShown')
  52. v-text-field(
  53. ref='searchField',
  54. v-if='searchIsShown && $vuetify.breakpoint.mdAndUp',
  55. v-model='search',
  56. color='white',
  57. :label='$t(`common:header.search`)',
  58. single-line,
  59. solo
  60. flat
  61. rounded
  62. hide-details,
  63. prepend-inner-icon='mdi-magnify',
  64. :loading='searchIsLoading',
  65. @keyup.enter='searchEnter'
  66. @keyup.esc='searchClose'
  67. @focus='searchFocus'
  68. @blur='searchBlur'
  69. @keyup.down='searchMove(`down`)'
  70. @keyup.up='searchMove(`up`)'
  71. autocomplete='off'
  72. )
  73. v-tooltip(bottom)
  74. template(v-slot:activator='{ on }')
  75. v-btn.ml-2.mr-0(icon, v-on='on', href='/t', :aria-label='$t(`common:header.browseTags`)')
  76. v-icon(color='grey') mdi-tag-multiple
  77. span {{$t('common:header.browseTags')}}
  78. v-flex(xs7, md4)
  79. v-toolbar.nav-header-inner.pr-4(color='black', dark, flat)
  80. v-spacer
  81. .navHeaderLoading.mr-3
  82. v-progress-circular(indeterminate, color='blue', :size='22', :width='2' v-show='isLoading')
  83. slot(name='actions')
  84. //- (mobile) SEARCH TOGGLE
  85. v-btn(
  86. v-if='!hideSearch && $vuetify.breakpoint.smAndDown'
  87. @click='searchToggle'
  88. icon
  89. )
  90. v-icon(color='grey') mdi-magnify
  91. //- LANGUAGES
  92. template(v-if='mode === `view` && locales.length > 0')
  93. v-menu(offset-y, bottom, transition='slide-y-transition', max-height='320px', min-width='210px', left)
  94. template(v-slot:activator='{ on: menu, attrs }')
  95. v-tooltip(bottom)
  96. template(v-slot:activator='{ on: tooltip }')
  97. v-btn(
  98. icon
  99. v-bind='attrs'
  100. v-on='{ ...menu, ...tooltip }'
  101. :class='$vuetify.rtl ? `ml-3` : ``'
  102. tile
  103. height='64'
  104. :aria-label='$t(`common:header.language`)'
  105. )
  106. v-icon(color='grey') mdi-web
  107. span {{$t('common:header.language')}}
  108. v-list(nav)
  109. template(v-for='(lc, idx) of locales')
  110. v-list-item(@click='changeLocale(lc)')
  111. v-list-item-action(style='min-width:auto;'): v-chip(:color='lc.code === locale ? `blue` : `grey`', small, label, dark) {{lc.code.toUpperCase()}}
  112. v-list-item-title {{lc.name}}
  113. v-divider(vertical)
  114. //- PAGE ACTIONS
  115. template(v-if='hasAnyPagePermissions && path && mode !== `edit`')
  116. v-menu(offset-y, bottom, transition='slide-y-transition', left)
  117. template(v-slot:activator='{ on: menu, attrs }')
  118. v-tooltip(bottom)
  119. template(v-slot:activator='{ on: tooltip }')
  120. v-btn(
  121. icon
  122. v-bind='attrs'
  123. v-on='{ ...menu, ...tooltip }'
  124. :class='$vuetify.rtl ? `ml-3` : ``'
  125. tile
  126. height='64'
  127. :aria-label='$t(`common:header.pageActions`)'
  128. )
  129. v-icon(color='grey') mdi-file-document-edit-outline
  130. span {{$t('common:header.pageActions')}}
  131. v-list(nav, :light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark', :class='$vuetify.theme.dark ? `grey darken-4` : ``')
  132. .overline.pa-4.grey--text {{$t('common:header.currentPage')}}
  133. v-list-item.pl-4(@click='pageView', v-if='mode !== `view`')
  134. v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-file-document-outline
  135. v-list-item-title.body-2 {{$t('common:header.view')}}
  136. v-list-item.pl-4(@click='pageEdit', v-if='mode !== `edit` && hasWritePagesPermission')
  137. v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-file-document-edit-outline
  138. v-list-item-title.body-2 {{$t('common:header.edit')}}
  139. v-list-item.pl-4(@click='pageHistory', v-if='mode !== `history` && hasReadHistoryPermission')
  140. v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-history
  141. v-list-item-content
  142. v-list-item-title.body-2 {{$t('common:header.history')}}
  143. v-list-item.pl-4(@click='pageSource', v-if='mode !== `source` && hasReadSourcePermission')
  144. v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-code-tags
  145. v-list-item-title.body-2 {{$t('common:header.viewSource')}}
  146. v-list-item.pl-4(@click='pageDuplicate', v-if='hasWritePagesPermission')
  147. v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-content-duplicate
  148. v-list-item-title.body-2 {{$t('common:header.duplicate')}}
  149. v-list-item.pl-4(@click='pageMove', v-if='hasManagePagesPermission')
  150. v-list-item-avatar(size='24', tile): v-icon(color='indigo') mdi-content-save-move-outline
  151. v-list-item-content
  152. v-list-item-title.body-2 {{$t('common:header.move')}}
  153. v-list-item.pl-4(@click='pageDelete', v-if='hasDeletePagesPermission')
  154. v-list-item-avatar(size='24', tile): v-icon(color='red darken-2') mdi-trash-can-outline
  155. v-list-item-title.body-2 {{$t('common:header.delete')}}
  156. v-divider(vertical)
  157. //- NEW PAGE
  158. template(v-if='hasNewPagePermission && path && mode !== `edit`')
  159. v-tooltip(bottom)
  160. template(v-slot:activator='{ on }')
  161. v-btn(icon, tile, height='64', v-on='on', @click='pageNew', :aria-label='$t(`common:header.newPage`)')
  162. v-icon(color='grey') mdi-text-box-plus-outline
  163. span {{$t('common:header.newPage')}}
  164. v-divider(vertical)
  165. //- ACCOUNT
  166. v-menu(v-if='isAuthenticated', offset-y, bottom, min-width='300', transition='slide-y-transition', left)
  167. template(v-slot:activator='{ on: menu, attrs }')
  168. v-tooltip(bottom)
  169. template(v-slot:activator='{ on: tooltip }')
  170. v-btn(
  171. icon
  172. v-bind='attrs'
  173. v-on='{ ...menu, ...tooltip }'
  174. :class='$vuetify.rtl ? `ml-0` : ``'
  175. tile
  176. height='64'
  177. :aria-label='$t(`common:header.account`)'
  178. )
  179. v-icon(v-if='picture.kind === `initials`', color='grey') mdi-account-circle
  180. v-avatar(v-else-if='picture.kind === `image`', :size='34')
  181. v-img(:src='picture.url')
  182. span {{$t('common:header.account')}}
  183. v-list(nav)
  184. v-list-item.py-3.grey(:class='$vuetify.theme.dark ? `darken-4-l5` : `lighten-5`')
  185. v-list-item-avatar
  186. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  187. span.white--text.subheading {{picture.initials}}
  188. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  189. v-img(:src='picture.url')
  190. v-list-item-content
  191. v-list-item-title {{name}}
  192. v-list-item-subtitle {{email}}
  193. //- v-list-item(href='/w', disabled)
  194. //- v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
  195. //- v-list-item-content
  196. //- v-list-item-title {{$t('common:header.myWiki')}}
  197. //- v-list-item-subtitle.overline Coming soon
  198. v-list-item(href='/p')
  199. v-list-item-action: v-icon(color='blue-grey') mdi-face-profile
  200. v-list-item-content
  201. v-list-item-title(:class='$vuetify.theme.dark ? `blue-grey--text text--lighten-3` : `blue-grey--text`') {{$t('common:header.profile')}}
  202. v-list-item(href='/a', v-if='isAuthenticated && isAdmin')
  203. v-list-item-action.btn-animate-rotate: v-icon(:color='$vuetify.theme.dark ? `blue-grey lighten-3` : `blue-grey`') mdi-cog
  204. v-list-item-title(:class='$vuetify.theme.dark ? `blue-grey--text text--lighten-3` : `blue-grey--text`') {{$t('common:header.admin')}}
  205. v-list-item(@click='logout')
  206. v-list-item-action: v-icon(color='red') mdi-logout
  207. v-list-item-title.red--text {{$t('common:header.logout')}}
  208. v-tooltip(v-else, left)
  209. template(v-slot:activator='{ on }')
  210. v-btn(icon, v-on='on', color='grey darken-3', href='/login', :aria-label='$t(`common:header.login`)')
  211. v-icon(color='grey') mdi-account-circle
  212. span {{$t('common:header.login')}}
  213. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate', :locale='locale')
  214. page-selector(mode='move', v-model='movePageModal', :open-handler='pageMoveRename', :path='path', :locale='locale')
  215. page-selector(mode='create', v-model='duplicateOpts.modal', :open-handler='pageDuplicateHandle', :path='duplicateOpts.path', :locale='duplicateOpts.locale')
  216. page-delete(v-model='deletePageModal', v-if='path && path.length')
  217. .nav-header-dev(v-if='isDevMode')
  218. v-icon mdi-alert
  219. div
  220. .overline DEVELOPMENT VERSION
  221. .overline This code base is NOT for production use!
  222. </template>
  223. <script>
  224. import { get, sync } from 'vuex-pathify'
  225. import _ from 'lodash'
  226. import Cookies from 'js-cookie'
  227. import movePageMutation from 'gql/common/common-pages-mutation-move.gql'
  228. /* global siteConfig, siteLangs */
  229. export default {
  230. components: {
  231. PageDelete: () => import('./page-delete.vue')
  232. },
  233. props: {
  234. dense: {
  235. type: Boolean,
  236. default: false
  237. },
  238. hideSearch: {
  239. type: Boolean,
  240. default: false
  241. }
  242. },
  243. data() {
  244. return {
  245. menuIsShown: true,
  246. searchIsShown: true,
  247. searchAdvMenuShown: false,
  248. newPageModal: false,
  249. movePageModal: false,
  250. deletePageModal: false,
  251. locales: siteLangs,
  252. isDevMode: false,
  253. duplicateOpts: {
  254. locale: 'en',
  255. path: 'new-page',
  256. modal: false
  257. }
  258. }
  259. },
  260. computed: {
  261. search: sync('site/search'),
  262. searchIsFocused: sync('site/searchIsFocused'),
  263. searchIsLoading: sync('site/searchIsLoading'),
  264. searchRestrictLocale: sync('site/searchRestrictLocale'),
  265. searchRestrictPath: sync('site/searchRestrictPath'),
  266. isLoading: get('isLoading'),
  267. title: get('site/title'),
  268. logoUrl: get('site/logoUrl'),
  269. path: get('page/path'),
  270. locale: get('page/locale'),
  271. mode: get('page/mode'),
  272. name: get('user/name'),
  273. email: get('user/email'),
  274. pictureUrl: get('user/pictureUrl'),
  275. isAuthenticated: get('user/authenticated'),
  276. permissions: get('user/permissions'),
  277. picture () {
  278. if (this.pictureUrl && this.pictureUrl.length > 1) {
  279. return {
  280. kind: 'image',
  281. url: this.pictureUrl
  282. }
  283. } else {
  284. const nameParts = this.name.toUpperCase().split(' ')
  285. let initials = _.head(nameParts).charAt(0)
  286. if (nameParts.length > 1) {
  287. initials += _.last(nameParts).charAt(0)
  288. }
  289. return {
  290. kind: 'initials',
  291. initials
  292. }
  293. }
  294. },
  295. isAdmin () {
  296. return _.intersection(this.permissions, ['manage:system', 'write:users', 'manage:users', 'write:groups', 'manage:groups', 'manage:navigation', 'manage:theme', 'manage:api']).length > 0
  297. },
  298. hasNewPagePermission () {
  299. return this.hasAdminPermission || _.intersection(this.permissions, ['write:pages']).length > 0
  300. },
  301. hasAdminPermission: get('page/effectivePermissions@system.manage'),
  302. hasWritePagesPermission: get('page/effectivePermissions@pages.write'),
  303. hasManagePagesPermission: get('page/effectivePermissions@pages.manage'),
  304. hasDeletePagesPermission: get('page/effectivePermissions@pages.delete'),
  305. hasReadSourcePermission: get('page/effectivePermissions@source.read'),
  306. hasReadHistoryPermission: get('page/effectivePermissions@history.read'),
  307. hasAnyPagePermissions () {
  308. return this.hasAdminPermission || this.hasWritePagesPermission || this.hasManagePagesPermission ||
  309. this.hasDeletePagesPermission || this.hasReadSourcePermission || this.hasReadHistoryPermission
  310. }
  311. },
  312. created () {
  313. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  314. this.searchIsShown = false
  315. }
  316. },
  317. mounted () {
  318. this.$root.$on('pageEdit', () => {
  319. this.pageEdit()
  320. })
  321. this.$root.$on('pageHistory', () => {
  322. this.pageHistory()
  323. })
  324. this.$root.$on('pageSource', () => {
  325. this.pageSource()
  326. })
  327. this.$root.$on('pageMove', () => {
  328. this.pageMove()
  329. })
  330. this.$root.$on('pageDuplicate', () => {
  331. this.pageDuplicate()
  332. })
  333. this.$root.$on('pageDelete', () => {
  334. this.pageDelete()
  335. })
  336. this.isDevMode = siteConfig.devMode === true
  337. },
  338. methods: {
  339. searchFocus () {
  340. this.searchIsFocused = true
  341. },
  342. searchBlur () {
  343. this.searchIsFocused = false
  344. },
  345. searchClose () {
  346. this.search = ''
  347. this.searchBlur()
  348. },
  349. searchToggle () {
  350. this.searchIsShown = !this.searchIsShown
  351. if (this.searchIsShown) {
  352. _.delay(() => {
  353. this.$refs.searchFieldMobile.focus()
  354. }, 200)
  355. }
  356. },
  357. searchEnter () {
  358. this.$root.$emit('searchEnter', true)
  359. },
  360. searchMove(dir) {
  361. this.$root.$emit('searchMove', dir)
  362. },
  363. pageNew () {
  364. this.newPageModal = true
  365. },
  366. pageNewCreate ({ path, locale }) {
  367. window.location.assign(`/e/${locale}/${path}`)
  368. },
  369. pageView () {
  370. window.location.assign(`/${this.locale}/${this.path}`)
  371. },
  372. pageEdit () {
  373. window.location.assign(`/e/${this.locale}/${this.path}`)
  374. },
  375. pageHistory () {
  376. window.location.assign(`/h/${this.locale}/${this.path}`)
  377. },
  378. pageSource () {
  379. window.location.assign(`/s/${this.locale}/${this.path}`)
  380. },
  381. pageDuplicate () {
  382. const pathParts = this.path.split('/')
  383. this.duplicateOpts = {
  384. locale: this.locale,
  385. path: (pathParts.length > 1) ? _.initial(pathParts).join('/') + `/new-page` : `new-page`,
  386. modal: true
  387. }
  388. },
  389. pageDuplicateHandle ({ locale, path }) {
  390. window.location.assign(`/e/${locale}/${path}?from=${this.$store.get('page/id')}`)
  391. },
  392. pageMove () {
  393. this.movePageModal = true
  394. },
  395. async pageMoveRename ({ path, locale }) {
  396. this.$store.commit(`loadingStart`, 'page-move')
  397. try {
  398. const resp = await this.$apollo.mutate({
  399. mutation: movePageMutation,
  400. variables: {
  401. id: this.$store.get('page/id'),
  402. destinationLocale: locale,
  403. destinationPath: path
  404. }
  405. })
  406. if (_.get(resp, 'data.pages.move.responseResult.succeeded', false)) {
  407. window.location.replace(`/${locale}/${path}`)
  408. } else {
  409. throw new Error(_.get(resp, 'data.pages.move.responseResult.message', this.$t('common:error.unexpected')))
  410. }
  411. } catch (err) {
  412. this.$store.commit('pushGraphError', err)
  413. this.$store.commit(`loadingStop`, 'page-move')
  414. }
  415. },
  416. pageDelete () {
  417. this.deletePageModal = true
  418. },
  419. assets () {
  420. // window.location.assign(`/f`)
  421. this.$store.commit('showNotification', {
  422. style: 'indigo',
  423. message: `Coming soon...`,
  424. icon: 'ferry'
  425. })
  426. },
  427. async changeLocale (locale) {
  428. await this.$i18n.i18next.changeLanguage(locale.code)
  429. switch (this.mode) {
  430. case 'view':
  431. case 'history':
  432. window.location.assign(`/${locale.code}/${this.path}`)
  433. break
  434. }
  435. },
  436. logout () {
  437. Cookies.remove('jwt')
  438. window.location.assign('/')
  439. },
  440. goHome () {
  441. window.location.assign('/')
  442. }
  443. }
  444. }
  445. </script>
  446. <style lang='scss'>
  447. .nav-header {
  448. //z-index: 1000;
  449. .v-toolbar__extension {
  450. padding: 0;
  451. .v-toolbar__content {
  452. padding: 0;
  453. }
  454. .v-text-field .v-input__prepend-inner {
  455. padding: 0 14px 0 5px;
  456. padding-right: 14px;
  457. }
  458. }
  459. .org-logo {
  460. cursor: pointer;
  461. }
  462. &-inner {
  463. .v-toolbar__content {
  464. padding: 0;
  465. }
  466. }
  467. &-search-adv {
  468. position: absolute;
  469. top: 7px;
  470. right: 12px;
  471. border-radius: 4px !important;
  472. @at-root .v-application--is-rtl & {
  473. right: initial;
  474. left: 12px;
  475. }
  476. &::before {
  477. border-radius: 4px !important;
  478. }
  479. &:hover, &:focus {
  480. position: absolute !important;
  481. &::before {
  482. border-radius: 4px;
  483. }
  484. }
  485. }
  486. &-dev {
  487. background-color: mc('red', '600');
  488. position: absolute;
  489. top: 11px;
  490. left: 255px;
  491. padding: 5px 15px;
  492. border-radius: 5px;
  493. display: flex;
  494. .v-icon {
  495. margin-right: 15px;
  496. }
  497. .overline:nth-child(2) {
  498. text-transform: none;
  499. }
  500. }
  501. }
  502. .navHeaderSearch {
  503. &-enter-active, &-leave-active {
  504. transition: opacity .25s ease, transform .25s ease;
  505. opacity: 1;
  506. }
  507. &-enter-active {
  508. transition-delay: .25s;
  509. }
  510. &-enter, &-leave-to {
  511. opacity: 0;
  512. transform: scale(.7, .7);
  513. }
  514. }
  515. .navHeaderLoading { // To avoid search bar jumping
  516. width: 22px;
  517. }
  518. </style>