nav-header.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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, nudge-bottom='30', 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: 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, nudge-bottom='30', 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, nudge-bottom='30', 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. /* global siteLangs */
  193. export default {
  194. components: {
  195. PageDelete: () => import('./page-delete.vue')
  196. },
  197. props: {
  198. dense: {
  199. type: Boolean,
  200. default: false
  201. },
  202. hideSearch: {
  203. type: Boolean,
  204. default: false
  205. }
  206. },
  207. data() {
  208. return {
  209. menuIsShown: true,
  210. searchIsShown: true,
  211. searchAdvMenuShown: false,
  212. newPageModal: false,
  213. movePageModal: false,
  214. deletePageModal: false,
  215. locales: siteLangs
  216. }
  217. },
  218. computed: {
  219. search: sync('site/search'),
  220. searchIsFocused: sync('site/searchIsFocused'),
  221. searchIsLoading: sync('site/searchIsLoading'),
  222. searchRestrictLocale: sync('site/searchRestrictLocale'),
  223. searchRestrictPath: sync('site/searchRestrictPath'),
  224. isLoading: get('isLoading'),
  225. title: get('site/title'),
  226. path: get('page/path'),
  227. locale: get('page/locale'),
  228. mode: get('page/mode'),
  229. name: get('user/name'),
  230. email: get('user/email'),
  231. pictureUrl: get('user/pictureUrl'),
  232. isAuthenticated: get('user/authenticated'),
  233. permissions: get('user/permissions'),
  234. picture () {
  235. if (this.pictureUrl && this.pictureUrl.length > 1) {
  236. return {
  237. kind: 'image',
  238. url: this.pictureUrl
  239. }
  240. } else {
  241. const nameParts = this.name.toUpperCase().split(' ')
  242. let initials = _.head(nameParts).charAt(0)
  243. if (nameParts.length > 1) {
  244. initials += _.last(nameParts).charAt(0)
  245. }
  246. return {
  247. kind: 'initials',
  248. initials
  249. }
  250. }
  251. },
  252. isAdmin () {
  253. return _.intersection(this.permissions, ['manage:system', 'write:users', 'manage:users', 'write:groups', 'manage:groups', 'manage:navigation', 'manage:theme', 'manage:api']).length > 0
  254. }
  255. },
  256. created () {
  257. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  258. this.searchIsShown = false
  259. }
  260. },
  261. mounted () {
  262. this.$root.$on('pageEdit', () => {
  263. this.pageEdit()
  264. })
  265. this.$root.$on('pageHistory', () => {
  266. this.pageHistory()
  267. })
  268. this.$root.$on('pageSource', () => {
  269. this.pageSource()
  270. })
  271. this.$root.$on('pageMove', () => {
  272. this.pageMove()
  273. })
  274. this.$root.$on('pageDelete', () => {
  275. this.pageDelete()
  276. })
  277. },
  278. methods: {
  279. searchFocus () {
  280. this.searchIsFocused = true
  281. },
  282. searchBlur () {
  283. this.searchIsFocused = false
  284. },
  285. searchClose () {
  286. this.search = ''
  287. this.searchBlur()
  288. },
  289. searchToggle () {
  290. this.searchIsShown = !this.searchIsShown
  291. if (this.searchIsShown) {
  292. _.delay(() => {
  293. this.$refs.searchFieldMobile.focus()
  294. }, 200)
  295. }
  296. },
  297. searchEnter () {
  298. this.$root.$emit('searchEnter', true)
  299. },
  300. searchMove(dir) {
  301. this.$root.$emit('searchMove', dir)
  302. },
  303. pageNew () {
  304. this.newPageModal = true
  305. },
  306. pageNewCreate ({ path, locale }) {
  307. window.location.assign(`/e/${locale}/${path}`)
  308. },
  309. pageView () {
  310. window.location.assign(`/${this.locale}/${this.path}`)
  311. },
  312. pageEdit () {
  313. window.location.assign(`/e/${this.locale}/${this.path}`)
  314. },
  315. pageHistory () {
  316. this.$store.commit('showNotification', {
  317. style: 'indigo',
  318. message: `Coming soon...`,
  319. icon: 'ferry'
  320. })
  321. // window.location.assign(`/h/${this.locale}/${this.path}`)
  322. },
  323. pageSource () {
  324. window.location.assign(`/s/${this.locale}/${this.path}`)
  325. },
  326. pageMove () {
  327. this.movePageModal = true
  328. },
  329. pageMoveRename ({ path, locale }) {
  330. },
  331. pageDelete () {
  332. this.deletePageModal = true
  333. },
  334. assets () {
  335. // window.location.assign(`/f`)
  336. this.$store.commit('showNotification', {
  337. style: 'indigo',
  338. message: `Coming soon...`,
  339. icon: 'ferry'
  340. })
  341. },
  342. async changeLocale (locale) {
  343. await this.$i18n.i18next.changeLanguage(locale.code)
  344. switch (this.mode) {
  345. case 'view':
  346. case 'history':
  347. window.location.assign(`/${locale.code}/${this.path}`)
  348. break
  349. }
  350. },
  351. logout () {
  352. Cookies.remove('jwt')
  353. window.location.assign('/')
  354. }
  355. }
  356. }
  357. </script>
  358. <style lang='scss'>
  359. .nav-header {
  360. //z-index: 1000;
  361. .v-toolbar__extension {
  362. padding: 0;
  363. .v-toolbar__content {
  364. padding: 0;
  365. }
  366. .v-text-field .v-input__prepend-inner {
  367. padding: 0 14px 0 5px;
  368. padding-right: 14px;
  369. }
  370. }
  371. &-inner {
  372. .v-toolbar__content {
  373. padding: 0;
  374. }
  375. }
  376. &-search-adv {
  377. position: absolute;
  378. top: 7px;
  379. right: 12px;
  380. border-radius: 4px !important;
  381. @at-root .v-application--is-rtl & {
  382. right: initial;
  383. left: 12px;
  384. }
  385. &::before {
  386. border-radius: 4px !important;
  387. }
  388. &:hover, &:focus {
  389. position: absolute !important;
  390. &::before {
  391. border-radius: 4px;
  392. }
  393. }
  394. }
  395. }
  396. .navHeaderSearch {
  397. &-enter-active, &-leave-active {
  398. transition: opacity .25s ease, transform .25s ease;
  399. opacity: 1;
  400. }
  401. &-enter-active {
  402. transition-delay: .25s;
  403. }
  404. &-enter, &-leave-to {
  405. opacity: 0;
  406. transform: scale(.7, .7);
  407. }
  408. }
  409. .navHeaderLoading { // To avoid search bar jumping
  410. width: 22px;
  411. }
  412. </style>