-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvagas-visitantes.html
More file actions
266 lines (230 loc) · 8.78 KB
/
vagas-visitantes.html
File metadata and controls
266 lines (230 loc) · 8.78 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vagas para Visitantes | Edifício Texas</title>
<link rel="stylesheet" href="css/estilo.css">
<link rel="stylesheet" href="css/dashboard.css">
<style>
/* Estilos específicos para esta página */
.table-container {
overflow-x: auto;
margin-top: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 15px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 15px;
font-size: 0.9em;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #e0e0e0;
}
th {
background-color: #2e7d32;
color: white;
position: sticky;
top: 0;
}
tr:hover {
background-color: #f5f5f5;
}
.status-ativo {
color: #2e7d32;
font-weight: bold;
background-color: #e8f5e9;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
}
.status-pendente {
color: #ff8f00;
font-weight: bold;
background-color: #fff3e0;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
}
.status-inativo {
color: #d32f2f;
font-weight: bold;
background-color: #ffebee;
padding: 5px 10px;
border-radius: 4px;
display: inline-block;
}
.vaga-atual {
background-color: #e3f2fd !important;
}
.loading {
text-align: center;
padding: 20px;
color: #666;
}
.error-message {
color: #d32f2f;
text-align: center;
padding: 20px;
}
@media (max-width: 768px) {
th, td {
padding: 8px 10px;
font-size: 0.8em;
}
.table-container {
padding: 10px;
}
}
</style>
</head>
<body>
<header class="header">
<div class="header-brand">
<img src="img/600texas900.webp" alt="Logo" class="header-logo">
<h1>Vagas para Visitantes</h1>
</div>
<button onclick="window.location.href='index.html'">Voltar</button>
</header>
<nav class="menu">
<a href="index.html">Início</a>
<a href="avisos.html">Avisos</a>
<a href="agenda.html">Agenda</a>
<a href="moradores.html">Moradores</a>
<a href="vagas-visitantes.html" class="active">Vagas Visitantes</a>
</nav>
<main class="main-content">
<h2>Calendário de Vagas para Visitantes</h2>
<p class="subtitle">Confira as vagas designadas para cada apartamento</p>
<div class="info-box">
<p>Legenda:</p>
<p><span class="status-ativo">EM VIGOR</span> - Período atual de utilização</p>
<p><span class="status-pendente">FUTURA</span> - Período que ainda vai acontecer</p>
<p><span class="status-inativo">ENCERRADA</span> - Período que já passou</p>
</div>
<div class="table-container">
<table id="tabelaVagas">
<thead>
<tr>
<th>Semana</th>
<th>Data Início</th>
<th>Data Fim</th>
<th>Vaga 01</th>
<th>Vaga 02</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="6" class="loading">Carregando informações...</td>
</tr>
</tbody>
</table>
</div>
</main>
<script>
document.addEventListener('DOMContentLoaded', async () => {
const usuario = JSON.parse(localStorage.getItem('usuario'));
// Verifica autenticação
if (!usuario) {
window.location.href = 'login.html';
return;
}
// Elementos da página
const tabelaBody = document.querySelector('#tabelaVagas tbody');
try {
// Faz a requisição para o backend
const response = await fetch('https://condominio-cc5u.onrender.com/api/vagas-visitantes', {
headers: {
'Authorization': `Bearer ${usuario.token}`,
'Content-Type': 'application/json'
}
});
// Verifica se a resposta foi bem sucedida
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Erro ${response.status}: ${errorText || 'Erro ao carregar dados'}`);
}
const vagas = await response.json();
const hoje = new Date();
hoje.setHours(0, 0, 0, 0);
// Limpa o loading
tabelaBody.innerHTML = '';
// Se não houver vagas
if (vagas.length === 0) {
tabelaBody.innerHTML = `
<tr>
<td colspan="6">Nenhuma vaga de visitante cadastrada</td>
</tr>
`;
return;
}
// Ordena as vagas por data
vagas.sort((a, b) => new Date(a.dataInicio) - new Date(b.dataInicio));
// Processa cada vaga
vagas.forEach(vaga => {
const dataInicio = new Date(vaga.dataInicio);
const dataFim = new Date(dataInicio);
dataFim.setDate(dataFim.getDate() + 6); // Adiciona 6 dias para completar a semana
// Determina o status
let status = '';
let isCurrent = false;
if (hoje >= dataInicio && hoje <= dataFim) {
status = '<span class="status-ativo">EM VIGOR</span>';
isCurrent = true;
} else if (hoje < dataInicio) {
status = '<span class="status-pendente">FUTURA</span>';
} else {
status = '<span class="status-inativo">ENCERRADA</span>';
}
// Cria a linha da tabela
const row = document.createElement('tr');
if (isCurrent) {
row.classList.add('vaga-atual');
}
row.innerHTML = `
<td>${vaga.semana}</td>
<td>${formatarData(vaga.dataInicio)}</td>
<td>${formatarData(dataFim)}</td>
<td>${vaga.vaga1 || '-'}</td>
<td>${vaga.vaga2 || '-'}</td>
<td>${status}</td>
`;
tabelaBody.appendChild(row);
});
} catch (error) {
console.error('Erro ao carregar vagas:', error);
tabelaBody.innerHTML = `
<tr>
<td colspan="6" class="error-message">
Erro ao carregar dados: ${error.message}<br>
<button onclick="window.location.reload()">Tentar novamente</button>
</td>
</tr>
`;
}
});
// Função para formatar data no formato DD/MM/AAAA
function formatarData(dataString) {
if (!dataString) return '-';
try {
const data = new Date(dataString);
if (isNaN(data.getTime())) return '-';
const dia = String(data.getDate()).padStart(2, '0');
const mes = String(data.getMonth() + 1).padStart(2, '0');
const ano = data.getFullYear();
return `${dia}/${mes}/${ano}`;
} catch (e) {
console.error('Erro ao formatar data:', e);
return '-';
}
}
</script>
</body>
</html>