Skip to content

Commit

Permalink
delete_node 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
1K3H committed Jul 10, 2020
1 parent 9f488bb commit b114d67
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app.py
Expand Up @@ -29,5 +29,17 @@ def list_node():
nodes = list(db.nodes.find({}, {'_id':False}))
return jsonify({'result':'success', 'nodes':nodes})

@app.route('/delete', methods=['POST'])
def delete_node():
receive_from_input = request.form['give_from_input']
receive_to_input = request.form['give_to_input']
receive_edge_id = request.form['give_edge_id']
db.nodes.delete_one({
'from': receive_from_input,
'to': receive_to_input,
'edge': receive_edge_id
})
return jsonify({'result':'success'})

if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
30 changes: 30 additions & 0 deletions templates/index.html
Expand Up @@ -110,6 +110,35 @@
});
};
};

// node 지우는 함수
function delete_node() {
let from_input = $('#from').val();
let to_input = $('#to').val();
// input 빈칸 검출
if (from_input == '') {
alert('FROM 값을 입력해 주세요.');
}
else if (to_input == '') {
alert('TO 값을 입력해 주세요.');
}
else {
$.ajax({
type: 'POST',
url: '/delete',
data: {
'give_from_input': from_input,
'give_to_input': to_input,
'give_edge_id': from_input + to_input
},
success: function (response) {
if (response['result'] == 'success') {
window.location.reload();
}
}
});
};
};

</script>
</head>
Expand All @@ -118,6 +147,7 @@
<input id="from" type="text" placeholder="FROM">
<input id="to" type="text" placeholder="TO">
<button onclick="save_node()" type="button">CREATE</button>
<button onclick="delete_node()" type="button">DELETE</button>
<div id="cy"></div>
</body>

Expand Down

0 comments on commit b114d67

Please sign in to comment.