nav-header.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. //- ADMIN
  166. template(v-if='isAuthenticated && isAdmin')
  167. v-tooltip(bottom, v-if='mode !== `admin`')
  168. template(v-slot:activator='{ on }')
  169. v-btn(icon, tile, height='64', v-on='on', href='/a', :aria-label='$t(`common:header.admin`)')
  170. v-icon(color='grey') mdi-cog
  171. span {{$t('common:header.admin')}}
  172. v-btn(v-else, text, tile, height='64', href='/', :aria-label='$t(`common:actions.exit`)')
  173. v-icon(left, color='grey') mdi-exit-to-app
  174. span {{$t('common:actions.exit')}}
  175. v-divider(vertical)
  176. //- ACCOUNT
  177. v-menu(v-if='isAuthenticated', offset-y, bottom, min-width='300', transition='slide-y-transition', left)
  178. template(v-slot:activator='{ on: menu, attrs }')
  179. v-tooltip(bottom)
  180. template(v-slot:activator='{ on: tooltip }')
  181. v-btn(
  182. icon
  183. v-bind='attrs'
  184. v-on='{ ...menu, ...tooltip }'
  185. :class='$vuetify.rtl ? `ml-0` : ``'
  186. tile
  187. height='64'
  188. :aria-label='$t(`common:header.account`)'
  189. )
  190. v-icon(v-if='picture.kind === `initials`', color='grey') mdi-account-circle
  191. v-avatar(v-else-if='picture.kind === `image`', :size='34')
  192. v-img(:src='picture.url')
  193. span {{$t('common:header.account')}}
  194. v-list(nav)
  195. v-list-item.py-3.grey(:class='$vuetify.theme.dark ? `darken-4-l5` : `lighten-5`')
  196. v-list-item-avatar
  197. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  198. span.white--text.subheading {{picture.initials}}
  199. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  200. v-img(:src='picture.url')
  201. v-list-item-content
  202. v-list-item-title {{name}}
  203. v-list-item-subtitle {{email}}
  204. //- v-list-item(href='/w', disabled)
  205. //- v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
  206. //- v-list-item-content
  207. //- v-list-item-title {{$t('common:header.myWiki')}}
  208. //- v-list-item-subtitle.overline Coming soon
  209. v-list-item(href='/p')
  210. v-list-item-action: v-icon(color='blue-grey') mdi-face-profile
  211. v-list-item-content
  212. v-list-item-title(:class='$vuetify.theme.dark ? `blue-grey--text text--lighten-3` : `blue-grey--text`') {{$t('common:header.profile')}}
  213. v-list-item(@click='logout')
  214. v-list-item-action: v-icon(color='red') mdi-logout
  215. v-list-item-title.red--text {{$t('common:header.logout')}}
  216. v-tooltip(v-else, left)
  217. template(v-slot:activator='{ on }')
  218. v-btn(icon, v-on='on', color='grey darken-3', href='/login', :aria-label='$t(`common:header.login`)')
  219. v-icon(color='grey') mdi-account-circle
  220. span {{$t('common:header.login')}}
  221. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate', :locale='locale')
  222. page-selector(mode='move', v-model='movePageModal', :open-handler='pageMoveRename', :path='path', :locale='locale')
  223. page-selector(mode='create', v-model='duplicateOpts.modal', :open-handler='pageDuplicateHandle', :path='duplicateOpts.path', :locale='duplicateOpts.locale')
  224. page-delete(v-model='deletePageModal', v-if='path && path.length')
  225. .nav-header-dev(v-if='isDevMode')
  226. v-icon mdi-alert
  227. div
  228. .overline DEVELOPMENT VERSION
  229. .overline This code base is NOT for production use!
  230. </template>
  231. <script>
  232. import { get, sync } from 'vuex-pathify'
  233. import _ from 'lodash'
  234. import Cookies from 'js-cookie'
  235. import movePageMutation from 'gql/common/common-pages-mutation-move.gql'
  236. /* global siteConfig, siteLangs */
  237. export default {
  238. components: {
  239. PageDelete: () => import('./page-delete.vue')
  240. },
  241. props: {
  242. dense: {
  243. type: Boolean,
  244. default: false
  245. },
  246. hideSearch: {
  247. type: Boolean,
  248. default: false
  249. }
  250. },
  251. data() {
  252. return {
  253. menuIsShown: true,
  254. searchIsShown: true,
  255. searchAdvMenuShown: false,
  256. newPageModal: false,
  257. movePageModal: false,
  258. deletePageModal: false,
  259. locales: siteLangs,
  260. isDevMode: false,
  261. duplicateOpts: {
  262. locale: 'en',
  263. path: 'new-page',
  264. modal: false
  265. }
  266. }
  267. },
  268. computed: {
  269. search: sync('site/search'),
  270. searchIsFocused: sync('site/searchIsFocused'),
  271. searchIsLoading: sync('site/searchIsLoading'),
  272. searchRestrictLocale: sync('site/searchRestrictLocale'),
  273. searchRestrictPath: sync('site/searchRestrictPath'),
  274. isLoading: get('isLoading'),
  275. title: get('site/title'),
  276. logoUrl: get('site/logoUrl'),
  277. path: get('page/path'),
  278. locale: get('page/locale'),
  279. mode: get('page/mode'),
  280. name: get('user/name'),
  281. email: get('user/email'),
  282. pictureUrl: get('user/pictureUrl'),
  283. isAuthenticated: get('user/authenticated'),
  284. permissions: get('user/permissions'),
  285. picture () {
  286. if (this.pictureUrl && this.pictureUrl.length > 1) {
  287. return {
  288. kind: 'image',
  289. url: this.pictureUrl
  290. }
  291. } else {
  292. const nameParts = this.name.toUpperCase().split(' ')
  293. let initials = _.head(nameParts).charAt(0)
  294. if (nameParts.length > 1) {
  295. initials += _.last(nameParts).charAt(0)
  296. }
  297. return {
  298. kind: 'initials',
  299. initials
  300. }
  301. }
  302. },
  303. isAdmin () {
  304. return _.intersection(this.permissions, ['manage:system', 'write:users', 'manage:users', 'write:groups', 'manage:groups', 'manage:navigation', 'manage:theme', 'manage:api']).length > 0
  305. },
  306. hasNewPagePermission () {
  307. return this.hasAdminPermission || _.intersection(this.permissions, ['write:pages']).length > 0
  308. },
  309. hasAdminPermission: get('page/effectivePermissions@system.manage'),
  310. hasWritePagesPermission: get('page/effectivePermissions@pages.write'),
  311. hasManagePagesPermission: get('page/effectivePermissions@pages.manage'),
  312. hasDeletePagesPermission: get('page/effectivePermissions@pages.delete'),
  313. hasReadSourcePermission: get('page/effectivePermissions@source.read'),
  314. hasReadHistoryPermission: get('page/effectivePermissions@history.read'),
  315. hasAnyPagePermissions () {
  316. return this.hasAdminPermission || this.hasWritePagesPermission || this.hasManagePagesPermission ||
  317. this.hasDeletePagesPermission || this.hasReadSourcePermission || this.hasReadHistoryPermission
  318. }
  319. },
  320. created () {
  321. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  322. this.searchIsShown = false
  323. }
  324. },
  325. mounted () {
  326. this.$root.$on('pageEdit', () => {
  327. this.pageEdit()
  328. })
  329. this.$root.$on('pageHistory', () => {
  330. this.pageHistory()
  331. })
  332. this.$root.$on('pageSource', () => {
  333. this.pageSource()
  334. })
  335. this.$root.$on('pageMove', () => {
  336. this.pageMove()
  337. })
  338. this.$root.$on('pageDuplicate', () => {
  339. this.pageDuplicate()
  340. })
  341. this.$root.$on('pageDelete', () => {
  342. this.pageDelete()
  343. })
  344. this.isDevMode = siteConfig.devMode === true
  345. },
  346. methods: {
  347. searchFocus () {
  348. this.searchIsFocused = true
  349. },
  350. searchBlur () {
  351. this.searchIsFocused = false
  352. },
  353. searchClose () {
  354. this.search = ''
  355. this.searchBlur()
  356. },
  357. searchToggle () {
  358. this.searchIsShown = !this.searchIsShown
  359. if (this.searchIsShown) {
  360. _.delay(() => {
  361. this.$refs.searchFieldMobile.focus()
  362. }, 200)
  363. }
  364. },
  365. searchEnter () {
  366. this.$root.$emit('searchEnter', true)
  367. },
  368. searchMove(dir) {
  369. this.$root.$emit('searchMove', dir)
  370. },
  371. pageNew () {
  372. this.newPageModal = true
  373. },
  374. pageNewCreate ({ path, locale }) {
  375. window.location.assign(`/e/${locale}/${path}`)
  376. },
  377. pageView () {
  378. window.location.assign(`/${this.locale}/${this.path}`)
  379. },
  380. pageEdit () {
  381. window.location.assign(`/e/${this.locale}/${this.path}`)
  382. },
  383. pageHistory () {
  384. window.location.assign(`/h/${this.locale}/${this.path}`)
  385. },
  386. pageSource () {
  387. window.location.assign(`/s/${this.locale}/${this.path}`)
  388. },
  389. pageDuplicate () {
  390. const pathParts = this.path.split('/')
  391. this.duplicateOpts = {
  392. locale: this.locale,
  393. path: (pathParts.length > 1) ? _.initial(pathParts).join('/') + `/new-page` : `new-page`,
  394. modal: true
  395. }
  396. },
  397. pageDuplicateHandle ({ locale, path }) {
  398. window.location.assign(`/e/${locale}/${path}?from=${this.$store.get('page/id')}`)
  399. },
  400. pageMove () {
  401. this.movePageModal = true
  402. },
  403. async pageMoveRename ({ path, locale }) {
  404. this.$store.commit(`loadingStart`, 'page-move')
  405. try {
  406. const resp = await this.$apollo.mutate({
  407. mutation: movePageMutation,
  408. variables: {
  409. id: this.$store.get('page/id'),
  410. destinationLocale: locale,
  411. destinationPath: path
  412. }
  413. })
  414. if (_.get(resp, 'data.pages.move.responseResult.succeeded', false)) {
  415. window.location.replace(`/${locale}/${path}`)
  416. } else {
  417. throw new Error(_.get(resp, 'data.pages.move.responseResult.message', this.$t('common:error.unexpected')))
  418. }
  419. } catch (err) {
  420. this.$store.commit('pushGraphError', err)
  421. this.$store.commit(`loadingStop`, 'page-move')
  422. }
  423. },
  424. pageDelete () {
  425. this.deletePageModal = true
  426. },
  427. assets () {
  428. // window.location.assign(`/f`)
  429. this.$store.commit('showNotification', {
  430. style: 'indigo',
  431. message: `Coming soon...`,
  432. icon: 'ferry'
  433. })
  434. },
  435. async changeLocale (locale) {
  436. await this.$i18n.i18next.changeLanguage(locale.code)
  437. switch (this.mode) {
  438. case 'view':
  439. case 'history':
  440. window.location.assign(`/${locale.code}/${this.path}`)
  441. break
  442. }
  443. },
  444. logout () {
  445. Cookies.remove('jwt')
  446. window.location.assign('/')
  447. },
  448. goHome () {
  449. window.location.assign('/')
  450. }
  451. }
  452. }
  453. </script>
  454. <style lang='scss'>
  455. .nav-header {
  456. //z-index: 1000;
  457. .v-toolbar__extension {
  458. padding: 0;
  459. .v-toolbar__content {
  460. padding: 0;
  461. }
  462. .v-text-field .v-input__prepend-inner {
  463. padding: 0 14px 0 5px;
  464. padding-right: 14px;
  465. }
  466. }
  467. .org-logo {
  468. cursor: pointer;
  469. }
  470. &-inner {
  471. .v-toolbar__content {
  472. padding: 0;
  473. }
  474. }
  475. &-search-adv {
  476. position: absolute;
  477. top: 7px;
  478. right: 12px;
  479. border-radius: 4px !important;
  480. @at-root .v-application--is-rtl & {
  481. right: initial;
  482. left: 12px;
  483. }
  484. &::before {
  485. border-radius: 4px !important;
  486. }
  487. &:hover, &:focus {
  488. position: absolute !important;
  489. &::before {
  490. border-radius: 4px;
  491. }
  492. }
  493. }
  494. &-dev {
  495. background-color: mc('red', '600');
  496. position: absolute;
  497. top: 11px;
  498. left: 255px;
  499. padding: 5px 15px;
  500. border-radius: 5px;
  501. display: flex;
  502. .v-icon {
  503. margin-right: 15px;
  504. }
  505. .overline:nth-child(2) {
  506. text-transform: none;
  507. }
  508. }
  509. }
  510. .navHeaderSearch {
  511. &-enter-active, &-leave-active {
  512. transition: opacity .25s ease, transform .25s ease;
  513. opacity: 1;
  514. }
  515. &-enter-active {
  516. transition-delay: .25s;
  517. }
  518. &-enter, &-leave-to {
  519. opacity: 0;
  520. transform: scale(.7, .7);
  521. }
  522. }
  523. .navHeaderLoading { // To avoid search bar jumping
  524. width: 22px;
  525. }
  526. </style>