-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
258 lines (218 loc) · 8.16 KB
/
admin.html
File metadata and controls
258 lines (218 loc) · 8.16 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
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Editor Database JSON</title>
<script src="https://cdn.emailjs.com/dist/email.min.js"></script>
<script>
window.onload = () => {
emailjs.init("4pck4wyzmd3xsR73q"); // ← Inserisci qui il tuo USER ID di EmailJS
};
</script>
<style>
body { font-family: sans-serif; max-width: 800px; margin: auto; padding: 20px; }
h1, h2 { text-align: center; }
.obj { border: 1px solid #ccc; padding: 10px; margin-bottom: 10px; border-radius: 6px; }
input[type="text"] { width: 100%; margin: 5px 0; padding: 5px; }
button { padding: 6px 10px; margin: 5px 4px 10px 0; }
summary { cursor: pointer; }
</style>
</head>
<body>
<body>
<p style="text-align: center; margin-top: 10px;">
🔙 <a href="index.html">Torna alla pagina principale</a>
</p>
<!-- GUIDA -->
<details open style="margin-bottom: 20px; border: 1px solid #ccc; padding: 10px; border-radius: 6px;">
<summary style="font-weight: bold; font-size: 1.2em;">📘 Guida: Come proporre modifiche al database</summary>
<ol>
<li>Modifica o aggiungi oggetti</li>
<li>Esporta i file modificati (opzionale)</li>
<li>Invia direttamente via email con un clic</li>
</ol>
</details>
<h1>🔧 Proponi Modifiche al Database</h1>
<div id="listaOggetti"></div>
<h2>➕ Aggiungi nuovo oggetto</h2>
<div class="obj">
<input type="text" id="nuovoNome" placeholder="Nome oggetto">
<input type="text" id="nuoviTags" placeholder="Proprietà separate da virgola">
<button onclick="aggiungiOggetto()">Aggiungi</button>
</div>
<hr>
<button onclick="esportaProposta()">📤 Esporta proposta di modifica</button>
<button onclick="inviaEmail()">📧 Invia via email</button>
<p><em>⚠️ Le modifiche non vengono salvate nel sito, ma puoi inviarle via email.</em></p>
<!-- Form invisibile per EmailJS -->
<form id="emailForm" style="display: none;">
<textarea name="message" id="emailMessage"></textarea>
</form>
<script>
// ✅ Cancella ogni versione locale salvata al caricamento
localStorage.removeItem("database");
let database = [];
let originalDB = [];
function caricaDatabase() {
fetch("https://giovannibarbarino.github.io/LA-examples.github.io/data/database.json")
.then(r => r.json())
.then(data => {
originalDB = JSON.parse(JSON.stringify(data));
const local = localStorage.getItem("database");
database = local ? JSON.parse(local) : data;
renderListaOggetti();
})
.catch(() => {
alert("Errore nel caricamento del database.");
database = [];
originalDB = [];
renderListaOggetti();
});
}
function renderListaOggetti() {
const container = document.getElementById("listaOggetti");
if (database.length === 0) {
container.innerHTML = "<p>Nessun oggetto presente.</p>";
return;
}
container.innerHTML = database.map(obj => `
<div class="obj">
<input type="text" value="${obj.nome}" onchange="modificaNome(${obj.id}, this.value)">
<input type="text" value="${obj.tags.join(', ')}" onchange="modificaTags(${obj.id}, this.value)">
<button onclick="eliminaOggetto(${obj.id})">❌ Elimina</button>
</div>
`).join("");
}
function modificaNome(id, nuovoNome) {
const index = database.findIndex(o => o.id === id);
if (index !== -1) {
database[index].nome = nuovoNome;
salva();
}
}
function modificaTags(id, tagString) {
const index = database.findIndex(o => o.id === id);
if (index !== -1) {
database[index].tags = tagString.split(',').map(t => t.trim()).filter(t => t);
salva();
}
}
function eliminaOggetto(id) {
if (!confirm("Sicuro di voler eliminare?")) return;
database = database.filter(o => o.id !== id);
salva();
renderListaOggetti();
}
function aggiungiOggetto() {
const nome = document.getElementById("nuovoNome").value.trim();
const tags = document.getElementById("nuoviTags").value.split(",").map(t => t.trim()).filter(Boolean);
if (!nome || tags.length === 0) return alert("Inserisci nome e almeno un tag.");
const id = generaProssimoId();
database.push({ id, nome, tags });
salva();
document.getElementById("nuovoNome").value = "";
document.getElementById("nuoviTags").value = "";
renderListaOggetti();
}
function generaProssimoId() {
const idsEsistenti = database.map(obj => obj.id);
let nuovoId = 1;
while (idsEsistenti.includes(nuovoId)) {
nuovoId++;
}
return nuovoId;
}
function salva() {
localStorage.setItem("database", JSON.stringify(database));
}
function esportaProposta() {
const jsonBlob = new Blob([JSON.stringify(database, null, 2)], { type: "application/json" });
downloadFile(jsonBlob, "database-modificato.json");
const modifiche = generaChangelog(originalDB, database);
const txtBlob = new Blob([modifiche], { type: "text/plain" });
downloadFile(txtBlob, "modifiche.txt");
alert("File esportati!");
}
function downloadFile(blob, filename) {
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
function generaChangelog(oldDb, newDb) {
const log = [];
const byId = arr => Object.fromEntries(arr.map(o => [o.id, o]));
const oldMap = byId(oldDb);
const newMap = byId(newDb);
for (const id in newMap) {
const nuovo = newMap[id];
if (!oldMap[id]) {
log.push(`➕ Aggiunto: "${nuovo.nome}" [${nuovo.tags.join(", ")}]`);
} else {
const vecchio = oldMap[id];
if (nuovo.nome !== vecchio.nome) {
log.push(`✏️ Modificato nome (ID ${id}): "${vecchio.nome}" → "${nuovo.nome}"`);
}
if (JSON.stringify(nuovo.tags) !== JSON.stringify(vecchio.tags)) {
log.push(`✏️ Modificati tag (ID ${id}): [${vecchio.tags.join(", ")}] → [${nuovo.tags.join(", ")}]`);
}
}
}
for (const id in oldMap) {
if (!newMap[id]) {
log.push(`❌ Eliminato: "${oldMap[id].nome}"`);
}
}
return log.join("\n");
}
function inviaEmail() {
const jsonStr = JSON.stringify(database, null, 2);
const logStr = generaChangelog(originalDB, database);
const fullMessage = `=== DATABASE ===\n${jsonStr}\n\n=== MODIFICHE ===\n${logStr}`;
document.getElementById("emailMessage").value = fullMessage;
emailjs.sendForm("service_kmh2yna", "template_o0qvp9n", "#emailForm")
.then(() => {
alert("Email inviata con successo!");
}, (err) => {
console.error("Errore invio:", err);
alert("Errore durante l'invio dell'email.");
});
}
caricaDatabase();
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
function scrollToBottom() {
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}
</script>
<!-- Pulsanti scroll circolari -->
<div id="scrollButtons" style="position: fixed; bottom: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 12px;">
<button onclick="scrollToTop()" aria-label="Vai all'inizio"
style="
width: 48px; height: 48px; border-radius: 50%; background-color: #007bff; border: none;
color: white; font-size: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center;
box-shadow: 0 3px 6px rgba(0,0,0,0.2);
transition: background-color 0.3s ease;
"
onmouseenter="this.style.backgroundColor='#0056b3'"
onmouseleave="this.style.backgroundColor='#007bff'">
▲
</button>
<button onclick="scrollToBottom()" aria-label="Vai alla fine"
style="
width: 48px; height: 48px; border-radius: 50%; background-color: #007bff; border: none;
color: white; font-size: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center;
box-shadow: 0 3px 6px rgba(0,0,0,0.2);
transition: background-color 0.3s ease;
"
onmouseenter="this.style.backgroundColor='#0056b3'"
onmouseleave="this.style.backgroundColor='#007bff'">
▼
</button>
</div>
</body>
</html>