You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
9.7 KiB

  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. clearable,
  68. color='white',
  69. label='Search...',
  70. single-line,
  71. solo
  72. flat
  73. hide-details,
  74. prepend-inner-icon='search',
  75. :loading='searchIsLoading',
  76. @keyup.enter='searchEnter'
  77. )
  78. v-progress-linear(
  79. indeterminate,
  80. slot='progress',
  81. height='2',
  82. color='blue'
  83. )
  84. v-flex(xs6, :md4='searchIsShown', :md6='!searchIsShown')
  85. v-toolbar.nav-header-inner(color='black', dark, flat)
  86. v-spacer
  87. .navHeaderLoading.mr-3
  88. v-progress-circular(indeterminate, color='blue', :size='22', :width='2' v-show='isLoading')
  89. slot(name='actions')
  90. v-btn(
  91. v-if='!hideSearch && $vuetify.breakpoint.smAndDown'
  92. @click='searchToggle'
  93. icon
  94. )
  95. v-icon(color='grey') search
  96. v-tooltip(bottom, v-if='isAuthenticated && isAdmin')
  97. v-btn.btn-animate-rotate(icon, href='/a', slot='activator')
  98. v-icon(color='grey') settings
  99. span Admin
  100. v-menu(offset-y, min-width='300')
  101. v-tooltip(bottom, slot='activator')
  102. v-btn.btn-animate-grow(icon, slot='activator', outline, :color='isAuthenticated ? `blue` : `grey darken-3`')
  103. v-icon(color='grey') account_circle
  104. span Account
  105. v-list.py-0
  106. template(v-if='isAuthenticated')
  107. v-list-tile.py-3.grey(avatar, :class='$vuetify.dark ? `darken-4-l5` : `lighten-5`')
  108. v-list-tile-avatar
  109. v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
  110. span.white--text.subheading {{picture.initials}}
  111. v-avatar(v-else-if='picture.kind === `image`', :size='40')
  112. v-img(:src='picture.url')
  113. v-list-tile-content
  114. v-list-tile-title {{name}}
  115. v-list-tile-sub-title {{email}}
  116. v-divider.my-0
  117. v-list-tile(href='/w')
  118. v-list-tile-action: v-icon(color='blue') web
  119. v-list-tile-title My Wiki
  120. v-divider.my-0
  121. v-list-tile(href='/p')
  122. v-list-tile-action: v-icon(color='blue') person
  123. v-list-tile-title Profile
  124. v-divider.my-0
  125. v-list-tile(@click='logout')
  126. v-list-tile-action: v-icon(color='red') exit_to_app
  127. v-list-tile-title Logout
  128. template(v-else)
  129. v-list-tile(href='/login')
  130. v-list-tile-action: v-icon(color='grey') person
  131. v-list-tile-title Login
  132. v-divider.my-0
  133. v-list-tile(href='/register')
  134. v-list-tile-action: v-icon(color='grey') person_add
  135. v-list-tile-title Register
  136. page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate')
  137. </template>
  138. <script>
  139. import { get } from 'vuex-pathify'
  140. import _ from 'lodash'
  141. import Cookies from 'js-cookie'
  142. export default {
  143. props: {
  144. dense: {
  145. type: Boolean,
  146. default: false
  147. },
  148. hideSearch: {
  149. type: Boolean,
  150. default: false
  151. }
  152. },
  153. data() {
  154. return {
  155. menuIsShown: true,
  156. searchIsLoading: false,
  157. searchIsShown: true,
  158. search: '',
  159. newPageModal: false
  160. }
  161. },
  162. computed: {
  163. isLoading: get('isLoading'),
  164. title: get('site/title'),
  165. path: get('page/path'),
  166. mode: get('page/mode'),
  167. name: get('user/name'),
  168. email: get('user/email'),
  169. pictureUrl: get('user/pictureUrl'),
  170. isAuthenticated: get('user/authenticated'),
  171. permissions: get('user/permissions'),
  172. picture() {
  173. if (this.pictureUrl && this.pictureUrl.length > 1) {
  174. return {
  175. kind: 'image',
  176. url: this.pictureUrl
  177. }
  178. } else {
  179. const nameParts = this.name.toUpperCase().split(' ')
  180. let initials = _.head(nameParts).charAt(0)
  181. if (nameParts.length > 1) {
  182. initials += _.last(nameParts).charAt(0)
  183. }
  184. return {
  185. kind: 'initials',
  186. initials
  187. }
  188. }
  189. },
  190. isAdmin() {
  191. return _.includes(this.permissions, 'manage:system')
  192. }
  193. },
  194. created() {
  195. if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
  196. this.searchIsShown = false
  197. }
  198. },
  199. methods: {
  200. searchToggle() {
  201. this.searchIsShown = !this.searchIsShown
  202. if (this.searchIsShown) {
  203. _.delay(() => {
  204. this.$refs.searchFieldMobile.focus()
  205. }, 200)
  206. }
  207. },
  208. searchEnter() {
  209. this.searchIsLoading = true
  210. },
  211. pageNew () {
  212. this.newPageModal = true
  213. },
  214. pageNewCreate ({ path, locale }) {
  215. window.location.assign(`/e/${path}`)
  216. },
  217. pageView () {
  218. window.location.assign(`/${this.path}`)
  219. },
  220. pageEdit () {
  221. window.location.assign(`/e/${this.path}`)
  222. },
  223. pageHistory () {
  224. window.location.assign(`/h/${this.path}`)
  225. },
  226. pageSource () {
  227. window.location.assign(`/s/${this.path}`)
  228. },
  229. pageMove () {
  230. this.$store.commit('showNotification', {
  231. style: 'indigo',
  232. message: `Coming soon...`,
  233. icon: 'directions_boat'
  234. })
  235. },
  236. pageDelete () {
  237. this.$store.commit('showNotification', {
  238. style: 'indigo',
  239. message: `Coming soon...`,
  240. icon: 'directions_boat'
  241. })
  242. },
  243. assets () {
  244. this.$store.commit('showNotification', {
  245. style: 'indigo',
  246. message: `Coming soon...`,
  247. icon: 'directions_boat'
  248. })
  249. },
  250. logout () {
  251. Cookies.remove('jwt')
  252. window.location.assign('/')
  253. }
  254. }
  255. }
  256. </script>
  257. <style lang='scss'>
  258. .nav-header {
  259. .v-toolbar__extension {
  260. padding: 0;
  261. .v-toolbar__content {
  262. padding: 0;
  263. }
  264. .v-text-field .v-input__prepend-inner {
  265. padding: 0 14px 0 5px;
  266. padding-right: 14px;
  267. }
  268. }
  269. &-inner {
  270. .v-toolbar__content {
  271. padding: 0;
  272. }
  273. }
  274. }
  275. .navHeaderSearch {
  276. &-enter-active, &-leave-active {
  277. transition: opacity .25s ease, transform .25s ease;
  278. opacity: 1;
  279. }
  280. &-enter-active {
  281. transition-delay: .25s;
  282. }
  283. &-enter, &-leave-to {
  284. opacity: 0;
  285. transform: scale(.7, .7);
  286. }
  287. }
  288. .navHeaderLoading { // To avoid search bar jumping
  289. width: 22px;
  290. }
  291. </style>