-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline.html
More file actions
244 lines (219 loc) · 9.64 KB
/
Copy pathoffline.html
File metadata and controls
244 lines (219 loc) · 9.64 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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SUPACO - Offline</title>
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--primary-color: #0d6efd;
--primary-dark: #0a58ca;
--background-light: #f8f9fa;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: var(--background-light);
}
.offline-container {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 2rem;
text-align: center;
}
.offline-icon {
font-size: 5rem;
color: var(--primary-color);
margin-bottom: 1.5rem;
animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse {
0% { opacity: 0.6; transform: scale(0.95); }
50% { opacity: 1; transform: scale(1.05); }
100% { opacity: 0.6; transform: scale(0.95); }
}
.card {
width: 100%;
max-width: 600px;
border: none;
border-radius: 12px;
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
overflow: hidden;
}
.card-header {
background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
color: white;
border-bottom: none;
padding: 1.2rem 1.5rem;
}
.cached-data-section {
background-color: white;
border-radius: 8px;
padding: 1rem;
margin-top: 1rem;
box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.data-item {
border-left: 3px solid var(--primary-color);
padding-left: 1rem;
margin-bottom: 1rem;
}
.btn-primary {
background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
border: none;
padding: 0.6rem 1.5rem;
border-radius: 6px;
}
</style>
</head>
<body>
<div class="offline-container">
<div class="card animate__animated animate__fadeIn">
<div class="card-header">
<h4 class="mb-0">
<i class="fas fa-wifi-slash me-2"></i>
Você está offline
</h4>
</div>
<div class="card-body p-4">
<div class="offline-icon">
<i class="fas fa-cloud"></i>
</div>
<h2 class="mb-3">Sem conexão com a internet</h2>
<p class="text-muted mb-4">
Não foi possível conectar ao servidor. No entanto, você ainda pode acessar os dados que foram salvos para uso offline.
</p>
<div id="cached-data" class="my-4">
<h5 class="border-bottom pb-2 mb-3">Dados disponíveis offline:</h5>
<div class="cached-data-section">
<div id="offline-data-list">
<div class="text-center text-muted py-3">
<i class="fas fa-spinner fa-spin me-2"></i>
Verificando dados disponíveis...
</div>
</div>
</div>
</div>
<div class="d-grid gap-2">
<button class="btn btn-primary" onclick="checkConnection()">
<i class="fas fa-sync-alt me-2"></i>
Tentar novamente
</button>
<a href="index.php" class="btn btn-outline-secondary">
<i class="fas fa-home me-2"></i>
Voltar para a página inicial
</a>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Verifica dados disponíveis offline
checkOfflineData();
// Verifica a conexão a cada 5 segundos
setInterval(checkConnection, 5000);
});
function checkConnection() {
if (navigator.onLine) {
// Se estiver online, redireciona para a página principal
window.location.href = 'index.php';
}
}
async function checkOfflineData() {
try {
const dataList = document.getElementById('offline-data-list');
// Abre o IndexedDB
const request = indexedDB.open('supaco-db', 1);
request.onerror = function() {
dataList.innerHTML = `
<div class="alert alert-warning">
<i class="fas fa-exclamation-circle me-2"></i>
Não foi possível acessar os dados offline.
</div>
`;
};
request.onsuccess = function(event) {
const db = event.target.result;
// Verifica dados acadêmicos disponíveis
const transaction = db.transaction(['dados-academicos'], 'readonly');
const store = transaction.objectStore('dados-academicos');
const dataItems = [];
// Verifica boletim
const boletimRequest = store.get('boletim');
boletimRequest.onsuccess = function() {
if (boletimRequest.result) {
const data = boletimRequest.result;
dataItems.push({
id: 'boletim',
name: 'Boletim e Notas',
icon: 'fas fa-star',
timestamp: data.timestamp,
url: 'index.php?page=boletim'
});
}
};
// Verifica horários
const horariosRequest = store.get('horarios');
horariosRequest.onsuccess = function() {
if (horariosRequest.result) {
const data = horariosRequest.result;
dataItems.push({
id: 'horarios',
name: 'Horários de Aula',
icon: 'fas fa-calendar-alt',
timestamp: data.timestamp,
url: 'index.php?page=horarios'
});
}
};
// Aguarda todas as operações e exibe os resultados
transaction.oncomplete = function() {
if (dataItems.length === 0) {
dataList.innerHTML = `
<div class="alert alert-info">
<i class="fas fa-info-circle me-2"></i>
Nenhum dado foi salvo para uso offline ainda. Conecte-se à internet pelo menos uma vez.
</div>
`;
} else {
let html = '';
dataItems.forEach(item => {
const date = new Date(item.timestamp);
html += `
<div class="data-item">
<a href="${item.url}" class="text-decoration-none d-block">
<div class="d-flex align-items-center">
<div class="me-3 fs-4 text-primary">
<i class="${item.icon}"></i>
</div>
<div>
<h6 class="mb-0">${item.name}</h6>
<small class="text-muted">
Atualizado em: ${date.toLocaleDateString()} às ${date.toLocaleTimeString()}
</small>
</div>
</div>
</a>
</div>
`;
});
dataList.innerHTML = html;
}
};
};
} catch (error) {
console.error('Erro ao verificar dados offline:', error);
}
}
</script>
</body>
</html>