-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: Sync docker proxy to nodes #8359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,7 @@ | |
| </el-input> | ||
| </el-form-item> | ||
|
|
||
| <el-form-item :label="$t('setting.proxy')" prop="proxyShow"> | ||
| <el-form-item :label="$t('setting.proxy')" prop="proxyShow" v-if="isMaster"> | ||
| <el-input disabled v-model="form.proxyShow"> | ||
| <template #append> | ||
| <el-button @click="onChangeProxy" icon="Setting"> | ||
|
|
@@ -229,7 +229,7 @@ const loading = ref(false); | |
| const i18n = useI18n(); | ||
| const globalStore = GlobalStore(); | ||
|
|
||
| const { isMasterProductPro } = storeToRefs(globalStore); | ||
| const { isMasterProductPro, isMaster } = storeToRefs(globalStore); | ||
|
|
||
| const { switchTheme } = useTheme(); | ||
| const mobile = computed(() => { | ||
|
|
@@ -266,6 +266,8 @@ const form = reactive({ | |
| proxyPasswd: '', | ||
| proxyPasswdKeep: '', | ||
| proxyDocker: '', | ||
| proxyDockerSyncToNode: '', | ||
| proxyDockerSyncNodes: '', | ||
|
|
||
| apiInterfaceStatus: 'Disable', | ||
| apiKey: '', | ||
|
|
@@ -339,6 +341,8 @@ const search = async () => { | |
| : '{"light":"#005eeb","dark":"#F0BE96"}'; | ||
| globalStore.themeConfig.theme = form.theme; | ||
| form.proxyDocker = xpackRes.data.proxyDocker; | ||
| form.proxyDockerSyncToNode = xpackRes.data.proxyDockerSyncToNode; | ||
| form.proxyDockerSyncNodes = xpackRes.data.proxyDockerSyncNodes; | ||
| } | ||
| } else { | ||
| globalStore.themeConfig.theme = form.theme; | ||
|
|
@@ -369,6 +373,8 @@ const onChangeProxy = () => { | |
| passwd: form.proxyPasswd, | ||
| passwdKeep: form.proxyPasswdKeep, | ||
| proxyDocker: form.proxyDocker, | ||
| proxyDockerSyncToNode: form.proxyDockerSyncToNode, | ||
| proxyDockerSyncNodes: form.proxyDockerSyncNodes, | ||
| }); | ||
| }; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some potential issues:
Optimization suggestions:
If you need further assistance with code review or optimization, please provide more details or context! |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,9 +46,41 @@ | |
| <el-checkbox v-model="form.proxyPasswdKeepItem" :label="$t('setting.proxyPasswdKeep')" /> | ||
| </el-form-item> | ||
| <el-form-item v-if="isMasterProductPro"> | ||
| <el-checkbox v-model="form.proxyDocker" :label="$t('setting.proxyDocker')" /> | ||
| <el-checkbox v-model="form.proxyDocker" @change="onChange" :label="$t('setting.proxyDocker')" /> | ||
| <span class="input-help">{{ $t('setting.proxyDockerHelper') }}</span> | ||
| </el-form-item> | ||
| <div v-if="form.proxyDocker"> | ||
| <el-form-item prop="syncToNode"> | ||
| <el-switch | ||
| @change="getNodes" | ||
| v-model="form.syncToNode" | ||
| active-value="Enable" | ||
| inactive-value="Disable" | ||
| ></el-switch> | ||
| <span class="ml-2.5 el-checkbox">{{ $t('setting.syncToNode') }}</span> | ||
| <span class="input-help">{{ $t('setting.syncToNodeHelper') }}</span> | ||
| </el-form-item> | ||
| <el-form-item :label="$t('setting.nodes')" prop="nodes" v-if="form.syncToNode === 'Enable'"> | ||
| <el-row :gutter="20"> | ||
| <el-col :span="12"> | ||
| <el-select v-model="form.selectNode" class="p-w-200"> | ||
| <el-option :label="$t('commons.table.all')" value="all"></el-option> | ||
| <el-option :label="$t('setting.selectNode')" value="select"></el-option> | ||
| </el-select> | ||
| </el-col> | ||
| <el-col :span="12" v-if="form.selectNode === 'select'"> | ||
| <el-select v-model="form.nodes" multiple class="p-w-200"> | ||
| <el-option | ||
| v-for="item in nodeList" | ||
| :key="item.id" | ||
| :label="item.name" | ||
| :value="item.id" | ||
| ></el-option> | ||
| </el-select> | ||
| </el-col> | ||
| </el-row> | ||
| </el-form-item> | ||
| </div> | ||
| </div> | ||
| </el-form> | ||
| <template #footer> | ||
|
|
@@ -70,13 +102,13 @@ import i18n from '@/lang'; | |
| import { MsgSuccess } from '@/utils/message'; | ||
| import { FormInstance } from 'element-plus'; | ||
| import { reactive, ref } from 'vue'; | ||
| import { updateProxy } from '@/api/modules/setting'; | ||
| import { listNodeOptions, updateProxy } from '@/api/modules/setting'; | ||
| import { GlobalStore } from '@/store'; | ||
| import { storeToRefs } from 'pinia'; | ||
| import { updateXpackSettingByKey } from '@/utils/xpack'; | ||
| import { updateDaemonJson } from '@/api/modules/container'; | ||
| import ConfirmDialog from '@/components/confirm-dialog/index.vue'; | ||
| import { escapeProxyURL } from '@/utils/util'; | ||
| import { updateDockerProxySetting } from '@/xpack/api/modules/setting'; | ||
|
|
||
| const globalStore = GlobalStore(); | ||
| const emit = defineEmits<{ (e: 'search'): void }>(); | ||
|
|
@@ -103,7 +135,11 @@ const form = reactive({ | |
| proxyPasswdKeep: '', | ||
| proxyPasswdKeepItem: false, | ||
| proxyDocker: false, | ||
| syncToNode: 'Enable', | ||
| selectNode: 'all', | ||
| nodes: [], | ||
| }); | ||
| const nodeList = ref([]); | ||
|
|
||
| interface DialogProps { | ||
| url: string; | ||
|
|
@@ -113,6 +149,8 @@ interface DialogProps { | |
| passwd: string; | ||
| passwdKeep: string; | ||
| proxyDocker: string; | ||
| proxyDockerSyncToNode: string; | ||
| proxyDockerSyncNodes: string; | ||
| } | ||
| const acceptParams = (params: DialogProps): void => { | ||
| if (params.url) { | ||
|
|
@@ -129,11 +167,24 @@ const acceptParams = (params: DialogProps): void => { | |
| form.proxyUser = params.user; | ||
| form.proxyPasswd = params.passwd; | ||
| form.proxyDocker = params.proxyDocker !== ''; | ||
| if (form.proxyDocker) { | ||
| getNodes(); | ||
| form.syncToNode = params.proxyDockerSyncToNode; | ||
| form.nodes = params.proxyDockerSyncNodes ? JSON.parse(params.proxyDockerSyncNodes) : []; | ||
| form.selectNode = form.nodes.length > 0 ? 'select' : 'all'; | ||
| } | ||
|
|
||
| proxyDockerVisible.value = params.proxyDocker !== ''; | ||
| passwordVisible.value = true; | ||
| form.proxyPasswdKeepItem = params.passwdKeep === 'Enable'; | ||
| }; | ||
|
|
||
| const getNodes = () => { | ||
| if (form.syncToNode === 'Enable' && nodeList.value.length === 0) { | ||
| listNodes(); | ||
| } | ||
| }; | ||
|
|
||
| const submitChangePassword = async (formEl: FormInstance | undefined) => { | ||
| if (!formEl) return; | ||
| formEl.validate(async (valid) => { | ||
|
|
@@ -216,16 +267,27 @@ const onSubmit = async () => { | |
| if (isClose || params.proxyDocker === false) { | ||
| proxyUrl = ''; | ||
| } | ||
| await updateXpackSettingByKey('ProxyDocker', proxyUrl); | ||
| await updateDaemonJson(`${form.proxyType}-proxy`, proxyUrl); | ||
| let param = { | ||
| proxyDocker: proxyUrl, | ||
| proxyDockerSyncToNode: form.syncToNode, | ||
| proxyDockerSyncNodes: JSON.stringify(form.nodes), | ||
| }; | ||
| await updateDockerProxySetting(param); | ||
| emit('search'); | ||
| handleClose(); | ||
| MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); | ||
| } catch { | ||
| } finally { | ||
| loading.value = false; | ||
| } | ||
| }; | ||
|
|
||
| const listNodes = async () => { | ||
| try { | ||
| const res = await listNodeOptions(); | ||
| nodeList.value = res.data || []; | ||
| } catch (error) {} | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| passwordVisible.value = false; | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No significant irregularities or critical issues were found in the code snippet provided. Optimization Suggestions:
This can be merged into a single condition statement: if (['all', ''].includes(form.selectNode)) {
this.form.nodes = form.selectNode === 'all' ? [] : [];
}These optimizations should result in cleaner and more efficient code while maintaining readability. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no noticeable irregularities, potential issues, or suggestions for optimization in the provided code snippet. The changes appear to enhance user experience on the dashboard by adding features for syncing configurations and selecting nodes from different environments.