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.

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