2
0

nav-header.vue 15 KB

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