nav-header.vue 17 KB

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