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.

560 lines
21 KiB

5 years ago
5 years ago
  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='none'
  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='none'
  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 movePageMutation from 'gql/common/common-pages-mutation-move.gql'
  235. /* global siteConfig, siteLangs */
  236. export default {
  237. components: {
  238. PageDelete: () => import('./page-delete.vue')
  239. },
  240. props: {
  241. dense: {
  242. type: Boolean,
  243. default: false
  244. },
  245. hideSearch: {
  246. type: Boolean,
  247. default: false
  248. }
  249. },
  250. data() {
  251. return {
  252. menuIsShown: true,
  253. searchIsShown: true,
  254. searchAdvMenuShown: false,
  255. newPageModal: false,
  256. movePageModal: false,
  257. deletePageModal: false,
  258. locales: siteLangs,
  259. isDevMode: false,
  260. duplicateOpts: {
  261. locale: 'en',
  262. path: 'new-page',
  263. modal: false
  264. }
  265. }
  266. },
  267. computed: {
  268. search: sync('site/search'),
  269. searchIsFocused: sync('site/searchIsFocused'),
  270. searchIsLoading: sync('site/searchIsLoading'),
  271. searchRestrictLocale: sync('site/searchRestrictLocale'),
  272. searchRestrictPath: sync('site/searchRestrictPath'),
  273. isLoading: get('isLoading'),
  274. title: get('site/title'),
  275. logoUrl: get('site/logoUrl'),
  276. path: get('page/path'),
  277. locale: get('page/locale'),
  278. mode: get('page/mode'),
  279. name: get('user/name'),
  280. email: get('user/email'),
  281. pictureUrl: get('user/pictureUrl'),
  282. isAuthenticated: get('user/authenticated'),
  283. permissions: get('user/permissions'),
  284. picture () {
  285. if (this.pictureUrl && this.pictureUrl.length > 1) {
  286. return {
  287. kind: 'image',
  288. url: (this.pictureUrl === 'internal') ? `/_userav/${this.$store.get('user/id')}` : this.pictureUrl
  289. }
  290. } else {
  291. const nameParts = this.name.toUpperCase().split(' ')
  292. let initials = _.head(nameParts).charAt(0)
  293. if (nameParts.length > 1) {
  294. initials += _.last(nameParts).charAt(0)
  295. }
  296. return {
  297. kind: 'initials',
  298. initials
  299. }
  300. }
  301. },
  302. isAdmin () {
  303. return _.intersection(this.permissions, ['manage:system', 'write:users', 'manage:users', 'write:groups', 'manage:groups', 'manage:navigation', 'manage:theme', 'manage:api']).length > 0
  304. },
  305. hasNewPagePermission () {
  306. return this.hasAdminPermission || _.intersection(this.permissions, ['write:pages']).length > 0
  307. },
  308. hasAdminPermission: get('page/effectivePermissions@system.manage'),
  309. hasWritePagesPermission: get('page/effectivePermissions@pages.write'),
  310. hasManagePagesPermission: get('page/effectivePermissions@pages.manage'),
  311. hasDeletePagesPermission: get('page/effectivePermissions@pages.delete'),
  312. hasReadSourcePermission: get('page/effectivePermissions@source.read'),
  313. hasReadHistoryPermission: get('page/effectivePermissions@history.read'),
  314. hasAnyPagePermissions () {
  315. return this.hasAdminPermission || this.hasWritePagesPermission || this.hasManagePagesPermission ||
  316. this.hasDeletePagesPermission || this.hasReadSourcePermission || this.hasReadHistoryPermission
  317. }
  318. },
  319. created () {
  320. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  321. this.searchIsShown = false
  322. }
  323. },
  324. mounted () {
  325. this.$root.$on('pageEdit', () => {
  326. this.pageEdit()
  327. })
  328. this.$root.$on('pageHistory', () => {
  329. this.pageHistory()
  330. })
  331. this.$root.$on('pageSource', () => {
  332. this.pageSource()
  333. })
  334. this.$root.$on('pageMove', () => {
  335. this.pageMove()
  336. })
  337. this.$root.$on('pageDuplicate', () => {
  338. this.pageDuplicate()
  339. })
  340. this.$root.$on('pageDelete', () => {
  341. this.pageDelete()
  342. })
  343. this.isDevMode = siteConfig.devMode === true
  344. },
  345. methods: {
  346. searchFocus () {
  347. this.searchIsFocused = true
  348. },
  349. searchBlur () {
  350. this.searchIsFocused = false
  351. },
  352. searchClose () {
  353. this.search = ''
  354. this.searchBlur()
  355. },
  356. searchToggle () {
  357. this.searchIsShown = !this.searchIsShown
  358. if (this.searchIsShown) {
  359. _.delay(() => {
  360. this.$refs.searchFieldMobile.focus()
  361. }, 200)
  362. }
  363. },
  364. searchEnter () {
  365. this.$root.$emit('searchEnter', true)
  366. },
  367. searchMove(dir) {
  368. this.$root.$emit('searchMove', dir)
  369. },
  370. pageNew () {
  371. this.newPageModal = true
  372. },
  373. pageNewCreate ({ path, locale }) {
  374. window.location.assign(`/e/${locale}/${path}`)
  375. },
  376. pageView () {
  377. window.location.assign(`/${this.locale}/${this.path}`)
  378. },
  379. pageEdit () {
  380. window.location.assign(`/e/${this.locale}/${this.path}`)
  381. },
  382. pageHistory () {
  383. window.location.assign(`/h/${this.locale}/${this.path}`)
  384. },
  385. pageSource () {
  386. window.location.assign(`/s/${this.locale}/${this.path}`)
  387. },
  388. pageDuplicate () {
  389. const pathParts = this.path.split('/')
  390. this.duplicateOpts = {
  391. locale: this.locale,
  392. path: (pathParts.length > 1) ? _.initial(pathParts).join('/') + `/new-page` : `new-page`,
  393. modal: true
  394. }
  395. },
  396. pageDuplicateHandle ({ locale, path }) {
  397. window.location.assign(`/e/${locale}/${path}?from=${this.$store.get('page/id')}`)
  398. },
  399. pageMove () {
  400. this.movePageModal = true
  401. },
  402. async pageMoveRename ({ path, locale }) {
  403. this.$store.commit(`loadingStart`, 'page-move')
  404. try {
  405. const resp = await this.$apollo.mutate({
  406. mutation: movePageMutation,
  407. variables: {
  408. id: this.$store.get('page/id'),
  409. destinationLocale: locale,
  410. destinationPath: path
  411. }
  412. })
  413. if (_.get(resp, 'data.pages.move.responseResult.succeeded', false)) {
  414. window.location.replace(`/${locale}/${path}`)
  415. } else {
  416. throw new Error(_.get(resp, 'data.pages.move.responseResult.message', this.$t('common:error.unexpected')))
  417. }
  418. } catch (err) {
  419. this.$store.commit('pushGraphError', err)
  420. this.$store.commit(`loadingStop`, 'page-move')
  421. }
  422. },
  423. pageDelete () {
  424. this.deletePageModal = true
  425. },
  426. assets () {
  427. // window.location.assign(`/f`)
  428. this.$store.commit('showNotification', {
  429. style: 'indigo',
  430. message: `Coming soon...`,
  431. icon: 'ferry'
  432. })
  433. },
  434. async changeLocale (locale) {
  435. await this.$i18n.i18next.changeLanguage(locale.code)
  436. switch (this.mode) {
  437. case 'view':
  438. case 'history':
  439. window.location.assign(`/${locale.code}/${this.path}`)
  440. break
  441. }
  442. },
  443. logout () {
  444. window.location.assign('/logout')
  445. },
  446. goHome () {
  447. window.location.assign('/')
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang='scss'>
  453. .nav-header {
  454. //z-index: 1000;
  455. .v-toolbar__extension {
  456. padding: 0;
  457. .v-toolbar__content {
  458. padding: 0;
  459. }
  460. .v-text-field .v-input__prepend-inner {
  461. padding: 0 14px 0 5px;
  462. padding-right: 14px;
  463. }
  464. }
  465. .org-logo {
  466. cursor: pointer;
  467. }
  468. &-inner {
  469. .v-toolbar__content {
  470. padding: 0;
  471. }
  472. }
  473. &-search-adv {
  474. position: absolute;
  475. top: 7px;
  476. right: 12px;
  477. border-radius: 4px !important;
  478. @at-root .v-application--is-rtl & {
  479. right: initial;
  480. left: 12px;
  481. }
  482. &::before {
  483. border-radius: 4px !important;
  484. }
  485. &:hover, &:focus {
  486. position: absolute !important;
  487. &::before {
  488. border-radius: 4px;
  489. }
  490. }
  491. }
  492. &-dev {
  493. background-color: mc('red', '600');
  494. position: absolute;
  495. top: 11px;
  496. left: 255px;
  497. padding: 5px 15px;
  498. border-radius: 5px;
  499. display: flex;
  500. .v-icon {
  501. margin-right: 15px;
  502. }
  503. .overline:nth-child(2) {
  504. text-transform: none;
  505. }
  506. }
  507. }
  508. .navHeaderSearch {
  509. &-enter-active, &-leave-active {
  510. transition: opacity .25s ease, transform .25s ease;
  511. opacity: 1;
  512. }
  513. &-enter-active {
  514. transition-delay: .25s;
  515. }
  516. &-enter, &-leave-to {
  517. opacity: 0;
  518. transform: scale(.7, .7);
  519. }
  520. }
  521. .navHeaderLoading { // To avoid search bar jumping
  522. width: 22px;
  523. }
  524. </style>