Basic.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script setup lang="ts">
  2. import type { CheckedType } from '@/types'
  3. import envGroup from '@/api/env_group'
  4. import stream from '@/api/stream'
  5. import NodeSelector from '@/components/NodeSelector/NodeSelector.vue'
  6. import StdSelector from '@/components/StdDesign/StdDataEntry/components/StdSelector.vue'
  7. import { formatDateTime } from '@/lib/helper'
  8. import { useSettingsStore } from '@/pinia'
  9. import envGroupColumns from '@/views/environments/group/columns'
  10. import { InfoCircleOutlined } from '@ant-design/icons-vue'
  11. import { message, Modal } from 'ant-design-vue'
  12. import { storeToRefs } from 'pinia'
  13. import { useStreamEditorStore } from '../../store'
  14. import ConfigName from '../ConfigName.vue'
  15. const settings = useSettingsStore()
  16. const store = useStreamEditorStore()
  17. const { name, enabled, data } = storeToRefs(store)
  18. const [modal, ContextHolder] = Modal.useModal()
  19. const showSync = computed(() => !settings.is_remote)
  20. function enable() {
  21. stream.enable(name.value).then(() => {
  22. message.success($gettext('Enabled successfully'))
  23. enabled.value = true
  24. }).catch(r => {
  25. message.error($gettext('Failed to enable %{msg}', { msg: r.message ?? '' }), 10)
  26. })
  27. }
  28. function disable() {
  29. stream.disable(name.value).then(() => {
  30. message.success($gettext('Disabled successfully'))
  31. enabled.value = false
  32. }).catch(r => {
  33. message.error($gettext('Failed to disable %{msg}', { msg: r.message ?? '' }))
  34. })
  35. }
  36. function onChangeEnabled(checked: CheckedType) {
  37. modal.confirm({
  38. title: checked ? $gettext('Do you want to enable this stream?') : $gettext('Do you want to disable this stream?'),
  39. mask: false,
  40. centered: true,
  41. okText: $gettext('OK'),
  42. cancelText: $gettext('Cancel'),
  43. async onOk() {
  44. if (checked)
  45. enable()
  46. else
  47. disable()
  48. },
  49. })
  50. }
  51. </script>
  52. <template>
  53. <div>
  54. <ContextHolder />
  55. <AFormItem :label="$gettext('Enabled')">
  56. <ASwitch
  57. :checked="enabled"
  58. @change="onChangeEnabled"
  59. />
  60. </AFormItem>
  61. <AFormItem :label="$gettext('Name')">
  62. <ConfigName :name />
  63. </AFormItem>
  64. <AFormItem :label="$gettext('Updated at')">
  65. {{ formatDateTime(data.modified_at) }}
  66. </AFormItem>
  67. <AFormItem :label="$gettext('Node Group')">
  68. <StdSelector
  69. v-model:selected-key="data.env_group_id"
  70. :api="envGroup"
  71. :columns="envGroupColumns"
  72. record-value-index="name"
  73. selection-type="radio"
  74. />
  75. </AFormItem>
  76. <!-- Synchronization Section -->
  77. <div v-if="showSync" class="mt-4">
  78. <div class="flex items-center justify-between mb-4">
  79. <div>
  80. {{ $gettext('Synchronization') }}
  81. </div>
  82. <APopover placement="bottomRight" :title="$gettext('Sync strategy')">
  83. <template #content>
  84. <div class="max-w-200px mb-2">
  85. {{ $gettext('When you enable/disable, delete, or save this site, '
  86. + 'the nodes set in the Node Group and the nodes selected below will be synchronized.') }}
  87. </div>
  88. <div class="max-w-200px">
  89. {{ $gettext('Note, if the configuration file include other configurations or certificates, '
  90. + 'please synchronize them to the remote nodes in advance.') }}
  91. </div>
  92. </template>
  93. <div class="text-trueGray-600">
  94. <InfoCircleOutlined class="mr-1" />
  95. {{ $gettext('Sync strategy') }}
  96. </div>
  97. </APopover>
  98. </div>
  99. <NodeSelector
  100. v-model:target="data.sync_node_ids"
  101. class="mb-4"
  102. hidden-local
  103. />
  104. </div>
  105. </div>
  106. </template>