nav-header.vue 12 KB

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