2
0

admin-theme.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. v-model='darkMode'
  48. :label='$t(`admin:theme.darkMode`)'
  49. color='primary'
  50. persistent-hint
  51. :hint='$t(`admin:theme.darkModeHint`)'
  52. )
  53. //- v-card.mt-3.animated.fadeInUp.wait-p1s
  54. //- v-toolbar(color='primary', dark, dense, flat)
  55. //- v-toolbar-title.subtitle-1 {{$t(`admin:theme.options`)}}
  56. //- v-spacer
  57. //- v-chip(label, color='white', small).primary--text coming soon
  58. //- v-card-text
  59. //- v-select(
  60. //- :items='iconsets'
  61. //- outlined
  62. //- prepend-icon='mdi-border-vertical'
  63. //- v-model='config.iconset'
  64. //- label='Table of Contents Position'
  65. //- persistent-hint
  66. //- hint='Select whether the table of contents is shown on the left, right or not at all.'
  67. //- )
  68. v-card.mt-3.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(
  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.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.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. v-flex(lg6 xs12)
  103. v-card.animated.fadeInUp.wait-p2s
  104. v-toolbar(color='teal', dark, dense, flat)
  105. v-toolbar-title.subtitle-1 {{$t('admin:theme.downloadThemes')}}
  106. v-spacer
  107. v-chip(label, color='white', small).teal--text coming soon
  108. v-data-table(
  109. :headers='headers',
  110. :items='themes',
  111. hide-default-footer,
  112. item-key='value',
  113. :items-per-page='1000'
  114. )
  115. template(v-slot:items='thm')
  116. td
  117. strong {{thm.item.text}}
  118. td
  119. span {{ thm.item.author }}
  120. td.text-xs-center
  121. v-progress-circular(v-if='thm.item.isDownloading', indeterminate, color='blue', size='20', :width='2')
  122. v-btn(v-else-if='thm.item.isInstalled && thm.item.installDate < thm.item.updatedAt', icon)
  123. v-icon.blue--text mdi-cached
  124. v-btn(v-else-if='thm.item.isInstalled', icon)
  125. v-icon.green--text mdi-check
  126. v-btn(v-else, icon)
  127. v-icon.grey--text mdi-cloud-download
  128. </template>
  129. <script>
  130. import _ from 'lodash'
  131. import { sync } from 'vuex-pathify'
  132. import themeConfigQuery from 'gql/admin/theme/theme-query-config.gql'
  133. import themeSaveMutation from 'gql/admin/theme/theme-mutation-save.gql'
  134. export default {
  135. data() {
  136. return {
  137. loading: false,
  138. themes: [
  139. { text: 'Default', author: 'requarks.io', value: 'default', isInstalled: true, installDate: '', updatedAt: '' }
  140. ],
  141. iconsets: [
  142. { text: 'Material Design Icons (default)', value: 'mdi' },
  143. { text: 'Font Awesome 5', value: 'fa' },
  144. { text: 'Font Awesome 4', value: 'fa4' }
  145. ],
  146. config: {
  147. theme: 'default',
  148. darkMode: false,
  149. iconset: '',
  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. },
  181. watch: {
  182. 'darkMode' (newValue, oldValue) {
  183. this.$vuetify.theme.dark = newValue
  184. }
  185. },
  186. mounted() {
  187. this.darkModeInitial = this.darkMode
  188. },
  189. beforeDestroy() {
  190. this.darkMode = this.darkModeInitial
  191. this.$vuetify.theme.dark = this.darkModeInitial
  192. },
  193. methods: {
  194. async save () {
  195. this.loading = true
  196. this.$store.commit(`loadingStart`, 'admin-theme-save')
  197. try {
  198. const respRaw = await this.$apollo.mutate({
  199. mutation: themeSaveMutation,
  200. variables: {
  201. theme: this.config.theme,
  202. iconset: this.config.iconset,
  203. darkMode: this.darkMode,
  204. injectCSS: this.config.injectCSS,
  205. injectHead: this.config.injectHead,
  206. injectBody: this.config.injectBody
  207. }
  208. })
  209. const resp = _.get(respRaw, 'data.theming.setConfig.responseResult', {})
  210. if (resp.succeeded) {
  211. this.darkModeInitial = this.darkMode
  212. this.$store.commit('showNotification', {
  213. message: 'Theme settings updated successfully.',
  214. style: 'success',
  215. icon: 'check'
  216. })
  217. } else {
  218. throw new Error(resp.message)
  219. }
  220. } catch (err) {
  221. this.$store.commit('pushGraphError', err)
  222. }
  223. this.$store.commit(`loadingStop`, 'admin-theme-save')
  224. this.loading = false
  225. }
  226. },
  227. apollo: {
  228. config: {
  229. query: themeConfigQuery,
  230. fetchPolicy: 'network-only',
  231. update: (data) => data.theming.config,
  232. watchLoading (isLoading) {
  233. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-theme-refresh')
  234. }
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang='scss'>
  240. </style>