Skip to content

Commit

Permalink
feat: added install by version
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Nov 22, 2023
1 parent c0fa9a7 commit 0afa224
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/i18n/lang/en/views/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const env: LViewsEnv = {
selectedNodes: 'Selected nodes',
upgrade: 'Upgrade',
mode: 'Mode',
version: 'Version',
},
},
task: {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/zh/views/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const env: LViewsEnv = {
selectedNodes: '已选节点',
upgrade: '是否升级',
mode: '模式',
version: '版本',
},
},
task: {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/i18n/views/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface LViewsEnv {
enabled: string;
cmd: string;
proxy: string;
version: string;
};
lang: {
python: {
Expand All @@ -29,6 +28,7 @@ interface LViewsEnv {
selectedNodes: string;
upgrade: string;
mode: string;
version: string;
};
};
task: {
Expand Down
56 changes: 42 additions & 14 deletions src/views/deps/components/form/InstallForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,48 @@
<el-option value="selected-nodes" :label="t('views.env.deps.dependency.form.selectedNodes')"/>
</el-select>
</cl-form-item>
<cl-form-item :span="4" :label="t('views.env.deps.dependency.form.version')">
<el-select v-model="version">
</el-select>
</cl-form-item>
<cl-form-item :label="t('views.env.deps.dependency.form.upgrade')">
<cl-switch v-model="upgrade"/>
</cl-form-item>
<cl-form-item v-if="mode === 'selected-nodes'" :span="4"
:label="t('views.env.deps.dependency.form.selectedNodes')">
<el-select v-model="nodeIds" multiple :placeholder="t('views.env.deps.dependency.form.selectedNodes')">
<el-option v-for="n in nodes" :key="n.key" :value="n._id" :label="n.name"/>
</el-select>
</cl-form-item>
<cl-form-item :span="4" :label="t('views.env.deps.dependency.form.version')">
<el-select v-model="version" :disabled="versionsLoading" :placeholder="t('common.status.loading')">
<el-option
v-for="(v, $index) in versions"
:key="$index"
:label="v"
:value="v"
/>
</el-select>
</cl-form-item>
</cl-form>
</cl-dialog>
</template>

<script lang="ts">
import {defineComponent, onBeforeMount, ref} from 'vue';
import {defineComponent, onBeforeMount, ref, watch} from 'vue';
import {translate} from '@/utils';
import useRequest from "@/services/request";
const t = translate;
const endpointL = '/deps/lang';
const {
get,
} = useRequest();
export default defineComponent({
name: 'InstallForm',
props: {
visible: {
type: Boolean,
},
lang: {
type: String,
},
names: {
type: Array,
default: () => {
Expand All @@ -73,9 +86,8 @@ export default defineComponent({
'confirm',
'close',
],
setup(_, {emit}) {
setup(props, {emit}) {
const mode = ref('all');
const upgrade = ref(true);
const nodeIds = ref([]);
const version = ref('');
Expand All @@ -88,8 +100,8 @@ export default defineComponent({
const onConfirm = () => {
emit('confirm', {
mode: mode.value,
upgrade: upgrade.value,
nodeIds: nodeIds.value,
version: version.value,
});
reset();
};
Expand All @@ -99,14 +111,30 @@ export default defineComponent({
reset();
};
onBeforeMount(async () => {
});
const versions = ref([]);
const versionsLoading = ref(false);
const getVersions = async () => {
if (!props.visible) return;
versionsLoading.value = true;
try {
const res = await get(`${endpointL}/${props.lang}/${props.names[0]}/versions`)
versions.value = res.data;
if (versions.value.length > 0) {
version.value = versions.value[0];
}
} finally {
versionsLoading.value = false;
}
};
watch(() => props.visible, getVersions);
onBeforeMount(getVersions);
return {
mode,
upgrade,
nodeIds,
version,
versions,
versionsLoading,
onConfirm,
onClose,
t,
Expand Down
22 changes: 4 additions & 18 deletions src/views/deps/components/lang/DependencyLang.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<template #extra>
<cl-install-form
:visible="dialogVisible.install"
:lang="lang"
:nodes="allNodes"
:names="installForm.names"
@confirm="onInstall"
Expand Down Expand Up @@ -242,19 +243,6 @@ export default defineComponent({
names: [],
});
const isInstallable = (dep: EnvDepsDependency) => {
if (dep.upgradable) return true;
let node_ids = [];
if (installed.value) {
node_ids = dep.node_ids || [];
} else if (dep.result) {
node_ids = dep.result.node_ids || [];
} else {
return false;
}
return node_ids.length < allNodes.value.length;
};
const isUninstallable = (dep: EnvDepsDependency) => {
let node_ids = [];
if (installed.value) {
Expand Down Expand Up @@ -353,8 +341,7 @@ export default defineComponent({
{
type: 'primary',
icon: ['fa', 'download'],
tooltip: row.upgradable ? t('views.env.deps.common.actions.installAndUpgrade') : t('common.actions.install'),
disabled: (row) => !isInstallable(row),
tooltip: t('common.actions.install'),
onClick: async (row) => {
installForm.value.names = [row.name];
dialogVisible.value.install = true;
Expand Down Expand Up @@ -514,10 +501,9 @@ export default defineComponent({
uninstallForm.value.names = rows.map(d => d.name || '');
};
const onInstall = async ({mode, upgrade, nodeIds, version}: { mode: string; upgrade: boolean; nodeIds: string[]; version: string; }) => {
const onInstall = async ({mode, nodeIds, version}: { mode: string; nodeIds: string[]; version: string; }) => {
const data = {
mode,
upgrade,
names: installForm.value.names,
node_id: [] as string[],
version,
Expand All @@ -541,7 +527,7 @@ export default defineComponent({
data['node_id'] = nodeIds;
}
await post(`${endpoint.value}/uninstall`, data);
await ElMessage.success(t('common.message.success.uninstall'));
ElMessage.success(t('common.message.success.uninstall'));
await getRunningTaskList();
onDialogClose('uninstall');
};
Expand Down

0 comments on commit 0afa224

Please sign in to comment.