summaryrefslogtreecommitdiff
path: root/Pages/ViewMedia.cshtml
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2023-08-10 01:56:12 +1000
committerJake Mannens <jake@asger.xyz>2025-08-18 10:59:32 +1000
commit812eae0b5b75f24adebfe6347ecda26c04b8181b (patch)
treee99812d57ef7ae4c8afe9bf83e61ca83ef375b36 /Pages/ViewMedia.cshtml
parent5247aa5a136fcf48d80c8e75625ae773a14fbd26 (diff)
Added ability to tag media
Diffstat (limited to 'Pages/ViewMedia.cshtml')
-rw-r--r--Pages/ViewMedia.cshtml66
1 files changed, 64 insertions, 2 deletions
diff --git a/Pages/ViewMedia.cshtml b/Pages/ViewMedia.cshtml
index 3d0ce4a..e37bbf1 100644
--- a/Pages/ViewMedia.cshtml
+++ b/Pages/ViewMedia.cshtml
@@ -7,8 +7,9 @@
<link rel="stylesheet" type="text/css" href="@(nameof(HyperBooru)).styles.css"/>
<script>
+ var mediaId = new URL(window.location.href).searchParams.get('m');
+
async function deleteMedia() {
- var mediaId = new URL(window.location.href).searchParams.get('m');
var resp = await fetch('/media/' + mediaId, { method: 'delete' });
if(resp.ok) {
window.location.href = '/';
@@ -17,10 +18,44 @@
}
}
+ async function applyTags() {
+ var checkboxes = Array.from(document
+ .getElementById('tag-definitions')
+ .getElementsByTagName('input'));
+
+ var tagDefIds = checkboxes
+ .filter(cb => cb.checked)
+ .map(cb => cb.id.replace(/^tagdef-/, ''));
+
+ var pendingRequests = tagDefIds
+ .map(id => fetch(`/api/tag/${mediaId}/${id}`, { method: 'POST' }));
+
+ var responses = await Promise.all(pendingRequests);
+
+ if(responses.some(r => !r.ok && r.status != 400)) {
+ alert('Error setting tags!');
+ }
+ showTagDialog(false);
+ }
+
+ async function removeTag(e, tagDefId) {
+ var resp = await fetch(`/api/tag/${mediaId}/${tagDefId}`, { method: 'DELETE' });
+ if(!resp.ok && resp.status != 400) {
+ alert('Error removing tag!');
+ } else {
+ e.closest('tr').remove();
+ }
+ }
+
function showDeleteDialog(visible) {
document.getElementById('delete-dialog').classList.toggle('visible', visible);
}
+ function showTagDialog(visible) {
+ document.getElementById('tag-dialog').classList.toggle('visible', visible);
+ document.querySelector('div#tag-dialog input').focus();
+ }
+
function selectPane(tab) {
var tabs = Array.from(document.querySelectorAll('div#metadata-header > a'));
@@ -86,11 +121,22 @@
<div id="metadata-tags">
<table class="data-table">
<tr>
+ <th>Source</th>
+ <th>Namespace</th>
<th>Tag Name</th>
+ <th></th>
</tr>
+ @foreach(var tag in Model.Media.Tags.Select(t => t.TagDefinition)) {
+ <tr>
+ <td>@tag.Source</td>
+ <td>@tag.Namespace</td>
+ <td>@tag.Name</td>
+ <td><a href="javascript:;" onclick="removeTag(this, '@tag.Guid')">Delete</a></td>
+ </tr>
+ }
</table>
<div class="button-container">
- <button>Add Tag</button>
+ <button onclick="showTagDialog(true)">Add Tag</button>
</div>
</div>
</div>
@@ -104,3 +150,19 @@
<button onclick="deleteMedia()">Confirm</button>
</div>
</div>
+
+<div id="tag-dialog" class="dialog">
+ <p>Select one or more tag(s) to add</p>
+ <hr/>
+ <input type="text" placeholder="Search"/>
+ <div id="tag-definitions">
+ @foreach(var tagdef in Model.TagDefinitions) {
+ <input type="checkbox" id="tagdef-@tagdef.Guid"/>
+ <label for="tagdef-@tagdef.Guid">@tagdef.Name</label>
+ }
+ </div>
+ <div class="button-container">
+ <button onclick="showTagDialog(false)" class="secondary">Cancel</button>
+ <button onclick="applyTags()">Accept</button>
+ </div>
+</div>