nav-header.vue 11 KB

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