nav-header.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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='searchIsShown && $vuetify.breakpoint.mdAndUp')
  61. v-toolbar.nav-header-inner(color='black', dark, flat)
  62. transition(name='navHeaderSearch')
  63. v-text-field(
  64. ref='searchField',
  65. v-if='searchIsShown && $vuetify.breakpoint.mdAndUp',
  66. v-model='search',
  67. color='white',
  68. label='Search...',
  69. single-line,
  70. solo
  71. flat
  72. hide-details,
  73. prepend-inner-icon='search',
  74. :loading='searchIsLoading',
  75. @keyup.enter='searchEnter'
  76. @keyup.esc='searchClose'
  77. @focus='searchFocus'
  78. @blur='searchBlur'
  79. @keyup.down='searchMove(`down`)'
  80. @keyup.up='searchMove(`up`)'
  81. )
  82. v-progress-linear(
  83. indeterminate,
  84. slot='progress',
  85. height='2',
  86. color='blue'
  87. )
  88. v-menu(
  89. v-model='searchAdvMenuShown'
  90. left
  91. offset-y
  92. min-width='450'
  93. :close-on-content-click='false'
  94. nudge-bottom='7'
  95. nudge-right='5'
  96. )
  97. v-btn.nav-header-search-adv(icon, outline, color='grey darken-2', slot='activator')
  98. v-icon(color='white') expand_more
  99. v-card.radius-0(dark)
  100. v-toolbar(flat, color='grey darken-4', dense)
  101. v-icon.mr-2 search
  102. v-subheader.pl-0 Advanced Search
  103. v-spacer
  104. v-chip(label, small, color='primary') Coming soon
  105. v-card-text.pa-4
  106. v-checkbox.mt-0(
  107. label='Restrict to current language'
  108. color='white'
  109. v-model='searchRestrictLocale'
  110. hide-details
  111. )
  112. v-checkbox(
  113. label='Search below current path only'
  114. color='white'
  115. v-model='searchRestrictPath'
  116. hide-details
  117. )
  118. v-divider
  119. v-card-actions.grey.darken-3-d4
  120. v-btn(depressed, color='grey darken-3', block)
  121. v-icon(left) chevron_right
  122. span Save as defaults
  123. v-btn(depressed, color='grey darken-3', block)
  124. v-icon(left) cached
  125. span Reset
  126. v-flex(xs6, :md4='searchIsShown', :md6='!searchIsShown')
  127. v-toolbar.nav-header-inner(color='black', dark, flat)
  128. v-spacer
  129. .navHeaderLoading.mr-3
  130. v-progress-circular(indeterminate, color='blue', :size='22', :width='2' v-show='isLoading')
  131. slot(name='actions')
  132. v-btn(
  133. v-if='!hideSearch && $vuetify.breakpoint.smAndDown'
  134. @click='searchToggle'
  135. icon
  136. )
  137. v-icon(color='grey') search
  138. v-tooltip(bottom, v-if='isAuthenticated && isAdmin')
  139. v-btn.btn-animate-rotate(icon, href='/a', slot='activator')
  140. v-icon(color='grey') settings
  141. span Admin
  142. v-menu(v-if='isAuthenticated', offset-y, min-width='300', left)
  143. v-tooltip(bottom, slot='activator')
  144. v-btn.btn-animate-grow(icon, slot='activator', outline, color='blue')
  145. v-icon(color='grey') account_circle
  146. span Account
  147. v-list.py-0
  148. v-list-tile.py-3.grey(avatar, :class='$vuetify.dark ? `darken-4-l5` : `lighten-5`')
  149. v-list-tile-avatar
  150. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  151. span.white--text.subheading {{picture.initials}}
  152. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  153. v-img(:src='picture.url')
  154. v-list-tile-content
  155. v-list-tile-title {{name}}
  156. v-list-tile-sub-title {{email}}
  157. v-divider.my-0
  158. v-list-tile(href='/w')
  159. v-list-tile-action: v-icon(color='blue') web
  160. v-list-tile-title My Wiki
  161. v-divider.my-0
  162. v-list-tile(href='/p')
  163. v-list-tile-action: v-icon(color='blue') person
  164. v-list-tile-title Profile
  165. v-divider.my-0
  166. v-list-tile(@click='logout')
  167. v-list-tile-action: v-icon(color='red') exit_to_app
  168. v-list-tile-title Logout
  169. v-tooltip(v-else, left)
  170. v-btn(icon, slot='activator', outline, color='grey darken-3', href='/login')
  171. v-icon(color='grey') account_circle
  172. span Login
  173. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate')
  174. page-delete(v-model='deletePageModal', v-if='path && path.length')
  175. </template>
  176. <script>
  177. import { get, sync } from 'vuex-pathify'
  178. import _ from 'lodash'
  179. import Cookies from 'js-cookie'
  180. export default {
  181. components: {
  182. PageDelete: () => import('./page-delete.vue')
  183. },
  184. props: {
  185. dense: {
  186. type: Boolean,
  187. default: false
  188. },
  189. hideSearch: {
  190. type: Boolean,
  191. default: false
  192. }
  193. },
  194. data() {
  195. return {
  196. menuIsShown: true,
  197. searchIsShown: true,
  198. searchAdvMenuShown: false,
  199. newPageModal: false,
  200. deletePageModal: false
  201. }
  202. },
  203. computed: {
  204. search: sync('site/search'),
  205. searchIsFocused: sync('site/searchIsFocused'),
  206. searchIsLoading: sync('site/searchIsLoading'),
  207. searchRestrictLocale: sync('site/searchRestrictLocale'),
  208. searchRestrictPath: sync('site/searchRestrictPath'),
  209. isLoading: get('isLoading'),
  210. title: get('site/title'),
  211. path: get('page/path'),
  212. mode: get('page/mode'),
  213. name: get('user/name'),
  214. email: get('user/email'),
  215. pictureUrl: get('user/pictureUrl'),
  216. isAuthenticated: get('user/authenticated'),
  217. permissions: get('user/permissions'),
  218. picture() {
  219. if (this.pictureUrl && this.pictureUrl.length > 1) {
  220. return {
  221. kind: 'image',
  222. url: this.pictureUrl
  223. }
  224. } else {
  225. const nameParts = this.name.toUpperCase().split(' ')
  226. let initials = _.head(nameParts).charAt(0)
  227. if (nameParts.length > 1) {
  228. initials += _.last(nameParts).charAt(0)
  229. }
  230. return {
  231. kind: 'initials',
  232. initials
  233. }
  234. }
  235. },
  236. isAdmin() {
  237. return _.includes(this.permissions, 'manage:system')
  238. }
  239. },
  240. created() {
  241. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  242. this.searchIsShown = false
  243. }
  244. },
  245. methods: {
  246. searchFocus() {
  247. this.searchIsFocused = true
  248. },
  249. searchBlur() {
  250. this.searchIsFocused = false
  251. },
  252. searchClose() {
  253. this.search = ''
  254. this.searchBlur()
  255. },
  256. searchToggle() {
  257. this.searchIsShown = !this.searchIsShown
  258. if (this.searchIsShown) {
  259. _.delay(() => {
  260. this.$refs.searchFieldMobile.focus()
  261. }, 200)
  262. }
  263. },
  264. searchEnter() {
  265. this.$root.$emit('searchEnter', true)
  266. },
  267. searchMove(dir) {
  268. this.$root.$emit('searchMove', dir)
  269. },
  270. pageNew () {
  271. this.newPageModal = true
  272. },
  273. pageNewCreate ({ path, locale }) {
  274. window.location.assign(`/e/${path}`)
  275. },
  276. pageView () {
  277. window.location.assign(`/${this.path}`)
  278. },
  279. pageEdit () {
  280. window.location.assign(`/e/${this.path}`)
  281. },
  282. pageHistory () {
  283. window.location.assign(`/h/${this.path}`)
  284. },
  285. pageSource () {
  286. window.location.assign(`/s/${this.path}`)
  287. },
  288. pageMove () {
  289. this.$store.commit('showNotification', {
  290. style: 'indigo',
  291. message: `Coming soon...`,
  292. icon: 'directions_boat'
  293. })
  294. },
  295. pageDelete () {
  296. this.deletePageModal = true
  297. },
  298. assets () {
  299. this.$store.commit('showNotification', {
  300. style: 'indigo',
  301. message: `Coming soon...`,
  302. icon: 'directions_boat'
  303. })
  304. },
  305. logout () {
  306. Cookies.remove('jwt')
  307. window.location.assign('/')
  308. }
  309. }
  310. }
  311. </script>
  312. <style lang='scss'>
  313. .nav-header {
  314. .v-toolbar__extension {
  315. padding: 0;
  316. .v-toolbar__content {
  317. padding: 0;
  318. }
  319. .v-text-field .v-input__prepend-inner {
  320. padding: 0 14px 0 5px;
  321. padding-right: 14px;
  322. }
  323. }
  324. &-inner {
  325. .v-toolbar__content {
  326. padding: 0;
  327. }
  328. }
  329. &-search-adv {
  330. position: absolute;
  331. top: 7px;
  332. right: 12px;
  333. border-radius: 4px !important;
  334. &::before {
  335. border-radius: 4px !important;
  336. }
  337. &:hover, &:focus {
  338. position: absolute !important;
  339. &::before {
  340. border-radius: 4px;
  341. }
  342. }
  343. }
  344. }
  345. .navHeaderSearch {
  346. &-enter-active, &-leave-active {
  347. transition: opacity .25s ease, transform .25s ease;
  348. opacity: 1;
  349. }
  350. &-enter-active {
  351. transition-delay: .25s;
  352. }
  353. &-enter, &-leave-to {
  354. opacity: 0;
  355. transform: scale(.7, .7);
  356. }
  357. }
  358. .navHeaderLoading { // To avoid search bar jumping
  359. width: 22px;
  360. }
  361. </style>