8000 Approach for QR integration on the attendance UI by evrpress · Pull Request #1494 · WordPress/wordcamp.org · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Draft
wants to merge 26 commits into
base: production
Choose a base branch
from

Conversation

evrpress
Copy link
@evrpress evrpress commented Jun 5, 2025

See #613

Comment on lines 68 to 69
wp_enqueue_script( 'camptix-attendance-ui', plugins_url( '/assets/attendance-ui.js', __FILE__ ), array( 'backbone', 'jquery', 'wp-util', 'jquery-fastbutton', 'html5-qr-scanner' ), filemtime( __DIR__ . '/assets/attendance-ui.js' ) );
wp_enqueue_style( 'camptix-attendance-ui', plugins_url( '/assets/attendance-ui.css', __FILE__ ), array( 'dashicons' ), filemtime( __DIR__ . '/assets/attendance-ui.css' ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the HTML5 QR Code scripts, and it also duplicates the loading of the same files.

Suggested change
wp_enqueue_script( 'camptix-attendance-ui', plugins_url( '/assets/attendance-ui.js', __FILE__ ), array( 'backbone', 'jquery', 'wp-util', 'jquery-fastbutton', 'html5-qr-scanner' ), filemtime( __DIR__ . '/assets/attendance-ui.js' ) );
wp_enqueue_style( 'camptix-attendance-ui', plugins_url( '/assets/attendance-ui.css', __FILE__ ), array( 'dashicons' ), filemtime( __DIR__ . '/assets/attendance-ui.css' ) );
wp_enqueue_script( 'html5-qr-scanner', plugins_url( '/assets/html5-qrcode.min.js', __FILE__ ), array( 'jquery' ) );
wp_enqueue_script( 'camptix-attendance-ui', plugins_url( '/assets/attendance-ui.js', __FILE__ ), array( 'backbone', 'jquery', 'wp-util', 'jquery-fastbutton', 'html5-qr-scanner' ) );
wp_enqueue_style( 'camptix-attendance-ui', plugins_url( '/assets/attendance-ui.css', __FILE__ ), array( 'dashicons' ) );

Copy link
Author
@evrpress evrpress Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lib doesn't require jquery, using wp_register_script instead

}
.qr-scanner-active #attendees-list-wrapper .qr-scanner {
display: block;
}
Copy link
Contributor

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.

Comment on lines 408 to 410
alert: function () {
alert('asd');
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be removed.

Comment on lines 429 to 431
this.$header = this.$el.find('header');
this.$qrscanner = this.$el.find('.qr-scanner');
this.$menu = this.$header.find('.menu');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property this.$qrscanner is never used, so the changes in these lines can be reverted.

Comment on lines 448 to 449
) {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is happening in the body of this condition. Is the this.qr(); call meant to be in the body?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, probably for testing in the wrong spot. This initialize the qr code if the settings is enabled

this.$el.toggleClass('qr-scanner-active');
this.$menu.removeClass('dropdown');

var that = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The var keyword should be replaced with const (or let).


return false;
},

Copy link
Contributor

Choose a reason for hiding this comment

The 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).

Copy link
Author

Choose a reason for hiding this comment

The 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 😬

let lastScan;
let toggleView;

function onScanSuccess(decodedText, decodedResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter decodedResult is never used. Can it be removed?

)
.fail(function (res) {
console.log('fail', res);
})
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

})
.always(() => {
setTimeout(() => {
//html5QrcodeScanner.resume();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep this for now, it's there for a reason. Will be removed with the PR

html5QrcodeScanner.pause();
}

let c = document.getElementById('qr-reader').getBoundingClientRect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a more verbose name for the variable.

width: 8em;
float: right;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While there were changes in the .css file only before, these changes are only in the .scss file. It's not clear which library was used to compile the .css file, but I'd assume some older Sass version with the default settings.

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can probably be removed, since it's from the other QR code branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can probably be removed, since it's from the other QR code branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also include to non-minified file as well? Or at least comment somewhere, which library was not used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how it's built, that's why I left it in the first place

@@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

The 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).

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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

@@ -88,13 +90,15 @@
<span>Loading...</span>
</li>
</ul>
<div class="qr-scanner"><div id="qr-reader"></div></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two DIVs a requirement from the JS library? Wouldn't one be sufficient enough?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it was because the outer was for styling and the inner just contained the canvas. I'll check that though.

@@ -80,6 +82,11 @@ public function ajax_callback() {
if ( empty( $_REQUEST['camptix_secret'] ) || $_REQUEST['camptix_secret'] != $this->secret )
return;

// get qr code response if requested
if ( isset( $_GET['qrcode'] ) ) {
CEB7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $_REQUEST instead of $_GET, as with the other request parameters.

$qrcode = sanitize_text_field( $_GET['qrcode'] );

if ( ! preg_match( '/^[0-9a-f]{16}$/', $qrcode ) ) {
//return wp_send_json_error( 'invalid qrcode format' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do something.

*/
public function _ajax_qrcode() {

$qrcode = sanitize_text_field( $_GET['qrcode'] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might not be needed, if we return early, if the format does not match.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but check the value in the _ajax_qrcode method.

global $wpdb;

// get the attende ID by the qrcode
// this is maybe resource intensive for larger events allthough we don't had any WordCamp > 3000 tickets so I guess we're fine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be moved from code to the PR.

}
// if ( ! $attendee || 'tix_attendee' != $attendee->post_type || 'publish' != $attendee->post_status ) {
// return wp_send_json_error( 'user not found' );
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

Comment on lines 312 to 323
$where = $wpdb->prepare(
"
(
tix_first_name.meta_value LIKE '%%%s%%' OR
tix_last_name.meta_value LIKE '%%%s%%' OR
CONCAT( tix_first_name.meta_value, ' ', tix_last_name.meta_value ) LIKE '%%%s%%'
)
", $search, $search, $search );

return $clauses;
} );
",
$search,
$search,
$search
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent these lines correctly.

Comment on lines 327 to 329
$clauses['join'] .= "
INNER JOIN $wpdb->postmeta tix_access_token ON ( ID = tix_access_token.post_id AND tix_access_token.meta_key = 'tix_access_token' )
";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent these lines correctly.

Comment on lines +331 to +339
$where = '(' .
$where .
' OR (' .
$wpdb->prepare( "tix_access_token.meta_value LIKE '%%%s'", $search ) .
')' .
')';
}

$clauses['where'] .= ' AND ' . $where;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put the previous clauses into two variables and "join" them differently, then overwriting $where multiple times.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do an array an join them later? Skip this for now

'field_yesno',
'general',
esc_html__( 'Enable QR code scanning?', 'wordcamporg' )
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I prefer this wrapping in multiple lines, maybe write it in one line like the surrounding lines.

</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>
Copy link
Author

Choose a reason for hiding this comment

The 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

@evrpress
Copy link
Author

I like to write this down somewhere.

The QR code is based on the last 16 digits of the MD5 value of the access_token of the attendee.

This is of course debatable but I will use this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0