admin-theme.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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-select(
  59. :items='tocPositions'
  60. outlined
  61. prepend-icon='mdi-border-vertical'
  62. v-model='config.tocPosition'
  63. label='Table of Contents Position'
  64. persistent-hint
  65. hint='Select whether the table of contents is shown on the left, right or not at all.'
  66. )
  67. v-flex(lg6 xs12)
  68. //- v-card.animated.fadeInUp.wait-p2s
  69. //- v-toolbar(color='teal', dark, dense, flat)
  70. //- v-toolbar-title.subtitle-1 {{$t('admin:theme.downloadThemes')}}
  71. //- v-spacer
  72. //- v-chip(label, color='white', small).teal--text coming soon
  73. //- v-data-table(
  74. //- :headers='headers',
  75. //- :items='themes',
  76. //- hide-default-footer,
  77. //- item-key='value',
  78. //- :items-per-page='1000'
  79. //- )
  80. //- template(v-slot:item='thm')
  81. //- td
  82. //- strong {{thm.item.text}}
  83. //- td
  84. //- span {{ thm.item.author }}
  85. //- td.text-xs-center
  86. //- v-progress-circular(v-if='thm.item.isDownloading', indeterminate, color='blue', size='20', :width='2')
  87. //- v-btn(v-else-if='thm.item.isInstalled && thm.item.installDate < thm.item.updatedAt', icon)
  88. //- v-icon.blue--text mdi-cached
  89. //- v-btn(v-else-if='thm.item.isInstalled', icon)
  90. //- v-icon.green--text mdi-check-bold
  91. //- v-btn(v-else, icon)
  92. //- v-icon.grey--text mdi-cloud-download
  93. v-card.animated.fadeInUp.wait-p2s
  94. v-toolbar(color='primary', dark, dense, flat)
  95. v-toolbar-title.subtitle-1 {{$t(`admin:theme.codeInjection`)}}
  96. v-card-text
  97. v-textarea.is-monospaced(
  98. v-model='config.injectCSS'
  99. :label='$t(`admin:theme.cssOverride`)'
  100. outlined
  101. color='primary'
  102. persistent-hint
  103. :hint='$t(`admin:theme.cssOverrideHint`)'
  104. auto-grow
  105. )
  106. i18next.caption.pl-2.ml-1(path='admin:theme.cssOverrideWarning', tag='div')
  107. strong.red--text(place='caution') {{$t('admin:theme.cssOverrideWarningCaution')}}
  108. code(place='cssClass') .contents
  109. v-textarea.is-monospaced.mt-3(
  110. v-model='config.injectHead'
  111. :label='$t(`admin:theme.headHtmlInjection`)'
  112. outlined
  113. color='primary'
  114. persistent-hint
  115. :hint='$t(`admin:theme.headHtmlInjectionHint`)'
  116. auto-grow
  117. )
  118. v-textarea.is-monospaced.mt-2(
  119. v-model='config.injectBody'
  120. :label='$t(`admin:theme.bodyHtmlInjection`)'
  121. outlined
  122. color='primary'
  123. persistent-hint
  124. :hint='$t(`admin:theme.bodyHtmlInjectionHint`)'
  125. auto-grow
  126. )
  127. </template>
  128. <script>
  129. import _ from 'lodash'
  130. import { sync } from 'vuex-pathify'
  131. import themeConfigQuery from 'gql/admin/theme/theme-query-config.gql'
  132. import themeSaveMutation from 'gql/admin/theme/theme-mutation-save.gql'
  133. export default {
  134. data() {
  135. return {
  136. loading: false,
  137. themes: [
  138. { text: 'Default', author: 'requarks.io', value: 'default', isInstalled: true, installDate: '', updatedAt: '' }
  139. ],
  140. iconsets: [
  141. { text: 'Material Design Icons (default)', value: 'mdi' },
  142. { text: 'Font Awesome 5', value: 'fa' },
  143. { text: 'Font Awesome 4', value: 'fa4' }
  144. ],
  145. config: {
  146. theme: 'default',
  147. darkMode: false,
  148. iconset: '',
  149. tocPosition: 'left',
  150. injectCSS: '',
  151. injectHead: '',
  152. injectBody: ''
  153. },
  154. darkModeInitial: false
  155. }
  156. },
  157. computed: {
  158. darkMode: sync('site/dark'),
  159. headers() {
  160. return [
  161. {
  162. text: this.$t('admin:theme.downloadName'),
  163. align: 'left',
  164. value: 'text'
  165. },
  166. {
  167. text: this.$t('admin:theme.downloadAuthor'),
  168. align: 'left',
  169. value: 'author'
  170. },
  171. {
  172. text: this.$t('admin:theme.downloadDownload'),
  173. align: 'center',
  174. value: 'value',
  175. sortable: false,
  176. width: 100
  177. }
  178. ]
  179. },
  180. tocPositions () {
  181. return [
  182. { text: 'Left (default)', value: 'left' },
  183. { text: 'Right', value: 'right' },
  184. { text: 'Hidden', value: 'off' }
  185. ]
  186. }
  187. },
  188. watch: {
  189. 'darkMode' (newValue, oldValue) {
  190. this.$vuetify.theme.dark = newValue
  191. }
  192. },
  193. mounted() {
  194. this.darkModeInitial = this.darkMode
  195. },
  196. beforeDestroy() {
  197. this.darkMode = this.darkModeInitial
  198. this.$vuetify.theme.dark = this.darkModeInitial
  199. },
  200. methods: {
  201. async save () {
  202. this.loading = true
  203. this.$store.commit(`loadingStart`, 'admin-theme-save')
  204. try {
  205. const respRaw = await this.$apollo.mutate({
  206. mutation: themeSaveMutation,
  207. variables: {
  208. theme: this.config.theme,
  209. iconset: this.config.iconset,
  210. darkMode: this.darkMode,
  211. tocPosition: this.config.tocPosition,
  212. injectCSS: this.config.injectCSS,
  213. injectHead: this.config.injectHead,
  214. injectBody: this.config.injectBody
  215. }
  216. })
  217. const resp = _.get(respRaw, 'data.theming.setConfig.responseResult', {})
  218. if (resp.succeeded) {
  219. this.darkModeInitial = this.darkMode
  220. this.$store.commit('showNotification', {
  221. message: 'Theme settings updated successfully.',
  222. style: 'success',
  223. icon: 'check'
  224. })
  225. } else {
  226. throw new Error(resp.message)
  227. }
  228. } catch (err) {
  229. this.$store.commit('pushGraphError', err)
  230. }
  231. this.$store.commit(`loadingStop`, 'admin-theme-save')
  232. this.loading = false
  233. }
  234. },
  235. apollo: {
  236. config: {
  237. query: themeConfigQuery,
  238. fetchPolicy: 'network-only',
  239. update: (data) => data.theming.config,
  240. watchLoading (isLoading) {
  241. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-theme-refresh')
  242. }
  243. }
  244. }
  245. }
  246. </script>
  247. <style lang='scss'>
  248. .v-textarea.is-monospaced textarea {
  249. font-family: 'Roboto Mono', 'Courier New', Courier, monospace;
  250. font-size: 13px;
  251. font-weight: 600;
  252. line-height: 1.4;
  253. }
  254. </style>