admin-theme.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/_assets/svg/icon-paint-palette.svg', alt='Theme', style='width: 80px;')
  7. .admin-header-title
  8. .headline.primary--text.animated.fadeInLeft {{$t('admin:theme.title')}}
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s {{$t('admin:theme.subtitle')}}
  10. v-spacer
  11. v-btn.animated.fadeInRight(color='success', depressed, @click='save', large, :loading='loading')
  12. v-icon(left) mdi-check
  13. span {{$t('common:actions.apply')}}
  14. v-form.pt-3
  15. v-layout(row wrap)
  16. v-flex(lg6 xs12)
  17. v-card.animated.fadeInUp
  18. v-toolbar(color='primary', dark, dense, flat)
  19. v-toolbar-title.subtitle-1 {{$t('admin:theme.title')}}
  20. v-card-text
  21. v-select(
  22. :items='themes'
  23. outlined
  24. prepend-icon='mdi-palette'
  25. v-model='config.theme'
  26. :label='$t(`admin:theme.siteTheme`)'
  27. persistent-hint
  28. :hint='$t(`admin:theme.siteThemeHint`)'
  29. )
  30. template(slot='item', slot-scope='data')
  31. v-list-item-avatar
  32. v-icon.blue--text(dark) mdi-image-filter-frames
  33. v-list-item-content
  34. v-list-item-title(v-html='data.item.text')
  35. v-list-item-sub-title(v-html='data.item.author')
  36. v-select.mt-3(
  37. :items='iconsets'
  38. outlined
  39. prepend-icon='mdi-paw'
  40. v-model='config.iconset'
  41. :label='$t(`admin:theme.iconset`)'
  42. persistent-hint
  43. :hint='$t(`admin:theme.iconsetHint`)'
  44. )
  45. v-divider.mt-3
  46. v-switch(
  47. inset
  48. v-model='darkMode'
  49. :label='$t(`admin:theme.darkMode`)'
  50. color='primary'
  51. persistent-hint
  52. :hint='$t(`admin:theme.darkModeHint`)'
  53. )
  54. v-card.mt-3.animated.fadeInUp.wait-p1s
  55. v-toolbar(color='primary', dark, dense, flat)
  56. v-toolbar-title.subtitle-1 {{$t(`admin:theme.options`)}}
  57. v-card-text
  58. v-range-slider(
  59. prepend-icon='mdi-menu-open'
  60. :label='$t(`admin:theme.tocHeadingLevels`)'
  61. v-model='tocRange'
  62. :min='1'
  63. :max='6'
  64. :tick-labels='["H1", "H2", "H3", "H4", "H5", "H6"]'
  65. )
  66. .text-caption {{$t('admin:theme.tocHeadingLevelsHint')}}
  67. v-flex(lg6 xs12)
  68. v-card.animated.fadeInUp.wait-p2s
  69. v-toolbar(color='primary', dark, dense, flat)
  70. v-toolbar-title.subtitle-1 {{$t(`admin:theme.codeInjection`)}}
  71. v-card-text
  72. v-textarea.is-monospaced(
  73. v-model='config.injectCSS'
  74. :label='$t(`admin:theme.cssOverride`)'
  75. outlined
  76. color='primary'
  77. persistent-hint
  78. :hint='$t(`admin:theme.cssOverrideHint`)'
  79. auto-grow
  80. )
  81. i18next.caption.pl-2.ml-1(path='admin:theme.cssOverrideWarning', tag='div')
  82. strong.red--text(place='caution') {{$t('admin:theme.cssOverrideWarningCaution')}}
  83. code(place='cssClass') .contents
  84. v-textarea.is-monospaced.mt-3(
  85. v-model='config.injectHead'
  86. :label='$t(`admin:theme.headHtmlInjection`)'
  87. outlined
  88. color='primary'
  89. persistent-hint
  90. :hint='$t(`admin:theme.headHtmlInjectionHint`)'
  91. auto-grow
  92. )
  93. v-textarea.is-monospaced.mt-2(
  94. v-model='config.injectBody'
  95. :label='$t(`admin:theme.bodyHtmlInjection`)'
  96. outlined
  97. color='primary'
  98. persistent-hint
  99. :hint='$t(`admin:theme.bodyHtmlInjectionHint`)'
  100. auto-grow
  101. )
  102. </template>
  103. <script>
  104. import _ from 'lodash'
  105. import { sync } from 'vuex-pathify'
  106. import themeConfigQuery from 'gql/admin/theme/theme-query-config.gql'
  107. import themeSaveMutation from 'gql/admin/theme/theme-mutation-save.gql'
  108. export default {
  109. data() {
  110. return {
  111. loading: false,
  112. themes: [
  113. { text: 'Default', author: 'requarks.io', value: 'default', isInstalled: true, installDate: '', updatedAt: '' }
  114. ],
  115. iconsets: [
  116. { text: 'Material Design Icons (default)', value: 'mdi' },
  117. { text: 'Font Awesome 5', value: 'fa' },
  118. { text: 'Font Awesome 4', value: 'fa4' }
  119. ],
  120. config: {
  121. theme: 'default',
  122. darkMode: false,
  123. tocDepth: {
  124. min: 1,
  125. max: 2
  126. },
  127. iconset: '',
  128. injectCSS: '',
  129. injectHead: '',
  130. injectBody: ''
  131. },
  132. darkModeInitial: false
  133. }
  134. },
  135. computed: {
  136. tocRange: {
  137. get() {
  138. var range = [this.config.tocDepth.min, this.config.tocDepth.max]
  139. return range
  140. },
  141. set(value) {
  142. this.config.tocDepth = {
  143. min: parseInt(value[0]),
  144. max: parseInt(value[1])
  145. }
  146. }
  147. },
  148. darkMode: sync('site/dark'),
  149. headers() {
  150. return [
  151. {
  152. text: this.$t('admin:theme.downloadName'),
  153. align: 'left',
  154. value: 'text'
  155. },
  156. {
  157. text: this.$t('admin:theme.downloadAuthor'),
  158. align: 'left',
  159. value: 'author'
  160. },
  161. {
  162. text: this.$t('admin:theme.downloadDownload'),
  163. align: 'center',
  164. value: 'value',
  165. sortable: false,
  166. width: 100
  167. }
  168. ]
  169. }
  170. },
  171. watch: {
  172. 'darkMode' (newValue, oldValue) {
  173. this.$vuetify.theme.dark = newValue
  174. }
  175. },
  176. mounted() {
  177. this.darkModeInitial = this.darkMode
  178. },
  179. beforeDestroy() {
  180. this.darkMode = this.darkModeInitial
  181. this.$vuetify.theme.dark = this.darkModeInitial
  182. },
  183. methods: {
  184. async save () {
  185. this.loading = true
  186. this.$store.commit(`loadingStart`, 'admin-theme-save')
  187. try {
  188. const respRaw = await this.$apollo.mutate({
  189. mutation: themeSaveMutation,
  190. variables: {
  191. theme: this.config.theme,
  192. iconset: this.config.iconset,
  193. darkMode: this.darkMode,
  194. tocDepth: this.config.tocDepth,
  195. injectCSS: this.config.injectCSS,
  196. injectHead: this.config.injectHead,
  197. injectBody: this.config.injectBody
  198. }
  199. })
  200. const resp = _.get(respRaw, 'data.theming.setConfig.responseResult', {})
  201. if (resp.succeeded) {
  202. this.darkModeInitial = this.darkMode
  203. this.$store.commit('showNotification', {
  204. message: 'Theme settings updated successfully.',
  205. style: 'success',
  206. icon: 'check'
  207. })
  208. } else {
  209. throw new Error(resp.message)
  210. }
  211. } catch (err) {
  212. this.$store.commit('pushGraphError', err)
  213. }
  214. this.$store.commit(`loadingStop`, 'admin-theme-save')
  215. this.loading = false
  216. }
  217. },
  218. apollo: {
  219. config: {
  220. query: themeConfigQuery,
  221. fetchPolicy: 'network-only',
  222. update: (data) => data.theming.config,
  223. watchLoading (isLoading) {
  224. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-theme-refresh')
  225. }
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang='scss'>
  231. .v-textarea.is-monospaced textarea {
  232. font-family: 'Roboto Mono', 'Courier New', Courier, monospace;
  233. font-size: 13px;
  234. font-weight: 600;
  235. line-height: 1.4;
  236. }
  237. </style>