123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <template lang='pug'>
- v-container(fluid, grid-list-lg)
- v-layout(row wrap)
- v-flex(xs12)
- .admin-header
- img.animated.fadeInUp(src='/_assets/svg/icon-paint-palette.svg', alt='Theme', style='width: 80px;')
- .admin-header-title
- .headline.primary--text.animated.fadeInLeft {{$t('admin:theme.title')}}
- .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:theme.subtitle')}}
- v-spacer
- v-btn.animated.fadeInRight(color='success', depressed, @click='save', large, :loading='loading')
- v-icon(left) mdi-check
- span {{$t('common:actions.apply')}}
- v-form.pt-3
- v-layout(row wrap)
- v-flex(lg6 xs12)
- v-card.animated.fadeInUp
- v-toolbar(color='primary', dark, dense, flat)
- v-toolbar-title.subtitle-1 {{$t('admin:theme.title')}}
- v-card-text
- v-select(
- :items='themes'
- outlined
- prepend-icon='mdi-palette'
- v-model='config.theme'
- :label='$t(`admin:theme.siteTheme`)'
- persistent-hint
- :hint='$t(`admin:theme.siteThemeHint`)'
- )
- template(slot='item', slot-scope='data')
- v-list-item-avatar
- v-icon.blue--text(dark) mdi-image-filter-frames
- v-list-item-content
- v-list-item-title(v-html='data.item.text')
- v-list-item-sub-title(v-html='data.item.author')
- v-select.mt-3(
- :items='iconsets'
- outlined
- prepend-icon='mdi-paw'
- v-model='config.iconset'
- :label='$t(`admin:theme.iconset`)'
- persistent-hint
- :hint='$t(`admin:theme.iconsetHint`)'
- )
- v-divider.mt-3
- v-switch(
- inset
- v-model='darkMode'
- :label='$t(`admin:theme.darkMode`)'
- color='primary'
- persistent-hint
- :hint='$t(`admin:theme.darkModeHint`)'
- )
- v-card.mt-3.animated.fadeInUp.wait-p1s
- v-toolbar(color='primary', dark, dense, flat)
- v-toolbar-title.subtitle-1 {{$t(`admin:theme.options`)}}
- v-card-text
- v-range-slider(
- prepend-icon='mdi-menu-open'
- :label='$t(`admin:theme.tocHeadingLevels`)'
- v-model='tocRange'
- :min='1'
- :max='6'
- :tick-labels='["H1", "H2", "H3", "H4", "H5", "H6"]'
- )
- .text-caption {{$t('admin:theme.tocHeadingLevelsHint')}}
- v-flex(lg6 xs12)
- v-card.animated.fadeInUp.wait-p2s
- v-toolbar(color='primary', dark, dense, flat)
- v-toolbar-title.subtitle-1 {{$t(`admin:theme.codeInjection`)}}
- v-card-text
- v-textarea.is-monospaced(
- v-model='config.injectCSS'
- :label='$t(`admin:theme.cssOverride`)'
- outlined
- color='primary'
- persistent-hint
- :hint='$t(`admin:theme.cssOverrideHint`)'
- auto-grow
- )
- i18next.caption.pl-2.ml-1(path='admin:theme.cssOverrideWarning', tag='div')
- strong.red--text(place='caution') {{$t('admin:theme.cssOverrideWarningCaution')}}
- code(place='cssClass') .contents
- v-textarea.is-monospaced.mt-3(
- v-model='config.injectHead'
- :label='$t(`admin:theme.headHtmlInjection`)'
- outlined
- color='primary'
- persistent-hint
- :hint='$t(`admin:theme.headHtmlInjectionHint`)'
- auto-grow
- )
- v-textarea.is-monospaced.mt-2(
- v-model='config.injectBody'
- :label='$t(`admin:theme.bodyHtmlInjection`)'
- outlined
- color='primary'
- persistent-hint
- :hint='$t(`admin:theme.bodyHtmlInjectionHint`)'
- auto-grow
- )
- </template>
- <script>
- import _ from 'lodash'
- import { sync } from 'vuex-pathify'
- import themeConfigQuery from 'gql/admin/theme/theme-query-config.gql'
- import themeSaveMutation from 'gql/admin/theme/theme-mutation-save.gql'
- export default {
- data() {
- return {
- loading: false,
- themes: [
- { text: 'Default', author: 'requarks.io', value: 'default', isInstalled: true, installDate: '', updatedAt: '' }
- ],
- iconsets: [
- { text: 'Material Design Icons (default)', value: 'mdi' },
- { text: 'Font Awesome 5', value: 'fa' },
- { text: 'Font Awesome 4', value: 'fa4' }
- ],
- config: {
- theme: 'default',
- darkMode: false,
- tocDepth: {
- min: 1,
- max: 2
- },
- iconset: '',
- injectCSS: '',
- injectHead: '',
- injectBody: ''
- },
- darkModeInitial: false
- }
- },
- computed: {
- tocRange: {
- get() {
- var range = [this.config.tocDepth.min, this.config.tocDepth.max]
- return range
- },
- set(value) {
- this.config.tocDepth = {
- min: parseInt(value[0]),
- max: parseInt(value[1])
- }
- }
- },
- darkMode: sync('site/dark'),
- headers() {
- return [
- {
- text: this.$t('admin:theme.downloadName'),
- align: 'left',
- value: 'text'
- },
- {
- text: this.$t('admin:theme.downloadAuthor'),
- align: 'left',
- value: 'author'
- },
- {
- text: this.$t('admin:theme.downloadDownload'),
- align: 'center',
- value: 'value',
- sortable: false,
- width: 100
- }
- ]
- }
- },
- watch: {
- 'darkMode' (newValue, oldValue) {
- this.$vuetify.theme.dark = newValue
- }
- },
- mounted() {
- this.darkModeInitial = this.darkMode
- },
- beforeDestroy() {
- this.darkMode = this.darkModeInitial
- this.$vuetify.theme.dark = this.darkModeInitial
- },
- methods: {
- async save () {
- this.loading = true
- this.$store.commit(`loadingStart`, 'admin-theme-save')
- try {
- const respRaw = await this.$apollo.mutate({
- mutation: themeSaveMutation,
- variables: {
- theme: this.config.theme,
- iconset: this.config.iconset,
- darkMode: this.darkMode,
- tocDepth: this.config.tocDepth,
- injectCSS: this.config.injectCSS,
- injectHead: this.config.injectHead,
- injectBody: this.config.injectBody
- }
- })
- const resp = _.get(respRaw, 'data.theming.setConfig.responseResult', {})
- if (resp.succeeded) {
- this.darkModeInitial = this.darkMode
- this.$store.commit('showNotification', {
- message: 'Theme settings updated successfully.',
- style: 'success',
- icon: 'check'
- })
- } else {
- throw new Error(resp.message)
- }
- } catch (err) {
- this.$store.commit('pushGraphError', err)
- }
- this.$store.commit(`loadingStop`, 'admin-theme-save')
- this.loading = false
- }
- },
- apollo: {
- config: {
- query: themeConfigQuery,
- fetchPolicy: 'network-only',
- update: (data) => data.theming.config,
- watchLoading (isLoading) {
- this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-theme-refresh')
- }
- }
- }
- }
- </script>
- <style lang='scss'>
- .v-textarea.is-monospaced textarea {
- font-family: 'Roboto Mono', 'Courier New', Courier, monospace;
- font-size: 13px;
- font-weight: 600;
- line-height: 1.4;
- }
- </style>
|