2
0

nav-header.vue 16 KB

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