I have a template I display for different cards and sets of data on the screen, showing a QR Code. It should only show 1 time per element it relates to, which it does initially.
I have a on / off switch in the UI for the user to toggle, and when it’s toggled, the QR code gets repeated, so now there are 2 QR codes on the screen for the element stacked vertically.
I also have a timed event on the server that might update the screen reactively if certain data is changed, and when that happens the QR Code is also repeated for that element.
My code looks like this.
html template
<template name="clientCard">
{{#if Template.subscriptionsReady}}
<div class="col s12">
<div class="card horizontal">
<div class="card-image">
<img src="/images/{{interfaceOS}}.png">
</div>
<div class="card-stacked">
<div class="card-content">
<div class="row">
<div class="col s8">
<span class="card-title">{{interfaceName}}</span>
<div class="row">
<div class="col l4 m4 s6">
<strong>IP:</strong>
</div>
<div class="col l8 m8 s6">
{{interfaceIP}} : {{interfacePort}}
</div>
</div>
<div class="row">
<div class="col l4 m4 s6">
<strong>DNS:</strong>
</div>
<div class="col l8 m8 s6">
{{interfaceDNS}}
</div>
</div>
<div class="row">
<div class="col s12">
<strong>Public Key:</strong> {{interfacePublicKey}}
</div>
</div>
<div class="row">
<div class="col l4 m4 s6">
<strong>Check If Online:</strong>
</div>
<!-- <div class="col l8 m8 s6">
{{#if $eq checkOnline true}}
Yes
{{else}}
No
{{/if}}
</div> -->
<div class="switch">
<!-- Check if Online -->
<label>
No
<input type="checkbox" id="{{_id}}" checked="{{#if $eq checkOnline true}}checked{{/if}}" >
<span class="lever"></span>
Yes
</label>
</div>
</div>
<div class="row">
<div class="col l4 m4 s6">
<strong>Client Status:</strong>
</div>
<div class="col l8 m8 s6">
{{#if $eq status "online"}}
<strong>Online</strong>
{{else}}
Offline
{{/if}}
</div>
</div>
</div>
<div class="col s4">
<div id="QR{{_id}}">{{> qrcode text=clientQR size=150}}</div>
</div>
</div>
</div>
<div class="card-action">
<a href="#" id="downloadInterface">Download Interface File</a>
<a href="#" id="removeClient">Remove Client</a>
</div>
</div>
</div>
</div>
{{/if}}
</template>
With the offending section being:
<div class="col s4">
<div id="QR{{_id}}">{{> qrcode text=clientQR size=150}}</div>
</div>
and my helper methods look like:
Template.clientCard.helpers({
clientData: function() {
return Interfaces.find({});
},
clientQR: function() {
let interfaceId = this._id;
let thisInterface;
let myhost = location.hostname;
let interfaceInfo = Interfaces.findOne({ _id: interfaceId });
let serverInfo = ServerInfo.findOne({});
let qrBlob = "[Interface]\nPrivateKey = " + interfaceInfo.interfacePrivateKey + "\nDNS = " + interfaceInfo.interfaceDNS + "\n" + "Address = " + interfaceInfo.interfaceIP + "/22," + interfaceInfo.interfaceIPv6 +"/112\n\n[Peer]\nPublicKey = " + serverInfo.publicKey + "\nEndpoint = " + myhost + ":" + interfaceInfo.interfacePort + "\nAllowedIPs = 0.0.0.0/0, ::/0";
return qrBlob;
},
});
Any thoughts on why this element is being repeated on data updates, and any way I can stop it from happening?
I’m using the panter:qrcode
package for this functionality.
Additional Information:
The template appears to create a canvas tag with the height and width inside it, and that’s what’s being duplicated as data changes in the parent template.
As always, thanks for any help.