-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-paper.html
More file actions
316 lines (279 loc) · 13.6 KB
/
create-paper.html
File metadata and controls
316 lines (279 loc) · 13.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create New Paper</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">
</head>
<body>
<div class="container">
<h1 class="text-center my-3">Create A New Paper</h1>
<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="topics.html" class="btn btn-dark mr-2 mb-2">Topics</a>
<a href="useful-links.html" class="btn btn-info mb-2">Useful Links</a>
</div>
<form id="new-paper-form" class="mb-3">
<div class="form-group">
<label for="new-title">Title:</label>
<input type="text" class="form-control" id="new-title" required>
</div>
<div class="form-group">
<label for="new-authors">Authors:</label>
<input type="text" class="form-control" id="new-authors" required>
</div>
<div class="form-group">
<label for="new-conference">Conference:</label>
<input type="text" class="form-control" id="new-conference" required>
</div>
<div class="form-group">
<label for="new-year">Year:</label>
<input type="number" class="form-control" id="new-year" required>
</div>
<div class="form-group">
<label for="new-rating">Importance (1-5 stars):</label>
<select class="form-control" id="new-rating" required>
<option value="5">5 - Must-read</option>
<option value="4">4 - Very important</option>
<option value="3" selected>3 - Important</option>
<option value="2">2 - Optional</option>
<option value="1">1 - Low priority</option>
</select>
</div>
<div class="form-group">
<label for="new-keywords">Keywords (comma-separated):</label>
<input type="text" class="form-control" id="new-keywords">
</div>
<div class="form-group">
<label for="new-categories">Categories (comma-separated):</label>
<input type="text" class="form-control" id="new-categories">
</div>
<div class="form-group">
<label for="new-main-idea">Main Idea:</label>
<textarea class="form-control" id="new-main-idea" rows="3"></textarea>
</div>
<div class="form-group">
<label for="new-takeaways">Takeaways:</label>
<textarea class="form-control" id="new-takeaways" rows="3"></textarea>
</div>
<div class="form-group">
<label>Figures:</label>
<div id="figures-container">
<!-- Figures will be added here -->
</div>
<button type="button" class="btn btn-secondary" 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 type="button" onclick="createNewPaper()" class="btn btn-success">Create Paper and Download</button>
</form>
</div>
<script>
let figureCount = 0;
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();
}
}
// 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}" style="max-width: 200px; max-height: 200px;" class="mb-2" />
<input type="hidden" class="figure-data" value="${event.target.result}" />
`;
};
reader.readAsDataURL(file);
break;
}
}
}
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>
`;
// Make the entire figure input div a drop target
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, figureCount);
}
});
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 createNewPaper() {
const title = document.getElementById('new-title').value;
const authors = document.getElementById('new-authors').value;
const conference = document.getElementById('new-conference').value;
const year = document.getElementById('new-year').value;
const rating = parseInt(document.getElementById('new-rating').value, 10);
const keywords = document.getElementById('new-keywords').value.split(',').map(kw => kw.trim());
const categories = document.getElementById('new-categories').value.split(',').map(c => c.trim());
const mainIdea = document.getElementById('new-main-idea').value;
const takeaways = document.getElementById('new-takeaways').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 || ''
});
}
});
if (!title || !authors || !conference || !year) {
alert("Please fill in all required fields.");
return;
}
const paperFileName = title.replace(/[^a-zA-Z0-9]/g, '') + '.json';
const fullPath = `papers/${paperFileName}`;
// Create a timestamp for when the paper is created
const creationTime = new Date().toISOString();
const newPaperData = {
title: title,
authors: authors,
conference: conference,
year: parseInt(year),
rating: rating,
keywords: keywords,
categories: categories,
mainIdea: mainIdea,
takeaways: takeaways,
figures: figures,
addedTime: creationTime // Store the creation timestamp
};
const jsonDataStr = JSON.stringify(newPaperData, null, 2);
// Trigger the download of the new paper JSON file
download(jsonDataStr, paperFileName, 'text/json');
// Alert the user
alert(`New paper created!
1. Download the ${paperFileName} file (download should start automatically)
2. Save it to your papers/ directory
3. Refresh the main page at http://localhost:8001
The paper will be automatically discovered by the dynamic server - no manual configuration needed!`);
}
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {
type: contentType
});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
// 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);
</script>
</body>
</html>