summaryrefslogtreecommitdiff
path: root/Pages/ViewMedia.cshtml
blob: e77ec22a30a2db1e837d88e31306b09e78a1974d (plain)
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
@page
@model HyperBooru.Pages.ViewMediaModel
@{
    ViewBag.ContentScroll = false;
}

<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 resp = await fetch('/media/' + mediaId, { method: 'delete' });
        if(resp.ok) {
            window.location.href = '/';
        } else {
            alert('Failed to delete media object!');
        }
    }

    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'));

        var panes = Array.from(document.querySelectorAll('div#metadata > div'))
            .filter(x => x.id != 'metadata-header');
        var pane = panes.filter(x => x.id == tab.dataset.pane)[0];

        for(var t of tabs) {
            if(t == tab)
                t.classList.add('selected');
            else
                t.classList.remove('selected');
        }

        for(var p of panes) {
            if(p == pane)
                p.classList.add('selected');
            else
                p.classList.remove('selected');
        }
    }
</script>

<div id="content">
    <img src="/media/@(Model.Media.Guid)"/>
    <div id="metadata">
        <div id="metadata-header">
            <a href="javascript:;" onclick="selectPane(this);" data-pane="metadata-fileinfo" class="selected">File Info</a>
            <a href="javascript:;" onclick="selectPane(this);" data-pane="metadata-tags">Tags</a>
        </div>
@*        <form method="post">
            <label for="shortDescription">Short Description</label>
            <input type="text" name="shortDescription" placeholder="@Model.Media.ShortDescription"/>
            <label for="longDescription">Long Description</label>
            <input type="text" name="longDescription" placeholder="@Model.Media.LongDescription"/>
            <input type="submit" value="Update"/>
        </form>*@
        <div id="metadata-fileinfo" class="selected">
            <p>Upload history</p>
            <hr />
            <table class="data-table">
                <tr>
                    <th>Created On</th>
                    <th>Last Write</th>
                    <th>Uploaded On</th>
                    <th>Filename</th>
                    <th>Original Checksum</th>
                </tr>
                @foreach(var file in Model.Media.UploadedFiles) {
                    <tr>
                        <td>@(file.CreateTime?.ToString() ?? "N/A")</td>
                        <td>@(file.LastWriteTime?.ToString() ?? "N/A")</td>
                        <td>@file.UploadTime</td>
                        <td>@file.Filename</td>
                        <td>@file.OriginalChecksum</td>
                    </tr>
                }
            </table>
            <div class="button-container">
                <button onclick="showDeleteDialog(true)" id="delete-button">Delete</button>
                <button>Apply</button>
            </div>
        </div>
        <div id="metadata-tags">
            <table class="data-table">
                <tr>
                    <th>Namespace</th>
                    <th>Tag Name</th>
                    <th></th>
                </tr>
                @foreach(var tag in Model.UserTags) {
                    bool isImplicit = Model.IsImplicit(tag);
                    <tr>
                        <td>
                            @if(isImplicit) {
                                <i>@tag.Namespace</i>
                            } else {
                                @tag.Namespace
                            }
                        </td>
                        <td>
                            @if(isImplicit) {
                                <i>@tag.Name</i>
                            } else {
                                @tag.Name
                            }
                        </td>
                        <td><a href="javascript:;" onclick="removeTag(this, '@tag.Guid')">Delete</a></td>
                    </tr>
                }
            </table>
            <div class="button-container">
                <button onclick="showTagDialog(true)" class="secondary">Add Tag</button>
                <button onclick="show">Tagging Complete</button>
            </div>
        </div>
    </div>
</div>

<div id="delete-dialog" class="dialog">
    <p>Delete this media?</p>
    <hr/>
    <div class="button-container">
        <button class="secondary" onclick="showDeleteDialog(false)">Cancel</button>
        <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>