Skip to content

Commit

Permalink
Integrate Tracey's Robocritter certificate changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceJL committed Oct 14, 2024
1 parent 3ee2005 commit a225025
Show file tree
Hide file tree
Showing 10 changed files with 801 additions and 489 deletions.
43 changes: 43 additions & 0 deletions app/controllers/robocritter-certificate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

export default class RobocritterCertificateController extends Controller {
@tracked minutes: number = 0;
@tracked seconds: number = 0;
@tracked player: string = '';
@tracked robot: string = '';

@action
async downloadCertificate() {
const response = await fetch(
'http://127.0.0.1:5000/api/generate-certificate',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
player: this.player,
robot: this.robot,
minutes: this.minutes,
seconds: this.seconds,
}),
},
);

if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = this.player + '_' + this.robot + '_certificate.odg';
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
} else {
alert('Failed to generate the certificate');
}
}
}
23 changes: 23 additions & 0 deletions app/templates/robocritter-certificate.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- app/templates/robocritter-certificate.hbs -->
<div>
<label for="player">Player Name:</label>
<input type="text" id="player" value={{this.player}} oninput={{action (mut this.player) value="target.value"}} autocomplete="off" required>
</div>

<div>
<label for="robot">Robot Name:</label>
<input type="text" id="robot" value={{this.robot}} oninput={{action (mut this.robot) value="target.value"}} autocomplete="off" required>
</div>

<div>
<label for="minutes">Minutes:</label>
<input type="number" id="minutes" value={{this.minutes}} oninput={{action (mut this.minutes) value="target.value"}} autocomplete="off" required>
</div>

<div>
<label for="seconds">Seconds:</label>
<input type="number" id="seconds" value={{this.seconds}} oninput={{action (mut this.seconds) value="target.value"}} autocomplete="off" required>
</div>

<div><button {{on "click" this.downloadCertificate}}>Download Certificate</button></div>

Loading

0 comments on commit a225025

Please sign in to comment.