admin-theme.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template lang='pug'>
  2. v-container(fluid, fill-height, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .headline.primary--text Theme
  6. .subheading.grey--text Modify the look &amp; feel of your wiki
  7. v-form.pt-3
  8. v-layout(row wrap)
  9. v-flex(lg6 xs12)
  10. v-card
  11. v-toolbar(color='primary', dark, dense, flat)
  12. v-toolbar-title
  13. .subheading Theme
  14. v-card-text
  15. v-select(
  16. :items='themes'
  17. prepend-icon='palette'
  18. v-model='selectedTheme'
  19. label='Site Theme'
  20. persistent-hint
  21. hint='Themes affect how content pages are displayed. Other site sections (such as the editor or admin area) are not affected.'
  22. )
  23. template(slot='item', slot-scope='data')
  24. v-list-tile-avatar
  25. v-icon.blue--text(dark) filter_frames
  26. v-list-tile-content
  27. v-list-tile-title(v-html='data.item.text')
  28. v-list-tile-sub-title(v-html='data.item.author')
  29. v-divider
  30. v-switch(
  31. v-model='darkMode'
  32. label='Dark Mode'
  33. color='primary'
  34. persistent-hint
  35. hint='Not recommended for accessibility. May not be supported by all themes.'
  36. )
  37. v-card-chin
  38. v-spacer
  39. v-btn(color='primary', :loading='loading', @click='save')
  40. v-icon(left) chevron_right
  41. span Save
  42. v-flex(lg6 xs12)
  43. v-card
  44. v-toolbar(color='teal', dark, dense, flat)
  45. v-toolbar-title
  46. .subheading Download Themes
  47. v-card-text.caption -- Coming soon --
  48. </template>
  49. <script>
  50. import _ from 'lodash'
  51. import themeSaveMutation from 'gql/admin/theme/theme-mutation-save.gql'
  52. export default {
  53. data() {
  54. return {
  55. loading: false,
  56. themes: [
  57. { text: 'Default', author: 'requarks.io', value: 'default' }
  58. ],
  59. selectedTheme: 'default',
  60. darkMode: false,
  61. darkModeInitial: false
  62. }
  63. },
  64. watch: {
  65. darkMode(newValue, oldValue) {
  66. this.$store.commit('admin/setThemeDarkMode', newValue)
  67. }
  68. },
  69. mounted() {
  70. this.darkMode = this.$store.state.admin.theme.dark
  71. this.darkModeInitial = this.darkMode
  72. },
  73. beforeDestroy() {
  74. this.$store.commit('admin/setThemeDarkMode', this.darkModeInitial)
  75. },
  76. methods: {
  77. async save () {
  78. this.loading = true
  79. this.$store.commit(`loadingStart`, 'admin-theme-save')
  80. try {
  81. const respRaw = await this.$apollo.mutate({
  82. mutation: themeSaveMutation,
  83. variables: {
  84. theme: this.selectedTheme,
  85. darkMode: this.darkMode
  86. }
  87. })
  88. const resp = _.get(respRaw, 'data.theming.setConfig.responseResult', {})
  89. if (resp.succeeded) {
  90. this.darkModeInitial = this.darkMode
  91. this.$store.commit('showNotification', {
  92. message: 'Theme settings updated successfully.',
  93. style: 'success',
  94. icon: 'check'
  95. })
  96. } else {
  97. throw new Error(resp.message)
  98. }
  99. } catch (err) {
  100. this.$store.commit('showNotification', {
  101. message: `Error: ${err.message}`,
  102. style: 'error',
  103. icon: 'warning'
  104. })
  105. }
  106. this.$store.commit(`loadingStop`, 'admin-theme-save')
  107. this.loading = false
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang='scss'>
  113. </style>