-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentification.html.erb
More file actions
120 lines (94 loc) · 3.44 KB
/
identification.html.erb
File metadata and controls
120 lines (94 loc) · 3.44 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<div class="container text-center">
<h1>Validação de Acesso RU-Connect</h1>
<p class="mt-4"><small>Acesso administrativo: <%= link_to "Entrar", new_user_session_path %></small></p>
<p class="lead">Método de Identificação:</p>
<div class="row my-4">
<div class="col-md-6 mx-auto">
<h3>Entrada Manual</h3>
<p>Digite o CPF ou Matrícula</p>
<%= form_with url: identify_path, method: :post, local: true, data: { turbo: false } do |f| %>
<div class="form-group my-3">
<%= f.label :identifier, "Identificador:" %>
<%= f.text_field :identifier, class: "form-control form-control-lg", autofocus: true %>
<%= f.submit "Validar Manualmente", class: "btn btn-primary btn-lg" %>
</div>
<% end %>
</div>
<div class="col-md-12 my-4">
<hr>
<h3>OU</h3>
<hr>
</div>
<div class="col-md-6 mx-auto">
<h3>Leitura por Câmera</h3>
<button id="start-scanner-btn" class="btn btn-success btn-lg mb-3">
▶️ Start Scanning
</button>
<div id="reader" style="width:300px; margin: 0 auto; display: none;"></div>
</div>
</div>
<div class="my-5">
<% if notice %>
<div class="alert alert-success"><%= notice %></div>
<% end %>
<% if alert %>
<div class="alert alert-danger"><%= alert %></div>
<div><%= link_to "Cadastrar Novo Aluno", new_student_path %></div>
<% end %>
</div>
</div>
<hr class="my-5">
<script>
const feedbackElement = document.getElementById('scan-feedback');
const readerElement = document.getElementById('reader');
const startButton = document.getElementById('start-scanner-btn');
var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 }, false);
function onScanSuccess(decodedText, decodedResult) {
html5QrcodeScanner.pause(true);
if (readerElement) {
readerElement.style.display = 'none';
}
if (feedbackElement) {
feedbackElement.classList.remove('d-none');
}
console.log(`Enviando código lido: ${decodedText}`);
const form = document.createElement('form');
form.method = 'POST';
form.action = '<%= identify_path %>';
const identifierField = document.createElement('input');
identifierField.type = 'hidden';
identifierField.name = 'identifier';
identifierField.value = decodedText;
form.appendChild(identifierField);
const csrfToken = document.querySelector('meta[name="csrf-token"]').content;
const csrfField = document.createElement('input');
csrfField.type = 'hidden';
csrfField.name = 'authenticity_token';
csrfField.value = csrfToken;
form.appendChild(csrfField);
document.body.appendChild(form);
form.submit();
}
function startScanner() {
startButton.style.display = 'none';
readerElement.style.display = 'block';
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
}
if (startButton) {
startButton.addEventListener('click', startScanner);
}
function onScanFailure(error) {
}
document.addEventListener('turbo:before-render', () => {
html5QrcodeScanner.clear().catch(error => {
console.warn("Falha ao desligar o leitor de QR Code:", error);
});
});
</script>
<h2>Últimos Acessos de Hoje</h2>
<% if @today_logs.present? %>
<%= render 'access_logs/access_logs_table', logs: @today_logs %>
<% else %>
<p>Nenhum acesso registrado ainda hoje.</p>
<% end %>