Skip to content

Commit

Permalink
Merge pull request #100 from EliHaugu/94-add-api-connecting-to-run-tests
Browse files Browse the repository at this point in the history
Add api connection to run tests, complete node create and patch
  • Loading branch information
Furdook authored Nov 5, 2024
2 parents 313500e + 76e026a commit cbe986f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
4 changes: 3 additions & 1 deletion client/src/components/flow/NodesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const newNode = () => {
label: newNodeModel.value.label,
node_type: newNodeModel.value.node_type,
device: Number(newNodeModel.value.device),
function: newNodeModel.value.function
function: newNodeModel.value.function,
x_pos: 0,
y_pos: 0
}
createNode(node).then((res: Boolean) => {
if (res) {
Expand Down
18 changes: 14 additions & 4 deletions client/src/components/flow/NodesListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ const editNodeModel = ref({
label: props.node.data.label,
node_type: props.node.data.node_type,
device: props.node.data.device.toString(),
function: props.node.data.function
function: props.node.data.function,
x_pos: props.node.position.x,
y_pos: props.node.position.y
})
const { onDragStart } = useDragAndDrop()
const editNode = () => {
const node = {
id: parseInt(props.node.id),
label: editNodeModel.value.label,
node_type: editNodeModel.value.node_type,
device: Number(editNodeModel.value.device),
function: editNodeModel.value.function
function: editNodeModel.value.function,
x_pos: editNodeModel.value.x_pos,
y_pos: editNodeModel.value.y_pos
}
updateNode(parseInt(props.node.id), node).then(() => {
emit('update')
Expand All @@ -47,7 +52,7 @@ const deleteNode = () => {
}
const openModal = () => {
;(document.getElementById('editNode') as HTMLDialogElement).showModal()
;(document.getElementById('editNode-' + props.node.id) as HTMLDialogElement).showModal()
}
</script>

Expand All @@ -65,7 +70,12 @@ const openModal = () => {
<delete-icon class="fill-error" />
</base-button>

<base-modal id="editNode" submitButtonText="Change" title="Edit Node" @submit="editNode">
<base-modal
:id="'editNode-' + node.id"
submitButtonText="Change"
title="Edit Node"
@submit="editNode"
>
<base-input-field v-model="editNodeModel.label" label="Label" name="label" placeholder="" />
<base-input-field
v-model="editNodeModel.node_type"
Expand Down
16 changes: 3 additions & 13 deletions client/src/services/NodesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ export async function createNode(node: Partial<ImportNode>): Promise<Boolean> {
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
node,
/* label: node.label,
device: node.device,
node_type: node.node_type,
function: node.function, */
x_pos: 0,
y_pos: 0
})
body: JSON.stringify(node)
}
return (await fetch(`http://127.0.0.1:8000/data_manager/api/nodes/`, requestOptions)).ok
}
Expand All @@ -64,13 +56,11 @@ export async function deleteNode(id: number): Promise<Boolean> {
* @param node node to update, with the new values
* @returns true if response is 200/OK, signifying that the node was updated successfully
*/
export async function updateNode(id: number, node: Partial<ImportNode>): Promise<Boolean> {
export async function updateNode(id: number, node: ImportNode): Promise<Boolean> {
const requestOptions = {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
node
})
body: JSON.stringify(node)
}
return (await fetch(`http://127.0.0.1:8000/data_manager/api/nodes/${id}/`, requestOptions)).ok
}
11 changes: 11 additions & 0 deletions client/src/services/TestService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param testFlow ID of the test flow to run
* @returns the response from the server
*/
export async function runTest(testFlow: string): Promise<Object> {
const requestOptions = {
method: 'POST'
}
const res = await fetch(`http://127.0.0.1:8000/test_runner/run/${testFlow}/`, requestOptions)
return await res.json()
}
3 changes: 3 additions & 0 deletions client/src/views/FlowDetailedView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { useRoute } from 'vue-router'
import { webSocketService } from '@/services/WebSocketService'
import type { Log } from '@/types/WebSocketServiceTypes'
import { runTest } from '@/services/TestService'
const flows = inject<Ref<Flows>>('flows', ref([]))
const route = useRoute()
Expand Down Expand Up @@ -59,6 +61,7 @@ const toggleWebSocket = () => {
isRunning.value = !isRunning.value
if (isRunning.value) {
runTest(flowId[0])
webSocketService.connect(8765)
webSocketService.subscribe(handleNewLog)
} else {
Expand Down

0 comments on commit cbe986f

Please sign in to comment.