Spaces:
Running
Running
File size: 11,939 Bytes
c001f24 | 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 |
{% extends "base.html" %}
{% block title %}Session Dashboard{% endblock %}
{% block head %}
<style>
.name-column {
word-wrap: break-word;
white-space: normal;
max-width: 250px; /* Default max-width for larger screens */
}
@media (max-width: 768px) { /* For medium and smaller devices */
.name-column {
max-width: 25%; /* No more than 1/4th of the screen */
}
}
.table-responsive {
overflow-x: auto;
}
th:first-child, td:first-child {
position: sticky;
left: 0;
z-index: 2;
background-color: #212529; /* Match table background */
}
th:nth-child(2), td:nth-child(2) {
position: sticky;
left: 40px; /* Adjust based on the width of the first column */
z-index: 2;
background-color: #212529;
}
/* Enhanced table styling */
.table {
--bs-table-bg: transparent;
--bs-table-striped-bg: rgba(255, 255, 255, 0.03);
--bs-table-active-bg: rgba(255, 255, 255, 0.06);
--bs-table-hover-bg: rgba(13, 110, 253, 0.1);
color: #e9ecef;
border-color: #343a40;
}
.table th {
background-color: #212529;
color: #adb5bd;
font-weight: 600;
border-top: none;
}
.table td {
border-color: #343a40;
vertical-align: middle;
}
/* Enhanced badges */
.badge {
font-weight: 500;
padding: 0.5em 0.75em;
}
.badge.bg-success {
background-color: #198754 !important;
color: white;
}
.badge.bg-secondary {
background-color: #6c757d !important;
color: white;
}
/* Enhanced button styling */
.btn-group .btn {
border: 1px solid rgba(255, 255, 255, 0.1) !important;
}
.btn-primary {
background-color: #0d6efd;
border-color: #0d6efd;
}
.btn-primary:hover {
background-color: #0b5ed7;
border-color: #0a58ca;
}
.btn-secondary {
background-color: #6c757d;
border-color: #6c757d;
}
.btn-secondary:hover {
background-color: #5c636a;
border-color: #565e64;
}
.btn-info {
background-color: #17a2b8;
border-color: #17a2b8;
}
.btn-info:hover {
background-color: #138496;
border-color: #117a8b;
}
/* Size column styling */
.size-column {
font-weight: 600;
color: #4db8ff;
}
</style>
{% endblock %}
{% block content %}
<div class="container-fluid mt-4" style="width: 90%; margin: auto;">
<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-3">
<h2>Session Dashboard</h2>
<button id="delete-selected-btn" class="btn btn-danger" style="display: none;">Delete Selected</button>
</div>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th scope="col" style="width: 3%;">S.No.</th>
<th scope="col" style="width: 3%;"><input type="checkbox" id="select-all-checkbox"></th>
<th scope="col" class="name-column">Name</th>
<th scope="col">Created At</th>
<th scope="col">Pages</th>
<th scope="col">Questions</th>
{% if show_size %}
<th scope="col">Size</th>
{% endif %}
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for session in sessions %}
<tr data-session-id="{{ session.id }}">
<td>{{ loop.index }}</td>
<td><input type="checkbox" class="session-checkbox"></td>
<td class="editable-name name-column">
<span class="session-name">{{ session.name or session.original_filename }}</span>
<i class="fas fa-pencil-alt edit-name-icon ms-2" style="cursor: pointer;"></i>
<input type="text" class="form-control form-control-sm d-none" value="{{ session.name or session.original_filename }}">
</td>
<td><span class="badge bg-secondary">{{ session.created_at | humanize }}</span></td>
<td>{{ session.page_count }}</td>
<td>{{ session.question_count }}</td>
{% if show_size %}
<td class="size-column">{{ session.total_size_formatted }}</td>
{% endif %}
<td>
{% if session.persist %}
<span class="badge bg-success">Persisted</span>
{% else %}
<span class="badge bg-secondary">Not Persisted</span>
{% endif %}
</td>
<td>
<div class="btn-group" role="group">
{% if session.session_type == 'color_rm' %}
<a href="{{ url_for('main.color_rm_interface', session_id=session.id, image_index=0) }}" class="btn btn-sm btn-warning text-dark">Color RM</a>
<button class="btn btn-sm btn-info toggle-persist-btn">Toggle Persist</button>
{% if show_size %}
<button class="btn btn-sm btn-warning reduce-space-btn">Reduce Space</button>
{% endif %}
{% else %}
<a href="{{ url_for('main.question_entry_v2', session_id=session.id) }}" class="btn btn-sm btn-primary">View</a>
<a href="{{ url_for('main.crop_interface_v2', session_id=session.id, image_index=0) }}" class="btn btn-sm btn-secondary">Crop</a>
<button class="btn btn-sm btn-info toggle-persist-btn">Toggle Persist</button>
{% if show_size %}
<button class="btn btn-sm btn-warning reduce-space-btn">Reduce Space</button>
{% endif %}
{% endif %}
</div>
</td>
</tr>
{% else %}
{% if show_size %}
<tr>
<td colspan="10" class="text-center">No sessions found.</td>
</tr>
{% else %}
<tr>
<td colspan="9" class="text-center">No sessions found.</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
<script>
$(document).ready(function() {
// Checkbox selection logic
const deleteBtn = $('#delete-selected-btn');
const selectAllCheckbox = $('#select-all-checkbox');
const sessionCheckboxes = $('.session-checkbox');
function toggleDeleteButton() {
const anyChecked = sessionCheckboxes.is(':checked');
deleteBtn.css('display', anyChecked ? 'inline-block' : 'none');
}
selectAllCheckbox.on('change', function() {
sessionCheckboxes.prop('checked', $(this).prop('checked'));
toggleDeleteButton();
});
sessionCheckboxes.on('change', function() {
if (!$(this).prop('checked')) {
selectAllCheckbox.prop('checked', false);
}
toggleDeleteButton();
});
// Batch delete
deleteBtn.on('click', function() {
const selectedIds = [];
sessionCheckboxes.filter(':checked').each(function() {
selectedIds.push($(this).closest('tr').data('session-id'));
});
if (selectedIds.length > 0 && confirm('Are you sure you want to delete the selected sessions?')) {
$.ajax({
url: '/sessions/batch_delete',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ ids: selectedIds }),
success: function(response) {
if (response.success) {
location.reload();
} else {
alert('Error deleting sessions: ' + response.error);
}
}
});
}
});
// Editable name
$('.edit-name-icon').on('click', function() {
const icon = $(this);
const span = icon.prev('.session-name');
const input = icon.next('input');
span.addClass('d-none');
icon.addClass('d-none');
input.removeClass('d-none').focus();
});
$('.editable-name input').on('blur keyup', function(e) {
if (e.type === 'blur' || e.key === 'Enter') {
const input = $(this);
const span = input.siblings('.session-name');
const icon = input.siblings('.edit-name-icon');
const newName = input.val();
const oldName = span.text();
const sessionId = input.closest('tr').data('session-id');
if (newName && newName !== oldName) {
$.ajax({
url: `/rename_session/${sessionId}`,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ new_name: newName }),
success: function(response) {
if (response.success) {
span.text(newName);
} else {
alert('Error renaming session: ' + response.error);
input.val(oldName); // Revert on error
}
}
});
}
input.addClass('d-none');
span.removeClass('d-none');
icon.removeClass('d-none');
}
});
// Toggle persist
$('.toggle-persist-btn').on('click', function() {
const button = $(this);
const sessionId = button.closest('tr').data('session-id');
$.ajax({
url: `/toggle_persist/${sessionId}`,
type: 'POST',
success: function(response) {
if (response.success) {
location.reload(); // Simple reload for now
} else {
alert('Error toggling persistence: ' + response.error);
}
}
});
});
// Reduce space - only bind event if the button exists
{% if show_size %}
$('.reduce-space-btn').on('click', function() {
const button = $(this);
const row = button.closest('tr');
const sessionId = row.data('session-id');
if (confirm('Are you sure you want to reduce space? This will truncate the original page images to save disk space, but you will still be able to view questions and generate reports.')) {
$.ajax({
url: `/sessions/reduce_space/${sessionId}`,
type: 'POST',
success: function(response) {
if (response.success) {
alert(response.message);
// Refresh the page to update the size information
location.reload();
} else {
alert('Error reducing space: ' + response.error);
}
},
error: function(xhr) {
const response = JSON.parse(xhr.responseText);
alert('Error reducing space: ' + response.error);
}
});
}
});
{% endif %}
});
</script>
{% endblock %}
|