Skip to content

Commit

Permalink
Implement shows and enhance configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
WillemStaels committed Aug 5, 2021
1 parent 693717d commit 46b84b8
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 84 deletions.
4 changes: 2 additions & 2 deletions dist/app.js

Large diffs are not rendered by default.

54 changes: 34 additions & 20 deletions gate/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ class Router {
user.username = req.body.username;
}
if(typeof req.body.badges !== 'undefined'){
user.badges = req.body.badges
user.badges = (req.body.badges === true || req.body.badges === 'true') ? true : false;
}
if(typeof req.body.reports !== 'undefined'){
user.reports = req.body.reports
user.reports = (req.body.reports === true || req.body.reports === 'true') ? true : false;
}
if(typeof req.body.settings !== 'undefined'){
user.settings = req.body.settings
user.settings = (req.body.settings === true || req.body.settings === 'true') ? true: false;
}
if(typeof req.body.ticket_printer !== 'undefined'){
if(req.body.ticket_printer){
Expand Down Expand Up @@ -361,16 +361,15 @@ class Router {
return;
}
//Get all tickets from show
let allTickets = db.objects('Ticket').filtered('show_id = $0',show.id);
let allTickets = db.objects('Ticket').filtered('show_id = $0 && blocked_at = null',show.id);

let scans = {};
let types = [];

if(allTickets.length){
//Count scans
for(var t = 0; t < allTickets.length; t++){
let ticketScans = db.objects('Scan').filtered('ticket_id = "' + allTickets[t].id + '" DISTINCT(ticket_id)');
//scans += ticketScans.length;
let ticketScans = db.objects('Scan').filtered('ticket_id = "' + allTickets[t].ticket_id + '" DISTINCT(ticket_id)');

//Push type
if(!scans.hasOwnProperty(allTickets[t].type_id)){
Expand Down Expand Up @@ -540,7 +539,7 @@ class Router {
pocket: null,
order: null,
customer: null,
status: 'already_scanned'
status: 'allowed',
}

// Find type
Expand All @@ -549,13 +548,6 @@ class Router {
ticketData.type = type;
}

//Find scans
let scans = db.objects('Scan').filtered('ticket_id = "' + ticket.ticket_id + '"');

if(scans.length > 0){
ticketData.scans = Array.from(scans);
}

// Find pocket
if(ticket.pocket_id){
let pocket = db.objectForPrimaryKey('Pocket', ticket.pocket_id);
Expand All @@ -577,10 +569,20 @@ class Router {
}
}

//Scan and update status
if(scans.length == 0){
ticketData.status = "allowed";
//Save scan
//Find scans
let scans = db.objects('Scan').filtered('ticket_id = "' + ticket.ticket_id + '"');

if(scans.length > 0){
ticketData.scans = Array.from(scans);
ticketData.status = 'already_scanned';
}

if(ticket.blocked_at) {
ticketData.status = 'blocked';
}

// Save scan
if(scans.length === 0){
db.write(() => {
db.create('Scan', {
uuid: uuidv4(),
Expand Down Expand Up @@ -614,7 +616,7 @@ class Router {
customer = db.objectForPrimaryKey('Customer', pocket.customer_id);
}

let allTickets = db.objects('Ticket').filtered("pocket_id = '" + pocket.id + "'");
let allTickets = db.objects('Ticket').filtered("pocket_id = '" + pocket.id + "'").sorted('blocked_at');
let tickets = [];

//Parse tickets
Expand All @@ -630,13 +632,13 @@ class Router {
place: allTickets[i].place ? JSON.parse(allTickets[i].place) : null,
price: allTickets[i].price,
attendees: allTickets[i].attendees,
blocked_at: allTickets[i].blocked_at,
type: allTickets[i].type_id ? db.objectForPrimaryKey('Type', allTickets[i].type_id) : null,
show: allTickets[i].show_id ? db.objectForPrimaryKey('Show', allTickets[i].show_id) : null,
scans: Array.from(allScans)
});
}
}

res.send({
pocket: pocket,
customer: customer,
Expand All @@ -656,6 +658,18 @@ class Router {
res.sendStatus(200);
}.bind(this));

// Get all system settings
this.app.get('/api/settings', function(req, res){
this.db.open(db => {
let settings = db.objects('Setting');
res.send({
settings: Array.from(settings)
});
}, error => {
res.sendStatus(500);
});
}.bind(this));

//Update system setting
this.app.post('/api/settings', function(req, res){
this.db.open(db => {
Expand Down
10 changes: 5 additions & 5 deletions gate/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Sync {
}
auth() {
if(this.authenticating) return;
console.log('Starting authentication');
//Check macAddress
if(!this.macAddress){
console.warn('Macaddress is not available.');
Expand All @@ -82,6 +83,7 @@ class Sync {
}
})
.then(function (response) {
console.log(`Authenticated as ${response.data.device.device_id}`);
this.authenticating = false;
this.device_id = response.data.device.device_id;
this.sync();
Expand Down Expand Up @@ -227,11 +229,8 @@ class Sync {
});
}
processTickets(tickets) {

this.db.open(db => {

let scans = [];

db.write(() => {
//Sync tickets
for(var i=0;i<tickets.length;i++){
Expand All @@ -248,7 +247,8 @@ class Sync {
type_id: tickets[i].relations.type,
show_id: tickets[i].relations.show,
pocket_id: tickets[i].relations.pocket,
reserved: tickets[i].ticket_id ? false : true
reserved: tickets[i].ticket_id ? false : true,
blocked_at: tickets[i].blocked_at ? new Date(tickets[i].blocked_at.replace(/-/g,"/")) : null,
}, true);
if(tickets[i].scans.length){
for(var s=0;s<tickets[i].scans.length;s++){
Expand Down Expand Up @@ -369,7 +369,7 @@ class Sync {
let allBadges = db.objects('Badge');
db.delete(allBadges);
})
console.log('Reset all data');
console.log('All data was reset');
}, error => {
console.warn(error);
});
Expand Down
3 changes: 2 additions & 1 deletion lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ const TicketSchema = {
type_id: {type: 'string', optional: false},
show_id: {type: 'string', optional: true},
pocket_id: {type: 'string', optional: true},
reserved: {type: 'bool', optional: true, default: false}
reserved: {type: 'bool', optional: true, default: false},
blocked_at: {type: 'date', optional: true},
}
};

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"name": "eventsquare-gate",
"version": "3.0.9",
"version": "4.0.0",
"description": "Event support access control server.",
"main": "gate.js",
"scripts": {
"test": "node ./test/simple.js",
"kiosk": "node ./test/kiosk.js",
"zpl": "node ./test/zpl.js",
"watch": "webpack --watch --config webpack.dev.js",
"build": "webpack --config webpack.prod.js"
},
"dependencies": {
"axios": "^0.19.0",
"body-parser": "^1.18.3",
Expand Down Expand Up @@ -62,13 +69,6 @@
"type": "git",
"url": "https://github.com/eventsquare/gate.git"
},
"scripts": {
"test": "node ./test/test.js",
"kiosk": "node ./test/kiosk.js",
"zpl": "node ./test/zpl.js",
"watch": "webpack --watch --config webpack.dev.js",
"build": "webpack --config webpack.prod.js"
},
"engines": {
"node": ">=8.x"
}
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Server and client for real-time communication at events between devices.

```js
npm i eventsquare-gate
yarn add eventsquare-gate
```

## Starting a server
Expand Down
11 changes: 8 additions & 3 deletions src/components/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ class NavBar extends React.Component {
</li>
}
{ this.props.user.reports &&
<li className={"nav-item " + this.isActive('/reports')}>
<Link className="nav-link" to="/reports">Rapporten</Link>
</li>
<li className={"nav-item " + this.isActive('/shows')}>
<Link className="nav-link" to="/shows">Voorstellingen</Link>
</li>
}
{ this.props.user.reports &&
<li className={"nav-item " + this.isActive('/reports')}>
<Link className="nav-link" to="/reports">Rapporten</Link>
</li>
}
</ul>
<ul className="navbar-nav">
Expand Down
19 changes: 15 additions & 4 deletions src/views/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Customer extends React.Component {
this.printTicket = this.printTicket.bind(this);
};
componentDidMount() {
moment.locale('nl');
this.loadCustomer();
}
loadCustomer(){
Expand Down Expand Up @@ -123,28 +124,38 @@ class Customer extends React.Component {
</div>
)
}
getRowClassName(ticket) {
if(ticket.blocked_at) return "table-danger";
if(ticket.scans.length) return "table-success";
return "";
}
renderTicket(ticket){
return (
<tr key={ticket.id} className={ticket.scans.length ? "table-success" : ""}>
<tr key={ticket.id} className={this.getRowClassName(ticket)}>
<td>
<h6 className="mb-0"><b>{ (ticket.firstname ? ticket.firstname : '') + ' ' + (ticket.lastname ? ticket.lastname : '') }</b></h6>
<p className="mb-0">{ ticket.type ? ticket.type.name : '-' }</p>
<p className="mb-0 small">{ ticket.barcode }</p>
</td>
<td>
<h6 className="mb-0">{ ticket.show ? ticket.show.name : '' }</h6>
{ ticket.show && <h6 className="mb-0">{ticket.show.name ? ticket.show.name : moment(ticket.show.date_start).format("D MMMM YYYY - HH:mm")}</h6>}
<p className="mb-0 small">{ ticket.place ? ('Section: ' + ticket.place.data.section + ' - ' + 'Row: ' + ticket.place.data.row + ' - ' + 'Place: ' + ticket.place.data.seat) : '' }</p>
</td>
<td>{ ticket.scans.length ? moment(ticket.scans[0].scanned_at).format("DD-MM-YYYY HH:mm:ss") : '' }</td>
<td>
{!ticket.blocked_at &&
<div className="dropdown show">
<a className="btn btn-sm btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Acties</a>
<div className="dropdown-menu" aria-labelledby="dropdownMenuLink">
<button onClick={() => this.scanTicket(ticket.barcode)} className="dropdown-item" href="#">Scan</button>
<button onClick={() => this.printTicket(ticket)} className="dropdown-item" href="#">Afdrukken</button>
{/* <button onClick={() => this.openBadge(ticket)} className="dropdown-item" href="#">Maak badge</button> */}
<button onClick={() => this.openBadge(ticket)} className="dropdown-item" href="#">Maak badge</button>
{/* <button onClick={() => this.printTicket(ticket)} className="dropdown-item" href="#">Afdrukken</button> */}
</div>
</div>
}
{ ticket.blocked_at &&
<small className="text-muted">Geblokkeerd op {moment(ticket.blocked_at).format("DD-MM-YYYY HH:mm")}</small>
}
</td>
</tr>
);
Expand Down
68 changes: 42 additions & 26 deletions src/views/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,35 +255,51 @@ class DashBoard extends React.Component {
}
}
renderStatus(status){
if(status == "already_scanned"){
return (
<div>
<div className="mb-4 text-center">
{ this.state.ticket.ticket.firstname &&
<h3 style={{fontSize: 48}} className="display-4 mb-1"><b>{ this.state.ticket.ticket.firstname + " " + this.state.ticket.ticket.lastname }</b></h3>
}
<h4><b>{ this.state.ticket.type.name }</b></h4>
</div>
<div className="p-3 mb-5 bg-danger text-white text-center rounded">
<h1>REEDS GESCAND</h1>
<p className="lead mb-0">Dit ticket werd reeds gescand op { moment(this.state.ticket.scans[0].scanned_at).format("YYYY-MM-DD HH:mm:ss") }</p>
switch(status){
case 'already_scanned':
return (
<div>
<div className="mb-4 text-center">
{ this.state.ticket.ticket.firstname &&
<h3 style={{fontSize: 48}} className="display-4 mb-1"><b>{ this.state.ticket.ticket.firstname + " " + this.state.ticket.ticket.lastname }</b></h3>
}
<h4><b>{ this.state.ticket.type.name }</b></h4>
</div>
<div className="p-3 mb-5 bg-danger text-white text-center rounded">
<h1>REEDS GESCAND</h1>
<p className="lead mb-0">Dit ticket werd reeds gescand op { moment(this.state.ticket.scans[0].scanned_at).format("YYYY-MM-DD HH:mm:ss") }</p>
</div>
</div>
</div>
)
} else {
return (
<div>
<div className="mb-4 text-center">
{ this.state.ticket.ticket.firstname &&
<h3 style={{fontSize: 48}} className="display-4 mb-1"><b>{ this.state.ticket.ticket.firstname + " " + this.state.ticket.ticket.lastname }</b></h3>
}
<h4><b>{ this.state.ticket.type.name }</b></h4>
)
case 'blocked':
return (
<div>
<div className="mb-4 text-center">
{ this.state.ticket.ticket.firstname &&
<h3 style={{fontSize: 48}} className="display-4 mb-1"><b>{ this.state.ticket.ticket.firstname + " " + this.state.ticket.ticket.lastname }</b></h3>
}
<h4><b>{ this.state.ticket.type.name }</b></h4>
</div>
<div className="p-3 mb-5 bg-danger text-white text-center rounded">
<h1>GEBLOKKEERD</h1>
<p className="lead mb-0">Dit ticket werd geblokkeerd op { moment(this.state.ticket.blocked_at).format("YYYY-MM-DD HH:mm:ss") }</p>
</div>
</div>
<div className="p-3 mb-5 bg-success text-white text-center rounded">
<h1 className="mb-0">OK</h1>
)
case 'allowed':
return (
<div>
<div className="mb-4 text-center">
{ this.state.ticket.ticket.firstname &&
<h3 style={{fontSize: 48}} className="display-4 mb-1"><b>{ this.state.ticket.ticket.firstname + " " + this.state.ticket.ticket.lastname }</b></h3>
}
<h4><b>{ this.state.ticket.type.name }</b></h4>
</div>
<div className="p-3 mb-5 bg-success text-white text-center rounded">
<h1 className="mb-0">OK</h1>
</div>
</div>
</div>
)
)
}
}
render() {
Expand Down
Loading

0 comments on commit 46b84b8

Please sign in to comment.