Skip to content

Commit c88d77c

Browse files
committed
refactor(TaskConfig, mock)
1 parent 0afa63b commit c88d77c

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/api/mock.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ export const fetchTool = (_toolId: string) =>
2727
setTimeout(
2828
() =>
2929
resolve({
30-
data: JSON.parse(
31-
MOCK_TOOL.replace(/Basic_statistics_for_fields/, _toolId).replace(
32-
/qgis:basicstatisticsforfields/,
33-
_toolId,
34-
),
35-
),
30+
data: JSON.parse(MOCK_TOOL),
3631
}),
3732
500,
3833
);

src/components/TaskConfig.vue

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { Close, Download } from "@element-plus/icons-vue";
33
import { useTaskStore } from "@/store/task.ts";
4-
import { computed, reactive, ref } from "vue";
4+
import { computed, ref } from "vue";
55
import { downloadFile, process } from "@/api";
66
import { Response } from "@/type.ts";
77
@@ -14,14 +14,13 @@ const tableData = computed(
1414
1515
async function onExecute(
1616
id: string | undefined,
17-
input: typeof tableData.value,
17+
parameters: typeof tableData.value,
1818
) {
19-
const processConfig: { [key: string]: string } = reactive({});
20-
input.forEach((arg) => {
21-
processConfig[arg.name] = arg.input;
22-
});
19+
const config = Object.fromEntries(
20+
parameters.map((par) => [par.name, par.input]),
21+
);
2322
if (id) {
24-
res.value = (await process(id, processConfig)).data as Response;
23+
res.value = (await process(id, config)).data as Response;
2524
}
2625
}
2726
@@ -36,7 +35,7 @@ async function download() {
3635
const url = window.URL.createObjectURL(new Blob([response.data]));
3736
const link = document.createElement("a");
3837
link.href = url;
39-
link.setAttribute("download", "sample.txt");
38+
link.setAttribute("download", res.value.data.OUTPUT);
4039
link.click();
4140
}
4241
}

src/constant/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ export const TOOL_EXAMPLE = {
5454
],
5555
};
5656
export const MOCK_JOB = `{"code":70200,"message":"Success!","data":{"task":"Extract elevation data of Sri Lanka from multiple TIF files using the shape of the island from a vector file","subtasks":[{"task":"Merge multiple TIF files into a single raster dataset","toolId":"gdal:merge","subtasks":[],"toolName":"gdal:merge"},{"task":"Clip the merged raster dataset using the shape of the island from the vector file to extract the relevant elevation data","toolId":"gdal:cliprasterbymasklayer","subtasks":[],"toolName":"gdal:cliprasterbymasklayer"}],"toolId":"","toolName":""}}`;
57-
export const MOCK_TOOL = `{"id":"qgis:randompointsinsidepolygons","name":"qgis:randompointsinsidepolygons","description":"Generates basic statistics for a field of the attribute table of a vector layer.","args":[{"name":"INPUT","type":"[vector: any]","description":"Vector layer to calculate the statistics on.","required":true},{"name":"POINTS_NUMBER","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false},{"name":"MIN_DISTANCE","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false},{"name":"OUTPUT","description":"xxxxxxx"}]}`;
57+
export const MOCK_TOOL = `{"code":70200,"message":"success","data":{"id":"gdal:cliprasterbymasklayer","name":"Clip raster by mask layer","description":"Clip raster by mask layer","args":[{"name":"INPUT","description":"Input raster file","type":"raster","required":true},{"name":"MASK","description":"Mask layer","type":"vector","required":true},{"name":"OUTPUT","description":"Output raster file","type":"raster","required":true}]}}`;

0 commit comments

Comments
 (0)