nav-header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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')
  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 Home
  29. v-list-tile(avatar, @click='pageNew')
  30. v-list-tile-avatar: v-icon(color='green') add_box
  31. v-list-tile-content New Page
  32. template(v-if='path && path.length')
  33. v-divider.my-0
  34. v-subheader Current Page
  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 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 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 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 View Source
  47. v-list-tile(avatar, @click='pageMove')
  48. v-list-tile-avatar: v-icon(color='indigo') forward
  49. v-list-tile-content Move / Rename
  50. v-list-tile(avatar, @click='pageDelete')
  51. v-list-tile-avatar: v-icon(color='red darken-2') delete
  52. v-list-tile-content Delete
  53. v-divider.my-0
  54. v-subheader Assets
  55. v-list-tile(avatar, @click='assets')
  56. v-list-tile-avatar: v-icon(color='blue-grey') burst_mode
  57. v-list-tile-content Images &amp; Files
  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='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-tooltip(bottom, v-if='isAuthenticated && isAdmin')
  141. v-btn.btn-animate-rotate(icon, href='/a', slot='activator')
  142. v-icon(color='grey') settings
  143. span Admin
  144. v-menu(v-if='isAuthenticated', offset-y, min-width='300', left)
  145. v-tooltip(bottom, slot='activator')
  146. v-btn.btn-animate-grow(icon, slot='activator', outline, color='blue')
  147. v-icon(color='grey') account_circle
  148. span Account
  149. v-list.py-0
  150. v-list-tile.py-3.grey(avatar, :class='$vuetify.dark ? `darken-4-l5` : `lighten-5`')
  151. v-list-tile-avatar
  152. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  153. span.white--text.subheading {{picture.initials}}
  154. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  155. v-img(:src='picture.url')
  156. v-list-tile-content
  157. v-list-tile-title {{name}}
  158. v-list-tile-sub-title {{email}}
  159. v-divider.my-0
  160. v-list-tile(href='/w')
  161. v-list-tile-action: v-icon(color='blue') web
  162. v-list-tile-title My Wiki
  163. v-divider.my-0
  164. v-list-tile(href='/p')
  165. v-list-tile-action: v-icon(color='blue') person
  166. v-list-tile-title Profile
  167. v-divider.my-0
  168. v-list-tile(@click='logout')
  169. v-list-tile-action: v-icon(color='red') exit_to_app
  170. v-list-tile-title Logout
  171. v-tooltip(v-else, left)
  172. v-btn(icon, slot='activator', outline, color='grey darken-3', href='/login')
  173. v-icon(color='grey') account_circle
  174. span Login
  175. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate')
  176. page-delete(v-model='deletePageModal', v-if='path && path.length')
  177. </template>
  178. <script>
  179. import { get, sync } from 'vuex-pathify'
  180. import _ from 'lodash'
  181. import Cookies from 'js-cookie'
  182. export default {
  183. components: {
  184. PageDelete: () => import('./page-delete.vue')
  185. },
  186. props: {
  187. dense: {
  188. type: Boolean,
  189. default: false
  190. },
  191. hideSearch: {
  192. type: Boolean,
  193. default: false
  194. }
  195. },
  196. data() {
  197. return {
  198. menuIsShown: true,
  199. searchIsShown: true,
  200. searchAdvMenuShown: false,
  201. newPageModal: false,
  202. deletePageModal: false
  203. }
  204. },
  205. computed: {
  206. search: sync('site/search'),
  207. searchIsFocused: sync('site/searchIsFocused'),
  208. searchIsLoading: sync('site/searchIsLoading'),
  209. searchRestrictLocale: sync('site/searchRestrictLocale'),
  210. searchRestrictPath: sync('site/searchRestrictPath'),
  211. isLoading: get('isLoading'),
  212. title: get('site/title'),
  213. path: get('page/path'),
  214. mode: get('page/mode'),
  215. name: get('user/name'),
  216. email: get('user/email'),
  217. pictureUrl: get('user/pictureUrl'),
  218. isAuthenticated: get('user/authenticated'),
  219. permissions: get('user/permissions'),
  220. picture() {
  221. if (this.pictureUrl && this.pictureUrl.length > 1) {
  222. return {
  223. kind: 'image',
  224. url: this.pictureUrl
  225. }
  226. } else {
  227. const nameParts = this.name.toUpperCase().split(' ')
  228. let initials = _.head(nameParts).charAt(0)
  229. if (nameParts.length > 1) {
  230. initials += _.last(nameParts).charAt(0)
  231. }
  232. return {
  233. kind: 'initials',
  234. initials
  235. }
  236. }
  237. },
  238. isAdmin() {
  239. return _.includes(this.permissions, 'manage:system')
  240. }
  241. },
  242. created() {
  243. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  244. this.searchIsShown = false
  245. }
  246. },
  247. methods: {
  248. searchFocus() {
  249. this.searchIsFocused = true
  250. },
  251. searchBlur() {
  252. this.searchIsFocused = false
  253. },
  254. searchClose() {
  255. this.search = ''
  256. this.searchBlur()
  257. },
  258. searchToggle() {
  259. this.searchIsShown = !this.searchIsShown
  260. if (this.searchIsShown) {
  261. _.delay(() => {
  262. this.$refs.searchFieldMobile.focus()
  263. }, 200)
  264. }
  265. },
  266. searchEnter() {
  267. this.$root.$emit('searchEnter', true)
  268. },
  269. searchMove(dir) {
  270. this.$root.$emit('searchMove', dir)
  271. },
  272. pageNew () {
  273. this.newPageModal = true
  274. },
  275. pageNewCreate ({ path, locale }) {
  276. window.location.assign(`/e/${path}`)
  277. },
  278. pageView () {
  279. window.location.assign(`/${this.path}`)
  280. },
  281. pageEdit () {
  282. window.location.assign(`/e/${this.path}`)
  283. },
  284. pageHistory () {
  285. window.location.assign(`/h/${this.path}`)
  286. },
  287. pageSource () {
  288. window.location.assign(`/s/${this.path}`)
  289. },
  290. pageMove () {
  291. this.$store.commit('showNotification', {
  292. style: 'indigo',
  293. message: `Coming soon...`,
  294. icon: 'directions_boat'
  295. })
  296. },
  297. pageDelete () {
  298. this.deletePageModal = true
  299. },
  300. assets () {
  301. this.$store.commit('showNotification', {
  302. style: 'indigo',
  303. message: `Coming soon...`,
  304. icon: 'directions_boat'
  305. })
  306. },
  307. logout () {
  308. Cookies.remove('jwt')
  309. window.location.assign('/')
  310. }
  311. }
  312. }
  313. </script>
  314. <style lang='scss'>
  315. .nav-header {
  316. .v-toolbar__extension {
  317. padding: 0;
  318. .v-toolbar__content {
  319. padding: 0;
  320. }
  321. .v-text-field .v-input__prepend-inner {
  322. padding: 0 14px 0 5px;
  323. padding-right: 14px;
  324. }
  325. }
  326. &-inner {
  327. .v-toolbar__content {
  328. padding: 0;
  329. }
  330. }
  331. &-search-adv {
  332. position: absolute;
  333. top: 7px;
  334. right: 12px;
  335. border-radius: 4px !important;
  336. &::before {
  337. border-radius: 4px !important;
  338. }
  339. &:hover, &:focus {
  340. position: absolute !important;
  341. &::before {
  342. border-radius: 4px;
  343. }
  344. }
  345. }
  346. }
  347. .navHeaderSearch {
  348. &-enter-active, &-leave-active {
  349. transition: opacity .25s ease, transform .25s ease;
  350. opacity: 1;
  351. }
  352. &-enter-active {
  353. transition-delay: .25s;
  354. }
  355. &-enter, &-leave-to {
  356. opacity: 0;
  357. transform: scale(.7, .7);
  358. }
  359. }
  360. .navHeaderLoading { // To avoid search bar jumping
  361. width: 22px;
  362. }
  363. </style>