-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_packages.html
More file actions
394 lines (338 loc) · 11.9 KB
/
data_packages.html
File metadata and controls
394 lines (338 loc) · 11.9 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
{% extends "base.html" %}
{% block title %}Data Packages - CoT Server Admin{% endblock %}
{% block content %}
<h1 style="margin-bottom: 2rem;">📦 Data Packages</h1>
<div class="card">
<h2>Upload Data Package</h2>
<p style="color: #666; margin-bottom: 1rem;">
Upload data packages (.zip or .dpk) containing maps, overlays, configurations, or other resources for TAK clients.
</p>
<div class="upload-area" id="uploadArea">
<div class="upload-icon">📁</div>
<p>Drag and drop a file here, or click to select</p>
<p style="font-size: 0.85rem; color: #888;">Supported formats: .zip, .dpk (max 100MB)</p>
<input type="file" id="fileInput" accept=".zip,.dpk" style="display: none;">
</div>
<div id="uploadProgress" style="display: none; margin-top: 1rem;">
<div class="progress-bar">
<div class="progress-fill" id="progressFill"></div>
</div>
<p id="uploadStatus" style="text-align: center; margin-top: 0.5rem;"></p>
</div>
</div>
<div class="card">
<h2>Available Packages</h2>
<div id="packagesList">
<div class="loading">Loading packages...</div>
</div>
</div>
<!-- Package Details Modal -->
<div id="packageModal" class="modal">
<div class="modal-content" style="max-width: 600px;">
<h3 id="modalPackageName">Package Contents</h3>
<div id="packageContents" style="max-height: 400px; overflow-y: auto; margin: 1rem 0;">
<div class="loading">Loading contents...</div>
</div>
<div class="modal-actions">
<button class="btn" onclick="hideModal('packageModal')">Close</button>
</div>
</div>
</div>
<style>
.upload-area {
border: 2px dashed #ccc;
border-radius: 8px;
padding: 3rem;
text-align: center;
cursor: pointer;
transition: all 0.3s;
background: #fafafa;
}
.upload-area:hover,
.upload-area.dragover {
border-color: #667eea;
background: #f0f3ff;
}
.upload-icon {
font-size: 3rem;
margin-bottom: 1rem;
}
.progress-bar {
height: 8px;
background: #e0e0e0;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #667eea, #764ba2);
width: 0%;
transition: width 0.3s;
}
.package-item {
display: flex;
align-items: center;
padding: 1rem;
border-bottom: 1px solid #eee;
transition: background 0.2s;
}
.package-item:hover {
background: #f8f9fa;
}
.package-item:last-child {
border-bottom: none;
}
.package-icon {
font-size: 2rem;
margin-right: 1rem;
}
.package-info {
flex: 1;
}
.package-name {
font-weight: 600;
color: #333;
margin-bottom: 0.25rem;
}
.package-meta {
font-size: 0.85rem;
color: #666;
}
.package-actions {
display: flex;
gap: 0.5rem;
}
.btn-icon {
padding: 0.5rem;
border: none;
background: #f0f0f0;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
transition: all 0.2s;
}
.btn-icon:hover {
background: #e0e0e0;
}
.btn-icon.danger:hover {
background: #ffe0e0;
color: #d32f2f;
}
.empty-state {
text-align: center;
padding: 3rem;
color: #888;
}
.empty-state-icon {
font-size: 4rem;
margin-bottom: 1rem;
}
.file-list {
font-family: monospace;
font-size: 0.85rem;
background: #f5f5f5;
padding: 0.5rem;
border-radius: 4px;
}
.file-list-item {
padding: 0.25rem 0.5rem;
border-bottom: 1px solid #e0e0e0;
}
.file-list-item:last-child {
border-bottom: none;
}
.file-list-item.directory {
color: #1976d2;
font-weight: 600;
}
</style>
<script>
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const uploadProgress = document.getElementById('uploadProgress');
const progressFill = document.getElementById('progressFill');
const uploadStatus = document.getElementById('uploadStatus');
// Load packages on page load
document.addEventListener('DOMContentLoaded', loadPackages);
// Upload area click handler
uploadArea.addEventListener('click', () => fileInput.click());
// Drag and drop handlers
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
uploadFile(files[0]);
}
});
// File input change handler
fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
uploadFile(e.target.files[0]);
}
});
function uploadFile(file) {
// Validate file type
const validTypes = ['.zip', '.dpk'];
const ext = '.' + file.name.split('.').pop().toLowerCase();
if (!validTypes.includes(ext)) {
showAlert('Invalid file type. Only .zip and .dpk files allowed.', 'error');
return;
}
// Validate file size (100MB max)
if (file.size > 100 * 1024 * 1024) {
showAlert('File too large. Maximum size is 100MB.', 'error');
return;
}
const formData = new FormData();
formData.append('file', file);
uploadProgress.style.display = 'block';
progressFill.style.width = '0%';
uploadStatus.textContent = 'Uploading...';
const xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', (e) => {
if (e.lengthComputable) {
const percent = (e.loaded / e.total) * 100;
progressFill.style.width = percent + '%';
uploadStatus.textContent = `Uploading... ${Math.round(percent)}%`;
}
});
xhr.addEventListener('load', () => {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
if (response.success) {
showAlert(`Package uploaded: ${response.filename}`, 'success');
loadPackages();
} else {
showAlert(response.error || 'Upload failed', 'error');
}
} else {
showAlert('Upload failed', 'error');
}
uploadProgress.style.display = 'none';
fileInput.value = '';
});
xhr.addEventListener('error', () => {
showAlert('Upload failed - network error', 'error');
uploadProgress.style.display = 'none';
});
xhr.open('POST', '/api/data-packages/upload');
xhr.send(formData);
}
function loadPackages() {
fetch('/api/data-packages/list')
.then(r => r.json())
.then(data => {
if (data.success) {
renderPackages(data.packages);
} else {
document.getElementById('packagesList').innerHTML =
'<div class="alert alert-error">Failed to load packages</div>';
}
})
.catch(err => {
document.getElementById('packagesList').innerHTML =
'<div class="alert alert-error">Error loading packages</div>';
});
}
function renderPackages(packages) {
const container = document.getElementById('packagesList');
if (packages.length === 0) {
container.innerHTML = `
<div class="empty-state">
<div class="empty-state-icon">📦</div>
<p>No data packages uploaded yet</p>
<p style="font-size: 0.9rem;">Upload a .zip or .dpk file to get started</p>
</div>
`;
return;
}
let html = '';
packages.forEach(pkg => {
const date = new Date(pkg.modified).toLocaleString();
html += `
<div class="package-item">
<div class="package-icon">📦</div>
<div class="package-info">
<div class="package-name">${pkg.filename}</div>
<div class="package-meta">
${pkg.size_human} • ${pkg.file_count} files • ${date}
</div>
</div>
<div class="package-actions">
<button class="btn-icon" onclick="viewPackage('${pkg.filename}')" title="View Contents">
📋
</button>
<button class="btn-icon" onclick="downloadPackage('${pkg.filename}')" title="Download">
⬇️
</button>
<button class="btn-icon danger" onclick="deletePackage('${pkg.filename}')" title="Delete">
🗑️
</button>
</div>
</div>
`;
});
container.innerHTML = html;
}
function viewPackage(filename) {
document.getElementById('modalPackageName').textContent = filename;
document.getElementById('packageContents').innerHTML = '<div class="loading">Loading...</div>';
showModal('packageModal');
fetch(`/api/data-packages/contents/${encodeURIComponent(filename)}`)
.then(r => r.json())
.then(data => {
if (data.success) {
let html = '<div class="file-list">';
data.contents.forEach(file => {
const icon = file.is_dir ? '📁' : '📄';
const cls = file.is_dir ? 'directory' : '';
const size = file.is_dir ? '' : ` (${formatSize(file.size)})`;
html += `<div class="file-list-item ${cls}">${icon} ${file.name}${size}</div>`;
});
html += '</div>';
document.getElementById('packageContents').innerHTML = html;
} else {
document.getElementById('packageContents').innerHTML =
'<div class="alert alert-error">' + data.error + '</div>';
}
});
}
function downloadPackage(filename) {
window.location.href = `/api/data-packages/download/${encodeURIComponent(filename)}`;
}
function deletePackage(filename) {
if (!confirm(`Delete package "${filename}"?\n\nThis cannot be undone.`)) {
return;
}
fetch(`/api/data-packages/delete/${encodeURIComponent(filename)}`, {
method: 'DELETE'
})
.then(r => r.json())
.then(data => {
if (data.success) {
showAlert('Package deleted', 'success');
loadPackages();
} else {
showAlert(data.error || 'Delete failed', 'error');
}
});
}
function formatSize(bytes) {
const units = ['B', 'KB', 'MB', 'GB'];
let i = 0;
while (bytes >= 1024 && i < units.length - 1) {
bytes /= 1024;
i++;
}
return bytes.toFixed(1) + ' ' + units[i];
}
</script>
{% endblock %}