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