mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
feat: add active nodes management and project retrieval functionality
This commit is contained in:
@@ -8,10 +8,13 @@ import { isZeroObjectId } from '@/utils/mongo';
|
||||
import { useSpiderDetail } from '@/views';
|
||||
import { getToRunNodes, priorityOptions, translate } from '@/utils';
|
||||
import { getSpiderTemplateGroups, getSpiderTemplates } from '@/utils/spider';
|
||||
import useRequest from '@/services/request';
|
||||
|
||||
// i18n
|
||||
const t = translate;
|
||||
|
||||
const { get } = useRequest();
|
||||
|
||||
// store
|
||||
const store = useStore();
|
||||
|
||||
@@ -90,6 +93,29 @@ const activeTemplateOption = computed<SpiderTemplate | undefined>(() => {
|
||||
return getSpiderTemplates().find(d => d.name === form.value.template);
|
||||
});
|
||||
|
||||
const projectLoading = ref(false);
|
||||
const projectList = ref<Project[]>([]);
|
||||
const getProjects = async (query?: string) => {
|
||||
try {
|
||||
projectLoading.value = true;
|
||||
const res = await get<Project[]>('/projects', {
|
||||
conditions: {
|
||||
name: query,
|
||||
},
|
||||
limit: 1000,
|
||||
});
|
||||
projectList.value = res.data || [];
|
||||
} catch (e) {
|
||||
console.error('Error setting project loading state:', e);
|
||||
} finally {
|
||||
projectLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const getActiveNodes = async () => {
|
||||
await store.dispatch('node/getActiveNodes');
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
validate,
|
||||
});
|
||||
|
||||
@@ -13,9 +13,8 @@ interface NodeStoreState extends BaseStoreState<CNode> {
|
||||
type NodeStoreGetters = BaseStoreGetters<CNode>;
|
||||
|
||||
interface NodeStoreMutations extends BaseStoreMutations<CNode> {
|
||||
setAllNodeSelectOptions: StoreMutation<BaseStoreState<CNode>, SelectOption[]>;
|
||||
setAllNodeTags: StoreMutation<BaseStoreState<CNode>, string[]>;
|
||||
setNodeMetricsMap: StoreMutation<NodeStoreState, Record<string, Metric>>;
|
||||
setActiveNodes: StoreMutation<NodeStoreState, CNode[]>;
|
||||
}
|
||||
|
||||
interface NodeStoreActions extends BaseStoreActions<CNode> {
|
||||
|
||||
@@ -15,19 +15,13 @@ const { get } = useRequest();
|
||||
|
||||
const state = {
|
||||
...getDefaultStoreState<CNode>('node'),
|
||||
newFormFn: () => {
|
||||
return {
|
||||
tags: [],
|
||||
max_runners: 8,
|
||||
enabled: true,
|
||||
};
|
||||
},
|
||||
tabs: [
|
||||
{ id: TAB_NAME_OVERVIEW, title: 'common.tabs.overview' },
|
||||
{ id: TAB_NAME_TASKS, title: 'common.tabs.tasks' },
|
||||
{ id: TAB_NAME_MONITORING, title: 'common.tabs.monitoring' },
|
||||
],
|
||||
nodeMetricsMap: {},
|
||||
activeNodes: [],
|
||||
} as NodeStoreState;
|
||||
|
||||
const getters = {
|
||||
@@ -39,13 +33,16 @@ const mutations = {
|
||||
setNodeMetricsMap(state: NodeStoreState, metricsMap: Record<string, Metric>) {
|
||||
state.nodeMetricsMap = metricsMap;
|
||||
},
|
||||
setActiveNodes: (state: NodeStoreState, activeNodes: CNode[]) => {
|
||||
state.activeNodes = activeNodes;
|
||||
},
|
||||
} as NodeStoreMutations;
|
||||
|
||||
const actions = {
|
||||
...getDefaultStoreActions<CNode>('/nodes'),
|
||||
async getNodeMetrics({ state, commit }: StoreActionContext<NodeStoreState>) {
|
||||
const { page, size } = state.tablePagination;
|
||||
const res = await get<Record<string, Metric>>('nodes/metrics', {
|
||||
const res = await get<Record<string, Metric>>('/nodes/metrics', {
|
||||
page,
|
||||
size,
|
||||
conditions: JSON.stringify(state.tableListFilter),
|
||||
@@ -54,6 +51,11 @@ const actions = {
|
||||
commit('setNodeMetricsMap', res.data);
|
||||
return res;
|
||||
},
|
||||
async getActiveNodes({ commit }: StoreActionContext<NodeStoreState>) {
|
||||
const res = await get<CNode[]>('/nodes');
|
||||
commit('setActiveNodes', res.data || []);
|
||||
return res;
|
||||
},
|
||||
} as NodeStoreActions;
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user