More admin change

This commit is contained in:
2024-10-20 16:22:45 -04:00
parent fee6f755a3
commit f435aedf2b
4 changed files with 203 additions and 18 deletions

View File

@ -90,6 +90,31 @@
.logout a:hover {
text-decoration: underline;
}
.editable {
cursor: pointer;
}
.editable:hover {
background-color: #f0f0f0;
}
.editing {
background-color: #fff;
border: 1px solid #ccc;
padding: 2px;
}
.delete-btn {
background-color: #ff4136;
color: white;
border: none;
padding: 0.25rem 0.5rem;
border-radius: 4px;
cursor: pointer;
font-family: inherit;
font-weight: bold;
margin-left: 0.5rem;
}
.delete-btn:hover {
background-color: #ff1a1a;
}
</style>
</head>
<body>
@ -126,23 +151,105 @@
<th>Shutter Speed</th>
<th>ISO</th>
<th>Dimensions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for photo in photos %}
<tr>
<tr data-id="{{ photo.id }}">
<td><img src="{{ url_for('serve_thumbnail', filename=photo.thumbnail_filename) }}" alt="Thumbnail" class="thumbnail"></td>
<td>{{ photo.input_filename }}</td>
<td>{{ photo.date_taken.strftime('%Y-%m-%d %H:%M:%S') }}</td>
<td>{{ photo.focal_length }}</td>
<td>{{ photo.aperture }}</td>
<td>{{ photo.shutter_speed }}</td>
<td>{{ photo.iso }}</td>
<td class="editable" data-field="input_filename">{{ photo.input_filename }}</td>
<td class="editable" data-field="date_taken">{{ photo.date_taken.strftime('%Y-%m-%d %H:%M:%S') }}</td>
<td class="editable" data-field="focal_length">{{ photo.focal_length }}</td>
<td class="editable" data-field="aperture">{{ photo.aperture }}</td>
<td class="editable" data-field="shutter_speed">{{ photo.shutter_speed }}</td>
<td class="editable" data-field="iso">{{ photo.iso }}</td>
<td>{{ photo.width }}x{{ photo.height }}</td>
<td>
<button onclick="saveChanges(this)">Save</button>
<button onclick="deletePhoto(this)" class="delete-btn">Delete</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
function makeEditable(element) {
const value = element.textContent;
const input = document.createElement('input');
input.value = value;
input.classList.add('editing');
element.textContent = '';
element.appendChild(input);
input.focus();
input.addEventListener('blur', function() {
element.textContent = this.value;
element.classList.remove('editing');
});
}
document.querySelectorAll('.editable').forEach(el => {
el.addEventListener('click', function() {
if (!this.classList.contains('editing')) {
makeEditable(this);
}
});
});
function saveChanges(button) {
const row = button.closest('tr');
const photoId = row.dataset.id;
const updatedData = {};
row.querySelectorAll('.editable').forEach(el => {
updatedData[el.dataset.field] = el.textContent;
});
fetch('/admin/update_photo/' + photoId, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedData),
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Changes saved successfully!');
} else {
alert('Error saving changes: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('An error occurred while saving changes.');
});
}
function deletePhoto(button) {
if (confirm('Are you sure you want to delete this photo?')) {
const row = button.closest('tr');
const photoId = row.dataset.id;
fetch('/admin/delete_photo/' + photoId, {
method: 'POST',
})
.then(response => response.json())
.then(data => {
if (data.success) {
row.remove();
alert('Photo deleted successfully!');
} else {
alert('Error deleting photo: ' + data.error);
}
})
.catch((error) => {
console.error('Error:', error);
alert('An error occurred while deleting the photo.');
});
}
}
</script>
</body>
</html>

View File

@ -126,15 +126,8 @@
@media (max-width: 768px) {
body {
flex-direction: column;
}
.sidebar {
width: 100%;
height: auto;
position: static;
padding: 10px;
}
.main-content {
padding: 10px;
}
@ -149,6 +142,18 @@
height: auto;
}
}
@media (max-width: 1024px) {
body {
flex-direction: column;
}
.sidebar {
width: 100%;
height: auto;
position: static;
padding: 10px;
}
}
</style>
</head>
<body>