ConfigEdit.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script setup lang="ts">
  2. import FooterToolBar from '@/components/FooterToolbar/FooterToolBar.vue'
  3. import gettext from '@/gettext'
  4. import {useRoute} from 'vue-router'
  5. import {ref} from 'vue'
  6. import config from '@/api/config'
  7. import {message} from 'ant-design-vue'
  8. import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
  9. const {$gettext, interpolate} = gettext
  10. const route = useRoute()
  11. const name = ref(route.params.name)
  12. const configText = ref('')
  13. function init() {
  14. if (name.value) {
  15. config.get(name.value).then(r => {
  16. configText.value = r.config
  17. }).catch(r => {
  18. message.error(r.message ?? $gettext('Server error'))
  19. })
  20. } else {
  21. configText.value = ''
  22. }
  23. }
  24. init()
  25. function save() {
  26. config.save(name.value, {content: configText.value}).then(r => {
  27. configText.value = r.config
  28. message.success($gettext('Saved successfully'))
  29. }).catch(r => {
  30. message.error(interpolate($gettext('Save error %{msg}'), {msg: r.message ?? ''}))
  31. })
  32. }
  33. </script>
  34. <template>
  35. <a-card :title="$gettext('Edit Configuration')">
  36. <code-editor v-model:content="configText"/>
  37. <footer-tool-bar>
  38. <a-space>
  39. <a-button @click="$router.go(-1)">
  40. <translate>Cancel</translate>
  41. </a-button>
  42. <a-button type="primary" @click="save">
  43. <translate>Save</translate>
  44. </a-button>
  45. </a-space>
  46. </footer-tool-bar>
  47. </a-card>
  48. </template>
  49. <style lang="less" scoped>
  50. .ant-card {
  51. margin: 10px;
  52. @media (max-width: 512px) {
  53. margin: 10px 0;
  54. }
  55. }
  56. </style>