nav-header.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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')
  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='grey lighten-2') mdi-content-save-move-outline
  129. v-list-item-content
  130. v-list-item-title.body-2.grey--text.text--ligten-2 {{$t('common:header.move')}}
  131. v-list-item-subtitle.overline.grey--text.text--lighten-2 Coming soon
  132. v-list-item.pl-4(@click='pageDelete', v-if='isAuthenticated')
  133. v-list-item-avatar(size='24'): v-icon(color='red darken-2') mdi-trash-can-outline
  134. v-list-item-title.body-2 {{$t('common:header.delete')}}
  135. v-divider(vertical)
  136. //- NEW PAGE
  137. template(v-if='isAuthenticated')
  138. v-tooltip(bottom)
  139. template(v-slot:activator='{ on }')
  140. v-btn(icon, tile, height='64', v-on='on', @click='pageNew')
  141. v-icon(color='grey') mdi-file-document-box-plus-outline
  142. span {{$t('common:header.newPage')}}
  143. v-divider(vertical)
  144. //- ACCOUNT
  145. v-menu(v-if='isAuthenticated', offset-y, bottom, nudge-bottom='30', min-width='300', transition='slide-y-transition')
  146. template(v-slot:activator='{ on: menu }')
  147. v-tooltip(bottom)
  148. template(v-slot:activator='{ on: tooltip }')
  149. v-btn(icon, v-on='{ ...menu, ...tooltip }', :class='$vuetify.rtl ? `ml-0` : ``', tile, height='64')
  150. v-icon(v-if='picture.kind === `initials`', color='grey') mdi-account-circle
  151. v-avatar(v-else-if='picture.kind === `image`', :size='34')
  152. v-img(:src='picture.url')
  153. span {{$t('common:header.account')}}
  154. v-list(nav)
  155. v-list-item.py-3.grey(:class='$vuetify.theme.dark ? `darken-4-l5` : `lighten-5`')
  156. v-list-item-avatar
  157. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  158. span.white--text.subheading {{picture.initials}}
  159. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  160. v-img(:src='picture.url')
  161. v-list-item-content
  162. v-list-item-title {{name}}
  163. v-list-item-subtitle {{email}}
  164. v-list-item(href='/w', disabled)
  165. v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
  166. v-list-item-content
  167. v-list-item-title {{$t('common:header.myWiki')}}
  168. v-list-item-subtitle.overline Coming soon
  169. v-list-item(href='/p', disabled)
  170. v-list-item-action: v-icon(color='blue') mdi-face-profile
  171. v-list-item-content
  172. v-list-item-title {{$t('common:header.profile')}}
  173. v-list-item-subtitle.overline Coming soon
  174. v-list-item(href='/a', v-if='isAuthenticated && isAdmin')
  175. v-list-item-action.btn-animate-rotate: v-icon(color='blue-grey') mdi-settings
  176. v-list-item-title.blue-grey--text {{$t('common:header.admin')}}
  177. v-list-item(@click='logout')
  178. v-list-item-action: v-icon(color='red') mdi-logout
  179. v-list-item-title.red--text {{$t('common:header.logout')}}
  180. v-tooltip(v-else, left)
  181. template(v-slot:activator='{ on }')
  182. v-btn(icon, v-on='on', color='grey darken-3', href='/login')
  183. v-icon(color='grey') mdi-account-circle
  184. span {{$t('common:header.login')}}
  185. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate', :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. deletePageModal: false,
  214. locales: siteLangs
  215. }
  216. },
  217. computed: {
  218. search: sync('site/search'),
  219. searchIsFocused: sync('site/searchIsFocused'),
  220. searchIsLoading: sync('site/searchIsLoading'),
  221. searchRestrictLocale: sync('site/searchRestrictLocale'),
  222. searchRestrictPath: sync('site/searchRestrictPath'),
  223. isLoading: get('isLoading'),
  224. title: get('site/title'),
  225. path: get('page/path'),
  226. locale: get('page/locale'),
  227. mode: get('page/mode'),
  228. name: get('user/name'),
  229. email: get('user/email'),
  230. pictureUrl: get('user/pictureUrl'),
  231. isAuthenticated: get('user/authenticated'),
  232. permissions: get('user/permissions'),
  233. picture() {
  234. if (this.pictureUrl && this.pictureUrl.length > 1) {
  235. return {
  236. kind: 'image',
  237. url: this.pictureUrl
  238. }
  239. } else {
  240. const nameParts = this.name.toUpperCase().split(' ')
  241. let initials = _.head(nameParts).charAt(0)
  242. if (nameParts.length > 1) {
  243. initials += _.last(nameParts).charAt(0)
  244. }
  245. return {
  246. kind: 'initials',
  247. initials
  248. }
  249. }
  250. },
  251. isAdmin() {
  252. return _.includes(this.permissions, 'manage:system')
  253. }
  254. },
  255. created() {
  256. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  257. this.searchIsShown = false
  258. }
  259. },
  260. methods: {
  261. searchFocus() {
  262. this.searchIsFocused = true
  263. },
  264. searchBlur() {
  265. this.searchIsFocused = false
  266. },
  267. searchClose() {
  268. this.search = ''
  269. this.searchBlur()
  270. },
  271. searchToggle() {
  272. this.searchIsShown = !this.searchIsShown
  273. if (this.searchIsShown) {
  274. _.delay(() => {
  275. this.$refs.searchFieldMobile.focus()
  276. }, 200)
  277. }
  278. },
  279. searchEnter() {
  280. this.$root.$emit('searchEnter', true)
  281. },
  282. searchMove(dir) {
  283. this.$root.$emit('searchMove', dir)
  284. },
  285. pageNew () {
  286. this.newPageModal = true
  287. },
  288. pageNewCreate ({ path, locale }) {
  289. window.location.assign(`/e/${locale}/${path}`)
  290. },
  291. pageView () {
  292. window.location.assign(`/${this.locale}/${this.path}`)
  293. },
  294. pageEdit () {
  295. window.location.assign(`/e/${this.locale}/${this.path}`)
  296. },
  297. pageHistory () {
  298. this.$store.commit('showNotification', {
  299. style: 'indigo',
  300. message: `Coming soon...`,
  301. icon: 'ferry'
  302. })
  303. // window.location.assign(`/h/${this.locale}/${this.path}`)
  304. },
  305. pageSource () {
  306. window.location.assign(`/s/${this.locale}/${this.path}`)
  307. },
  308. pageMove () {
  309. this.$store.commit('showNotification', {
  310. style: 'indigo',
  311. message: `Coming soon...`,
  312. icon: 'ferry'
  313. })
  314. },
  315. pageDelete () {
  316. this.deletePageModal = true
  317. },
  318. assets () {
  319. // window.location.assign(`/f`)
  320. this.$store.commit('showNotification', {
  321. style: 'indigo',
  322. message: `Coming soon...`,
  323. icon: 'ferry'
  324. })
  325. },
  326. async changeLocale(locale) {
  327. await this.$i18n.i18next.changeLanguage(locale.code)
  328. switch (this.mode) {
  329. case 'view':
  330. case 'history':
  331. window.location.assign(`/${locale.code}/${this.path}`)
  332. break
  333. }
  334. },
  335. logout () {
  336. Cookies.remove('jwt')
  337. window.location.assign('/')
  338. }
  339. }
  340. }
  341. </script>
  342. <style lang='scss'>
  343. .nav-header {
  344. //z-index: 1000;
  345. .v-toolbar__extension {
  346. padding: 0;
  347. .v-toolbar__content {
  348. padding: 0;
  349. }
  350. .v-text-field .v-input__prepend-inner {
  351. padding: 0 14px 0 5px;
  352. padding-right: 14px;
  353. }
  354. }
  355. &-inner {
  356. .v-toolbar__content {
  357. padding: 0;
  358. }
  359. }
  360. &-search-adv {
  361. position: absolute;
  362. top: 7px;
  363. right: 12px;
  364. border-radius: 4px !important;
  365. @at-root .v-application--is-rtl & {
  366. right: initial;
  367. left: 12px;
  368. }
  369. &::before {
  370. border-radius: 4px !important;
  371. }
  372. &:hover, &:focus {
  373. position: absolute !important;
  374. &::before {
  375. border-radius: 4px;
  376. }
  377. }
  378. }
  379. }
  380. .navHeaderSearch {
  381. &-enter-active, &-leave-active {
  382. transition: opacity .25s ease, transform .25s ease;
  383. opacity: 1;
  384. }
  385. &-enter-active {
  386. transition-delay: .25s;
  387. }
  388. &-enter, &-leave-to {
  389. opacity: 0;
  390. transform: scale(.7, .7);
  391. }
  392. }
  393. .navHeaderLoading { // To avoid search bar jumping
  394. width: 22px;
  395. }
  396. </style>