You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

491 lines
18 KiB

5 years ago
5 years ago
  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(color='black', dark, flat, :class='$vuetify.rtl ? `pr-3` : `pl-3`')
  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', max-height='320px', min-width='210px', left)
  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', left)
  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='indigo') mdi-history
  123. v-list-item-content
  124. v-list-item-title.body-2 {{$t('common:header.history')}}
  125. v-list-item.pl-4(@click='pageSource', v-if='mode !== `source`')
  126. v-list-item-avatar(size='24'): v-icon(color='indigo') mdi-code-tags
  127. v-list-item-title.body-2 {{$t('common:header.viewSource')}}
  128. v-list-item.pl-4(@click='pageMove', v-if='isAuthenticated')
  129. v-list-item-avatar(size='24'): v-icon(color='indigo') mdi-content-save-move-outline
  130. v-list-item-content
  131. v-list-item-title.body-2 {{$t('common:header.move')}}
  132. v-list-item.pl-4(@click='pageDelete', v-if='isAuthenticated')
  133. v-list-item-avatar(size='24'): v-icon(color='red darken-2') mdi-trash-can-outline
  134. v-list-item-title.body-2 {{$t('common:header.delete')}}
  135. v-divider(vertical)
  136. //- NEW PAGE
  137. template(v-if='isAuthenticated && path && mode !== `edit`')
  138. v-tooltip(bottom)
  139. template(v-slot:activator='{ on }')
  140. v-btn(icon, tile, height='64', v-on='on', @click='pageNew')
  141. v-icon(color='grey') mdi-text-box-plus-outline
  142. span {{$t('common:header.newPage')}}
  143. v-divider(vertical)
  144. //- ACCOUNT
  145. v-menu(v-if='isAuthenticated', offset-y, bottom, min-width='300', transition='slide-y-transition', left)
  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-0` : ``', tile, height='64')
  150. v-icon(v-if='picture.kind === `initials`', color='grey') mdi-account-circle
  151. v-avatar(v-else-if='picture.kind === `image`', :size='34')
  152. v-img(:src='picture.url')
  153. span {{$t('common:header.account')}}
  154. v-list(nav)
  155. v-list-item.py-3.grey(:class='$vuetify.theme.dark ? `darken-4-l5` : `lighten-5`')
  156. v-list-item-avatar
  157. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  158. span.white--text.subheading {{picture.initials}}
  159. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  160. v-img(:src='picture.url')
  161. v-list-item-content
  162. v-list-item-title {{name}}
  163. v-list-item-subtitle {{email}}
  164. //- v-list-item(href='/w', disabled)
  165. //- v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
  166. //- v-list-item-content
  167. //- v-list-item-title {{$t('common:header.myWiki')}}
  168. //- v-list-item-subtitle.overline Coming soon
  169. //- v-list-item(href='/p', disabled)
  170. //- v-list-item-action: v-icon(color='blue') mdi-face-profile
  171. //- v-list-item-content
  172. //- v-list-item-title {{$t('common:header.profile')}}
  173. //- v-list-item-subtitle.overline Coming soon
  174. v-list-item(href='/a', v-if='isAuthenticated && isAdmin')
  175. v-list-item-action.btn-animate-rotate: v-icon(:color='$vuetify.theme.dark ? `blue-grey lighten-3` : `blue-grey`') mdi-cog
  176. v-list-item-title(:class='$vuetify.theme.dark ? `blue-grey--text text--lighten-3` : `blue-grey--text`') {{$t('common:header.admin')}}
  177. v-list-item(@click='logout')
  178. v-list-item-action: v-icon(color='red') mdi-logout
  179. v-list-item-title.red--text {{$t('common:header.logout')}}
  180. v-tooltip(v-else, left)
  181. template(v-slot:activator='{ on }')
  182. v-btn(icon, v-on='on', color='grey darken-3', href='/login')
  183. v-icon(color='grey') mdi-account-circle
  184. span {{$t('common:header.login')}}
  185. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate', :locale='locale')
  186. page-selector(mode='move', v-model='movePageModal', :open-handler='pageMoveRename', :path='path', :locale='locale')
  187. page-delete(v-model='deletePageModal', v-if='path && path.length')
  188. .nav-header-dev(v-if='isDevMode')
  189. v-icon mdi-alert
  190. div
  191. .overline DEVELOPMENT VERSION
  192. .overline This code base is NOT for production use!
  193. </template>
  194. <script>
  195. import { get, sync } from 'vuex-pathify'
  196. import _ from 'lodash'
  197. import Cookies from 'js-cookie'
  198. import movePageMutation from 'gql/common/common-pages-mutation-move.gql'
  199. /* global siteConfig, siteLangs */
  200. export default {
  201. components: {
  202. PageDelete: () => import('./page-delete.vue')
  203. },
  204. props: {
  205. dense: {
  206. type: Boolean,
  207. default: false
  208. },
  209. hideSearch: {
  210. type: Boolean,
  211. default: false
  212. }
  213. },
  214. data() {
  215. return {
  216. menuIsShown: true,
  217. searchIsShown: true,
  218. searchAdvMenuShown: false,
  219. newPageModal: false,
  220. movePageModal: false,
  221. deletePageModal: false,
  222. locales: siteLangs,
  223. isDevMode: false
  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. logoUrl: get('site/logoUrl'),
  235. path: get('page/path'),
  236. locale: get('page/locale'),
  237. mode: get('page/mode'),
  238. name: get('user/name'),
  239. email: get('user/email'),
  240. pictureUrl: get('user/pictureUrl'),
  241. isAuthenticated: get('user/authenticated'),
  242. permissions: get('user/permissions'),
  243. picture () {
  244. if (this.pictureUrl && this.pictureUrl.length > 1) {
  245. return {
  246. kind: 'image',
  247. url: this.pictureUrl
  248. }
  249. } else {
  250. const nameParts = this.name.toUpperCase().split(' ')
  251. let initials = _.head(nameParts).charAt(0)
  252. if (nameParts.length > 1) {
  253. initials += _.last(nameParts).charAt(0)
  254. }
  255. return {
  256. kind: 'initials',
  257. initials
  258. }
  259. }
  260. },
  261. isAdmin () {
  262. return _.intersection(this.permissions, ['manage:system', 'write:users', 'manage:users', 'write:groups', 'manage:groups', 'manage:navigation', 'manage:theme', 'manage:api']).length > 0
  263. }
  264. },
  265. created () {
  266. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  267. this.searchIsShown = false
  268. }
  269. },
  270. mounted () {
  271. this.$root.$on('pageEdit', () => {
  272. this.pageEdit()
  273. })
  274. this.$root.$on('pageHistory', () => {
  275. this.pageHistory()
  276. })
  277. this.$root.$on('pageSource', () => {
  278. this.pageSource()
  279. })
  280. this.$root.$on('pageMove', () => {
  281. this.pageMove()
  282. })
  283. this.$root.$on('pageDelete', () => {
  284. this.pageDelete()
  285. })
  286. this.isDevMode = siteConfig.devMode === true
  287. },
  288. methods: {
  289. searchFocus () {
  290. this.searchIsFocused = true
  291. },
  292. searchBlur () {
  293. this.searchIsFocused = false
  294. },
  295. searchClose () {
  296. this.search = ''
  297. this.searchBlur()
  298. },
  299. searchToggle () {
  300. this.searchIsShown = !this.searchIsShown
  301. if (this.searchIsShown) {
  302. _.delay(() => {
  303. this.$refs.searchFieldMobile.focus()
  304. }, 200)
  305. }
  306. },
  307. searchEnter () {
  308. this.$root.$emit('searchEnter', true)
  309. },
  310. searchMove(dir) {
  311. this.$root.$emit('searchMove', dir)
  312. },
  313. pageNew () {
  314. this.newPageModal = true
  315. },
  316. pageNewCreate ({ path, locale }) {
  317. window.location.assign(`/e/${locale}/${path}`)
  318. },
  319. pageView () {
  320. window.location.assign(`/${this.locale}/${this.path}`)
  321. },
  322. pageEdit () {
  323. window.location.assign(`/e/${this.locale}/${this.path}`)
  324. },
  325. pageHistory () {
  326. window.location.assign(`/h/${this.locale}/${this.path}`)
  327. },
  328. pageSource () {
  329. window.location.assign(`/s/${this.locale}/${this.path}`)
  330. },
  331. pageMove () {
  332. this.movePageModal = true
  333. },
  334. async pageMoveRename ({ path, locale }) {
  335. this.$store.commit(`loadingStart`, 'page-move')
  336. try {
  337. const resp = await this.$apollo.mutate({
  338. mutation: movePageMutation,
  339. variables: {
  340. id: this.$store.get('page/id'),
  341. destinationLocale: locale,
  342. destinationPath: path
  343. }
  344. })
  345. if (_.get(resp, 'data.pages.move.responseResult.succeeded', false)) {
  346. window.location.replace(`/${locale}/${path}`)
  347. } else {
  348. throw new Error(_.get(resp, 'data.pages.move.responseResult.message', this.$t('common:error.unexpected')))
  349. }
  350. } catch (err) {
  351. this.$store.commit('pushGraphError', err)
  352. this.$store.commit(`loadingStop`, 'page-move')
  353. }
  354. },
  355. pageDelete () {
  356. this.deletePageModal = true
  357. },
  358. assets () {
  359. // window.location.assign(`/f`)
  360. this.$store.commit('showNotification', {
  361. style: 'indigo',
  362. message: `Coming soon...`,
  363. icon: 'ferry'
  364. })
  365. },
  366. async changeLocale (locale) {
  367. await this.$i18n.i18next.changeLanguage(locale.code)
  368. switch (this.mode) {
  369. case 'view':
  370. case 'history':
  371. window.location.assign(`/${locale.code}/${this.path}`)
  372. break
  373. }
  374. },
  375. logout () {
  376. Cookies.remove('jwt')
  377. window.location.assign('/')
  378. },
  379. goHome () {
  380. window.location.assign('/')
  381. }
  382. }
  383. }
  384. </script>
  385. <style lang='scss'>
  386. .nav-header {
  387. //z-index: 1000;
  388. .v-toolbar__extension {
  389. padding: 0;
  390. .v-toolbar__content {
  391. padding: 0;
  392. }
  393. .v-text-field .v-input__prepend-inner {
  394. padding: 0 14px 0 5px;
  395. padding-right: 14px;
  396. }
  397. }
  398. .org-logo {
  399. cursor: pointer;
  400. }
  401. &-inner {
  402. .v-toolbar__content {
  403. padding: 0;
  404. }
  405. }
  406. &-search-adv {
  407. position: absolute;
  408. top: 7px;
  409. right: 12px;
  410. border-radius: 4px !important;
  411. @at-root .v-application--is-rtl & {
  412. right: initial;
  413. left: 12px;
  414. }
  415. &::before {
  416. border-radius: 4px !important;
  417. }
  418. &:hover, &:focus {
  419. position: absolute !important;
  420. &::before {
  421. border-radius: 4px;
  422. }
  423. }
  424. }
  425. &-dev {
  426. background-color: mc('red', '600');
  427. position: absolute;
  428. top: 11px;
  429. left: 255px;
  430. padding: 5px 15px;
  431. border-radius: 5px;
  432. display: flex;
  433. .v-icon {
  434. margin-right: 15px;
  435. }
  436. .overline:nth-child(2) {
  437. text-transform: none;
  438. }
  439. }
  440. }
  441. .navHeaderSearch {
  442. &-enter-active, &-leave-active {
  443. transition: opacity .25s ease, transform .25s ease;
  444. opacity: 1;
  445. }
  446. &-enter-active {
  447. transition-delay: .25s;
  448. }
  449. &-enter, &-leave-to {
  450. opacity: 0;
  451. transform: scale(.7, .7);
  452. }
  453. }
  454. .navHeaderLoading { // To avoid search bar jumping
  455. width: 22px;
  456. }
  457. </style>