]> git.aero2k.de Git - sirius.git/commitdiff
Add online/offline indicator to overview
authorJoe Rickerby <joerick@mac.com>
Wed, 10 Jan 2018 16:12:51 +0000 (16:12 +0000)
committerJoe Rickerby <joerick@mac.com>
Wed, 10 Jan 2018 16:12:51 +0000 (16:12 +0000)
sirius/models/hardware.py
sirius/protocol/protocol_loop.py
sirius/web/templates/overview.html

index f81f3ea7c481e27a0a9c1114e0b2eff144b6555c..ad112a4fe5049999939996c252d67a8445966b79 100644 (file)
@@ -4,7 +4,6 @@ from sqlalchemy import desc
 from sirius.coding import bitshuffle
 from sirius.models.db import db
 
-
 class Bridge(db.Model):
     """Bridges are not really interesting for users other than that they
     are connected so we don't store ownership for them.
@@ -90,6 +89,11 @@ class Printer(db.Model):
 
         return printer.used_claim_code
 
+    @property
+    def is_online(self):
+        from sirius.protocol import protocol_loop
+        return protocol_loop.device_is_online(self.device_address)
+
 
 class ClaimCode(db.Model):
     """Printer and claim codes are joined over the hardware xor. Claim
index 5511bef59015d6bcfd7d5135c283b040bc7d87da..f6b6076da99b4d4748e3c533bc9b58006189fc27 100644 (file)
@@ -74,6 +74,13 @@ def _get_next_command_id(local_data={}):
     return local_data['next_command_id']
 
 
+def device_is_online(device_address):
+    for bridge_state in bridge_by_address.values():
+        if device_address in bridge_state.connected_devices:
+            return True
+    return False
+
+
 def send_message(device_address, message):
     """Sends a single message to a connected device.
 
index 1acbf4306ea449f8773683a27a02f7d1a6989a2b..bcafa21abdbbc6e9c38ca226e19af3e14d6dab35 100644 (file)
                <ul>
 
                {% for p in my_printers %}
-               <li>{{ p.name }} (owned by you)
+               <li>
+                       {% if p.is_online %}
+                               <span class="label label-success">Online</span>
+                       {% else %}
+                               <span class="label label-default">Offline</span>
+                       {% endif %}
+                       {{ p.name }} (owned by you)
                        <a class="btn btn-default btn-xs" href="{{
                                                        url_for('printer_overview.printer_overview',
                                                                        printer_id=p.id) }}">Overview</a>
                {% endfor %}
                
                {% for p in friends_printers %}
-               <li>{{ p.name }} (owned by @{{ p.owner.username }})
+               <li>
+                       {% if p.is_online %}
+                               <span class="label label-success">Online</span>
+                       {% else %}
+                               <span class="label label-default">Offline</span>
+                       {% endif %}
+                       {{ p.name }} (owned by @{{ p.owner.username }})
                        <a class="btn btn-default btn-xs" href="{{
                                                        url_for('printer_print.printer_print',
                                                                printer_id=p.id) }}">Send message</a>