wikijs-fork/client/components/common/nav-header.vue

423 lines
15 KiB
Vue
Raw Normal View History

<template lang='pug'>
v-app-bar.nav-header(color='black', dark, app, :clipped-left='!$vuetify.rtl', :clipped-right='$vuetify.rtl', fixed, flat, :extended='searchIsShown && $vuetify.breakpoint.smAndDown')
2018-08-13 04:12:44 +00:00
v-toolbar(color='deep-purple', flat, slot='extension', v-if='searchIsShown && $vuetify.breakpoint.smAndDown')
v-text-field(
2019-03-09 23:43:32 +00:00
ref='searchFieldMobile'
v-model='search'
clearable
2018-08-13 04:12:44 +00:00
background-color='deep-purple'
2019-03-09 23:43:32 +00:00
color='white'
label='Search...'
single-line
2018-08-13 04:12:44 +00:00
solo
flat
2019-03-09 23:43:32 +00:00
hide-details
2019-08-04 02:51:29 +00:00
prepend-inner-icon='mdi-magnify'
2019-03-09 23:43:32 +00:00
:loading='searchIsLoading'
2018-08-13 04:12:44 +00:00
@keyup.enter='searchEnter'
)
v-layout(row)
2019-07-29 04:50:03 +00:00
v-flex(xs6, md4)
v-toolbar.nav-header-inner.pl-3(color='black', dark, flat)
2019-06-02 21:29:50 +00:00
v-menu(open-on-hover, offset-y, bottom, left, min-width='250', transition='slide-y-transition')
2019-07-29 04:50:03 +00:00
template(v-slot:activator='{ on }')
v-app-bar-nav-icon.btn-animate-app(v-on='on', :class='$vuetify.rtl ? `mx-0` : ``')
2019-07-29 04:50:03 +00:00
v-icon mdi-menu-open
v-list(nav, :light='!$vuetify.theme.dark', :dark='$vuetify.theme.dark', :class='$vuetify.theme.dark ? `grey darken-4` : ``')
2019-07-29 04:50:03 +00:00
v-list-item.pl-4(href='/')
v-list-item-avatar(size='24'): v-icon(color='blue') mdi-home
v-list-item-title.body-2 {{$t('common:header.home')}}
v-list-item.pl-4(@click='pageNew', v-if='isAuthenticated')
v-list-item-avatar(size='24'): v-icon(color='green') mdi-file-document-box-plus-outline
v-list-item-title.body-2 {{$t('common:header.newPage')}}
template(v-if='path && path.length')
v-divider.my-0
2019-08-03 04:48:55 +00:00
.overline.pa-4.grey--text {{$t('common:header.currentPage')}}
2019-07-29 04:50:03 +00:00
v-list-item.pl-4(@click='pageView', v-if='mode !== `view`')
2019-08-04 02:51:29 +00:00
v-list-item-avatar(size='24'): v-icon(color='indigo') mdi-file-document-box-outline
2019-07-29 04:50:03 +00:00
v-list-item-title.body-2 {{$t('common:header.view')}}
v-list-item.pl-4(@click='pageEdit', v-if='mode !== `edit` && isAuthenticated')
v-list-item-avatar(size='24'): v-icon(color='indigo') mdi-file-document-edit-outline
v-list-item-title.body-2 {{$t('common:header.edit')}}
v-list-item.pl-4(@click='pageHistory', v-if='mode !== `history`')
2019-08-17 22:29:58 +00:00
v-list-item-avatar(size='24'): v-icon(color='grey lighten-2') mdi-history
v-list-item-title.body-2.grey--text.text--ligten-2 {{$t('common:header.history')}}
2019-07-29 04:50:03 +00:00
v-list-item.pl-4(@click='pageSource', v-if='mode !== `source`')
v-list-item-avatar(size='24'): v-icon(color='indigo') mdi-code-tags
2019-07-29 04:50:03 +00:00
v-list-item-title.body-2 {{$t('common:header.viewSource')}}
v-list-item.pl-4(@click='pageMove', v-if='isAuthenticated')
v-list-item-avatar(size='24'): v-icon(color='grey lighten-2') mdi-content-save-move-outline
v-list-item-title.body-2.grey--text.text--ligten-2 {{$t('common:header.move')}}
v-list-item.pl-4(@click='pageDelete', v-if='isAuthenticated')
v-list-item-avatar(size='24'): v-icon(color='red darken-2') mdi-trash-can-outline
v-list-item-title.body-2 {{$t('common:header.delete')}}
v-divider.my-0
2019-08-03 04:48:55 +00:00
.overline.pa-4.grey--text {{$t('common:header.assets')}}
2019-07-29 04:50:03 +00:00
v-list-item.pl-4(@click='assets')
v-list-item-avatar(size='24'): v-icon(color='grey lighten-2') mdi-folder-multiple-image
v-list-item-title.body-2.grey--text.text--ligten-2 {{$t('common:header.imagesFiles')}}
2019-08-04 17:54:23 +00:00
v-toolbar-title(:class='{ "mx-2": $vuetify.breakpoint.mdAndUp, "mx-0": $vuetify.breakpoint.smAndDown }')
span.subheading {{title}}
v-flex(md4, v-if='$vuetify.breakpoint.mdAndUp')
v-toolbar.nav-header-inner(color='black', dark, flat)
slot(name='mid')
transition(name='navHeaderSearch', v-if='searchIsShown')
v-text-field(
ref='searchField',
v-if='searchIsShown && $vuetify.breakpoint.mdAndUp',
v-model='search',
color='white',
2019-06-09 01:00:12 +00:00
:label='$t(`common:header.search`)',
single-line,
solo
flat
hide-details,
2019-07-29 04:50:03 +00:00
prepend-inner-icon='mdi-magnify',
:loading='searchIsLoading',
@keyup.enter='searchEnter'
@keyup.esc='searchClose'
@focus='searchFocus'
@blur='searchBlur'
@keyup.down='searchMove(`down`)'
@keyup.up='searchMove(`up`)'
)
2019-08-25 18:23:56 +00:00
//- v-menu(
//- v-model='searchAdvMenuShown'
//- left
//- offset-y
//- min-width='450'
//- :close-on-content-click='false'
//- nudge-bottom='7'
//- nudge-right='5'
//- v-if='searchIsShown'
//- )
//- template(v-slot:activator='{ on }')
//- v-btn.nav-header-search-adv(icon, color='grey darken-2', v-on='on')
//- v-icon(color='white') mdi-chevron-down
//- v-card.radius-0(dark)
//- v-toolbar(flat, color='grey darken-4', dense)
//- v-icon.mr-2 mdi-feature-search-outline
//- v-subheader.pl-0 Advanced Search
//- v-spacer
//- v-chip(label, small, color='primary') Coming soon
//- v-card-text.pa-4
//- v-checkbox.mt-0(
//- label='Restrict to current language'
//- color='white'
//- v-model='searchRestrictLocale'
//- hide-details
//- )
//- v-checkbox(
//- label='Search below current path only'
//- color='white'
//- v-model='searchRestrictPath'
//- hide-details
//- )
//- v-divider
//- v-card-actions.grey.darken-3-d4
//- v-container.pa-0(grid-list-md)
//- v-layout(row)
//- v-flex(xs6)
//- v-btn(depressed, color='grey darken-3', block)
//- v-icon(left) mdi-chevron-right
//- span Save as defaults
//- v-flex(xs6)
//- v-btn(depressed, color='grey darken-3', block)
//- v-icon(left) mdi-cached
//- span Reset
2019-07-29 04:50:03 +00:00
v-flex(xs6, md4)
v-toolbar.nav-header-inner.pr-4(color='black', dark, flat)
v-spacer
.navHeaderLoading.mr-3
v-progress-circular(indeterminate, color='blue', :size='22', :width='2' v-show='isLoading')
slot(name='actions')
v-btn(
v-if='!hideSearch && $vuetify.breakpoint.smAndDown'
@click='searchToggle'
icon
)
2019-08-04 02:51:29 +00:00
v-icon(color='grey') mdi-magnify
2019-06-22 00:54:09 +00:00
v-menu(offset-y, left, transition='slide-y-transition', v-if='mode === `view` && locales.length > 0')
2019-07-29 04:50:03 +00:00
template(v-slot:activator='{ on: menu }')
v-tooltip(bottom)
template(v-slot:activator='{ on: tooltip }')
v-btn(icon, v-on='{ ...menu, ...tooltip }', :class='$vuetify.rtl ? `ml-3` : ``')
2019-07-29 04:50:03 +00:00
v-icon(color='grey') mdi-web
span {{$t('common:header.language')}}
2019-06-22 00:54:09 +00:00
v-list.py-0
template(v-for='(lc, idx) of locales')
2019-07-29 04:50:03 +00:00
v-list-item(@click='changeLocale(lc)')
v-list-item-action: v-chip(:color='lc.code === locale ? `blue` : `grey`', small, label, dark) {{lc.code.toUpperCase()}}
v-list-item-title {{lc.name}}
2019-06-22 00:54:09 +00:00
v-divider.my-0(v-if='idx < locales.length - 1')
v-tooltip(bottom, v-if='isAuthenticated && isAdmin')
2019-07-29 04:50:03 +00:00
template(v-slot:activator='{ on }')
v-btn.btn-animate-rotate(icon, href='/a', v-on='on', :class='$vuetify.rtl ? `ml-3` : ``')
2019-07-29 04:50:03 +00:00
v-icon(color='grey') mdi-settings
2019-06-09 01:00:12 +00:00
span {{$t('common:header.admin')}}
2019-06-02 21:29:50 +00:00
v-menu(v-if='isAuthenticated', offset-y, min-width='300', left, transition='slide-y-transition')
2019-07-29 04:50:03 +00:00
template(v-slot:activator='{ on: menu }')
v-tooltip(bottom)
template(v-slot:activator='{ on: tooltip }')
v-btn(icon, v-on='{ ...menu, ...tooltip }', :class='$vuetify.rtl ? `ml-0` : ``')
2019-07-29 04:50:03 +00:00
v-icon(v-if='picture.kind === `initials`', color='grey') mdi-account-circle
2019-08-11 04:12:07 +00:00
v-avatar(v-else-if='picture.kind === `image`', :size='34')
2019-07-29 04:50:03 +00:00
v-img(:src='picture.url')
span {{$t('common:header.account')}}
v-list.py-0
2019-08-11 04:12:07 +00:00
v-list-item.py-3.grey(:class='$vuetify.theme.dark ? `darken-4-l5` : `lighten-5`')
2019-07-29 04:50:03 +00:00
v-list-item-avatar
2019-01-12 23:33:30 +00:00
v-avatar.blue(v-if='picture.kind === `initials`', :size='40')
span.white--text.subheading {{picture.initials}}
v-avatar(v-else-if='picture.kind === `image`', :size='40')
v-img(:src='picture.url')
2019-07-29 04:50:03 +00:00
v-list-item-content
v-list-item-title {{name}}
2019-08-04 17:54:23 +00:00
v-list-item-subtitle {{email}}
2019-01-12 23:33:30 +00:00
v-divider.my-0
2019-07-29 04:50:03 +00:00
v-list-item(href='/w', disabled)
v-list-item-action: v-icon(color='blue') mdi-view-compact-outline
v-list-item-title {{$t('common:header.myWiki')}}
2019-01-12 23:33:30 +00:00
v-divider.my-0
2019-07-29 04:50:03 +00:00
v-list-item(href='/p', disabled)
v-list-item-action: v-icon(color='blue') mdi-face-profile
v-list-item-title {{$t('common:header.profile')}}
2019-01-12 23:33:30 +00:00
v-divider.my-0
2019-07-29 04:50:03 +00:00
v-list-item(@click='logout')
v-list-item-action: v-icon(color='red') mdi-logout
v-list-item-title {{$t('common:header.logout')}}
2019-01-12 23:33:30 +00:00
v-tooltip(v-else, left)
2019-07-29 04:50:03 +00:00
template(v-slot:activator='{ on }')
2019-08-11 04:12:07 +00:00
v-btn(icon, v-on='on', color='grey darken-3', href='/login')
2019-07-29 04:50:03 +00:00
v-icon(color='grey') mdi-account-circle
2019-06-09 01:00:12 +00:00
span {{$t('common:header.login')}}
2018-11-12 05:51:34 +00:00
page-selector(mode='create', v-model='newPageModal', :open-handler='pageNewCreate', :locale='locale')
2019-01-26 23:35:56 +00:00
page-delete(v-model='deletePageModal', v-if='path && path.length')
</template>
<script>
2019-03-09 05:51:02 +00:00
import { get, sync } from 'vuex-pathify'
2018-08-13 04:12:44 +00:00
import _ from 'lodash'
import Cookies from 'js-cookie'
2018-06-11 03:23:09 +00:00
2019-06-22 00:54:09 +00:00
/* global siteLangs */
export default {
2019-01-26 23:35:56 +00:00
components: {
PageDelete: () => import('./page-delete.vue')
},
props: {
dense: {
type: Boolean,
default: false
},
hideSearch: {
type: Boolean,
default: false
}
},
data() {
return {
menuIsShown: true,
searchIsShown: true,
2019-03-09 05:51:02 +00:00
searchAdvMenuShown: false,
2019-01-26 23:35:56 +00:00
newPageModal: false,
2019-06-02 21:29:50 +00:00
deletePageModal: false,
2019-06-22 00:54:09 +00:00
locales: siteLangs
}
},
computed: {
2019-03-09 05:51:02 +00:00
search: sync('site/search'),
2019-03-09 23:43:32 +00:00
searchIsFocused: sync('site/searchIsFocused'),
2019-03-09 05:51:02 +00:00
searchIsLoading: sync('site/searchIsLoading'),
searchRestrictLocale: sync('site/searchRestrictLocale'),
searchRestrictPath: sync('site/searchRestrictPath'),
2018-08-04 21:27:55 +00:00
isLoading: get('isLoading'),
2018-10-29 02:09:58 +00:00
title: get('site/title'),
path: get('page/path'),
2019-06-22 03:39:04 +00:00
locale: get('page/locale'),
2018-12-03 02:42:43 +00:00
mode: get('page/mode'),
name: get('user/name'),
email: get('user/email'),
pictureUrl: get('user/pictureUrl'),
isAuthenticated: get('user/authenticated'),
permissions: get('user/permissions'),
picture() {
if (this.pictureUrl && this.pictureUrl.length > 1) {
return {
kind: 'image',
url: this.pictureUrl
}
} else {
const nameParts = this.name.toUpperCase().split(' ')
let initials = _.head(nameParts).charAt(0)
if (nameParts.length > 1) {
initials += _.last(nameParts).charAt(0)
}
return {
kind: 'initials',
initials
}
}
},
isAdmin() {
return _.includes(this.permissions, 'manage:system')
}
},
created() {
2018-08-13 04:12:44 +00:00
if (this.hideSearch || this.dense || this.$vuetify.breakpoint.smAndDown) {
this.searchIsShown = false
}
},
methods: {
2019-03-09 23:43:32 +00:00
searchFocus() {
this.searchIsFocused = true
},
searchBlur() {
this.searchIsFocused = false
},
searchClose() {
this.search = ''
this.searchBlur()
},
2018-08-13 04:12:44 +00:00
searchToggle() {
this.searchIsShown = !this.searchIsShown
if (this.searchIsShown) {
_.delay(() => {
this.$refs.searchFieldMobile.focus()
}, 200)
}
},
searchEnter() {
this.$root.$emit('searchEnter', true)
},
searchMove(dir) {
this.$root.$emit('searchMove', dir)
},
pageNew () {
2018-11-12 05:51:34 +00:00
this.newPageModal = true
},
pageNewCreate ({ path, locale }) {
2019-06-22 03:39:04 +00:00
window.location.assign(`/e/${locale}/${path}`)
},
pageView () {
2019-06-22 03:39:04 +00:00
window.location.assign(`/${this.locale}/${this.path}`)
},
pageEdit () {
2019-06-22 03:39:04 +00:00
window.location.assign(`/e/${this.locale}/${this.path}`)
},
pageHistory () {
2019-08-17 22:29:58 +00:00
this.$store.commit('showNotification', {
style: 'indigo',
message: `Coming soon...`,
icon: 'ferry'
})
// window.location.assign(`/h/${this.locale}/${this.path}`)
},
pageSource () {
2019-06-22 03:39:04 +00:00
window.location.assign(`/s/${this.locale}/${this.path}`)
},
pageMove () {
this.$store.commit('showNotification', {
style: 'indigo',
message: `Coming soon...`,
2019-08-03 04:48:55 +00:00
icon: 'ferry'
})
},
pageDelete () {
2019-01-26 23:35:56 +00:00
this.deletePageModal = true
},
assets () {
2019-06-02 21:29:50 +00:00
// window.location.assign(`/f`)
this.$store.commit('showNotification', {
style: 'indigo',
message: `Coming soon...`,
2019-08-03 04:48:55 +00:00
icon: 'ferry'
2019-06-02 21:29:50 +00:00
})
},
async changeLocale(locale) {
await this.$i18n.i18next.changeLanguage(locale.code)
switch (this.mode) {
case 'view':
case 'history':
window.location.assign(`/${locale.code}/${this.path}`)
break
}
},
logout () {
Cookies.remove('jwt')
window.location.assign('/')
}
}
}
</script>
<style lang='scss'>
2018-08-13 04:12:44 +00:00
.nav-header {
//z-index: 1000;
2018-08-13 04:12:44 +00:00
.v-toolbar__extension {
padding: 0;
.v-toolbar__content {
padding: 0;
}
.v-text-field .v-input__prepend-inner {
padding: 0 14px 0 5px;
padding-right: 14px;
}
}
&-inner {
.v-toolbar__content {
padding: 0;
}
}
2019-03-09 05:51:02 +00:00
&-search-adv {
position: absolute;
top: 7px;
right: 12px;
border-radius: 4px !important;
2019-08-11 04:12:07 +00:00
@at-root .v-application--is-rtl & {
right: initial;
left: 12px;
}
2019-03-09 05:51:02 +00:00
&::before {
border-radius: 4px !important;
}
&:hover, &:focus {
position: absolute !important;
&::before {
border-radius: 4px;
}
}
}
2018-08-13 04:12:44 +00:00
}
.navHeaderSearch {
&-enter-active, &-leave-active {
transition: opacity .25s ease, transform .25s ease;
opacity: 1;
}
&-enter-active {
transition-delay: .25s;
}
&-enter, &-leave-to {
opacity: 0;
transform: scale(.7, .7);
}
}
.navHeaderLoading { // To avoid search bar jumping
width: 22px;
}
</style>