nav-header.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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-menu(open-on-hover, offset-y, bottom, left, min-width='250')
  20. v-toolbar-side-icon.btn-animate-app(slot='activator')
  21. v-icon view_module
  22. v-list(dense, :light='!$vuetify.dark', :dark='$vuetify.dark', :class='$vuetify.dark ? `grey darken-4` : ``').py-0
  23. v-list-tile(avatar, href='/')
  24. v-list-tile-avatar: v-icon(color='blue') home
  25. v-list-tile-content Home
  26. v-list-tile(avatar, @click='pageNew')
  27. v-list-tile-avatar: v-icon(color='green') add_box
  28. v-list-tile-content New Page
  29. template(v-if='path && path.length')
  30. v-divider.my-0
  31. v-subheader Current Page
  32. v-list-tile(avatar, @click='pageView', v-if='mode !== `view`')
  33. v-list-tile-avatar: v-icon(color='indigo') subject
  34. v-list-tile-content View
  35. v-list-tile(avatar, @click='pageEdit', v-if='mode !== `edit`')
  36. v-list-tile-avatar: v-icon(color='indigo') edit
  37. v-list-tile-content Edit
  38. v-list-tile(avatar, @click='pageHistory', v-if='mode !== `history`')
  39. v-list-tile-avatar: v-icon(color='indigo') history
  40. v-list-tile-content History
  41. v-list-tile(avatar, @click='pageSource', v-if='mode !== `source`')
  42. v-list-tile-avatar: v-icon(color='indigo') code
  43. v-list-tile-content View Source
  44. v-list-tile(avatar, @click='pageMove')
  45. v-list-tile-avatar: v-icon(color='indigo') forward
  46. v-list-tile-content Move / Rename
  47. v-list-tile(avatar, @click='pageDelete')
  48. v-list-tile-avatar: v-icon(color='red darken-2') delete
  49. v-list-tile-content Delete
  50. v-divider.my-0
  51. v-subheader Assets
  52. v-list-tile(avatar, @click='')
  53. v-list-tile-avatar: v-icon(color='blue-grey') burst_mode
  54. v-list-tile-content Images &amp; Files
  55. v-toolbar-title(:class='{ "ml-2": $vuetify.breakpoint.mdAndUp, "ml-0": $vuetify.breakpoint.smAndDown }')
  56. span.subheading {{title}}
  57. v-spacer(v-if='searchIsShown && $vuetify.breakpoint.mdAndUp')
  58. transition(name='navHeaderSearch')
  59. v-text-field(
  60. ref='searchField',
  61. v-if='searchIsShown && $vuetify.breakpoint.mdAndUp',
  62. v-model='search',
  63. clearable,
  64. color='white',
  65. label='Search...',
  66. single-line,
  67. solo
  68. flat
  69. hide-details,
  70. prepend-inner-icon='search',
  71. :loading='searchIsLoading',
  72. @keyup.enter='searchEnter'
  73. )
  74. v-progress-linear(
  75. indeterminate,
  76. slot='progress',
  77. height='2',
  78. color='blue'
  79. )
  80. v-spacer
  81. .navHeaderLoading.mr-3
  82. v-progress-circular(indeterminate, color='blue', :size='22', :width='2' v-show='isLoading')
  83. slot(name='actions')
  84. v-btn(
  85. v-if='!hideSearch && $vuetify.breakpoint.smAndDown'
  86. @click='searchToggle'
  87. icon
  88. )
  89. v-icon(color='grey') search
  90. v-tooltip(bottom, v-if='isAuthenticated && isAdmin')
  91. v-btn.btn-animate-rotate(icon, href='/a', slot='activator')
  92. v-icon(color='grey') settings
  93. span Admin
  94. v-menu(offset-y, min-width='300')
  95. v-tooltip(bottom, slot='activator')
  96. v-btn.btn-animate-grow(icon, slot='activator', outline, :color='isAuthenticated ? `blue` : `grey darken-3`')
  97. v-icon(color='grey') account_circle
  98. span Account
  99. v-list.py-0
  100. template(v-if='isAuthenticated')
  101. v-list-tile.py-3.grey(avatar, :class='$vuetify.dark ? `darken-4-l5` : `lighten-5`')
  102. v-list-tile-avatar
  103. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  104. span.white--text.subheading {{picture.initials}}
  105. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  106. v-img(:src='picture.url')
  107. v-list-tile-content
  108. v-list-tile-title {{name}}
  109. v-list-tile-sub-title {{email}}
  110. v-divider.my-0
  111. v-list-tile(href='/w')
  112. v-list-tile-action: v-icon(color='blue') web
  113. v-list-tile-title My Wiki
  114. v-divider.my-0
  115. v-list-tile(href='/p')
  116. v-list-tile-action: v-icon(color='blue') person
  117. v-list-tile-title Profile
  118. v-divider.my-0
  119. v-list-tile(@click='logout')
  120. v-list-tile-action: v-icon(color='red') exit_to_app
  121. v-list-tile-title Logout
  122. template(v-else)
  123. v-list-tile(href='/login')
  124. v-list-tile-action: v-icon(color='grey') person
  125. v-list-tile-title Login
  126. v-divider.my-0
  127. v-list-tile(href='/register')
  128. v-list-tile-action: v-icon(color='grey') person_add
  129. v-list-tile-title Register
  130. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate')
  131. </template>
  132. <script>
  133. import { get } from 'vuex-pathify'
  134. import _ from 'lodash'
  135. import Cookies from 'js-cookie'
  136. export default {
  137. props: {
  138. dense: {
  139. type: Boolean,
  140. default: false
  141. },
  142. hideSearch: {
  143. type: Boolean,
  144. default: false
  145. }
  146. },
  147. data() {
  148. return {
  149. menuIsShown: true,
  150. searchIsLoading: false,
  151. searchIsShown: true,
  152. search: '',
  153. newPageModal: false
  154. }
  155. },
  156. computed: {
  157. isLoading: get('isLoading'),
  158. title: get('site/title'),
  159. path: get('page/path'),
  160. mode: get('page/mode'),
  161. name: get('user/name'),
  162. email: get('user/email'),
  163. pictureUrl: get('user/pictureUrl'),
  164. isAuthenticated: get('user/authenticated'),
  165. permissions: get('user/permissions'),
  166. picture() {
  167. if (this.pictureUrl && this.pictureUrl.length > 1) {
  168. return {
  169. kind: 'image',
  170. url: this.pictureUrl
  171. }
  172. } else {
  173. const nameParts = this.name.toUpperCase().split(' ')
  174. let initials = _.head(nameParts).charAt(0)
  175. if (nameParts.length > 1) {
  176. initials += _.last(nameParts).charAt(0)
  177. }
  178. return {
  179. kind: 'initials',
  180. initials
  181. }
  182. }
  183. },
  184. isAdmin() {
  185. return _.includes(this.permissions, 'manage:system')
  186. }
  187. },
  188. created() {
  189. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  190. this.searchIsShown = false
  191. }
  192. },
  193. methods: {
  194. searchToggle() {
  195. this.searchIsShown = !this.searchIsShown
  196. if (this.searchIsShown) {
  197. _.delay(() => {
  198. this.$refs.searchFieldMobile.focus()
  199. }, 200)
  200. }
  201. },
  202. searchEnter() {
  203. this.searchIsLoading = true
  204. },
  205. pageNew () {
  206. this.newPageModal = true
  207. },
  208. pageNewCreate ({ path, locale }) {
  209. window.location.assign(`/e/${path}`)
  210. },
  211. pageView () {
  212. window.location.assign(`/${this.path}`)
  213. },
  214. pageEdit () {
  215. window.location.assign(`/e/${this.path}`)
  216. },
  217. pageHistory () {
  218. window.location.assign(`/h/${this.path}`)
  219. },
  220. pageSource () {
  221. window.location.assign(`/s/${this.path}`)
  222. },
  223. pageMove () {
  224. },
  225. pageDelete () {
  226. },
  227. logout () {
  228. Cookies.remove('jwt')
  229. window.location.assign('/')
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang='scss'>
  235. .nav-header {
  236. .v-toolbar__extension {
  237. padding: 0;
  238. .v-toolbar__content {
  239. padding: 0;
  240. }
  241. .v-text-field .v-input__prepend-inner {
  242. padding: 0 14px 0 5px;
  243. padding-right: 14px;
  244. }
  245. }
  246. }
  247. .navHeaderSearch {
  248. &-enter-active, &-leave-active {
  249. transition: opacity .25s ease, transform .25s ease;
  250. opacity: 1;
  251. }
  252. &-enter-active {
  253. transition-delay: .25s;
  254. }
  255. &-enter, &-leave-to {
  256. opacity: 0;
  257. transform: scale(.7, .7);
  258. }
  259. }
  260. .navHeaderLoading { // To avoid search bar jumping
  261. width: 22px;
  262. }
  263. </style>