nav-header.vue 18 KB

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