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.

255 lines
9.1 KiB

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