nav-header.vue 16 KB

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