2
0

admin-theme.vue 10 KB

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