Skip to content

Commit

Permalink
feat: allow set unlimited max runners for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Dec 11, 2024
1 parent c045aea commit b884db0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 14 deletions.
34 changes: 29 additions & 5 deletions src/components/core/node/NodeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useStore } from 'vuex';
import useNode from '@/components/core/node/useNode';
import { translate } from '@/utils';
import { ref, watch } from 'vue';
defineProps<{
readonly?: boolean;
Expand All @@ -14,6 +15,25 @@ const t = translate;
const store = useStore();
const { form, formRef, isSelectiveForm, isFormItemDisabled } = useNode(store);
const originalMaxRunners = ref(0);
const isUnlimitedMaxRunners = ref(false);
watch(isUnlimitedMaxRunners, () => {
if (isUnlimitedMaxRunners.value) {
form.value.max_runners = 0;
} else {
form.value.max_runners = originalMaxRunners.value || 16;
}
});
watch(
() => form.value.max_runners,
val => {
isUnlimitedMaxRunners.value = val! <= 0;
originalMaxRunners.value = val!;
},
{ immediate: true }
);
defineOptions({ name: 'ClNodeForm' });
</script>

Expand Down Expand Up @@ -96,15 +116,21 @@ defineOptions({ name: 'ClNodeForm' });
</cl-form-item>
<cl-form-item
:span="2"
:label="t('components.node.form.max_runners')"
:label="t('components.node.form.maxRunners')"
prop="max_runners"
>
<el-input-number
v-model="form.max_runners"
:disabled="isFormItemDisabled('max_runners')"
:disabled="isUnlimitedMaxRunners || isFormItemDisabled('max_runners')"
:min="0"
:placeholder="t('components.node.form.max_runners')"
:placeholder="t('components.node.form.maxRunners')"
/>
<el-checkbox
v-model="isUnlimitedMaxRunners"
:disabled="isFormItemDisabled('max_runners')"
>
{{ t('common.mode.unlimited') }}
</el-checkbox>
</cl-form-item>
<!--./Row-->

Expand All @@ -124,5 +150,3 @@ defineOptions({ name: 'ClNodeForm' });
</cl-form>
<!--./Row-->
</template>


12 changes: 6 additions & 6 deletions src/components/core/node/NodeRunners.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ const t = translate;
const label = computed<string>(() => {
const { current, max } = props;
if (max === 0) {
return `${current} / ∞`;
}
return `${current} / ${max}`;
});
const data = computed<TagProps>(() => {
const { current, max } = props;
if (current === max) {
if (max > 0 && current >= max) {
return {
label: label.value,
tooltip: t('components.node.nodeRunners.tooltip.unavailable'),
type: 'danger',
icon: ['fa', 'ban'],
};
} else if (current > 0) {
} else if (0 < current) {
return {
label: label.value,
tooltip: t('components.node.nodeRunners.tooltip.running', undefined, {
running: current,
max,
}),
tooltip: t('components.node.nodeRunners.tooltip.running'),
type: 'warning',
icon: ['far', 'check-square'],
};
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/lang/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const common: LCommon = {
viewTemplate: 'View Template',
viewChannels: 'View Channels',
viewMonitoring: 'View Monitoring',
viewDependencies: 'View Dependencies',
previewData: 'Preview Data',
insertBefore: 'Insert Before',
insertAfter: 'Insert After',
Expand Down Expand Up @@ -155,6 +156,7 @@ const common: LCommon = {
default: 'Default',
other: 'Other',
all: 'All',
unlimited: 'Unlimited',
},
placeholder: {
empty: 'Empty',
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/lang/en/components/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const node: LComponentsNode = {
mac: 'MAC Address',
hostname: 'Hostname',
enabled: 'Enabled',
max_runners: 'Max Runners',
maxRunners: 'Max Runners',
description: 'Description',
status: 'Status',
},
Expand Down
1 change: 1 addition & 0 deletions src/i18n/lang/zh/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const common: LCommon = {
default: '默认',
other: '其他',
all: '全部',
unlimited: '无限制',
},
placeholder: {
empty: '空',
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/lang/zh/components/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const node: LComponentsNode = {
mac: 'MAC 地址',
hostname: '主机名',
enabled: '是否启用',
max_runners: '最大执行器数',
maxRunners: '最大执行器数',
description: '描述',
status: '状态',
},
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/i18n/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export declare global {
default: string;
other: string;
all: string;
unlimited: string;
};
placeholder: {
empty: string;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/i18n/components/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface LComponentsNode {
mac: string;
hostname: string;
enabled: string;
max_runners: string;
maxRunners: string;
description: string;
status: string;
};
Expand Down

0 comments on commit b884db0

Please sign in to comment.