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.

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