From c7441434312024e1d3e43016f3d9b3600727aa62 Mon Sep 17 00:00:00 2001 From: iou1name Date: Thu, 20 Jun 2019 14:51:00 -0400 Subject: [PATCH] added delete() --- juice.py | 19 +++++++++++++++++++ static/fontawesome-webfont.woff2 | Bin 2932 -> 3140 bytes static/juice.css | 4 ++-- static/juice.js | 29 ++++++++++++++++++++++++++++- templates/index.html | 14 +++++++------- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/juice.py b/juice.py index b84d52d..d1f0183 100644 --- a/juice.py +++ b/juice.py @@ -277,6 +277,25 @@ def lock_device(): return jsonify(device_id=device.id, locked=device.locked) +@app_views.route('/delete') +def delete(): + """ + Deletes a device. + """ + device_id = request.args.get('device_id') + + for device in network: + if device.id == device_id: + break + else: + return make_error(404, "device_id not found") + + network.remove(device) + save_network() + + return jsonify(True) + + def make_error(code, message): """ Returns a JSON error. diff --git a/static/fontawesome-webfont.woff2 b/static/fontawesome-webfont.woff2 index 2d1883329e9de5096111e81076358b28d94d07c4..2153264f82dec31db2f0c5ad6be4e1abdea712b7 100644 GIT binary patch literal 3140 zcmV-K47>ApPew8T0RR9101QL`4*&oF02#ah01NE^0RR9100000000000000000000 z0000SR0dW6gFXl#36^jX2nvi?iw6r300A}vBm*1-AO(d@2V)F@1{=~BBN29LlhTv@ zRRT9;z-y?_s4bt^}jKYvZ1w)OV}tq-lVF zfsgS2uPvpbOjylRet1_KAj5>Tl(5ZGP-7};7iG?L)zyT{N6jQ#n>?ZtvM-sU#)j(= z?M}M}|NH4Td+z=DrS4`Bl6kZ$OqEFSTSDGTwj|pUYHhM~#R`?Bb_J>xSE^-jNQ6N+ zjKq0_M6rnH+{@#UVsH=XmqdUVjrysPv5PlJE$6paInDq80_C}7d0{S(k49lIBKg%0 zxUO!LSFoU-RNnwE=-*!cqA3Lmt7+WV)!ET$qJqECukUqN-{7s_N@BuN^hC8V4KfSL z9AFD-rHSc=R^4IRRR!}mimET5*FiF?Q_H<1<}aQDaWqm1GFc`&C{Pp#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Tagv|^K@Y>*08P|g;-=2kqxZX6KI{Z7X<%%c2-to z({YEOAZ9C@5J2E(2j&MJ%^d%aOV=g9Z#oK-t-|&;($V4o7d0G#<2edJy^R{%5X#Cy z{Sr;0tWrHuhTO8l1uOuHoLX0bt;80}pmKk7O3;()*@8=tt%z~L*0|)!m<8LCV8nKC zdDQl3vUvFf6<($h69-oKRLT~zWo$)S4oHoeEz*E_!nWkPUpipU+8$$a^^gR$ediCo z`$Y}@x9s*f$(*{_s>0iwy%X-@9o zZT?|f_pn=iMH<@^KICEV`DJa encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) + .join('&'); + + fetch(window.location.href + 'delete?' + query) + .then(function(response) { + return response.json(); + }) + .then(function(json) { + if (!json) { return; } + device.remove() + }); +} diff --git a/templates/index.html b/templates/index.html index d2ce55f..6e7ba0d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -18,7 +18,7 @@
{% for device in network %}
-
{{ device.id }}{% if not device.locked %}{% else %}{% endif %}
+
{{ device.id }}{% if not device.locked %}{% else %}{% endif %}
{{ device.description }}{% if not device.locked %}{% endif %}
{{ device.location }}{% if not device.locked %}{% endif %}
{{ device.ip_address }}{% if not device.locked %}{% endif %}
@@ -37,20 +37,20 @@