nav-header.vue 11 KB

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