-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin-tool-projects-editor.html
More file actions
437 lines (421 loc) · 18.1 KB
/
Copy pathAdmin-tool-projects-editor.html
File metadata and controls
437 lines (421 loc) · 18.1 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Projects Editor – RezaCypher</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body {
font-family:'Segoe UI', system-ui, sans-serif;
background:#0a0a0a; color:#ccc;
display:flex; flex-direction:column; align-items:center;
min-height:100vh; padding:20px;
}
.container { max-width:1100px; width:100%; }
h1 { color:#c22; font-weight:300; letter-spacing:2px; margin:20px 0; border-left:4px solid #c22; padding-left:15px; }
.note {
background:#1a1a1a; border:1px solid #333; border-radius:12px;
padding:12px 20px; margin-bottom:20px; font-size:14px;
}
.note strong { color:#ff4040; }
.toolbar { display:flex; gap:15px; align-items:center; flex-wrap:wrap; margin-bottom:20px; }
button, .file-label {
background:#c22; color:#fff; border:none; padding:10px 20px;
border-radius:30px; font-size:14px; cursor:pointer;
letter-spacing:1px; transition:background 0.3s, box-shadow 0.3s;
}
button:hover, .file-label:hover { background:#ff4040; box-shadow:0 0 15px rgba(200,0,0,0.6); }
.file-label { background:#333; display:inline-block; }
#fileInput { display:none; }
.section-block {
background:#1a1a1a; border:1px solid #333;
border-radius:15px; padding:20px; margin-bottom:25px;
}
.section-title {
color:#c22; font-size:20px; margin-bottom:15px;
text-transform:uppercase; letter-spacing:2px;
display:flex; justify-content:space-between; align-items:center;
}
.card-editor {
background:#111; border:1px solid #444;
border-radius:12px; padding:15px; margin-bottom:15px;
}
.card-header {
display:flex; gap:10px; align-items:center; margin-bottom:10px; flex-wrap:wrap;
}
.card-header input {
background:#0a0a0a; border:1px solid #555; color:#fff;
padding:8px; border-radius:8px; font-size:14px;
}
.card-header input[type="text"] { flex:1; min-width:120px; }
.image-input { flex:1; min-width:150px; }
.link-input { flex:1; min-width:150px; }
.delete-card-btn { background:#333; color:#f66; padding:6px 12px; border-radius:20px; font-size:12px; cursor:pointer; }
.timeline-editor { margin-top:10px; padding-left:15px; border-left:2px solid #c22; }
.timeline-entry { display:flex; gap:8px; align-items:center; margin-bottom:8px; flex-wrap:wrap; }
.timeline-entry input {
background:#0a0a0a; border:1px solid #555; color:#fff;
padding:6px; border-radius:6px; font-size:13px;
}
.timeline-entry .date-input { width:110px; }
.timeline-entry .desc-input { flex:1; min-width:150px; }
.add-btn {
background:#2a2a2a; color:#ccc; padding:5px 15px;
border-radius:20px; font-size:12px; cursor:pointer; margin-top:5px;
}
.export-area { margin-top:30px; }
pre {
background:#000; padding:15px; border-radius:10px;
overflow-x:auto; font-size:13px; color:#ccc;
white-space:pre-wrap; border:1px solid #333; max-height:400px;
}
.status-msg { color:#ff4040; margin:10px 0; font-size:14px; }
.img-preview {
width:40px; height:40px; object-fit:cover; border-radius:6px;
margin-left:5px; display:none;
}
</style>
</head>
<body>
<div class="container">
<h1>📁 Projects Editor</h1>
<div class="note">
<strong>📁 Image files:</strong> Place icons inside <code>img/projects/</code>. Enter the file name (e.g. <code>myicon.png</code>) in the "Image" field.<br>
<strong>🔗 Link:</strong> Optional URL – leave empty if none. The card becomes clickable if a link is provided.
</div>
<div class="toolbar">
<label class="file-label" for="fileInput">📂 Load projects.html</label>
<input type="file" id="fileInput" accept=".html">
<button id="addCardBtn">➕ Add Card (first section)</button>
<button id="exportBtn">💾 Export Full HTML</button>
<span class="status-msg" id="statusMsg"></span>
</div>
<div id="editorContainer">
<p style="color:#666;">Load a projects.html file to start editing.</p>
</div>
<div class="export-area" id="exportArea" style="display:none;">
<h3 style="color:#aaa; margin-bottom:10px;">Generated HTML – Copy or Save</h3>
<pre id="exportCode"></pre>
<button id="copyExportBtn">📋 Copy to Clipboard</button>
</div>
</div>
<script>
// ----- STATE -----
let currentSections = null;
let originalHTML = '';
const fileInput = document.getElementById('fileInput');
const editorContainer = document.getElementById('editorContainer');
const exportArea = document.getElementById('exportArea');
const exportCode = document.getElementById('exportCode');
const statusMsg = document.getElementById('statusMsg');
// ----- HELPERS -----
function escapeHtml(text) {
const map = { '&':'&','<':'<','>':'>','"':'"',"'":''' };
return text.replace(/[&<>"']/g, m => map[m]);
}
function isImageFilename(value) {
return value && /\.(png|jpg|jpeg|gif|svg|webp)$/i.test(value.trim());
}
// ----- PARSE projects.html -----
function parseProjectsHTML(htmlString) {
const parser = new DOMParser();
const doc = parser.parseFromString(htmlString, 'text/html');
const sections = [];
const sectionElements = doc.querySelectorAll('.cv-section');
sectionElements.forEach(sec => {
const titleEl = sec.querySelector('.section-title');
if (!titleEl) return;
const title = titleEl.textContent.trim();
if (!['Apps', 'Games', 'Others'].includes(title)) return;
const cards = [];
const cardElements = sec.querySelectorAll('.project-card');
cardElements.forEach(card => {
const id = card.id || '';
const nameEl = card.querySelector('.project-name');
const shortEl = card.querySelector('.project-short');
const iconEl = card.querySelector('.project-icon-placeholder');
const imgEl = card.querySelector('.project-icon img');
const name = nameEl ? nameEl.textContent.trim() : '';
const shortDesc = shortEl ? shortEl.textContent.trim() : '';
// Determine icon value
let icon = '📁';
if (imgEl) {
const src = imgEl.getAttribute('src') || '';
const parts = src.split('/');
icon = parts[parts.length-1];
} else if (iconEl) {
icon = iconEl.textContent.trim();
}
// Check for link: if card is inside an <a>, get href; else look for data-link attribute
let link = card.getAttribute('data-link') || '';
if (!link) {
const parentAnchor = card.closest('a');
if (parentAnchor) link = parentAnchor.getAttribute('href') || '';
}
// parse timeline
const timelineItems = [];
const timelineList = card.querySelector('.project-timeline');
if (timelineList) {
timelineList.querySelectorAll('li').forEach(li => {
const dateSpan = li.querySelector('.timeline-date');
const date = dateSpan ? dateSpan.textContent.trim() : '';
let fullText = li.textContent.trim();
if (dateSpan) fullText = fullText.replace(dateSpan.textContent, '').trim();
timelineItems.push({ date, desc: fullText });
});
}
cards.push({ id, name, icon, shortDesc, link, timelineItems });
});
sections.push({ title, cards });
});
return sections;
}
// ----- RENDER EDITOR FROM STATE -----
function renderEditor() {
editorContainer.innerHTML = '';
currentSections.forEach((section, secIndex) => {
const sectionDiv = document.createElement('div');
sectionDiv.className = 'section-block';
sectionDiv.innerHTML = `
<div class="section-title">
<span>${section.title}</span>
<button class="add-btn" data-section="${secIndex}">+ Add Card to ${section.title}</button>
</div>
<div class="cards-container" data-section-index="${secIndex}"></div>`;
const cardsContainer = sectionDiv.querySelector('.cards-container');
section.cards.forEach((card, cardIndex) => {
cardsContainer.appendChild(createCardEditor(card, secIndex, cardIndex));
});
editorContainer.appendChild(sectionDiv);
});
attachEvents();
}
function createCardEditor(card, secIndex, cardIndex) {
const div = document.createElement('div');
div.className = 'card-editor';
div.setAttribute('data-sec', secIndex);
div.setAttribute('data-card', cardIndex);
div.dataset.origId = card.id;
let previewHtml = '';
if (isImageFilename(card.icon)) {
previewHtml = `<img src="img/projects/${escapeHtml(card.icon)}" class="img-preview" onerror="this.style.display='none'" style="display:inline-block;">`;
}
div.innerHTML = `
<div class="card-header">
<input type="text" class="image-input" value="${escapeHtml(card.icon)}" placeholder="icon.png or emoji">
${previewHtml}
<input type="text" class="name-input" value="${escapeHtml(card.name)}" placeholder="Project Name">
<input type="text" class="short-input" value="${escapeHtml(card.shortDesc)}" placeholder="Short description">
<input type="text" class="link-input" value="${escapeHtml(card.link)}" placeholder="https://link.to/project (optional)">
<button class="delete-card-btn">🗑️ Delete</button>
</div>
<div class="timeline-editor">
<h4 style="color:#aaa; margin-bottom:5px;">Timeline</h4>
<div class="timeline-list">
${card.timelineItems.map((item, ti) => `
<div class="timeline-entry" data-ti="${ti}">
<input type="text" class="date-input" value="${escapeHtml(item.date)}" placeholder="YYYY/M/D">
<input type="text" class="desc-input" value="${escapeHtml(item.desc)}" placeholder="Description">
<button class="delete-btn add-btn" style="background:#333;color:#f66;">✕</button>
</div>
`).join('')}
</div>
<button class="add-btn add-timeline-btn">+ Add Timeline Entry</button>
</div>`;
return div;
}
// ----- COLLECT FORM DATA -----
function collectFormData() {
const sections = [];
document.querySelectorAll('.section-block').forEach(secEl => {
const title = secEl.querySelector('.section-title span').textContent;
const cards = [];
secEl.querySelectorAll('.card-editor').forEach(cardEl => {
const imageInput = cardEl.querySelector('.image-input');
const nameInput = cardEl.querySelector('.name-input');
const shortInput = cardEl.querySelector('.short-input');
const linkInput = cardEl.querySelector('.link-input');
const timelineEntries = [];
cardEl.querySelectorAll('.timeline-entry').forEach(entryEl => {
const dateInput = entryEl.querySelector('.date-input');
const descInput = entryEl.querySelector('.desc-input');
timelineEntries.push({
date: dateInput ? dateInput.value.trim() : '',
desc: descInput ? descInput.value.trim() : ''
});
});
const origId = cardEl.dataset.origId || '';
cards.push({
id: origId || 'proj-' + Math.random().toString(36).substr(2, 9),
name: nameInput ? nameInput.value.trim() : '',
icon: imageInput ? imageInput.value.trim() : '',
shortDesc: shortInput ? shortInput.value.trim() : '',
link: linkInput ? linkInput.value.trim() : '',
timelineItems: timelineEntries
});
});
sections.push({ title, cards });
});
currentSections = sections;
}
// ----- EVENT HANDLING -----
function attachEvents() {
document.querySelectorAll('.delete-card-btn').forEach(btn => {
btn.onclick = (e) => {
const cardEl = e.target.closest('.card-editor');
const secIndex = parseInt(cardEl.dataset.sec);
const cardIndex = parseInt(cardEl.dataset.card);
if (confirm('Delete this card?')) {
currentSections[secIndex].cards.splice(cardIndex, 1);
renderEditor();
}
};
});
document.querySelectorAll('.add-timeline-btn').forEach(btn => {
btn.onclick = (e) => {
const cardEl = e.target.closest('.card-editor');
const secIndex = parseInt(cardEl.dataset.sec);
const cardIndex = parseInt(cardEl.dataset.card);
currentSections[secIndex].cards[cardIndex].timelineItems.push({ date:'', desc:'' });
renderEditor();
};
});
document.querySelectorAll('.timeline-entry .delete-btn').forEach(btn => {
btn.onclick = (e) => {
const entryEl = e.target.closest('.timeline-entry');
const ti = parseInt(entryEl.dataset.ti);
const cardEl = entryEl.closest('.card-editor');
const secIndex = parseInt(cardEl.dataset.sec);
const cardIndex = parseInt(cardEl.dataset.card);
currentSections[secIndex].cards[cardIndex].timelineItems.splice(ti, 1);
renderEditor();
};
});
document.querySelectorAll('[data-section]').forEach(btn => {
btn.onclick = (e) => {
const secIndex = parseInt(btn.dataset.section);
currentSections[secIndex].cards.push({
id: 'new-' + Date.now(),
name: 'New Project',
icon: '',
shortDesc: 'Description',
link: '',
timelineItems: []
});
renderEditor();
};
});
document.querySelectorAll('input').forEach(input => {
input.addEventListener('input', () => collectFormData());
});
}
// ----- EXPORT FULL HTML -----
function generateUpdatedHTML() {
collectFormData();
const parser = new DOMParser();
const doc = parser.parseFromString(originalHTML, 'text/html');
const mainEl = doc.querySelector('.cv-main');
if (!mainEl) { alert('Could not find <main> in original HTML.'); return ''; }
let newContent = '';
currentSections.forEach(sec => {
newContent += `
<section class="cv-section">
<h2 class="section-title">${sec.title}</h2>
<div class="projects-grid">`;
sec.cards.forEach(card => {
// Build icon HTML
let iconHtml = '';
if (isImageFilename(card.icon)) {
iconHtml = `<img src="img/projects/${escapeHtml(card.icon)}" alt="${escapeHtml(card.name)}" style="width:100%; height:100%; object-fit:cover;">`;
} else {
const emoji = card.icon || '📁';
iconHtml = `<div class="project-icon-placeholder">${escapeHtml(emoji)}</div>`;
}
// Build card content
let cardContent = `
<div class="project-icon">
${iconHtml}
</div>
<h3 class="project-name">${escapeHtml(card.name)}</h3>
<p class="project-short">${escapeHtml(card.shortDesc)}</p>
<button class="toggle-expand" data-target="${escapeHtml(card.id)}">Details</button>
<div class="expandable-content" style="display: none;">
<ul class="project-timeline">`;
card.timelineItems.forEach(item => {
if (item.date || item.desc) {
cardContent += `
<li><span class="timeline-date">${escapeHtml(item.date)}</span> ${escapeHtml(item.desc)}</li>`;
}
});
cardContent += `
</ul>
</div>`;
// Wrap in <a> if link exists, else regular div
if (card.link) {
newContent += `
<a href="${escapeHtml(card.link)}" target="_blank" rel="noopener" class="project-card expandable-section" id="${escapeHtml(card.id)}" style="text-decoration:none; color:inherit; display:block;">
${cardContent}
</a>`;
} else {
newContent += `
<div class="project-card expandable-section" id="${escapeHtml(card.id)}">
${cardContent}
</div>`;
}
});
newContent += `
</div>
</section>`;
});
mainEl.innerHTML = newContent;
return '<!DOCTYPE html>\n' + doc.documentElement.outerHTML;
}
function exportHTML() {
const updated = generateUpdatedHTML();
if (!updated) return;
exportCode.textContent = updated;
exportArea.style.display = 'block';
}
// ----- FILE LOADING -----
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (ev) => {
originalHTML = ev.target.result;
currentSections = parseProjectsHTML(originalHTML);
if (currentSections.length === 0) {
statusMsg.textContent = 'No sections found (make sure there are Apps, Games, Others sections).';
} else {
const total = currentSections.reduce((sum, s) => sum + s.cards.length, 0);
statusMsg.textContent = `Loaded ${total} project(s) across ${currentSections.length} sections.`;
renderEditor();
}
};
reader.readAsText(file);
});
document.getElementById('addCardBtn').addEventListener('click', () => {
if (!currentSections || currentSections.length === 0) {
alert('Load a file first.');
return;
}
currentSections[0].cards.push({
id: 'new-' + Date.now(),
name: 'New Project',
icon: '',
shortDesc: 'Description',
link: '',
timelineItems: []
});
renderEditor();
});
document.getElementById('exportBtn').addEventListener('click', exportHTML);
document.getElementById('copyExportBtn').addEventListener('click', () => {
navigator.clipboard.writeText(exportCode.textContent).then(() => {
alert('Copied to clipboard!');
});
});
</script>
</body>
</html>