-
Notifications
You must be signed in to change notification settings - Fork 80
Approach for QR integration on the attendance UI #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: production
Are you sure you want to change the base?
Changes from all commits
ede50a0
0de09f5
04312a6
b9d6d14
797f3f2
ab3932c
4cdb23c
f8cd0bf
a94b1e4
54257b5
aa70269
9d2586f
4760dbf
b5dd456
c7511aa
7debcff
86c3217
7bdfd6b
40abc1c
1573898
6851937
3d1588b
3b943ac
7bef3f5
ac7304d
41094b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,12 +395,13 @@ jQuery(document).ready(function($){ | |
* Main Application events/controls. | ||
*/ | ||
events: { | ||
'fastClick .dashicons-menu': 'menu', | ||
'fastClick .submenu .search': 'searchView', | ||
'fastClick header h1': 'searchView', | ||
'fastClick .submenu .sort': 'sortView', | ||
'fastClick .submenu .refresh': 'refresh', | ||
'fastClick .submenu .filter': 'filterView' | ||
'click .dashicons-menu': 'menu', | ||
'click .submenu .search': 'searchView', | ||
'click header h1': 'searchView', | ||
'click .submenu .sort': 'sortView', | ||
'click .submenu .refresh': 'refresh', | ||
'click .submenu .qr': 'qr', | ||
'click .submenu .filter': 'filterView', | ||
}, | ||
|
||
/** | ||
|
@@ -421,8 +422,8 @@ jQuery(document).ready(function($){ | |
|
||
this.render(); | ||
|
||
this.$header = this.$el.find( 'header' ); | ||
this.$menu = this.$header.find( '.menu' ); | ||
this.$header = this.$el.find('header'); | ||
this.$menu = this.$header.find('.menu'); | ||
|
||
this.scroll = _.chain( this.scroll ).bind( this ).value(); | ||
this.$list = this.$el.find( '.attendees-list' ); | ||
|
@@ -435,6 +436,14 @@ jQuery(document).ready(function($){ | |
this.on( 'filter', this.filter, this ); | ||
|
||
this.setupCollection(); | ||
|
||
if ( | ||
_camptixAttendanceQRScanning !== undefined && | ||
_camptixAttendanceQRScanning | ||
) { | ||
this.qr(); | ||
} | ||
|
||
}, | ||
|
||
/** | ||
|
@@ -574,6 +583,99 @@ jQuery(document).ready(function($){ | |
return false; | ||
}, | ||
|
||
qr: function () { | ||
this.$el.toggleClass('qr-scanner-active'); | ||
this.$menu.removeClass('dropdown'); | ||
|
||
let that = this; | ||
|
||
let html5QrcodeScanner; | ||
let lastScan; | ||
let toggleView; | ||
let lastScanTimeout; | ||
|
||
function onScanSuccess(decodedText) { | ||
if (lastScan === decodedText) { | ||
return; | ||
} | ||
|
||
lastScan = decodedText; | ||
lastScanTimeout && clearTimeout(lastScanTimeout); | ||
|
||
if (toggleView) toggleView.close(); | ||
let method = 'read'; | ||
let model = that.collection; | ||
let options = { | ||
data: { qrcode: decodedText }, | ||
}; | ||
let attendeeModel; | ||
|
||
that.collection | ||
.sync(method, model, options) | ||
.done( | ||
function (res) { | ||
// not sure why this is an array | ||
attendeeModel = new camptix.models.Attendee(res[0]); | ||
toggleView = new camptix.views.AttendeeToggleView({ | ||
model: attendeeModel, | ||
controller: that, | ||
}); | ||
$(document.body).append(toggleView.render().el); | ||
}.bind(that) | ||
) | ||
.fail(function (res) { | ||
console.error(res); | ||
// play the sound to indicate that the scan is bad | ||
window._camptixAttendanceSounds.blm(); | ||
|
||
// let the sound play before showing the alert | ||
setTimeout(function () { | ||
if (typeof res === 'string') { | ||
alert(res); | ||
} else { | ||
alert('[' + res.status + '] ' + res.statusText); | ||
} | ||
lastScan = null; | ||
html5QrcodeScanner.resume(); | ||
}, 100); | ||
|
||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write some more helpful debug output or better remove it completely, when the PR is finished. |
||
.then(() => { | ||
// play the sound to indicate that the scan is good | ||
window._camptixAttendanceSounds.beep(); | ||
setTimeout(() => { | ||
html5QrcodeScanner.resume(); | ||
//lastScan = null; | ||
//that.refresh(); | ||
}, 3000); | ||
}) | ||
.always(() => { | ||
lastScanTimeout = setTimeout(() => { | ||
// clear last scan to allow for new scan | ||
lastScan = null; | ||
// play the sound to indicate that the scan is over | ||
//window._camptixAttendanceSounds.bob(); | ||
}, 15000); | ||
}); | ||
|
||
html5QrcodeScanner.pause(); | ||
} | ||
|
||
let qrReader = document.getElementById('qr-scanner').getBoundingClientRect(); | ||
|
||
let smallerSide = Math.min(qrReader.width, qrReader.height); | ||
|
||
let qrbox = { | ||
width: Math.max(smallerSide * 0.9, 50), | ||
height: Math.max(smallerSide * 0.9, 50), | ||
}; | ||
|
||
html5QrcodeScanner = new Html5QrcodeScanner('qr-scanner', { fps: 10, qrbox: qrbox }, false); | ||
html5QrcodeScanner.render(onScanSuccess); | ||
|
||
return false; | ||
}, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply WordPress coding styles on this hunk (and the rest of your changes in the file). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need more help on setting this up in my editor (Cursor/VsCode). I always break things in trying to do so 😬 |
||
/** | ||
* Re-initialize a calloction with a search term. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ header { | |
color: white; | ||
padding-left: 16px; | ||
|
||
z-index: 100; | ||
z-index: 300; | ||
} | ||
|
||
header h1, | ||
|
@@ -221,6 +221,20 @@ li.item { | |
display: block; | ||
margin-right: 50px; | ||
margin-left: 50px; | ||
|
||
.previews { | ||
position: fixed; | ||
bottom: 1em; | ||
left: 1em; | ||
right: 1em; | ||
|
||
video { | ||
max-height: 8em; | ||
max-width: 8em; | ||
width: 8em; | ||
float: right; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While there were changes in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure where this is comming from, I'll keep it for now |
||
} | ||
|
||
.attendee-search-view input { | ||
|
@@ -412,6 +426,72 @@ li.item { | |
} | ||
} | ||
|
||
.qr-scanner-wrap { | ||
display: none; | ||
z-index: 299; | ||
position: absolute; | ||
bottom: 1em; | ||
right: 1em; | ||
width: calc(100% - 2em); | ||
aspect-ratio: 4/3; | ||
max-width: 480px; | ||
background: #ccc; | ||
|
||
#qr-scanner { | ||
height: 100%; | ||
} | ||
#qr-scanner__scan_region{ | ||
display: flex; | ||
align-self: center; | ||
justify-content: center; | ||
position: absolute; | ||
inset: 0; | ||
} | ||
#qr-scanner__dashboard { | ||
display: none; | ||
position: absolute; | ||
background: #fff; | ||
bottom: 0; | ||
|
||
button{ | ||
height: 50px; | ||
display: block; | ||
width: calc(100% - 2em); | ||
margin:1em; | ||
line-height: 50px; | ||
font-size: 16px; | ||
background: #333; | ||
color: white; | ||
text-decoration: none; | ||
-webkit-appearance: none; | ||
cursor: pointer; | ||
} | ||
#html5-qrcode-anchor-scan-type-change{ | ||
display: none !important; | ||
} | ||
} | ||
&:hover #qr-scanner__dashboard { | ||
display: block; | ||
} | ||
|
||
} | ||
@media screen and (max-width: 480px) { | ||
.qr-scanner-wrap { | ||
position: fixed; | ||
inset:60px 1em 1em; | ||
width: calc(100% - 2em); | ||
height: calc(100% - 2em - 60px); | ||
margin: 0; | ||
#qr-scanner__dashboard { | ||
display: block; | ||
} | ||
} | ||
} | ||
|
||
.qr-scanner-active .qr-scanner-wrap { | ||
display: block; | ||
} | ||
|
||
/** Animations, courtesy of https://github.com/lukehaas/css-loaders **/ | ||
|
||
@-webkit-keyframes load1 { | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
<script> | ||
_camptixAttendanceSecret = '<?php echo esc_js( $_GET['camptix-attendance'] ); ?>'; | ||
_camptixAttendanceTickets = [ <?php echo esc_js( implode( ', ', array_map( 'absint', wp_list_pluck( $camptix_tickets, 'ID' ) ) ) ); ?> ]; | ||
_camptixAttendanceQRScanning = <?php echo ! empty( $camptix_options['attendance-qr-enabled'] ) ? 'true' : 'false'; ?>; | ||
</script> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> | ||
|
@@ -76,6 +77,7 @@ | |
<a href="#" class="search">Search</a> | ||
<a href="#" class="filter">Sort & Filter</a> | ||
<a href="#" class="refresh">Refresh</a> | ||
<a href="#" class="qr">QR Scanner</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a condition to only show this when the QR code scanner is enabled (or use a CSS class, switched by JS, to hide it - but better not render it at all). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was supposed to be always there (the menu entry): The settings should just show the camera field by default, so you don't have to open it manually every time. Since it's in the menu entry, I would keep it as it is and just show the camera, depending on the setting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, so if the setting is set to "On", the camera would always show, and with "Off", only when accessed thought the menu? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, so if you reload the page you don't have to click into the menu. We can change this behavior of course |
||
</div> | ||
</div> | ||
<h1><?php echo esc_html( $camptix_options['event_name'] ); ?></h1> | ||
|
@@ -88,13 +90,15 @@ | |
<span>Loading...</span> | ||
</li> | ||
</ul> | ||
<div class="qr-scanner-wrap"><div id="qr-scanner"></div></div> | ||
</div> | ||
</script> | ||
|
||
<script id="tmpl-attendee-search" type="text/template"> | ||
<a href="#" class="close dashicons dashicons-no"></a> | ||
<div class="wrapper"> | ||
<input type="text" autocomplete="off" placeholder="Search" /> | ||
<div class="previews"></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why this is here. It's also referenced in the scss above. I'll keep it for now |
||
</div> | ||
</script> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've only added the new styles to the compiled
.css
file, but you should have added them to the.scss
file instead and compile the.css
file again.