nav-header.vue 14 KB

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