From d0bfb9644d3e07d74f4cd453ff98fbd510d13003 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 21 Jul 2022 13:56:09 +0200 Subject: [PATCH] add phid and tags in labels --- ereuse_devicehub/resources/device/models.py | 21 +++++++- ereuse_devicehub/static/js/print.pdf.js | 50 +++++++++++++++++-- .../templates/labels/print_labels.html | 28 ++++++++++- 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index b0539ca0..ee0d08b5 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -411,7 +411,16 @@ class Device(Thing): @property def sid(self): - actions = [x for x in self.actions if x.t == 'Snapshot' and x.sid] + actions = [] + if self.placeholder and self.placeholder.binding: + actions = [ + x + for x in self.placeholder.binding.actions + if x.t == 'Snapshot' and x.sid + ] + else: + actions = [x for x in self.actions if x.t == 'Snapshot' and x.sid] + if actions: return actions[0].sid @@ -601,6 +610,16 @@ class Device(Thing): args[POLYMORPHIC_ON] = cls.type return args + def phid(self): + if self.placeholder: + return self.placeholder.phid + if self.binding: + return self.binding.phid + return '' + + def list_tags(self): + return ', '.join([t.id for t in self.tags]) + def appearance(self): actions = copy.copy(self.actions) actions.sort(key=lambda x: x.created) diff --git a/ereuse_devicehub/static/js/print.pdf.js b/ereuse_devicehub/static/js/print.pdf.js index b17f70ee..859ea44a 100644 --- a/ereuse_devicehub/static/js/print.pdf.js +++ b/ereuse_devicehub/static/js/print.pdf.js @@ -53,6 +53,8 @@ function save_settings() { data['logo'] = $("#logoCheck").prop('checked'); data['dhid'] = $("#dhidCheck").prop('checked'); data['sid'] = $("#sidCheck").prop('checked'); + data['phid'] = $("#phidCheck").prop('checked'); + data['tags'] = $("#tagsCheck").prop('checked'); data['qr'] = $("#qrCheck").prop('checked'); data['serial_number'] = $("#serialNumberCheck").prop('checked'); data['manufacturer'] = $("#manufacturerCheck").prop('checked'); @@ -69,11 +71,13 @@ function load_settings() { $("#qrCheck").prop('checked', data.qr); $("#dhidCheck").prop('checked', data.dhid); $("#sidCheck").prop('checked', data.sid); + $("#phidCheck").prop('checked', data.phid); + $("#tagsCheck").prop('checked', data.tags); $("#serialNumberCheck").prop('checked', data.serial_number); $("#manufacturerCheck").prop('checked', data.manufacturer); $("#modelCheck").prop('checked', data.model); if (data.logo) { - $("#logoCheck").prop('checked', data.sid); + // $("#logoCheck").prop('checked', data.sid); previewLogo(data.logoImg); $("#logoCheck").prop('checked', data.logo); } else { @@ -89,6 +93,8 @@ function reset_settings() { $("#qrCheck").prop('checked', true); $("#dhidCheck").prop('checked', true); $("#sidCheck").prop('checked', true); + $("#phidCheck").prop('checked', true); + $("#tagsCheck").prop('checked', false); $("#serialNumberCheck").prop('checked', false); $("#logoCheck").prop('checked', false); $("#manufacturerCheck").prop('checked', false); @@ -135,6 +141,18 @@ function change_check() { $(".sid").hide(); }; + if ($("#phidCheck").prop('checked')) { + $(".phid").show(); + } else { + $(".phid").hide(); + }; + + if ($("#tagsCheck").prop('checked')) { + $(".tags").show(); + } else { + $(".tags").hide(); + }; + if ($("#serialNumberCheck").prop('checked')) { $(".serial_number").show(); } else { @@ -190,6 +208,12 @@ function printpdf() { if ($("#sidCheck").prop('checked')) { height_need += line; }; + if ($("#phidCheck").prop('checked')) { + height_need += line; + }; + if ($("#tagsCheck").prop('checked')) { + height_need += line; + }; if ($("#serialNumberCheck").prop('checked')) { height_need += line; }; @@ -244,26 +268,42 @@ function printpdf() { var sn = $(y).data('sid'); pdf.setFontSize(12); if (sn) { - pdf.text(sn, border, hspace); + pdf.text(String(sn), border, hspace); + hspace += line; + } + }; + if ($("#phidCheck").prop('checked')) { + var sn = $(y).data('phid'); + pdf.setFontSize(12); + if (sn) { + pdf.text(String(sn), border, hspace); + hspace += line; + } + }; + if ($("#tagsCheck").prop('checked')) { + var sn = $(y).data('tags'); + pdf.setFontSize(12); + if (sn) { + pdf.text(String(sn), border, hspace); hspace += line; } }; if ($("#serialNumberCheck").prop('checked')) { var sn = $(y).data('serial-number'); pdf.setFontSize(12); - pdf.text(sn, border, hspace); + pdf.text(String(sn), border, hspace); hspace += line; }; if ($("#manufacturerCheck").prop('checked')) { var sn = $(y).data('manufacturer'); pdf.setFontSize(12); - pdf.text(sn, border, hspace); + pdf.text(String(sn), border, hspace); hspace += line; }; if ($("#modelCheck").prop('checked')) { var sn = $(y).data('model'); pdf.setFontSize(8); - pdf.text(sn, border, hspace); + pdf.text(String(sn), border, hspace); hspace += line; }; }); diff --git a/ereuse_devicehub/templates/labels/print_labels.html b/ereuse_devicehub/templates/labels/print_labels.html index 252ef18d..77e2048b 100644 --- a/ereuse_devicehub/templates/labels/print_labels.html +++ b/ereuse_devicehub/templates/labels/print_labels.html @@ -39,15 +39,33 @@ {{ dev.devicehub_id }} - + + +