nav-header.vue 16 KB

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