add phid and tags in labels

This commit is contained in:
Cayo Puigdefabregas 2022-07-21 13:56:09 +02:00
parent 71efe63ca9
commit d0bfb9644d
3 changed files with 92 additions and 7 deletions

View File

@ -411,7 +411,16 @@ class Device(Thing):
@property
def sid(self):
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)

View File

@ -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;
};
});

View File

@ -39,15 +39,33 @@
<b class="tag" data-serial-number="{{ dev.serial_number or '' }}"
data-manufacturer="{{ dev.manufacturer or '' }}"
data-model="{{ dev.model or '' }}"
data-tags="{{ dev.list_tags() }}"
data-phid="{{ dev.phid() }}"
data-sid="{{ dev.sid or '' }}">{{ dev.devicehub_id }}</b>
</div>
</div>
<div class="col sid" style="display: none">
</div>
<div class="row phid" style="display: none">
<div class="col">
<div>
<b>{{ dev.phid() }}</b>
</div>
</div>
</div>
<div class="row sid" style="display: none">
<div class="col">
<div>
<b>{{ dev.sid or '' }}</b>
</div>
</div>
</div>
<div class="row tags" style="display: none">
<div class="col">
<div>
<b>{{ dev.list_tags() }}</b>
</div>
</div>
</div>
<div class="row serial_number" style="display: none">
<div class="col">
<div>
@ -125,10 +143,18 @@
<input class="form-check-input" name="dhid" type="checkbox" id="dhidCheck" checked="">
<label class="form-check-label" for="dhidCheck">Dhid</label>
</div>
<div class="form-switch">
<input class="form-check-input" name="phid" type="checkbox" id="phidCheck">
<label class="form-check-label" for="phidCheck">Phid</label>
</div>
<div class="form-switch">
<input class="form-check-input" name="sid" type="checkbox" id="sidCheck">
<label class="form-check-label" for="sidCheck">Sid</label>
</div>
<div class="form-switch">
<input class="form-check-input" name="tags" type="checkbox" id="tagsCheck">
<label class="form-check-label" for="tagsCheck">Tags</label>
</div>
<div class="form-switch">
<input class="form-check-input" name="serial_number" type="checkbox" id="serialNumberCheck">
<label class="form-check-label" for="serialNumberCheck">Serial number</label>