-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlabels.blade.php
64 lines (57 loc) · 2.05 KB
/
labels.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
define('ACCESS_KEY', 'YOUR-ACCESS-KEY-HERE');
define('SERVER_ENDPOINT', 'http://127.0.0.1:8000/print');
$labels = [];
foreach ($assets as $asset) {
$labels[] = [
'id' => 'ID: ' . $asset->id,
'name' => empty($asset->name) ? '' : 'N: ' . $asset->name,
'serial' => empty($asset->serial) ? '' : 'S: ' . $asset->serial,
'model' => empty($asset->model->name) ? '' : 'M: ' . $asset->model->name,
'company' => $asset->company === null ? null : 'C: ' . $asset->company->name,
'asset_tag' => $asset->asset_tag,
'asset_url' => $_ENV['APP_URL'] . '/hardware/' . $asset->id,
];
}
?>
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Labels Print</title>
</head>
<body>
<div style="display: flex;flex-flow: column;gap: 12px">
<span>Labels Data: <?php echo count($labels); ?></span>
<div>
<button type="button" id="print" onclick="doPrint()">Click here to print</button>
</div>
<ul style="margin: 0;">
<?php
foreach ($labels as $l) {
echo ('<li>' . $l['asset_tag'] . ', ' . $l['model'] . ', ' . $l['serial'] . '</li>');
}
?>
</ul>
</div>
<script>
function doPrint() {
var el = document.getElementById('print');
el.setAttribute('disabled', true);
el.innerText = 'Requesting...';
el = el.parentElement;
fetch(<?php echo json_encode(SERVER_ENDPOINT); ?>, {
credentials: 'omit',
method: 'POST',
headers: {
'Authorization': 'Bearer <?php echo ACCESS_KEY; ?>',
},
// For readability
body: JSON.stringify(<?php echo json_encode($labels); ?>),
}).then(r => r.text())
.then(r => el.innerText = r)
.catch(e => el.innerText = 'Error: ' + e);
}
</script>
</body>
</html>