-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaper.html
More file actions
360 lines (316 loc) · 17.8 KB
/
paper.html
File metadata and controls
360 lines (316 loc) · 17.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ScholarSphere - Details</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/png" href="scholarsphere-icon.png">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</head>
<body>
<div class="container">
<div class="mb-3 d-flex flex-wrap gap-2">
<a href="index.html" class="btn btn-secondary mr-2 mb-2">Read Papers</a>
<a href="unread-papers.html" class="btn btn-primary mr-2 mb-2">Unread Papers</a>
<a href="datasets.html" class="btn btn-warning mr-2 mb-2">Datasets</a>
<a href="useful-links.html" class="btn btn-info mb-2">Useful Links</a>
</div>
<div id="paper-details">
<!-- Paper details will be dynamically loaded here -->
</div>
</div>
<script>
let paperData = null; // Global variable to store the paper data
const DEFAULT_RATING = 3;
function renderStars(rating) {
const safeRating = Math.max(0, Math.min(5, parseInt(rating, 10) || 0));
return safeRating ? '⭐'.repeat(safeRating) : 'Not rated';
}
function normalizeRating(value) {
const parsed = parseInt(value, 10);
if (isNaN(parsed) || parsed < 1) return DEFAULT_RATING;
return Math.max(1, Math.min(5, parsed));
}
async function getFileModificationTime(filePath) {
try {
const response = await fetch(filePath, { method: 'HEAD' });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const lastModified = response.headers.get('last-modified');
return lastModified ? new Date(lastModified).toISOString() : new Date().toISOString();
} catch (error) {
console.error('Error getting file modification time:', error);
return new Date().toISOString();
}
}
async function loadPaperDetails() {
const urlParams = new URLSearchParams(window.location.search);
const paperFile = urlParams.get('file');
if (!paperFile) {
document.getElementById('paper-details').innerHTML = "<p>Paper not found (no file specified).</p>";
return;
}
try {
const decodedPaperFile = decodeURIComponent(paperFile);
const filePath = decodedPaperFile.startsWith('papers/') ? decodedPaperFile : `papers/${decodedPaperFile}`;
const response = await fetch(filePath + '?t=' + Date.now(), { cache: 'no-store' });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
paperData = await response.json(); // Store the loaded data in the global variable
paperData.rating = normalizeRating(paperData.rating);
// Only set addedTime to file modification time if missing
if (!paperData.addedTime) {
paperData.addedTime = await getFileModificationTime(filePath);
}
document.getElementById('paper-details').innerHTML = `
<h1><input type="text" id="title-editor" class="form-control" value="${paperData.title}"></h1>
<p><strong>Created:</strong> ${new Date(paperData.addedTime || Date.now()).toLocaleString()}</p>
${paperData.lastModified ? `<p><strong>Last Modified:</strong> ${new Date(paperData.lastModified).toLocaleString()}</p>` : '<p><strong>Last Modified:</strong> Not available</p>'}
<p><strong>Authors:</strong> <input type="text" id="authors-editor" class="form-control" value="${paperData.authors}"></p>
<p><strong>Conference:</strong> <input type="text" id="conference-editor" class="form-control" value="${paperData.conference}"> (${paperData.year})</p>
<p><strong>Year:</strong> <input type="number" id="year-editor" class="form-control" value="${paperData.year}"></p>
<p><strong>Importance:</strong>
<select id="rating-editor" class="form-control d-inline-block w-auto">
${[1,2,3,4,5].map(r => `<option value="${r}" ${paperData.rating === r ? 'selected' : ''}>${r} star${r > 1 ? 's' : ''}</option>`).join('')}
</select>
<span class="ml-2">${renderStars(paperData.rating)}${paperData.rating ? ` (${paperData.rating}/5)` : ''}</span>
</p>
<p><strong>Keywords:</strong> <input type="text" id="keywords-editor" class="form-control" value="${paperData.keywords.join(', ')}"></p>
<p><strong>Categories:</strong> <input type="text" id="categories-editor" class="form-control" value="${(paperData.categories || []).join(', ')}"></p>
<div class="form-group">
<label for="main-idea-editor">Main Idea:</label>
<textarea id="main-idea-editor" class="form-control">${paperData.mainIdea || ''}</textarea>
</div>
<div class="form-group">
<label for="takeaways-editor">Takeaways:</label>
<textarea id="takeaways-editor" class="form-control">${paperData.takeaways || ''}</textarea>
</div>
<div class="form-group">
<label>Figures:</label>
<div id="figures-container">
${(paperData.figures || []).map((figure, index) => `
<div class="figure-input mb-3 border p-3">
<div class="form-group">
<label>Figure ${index + 1}</label>
<div class="mb-2">
<div class="input-group">
<input type="file" class="form-control" accept="image/*" onchange="handleImageUpload(this, ${index})" />
<div class="input-group-append">
<span class="input-group-text">or paste from clipboard</span>
</div>
</div>
</div>
<div class="mb-2">
<textarea class="form-control figure-description" placeholder="Figure description" rows="2">${figure.description || ''}</textarea>
</div>
<div class="preview-container mb-2">
<img src="${figure.image}" data-fullsrc="${figure.image}" style="max-width: 200px; max-height: 200px; cursor: zoom-in;" class="mb-2 figure-thumbnail" />
<input type="hidden" class="figure-data" value="${figure.image}" />
</div>
<button type="button" class="btn btn-danger btn-sm" onclick="removeFigure(this)">Remove Figure</button>
</div>
</div>
`).join('')}
</div>
<button type="button" class="btn btn-secondary mb-3" onclick="addFigureInput()">Add Figure</button>
<div class="alert alert-info mt-2">
Tip: You can also paste images directly from clipboard into any figure input area.
</div>
</div>
<button onclick="saveChanges('${filePath}')" class="btn btn-primary mt-2">Save Changes</button>
`;
// Initialize figure count
figureCount = (paperData.figures || []).length;
// Add drag and drop handlers to existing figures
document.querySelectorAll('.figure-input').forEach(setupDragAndDrop);
} catch (error) {
console.error(`Error loading paper details:`, error);
document.getElementById('paper-details').innerHTML = `<p>Error loading paper details: ${error}</p>`;
}
}
let figureCount = 0;
// Add clipboard paste event listener to the document
document.addEventListener('paste', function(e) {
// Check if the paste target is within a figure input
const figureInput = e.target.closest('.figure-input');
if (figureInput) {
handleClipboardPaste(e, figureInput);
}
});
function handleClipboardPaste(e, figureInput) {
const items = e.clipboardData.items;
for (let i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
e.preventDefault();
const file = items[i].getAsFile();
const reader = new FileReader();
reader.onload = function(event) {
const previewContainer = figureInput.querySelector('.preview-container');
previewContainer.innerHTML = `
<img src="${event.target.result}" data-fullsrc="${event.target.result}" style="max-width: 200px; max-height: 200px; cursor: zoom-in;" class="mb-2 figure-thumbnail" />
<input type="hidden" class="figure-data" value="${event.target.result}" />
`;
};
reader.readAsDataURL(file);
break;
}
}
}
function setupDragAndDrop(figureDiv) {
figureDiv.addEventListener('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
this.classList.add('border-primary');
});
figureDiv.addEventListener('dragleave', function(e) {
e.preventDefault();
e.stopPropagation();
this.classList.remove('border-primary');
});
figureDiv.addEventListener('drop', function(e) {
e.preventDefault();
e.stopPropagation();
this.classList.remove('border-primary');
const files = e.dataTransfer.files;
if (files.length > 0 && files[0].type.startsWith('image/')) {
const input = this.querySelector('input[type="file"]');
input.files = files;
handleImageUpload(input, Array.from(this.parentNode.children).indexOf(this));
}
});
}
function addFigureInput() {
const container = document.getElementById('figures-container');
const figureDiv = document.createElement('div');
figureDiv.className = 'figure-input mb-3 border p-3';
figureDiv.innerHTML = `
<div class="form-group">
<label>Figure ${figureCount + 1}</label>
<div class="mb-2">
<div class="input-group">
<input type="file" class="form-control" accept="image/*" onchange="handleImageUpload(this, ${figureCount})" />
<div class="input-group-append">
<span class="input-group-text">or paste from clipboard</span>
</div>
</div>
</div>
<div class="mb-2">
<textarea class="form-control figure-description" placeholder="Figure description" rows="2"></textarea>
</div>
<div class="preview-container mb-2"></div>
<button type="button" class="btn btn-danger btn-sm" onclick="removeFigure(this)">Remove Figure</button>
</div>
`;
setupDragAndDrop(figureDiv);
container.appendChild(figureDiv);
figureCount++;
}
function removeFigure(button) {
button.closest('.figure-input').remove();
}
function handleImageUpload(input, index) {
const file = input.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const previewContainer = input.closest('.figure-input').querySelector('.preview-container');
previewContainer.innerHTML = `
<img src="${e.target.result}" data-fullsrc="${e.target.result}" style="max-width: 200px; max-height: 200px; cursor: zoom-in;" class="mb-2 figure-thumbnail" />
<input type="hidden" class="figure-data" value="${e.target.result}" />
`;
};
reader.readAsDataURL(file);
}
}
async function saveChanges(paperFile) {
const title = document.getElementById('title-editor').value;
const authors = document.getElementById('authors-editor').value;
const conference = document.getElementById('conference-editor').value;
const year = document.getElementById('year-editor').value;
const ratingInput = document.getElementById('rating-editor');
const rating = normalizeRating(ratingInput ? ratingInput.value : paperData.rating);
const keywords = document.getElementById('keywords-editor').value.split(',').map(kw => kw.trim());
const categoriesInput = document.getElementById('categories-editor');
const categories = categoriesInput ? categoriesInput.value.split(',').map(c => c.trim()).filter(Boolean) : (paperData.categories || []);
const mainIdea = document.getElementById('main-idea-editor').value;
const takeaways = document.getElementById('takeaways-editor').value;
// Collect figures data
const figures = [];
document.querySelectorAll('.figure-input').forEach(figureDiv => {
const figureData = figureDiv.querySelector('.figure-data');
const description = figureDiv.querySelector('.figure-description').value;
if (figureData && figureData.value) {
figures.push({
image: figureData.value,
description: description || ''
});
}
});
const updatedPaperData = {
title: title,
authors: authors,
conference: conference,
year: parseInt(year),
rating: normalizeRating(rating),
keywords: keywords,
categories: categories,
mainIdea: mainIdea,
takeaways: takeaways,
figures: figures,
addedTime: paperData.addedTime, // Preserve the original creation time
lastModified: new Date().toISOString()
};
const updatedPaperJSON = JSON.stringify(updatedPaperData, null, 2);
const fileNameOnly = (paperFile || '').split('/').pop() || 'paper.json';
download(updatedPaperJSON, fileNameOnly, 'text/json');
alert(`Changes saved! Downloaded ${fileNameOnly}.\n\nSave it into your papers/ directory to apply changes. The page will now reload.`);
location.reload();
}
function download(content, filename, contentType) {
const a = document.createElement('a');
const blob = new Blob([content], { type: contentType });
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
URL.revokeObjectURL(a.href);
}
// Simple lightbox overlay
function ensureLightbox() {
if (document.getElementById('lightbox-overlay')) return;
const overlay = document.createElement('div');
overlay.id = 'lightbox-overlay';
overlay.style.position = 'fixed';
overlay.style.inset = '0';
overlay.style.background = 'rgba(0,0,0,0.8)';
overlay.style.display = 'none';
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.zIndex = '1050';
overlay.innerHTML = '<img id="lightbox-image" style="max-width: 95%; max-height: 95%; box-shadow: 0 0 12px rgba(0,0,0,0.6); cursor: zoom-out;" />';
overlay.addEventListener('click', () => overlay.style.display = 'none');
document.body.appendChild(overlay);
}
function openLightbox(src) {
ensureLightbox();
const overlay = document.getElementById('lightbox-overlay');
const img = document.getElementById('lightbox-image');
img.src = src;
overlay.style.display = 'flex';
}
// Delegate clicks on figure thumbnails to open lightbox
document.addEventListener('click', function(e) {
const img = e.target.closest('img.figure-thumbnail');
if (img) {
e.preventDefault();
e.stopPropagation();
openLightbox(img.getAttribute('data-fullsrc') || img.src);
}
}, true);
loadPaperDetails();
</script>
</body>
</html>