summaryrefslogtreecommitdiff
path: root/Pages/ViewMedia.razor
blob: 84361594b4b6adb31179c3c5525ad1e9093208ca (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
@page "/ViewMedia"
@inject IDbContextFactory<HBContext> dbFactory
@inject ITagService tagService

<PageTitle>@title</PageTitle>

<link rel="stylesheet" type="text/css" href="@(nameof(HyperBooru)).styles.css"/>

<div id="content">
    <img src="/media/@(media.Guid)"/>
    <div id="metadata">
        <TabContainer>
            <TabPane Title="Media Info">
                <div id="metadata-fileinfo">
                    <p>Title: <i>@(@media.ShortDescription ?? "None")</i></p>
                    <p>Description: <i>@(media.LongDescription ?? "None")</i></p>
                    <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 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=@(() => deleteDialog.Show()) class="warning">Delete</button>
                        <button>Apply</button>
                    </div>
                </div>
            </TabPane>
            <TabPane Title="Tags">
                <div id="metadata-tags">
                    <MediaTagTable Media=media @ref=mediaTagTable/>
                    <div class="button-container">
                        <button @onclick=@(() => tagDialog.Show()) class="secondary">Add Tag</button>
                        @if(media.IsIngest) {
                            <button @onclick=@(() => SetIngest(false))>Mark Tagging Complete</button>
                        } else {
                            <button class="secondary" @onclick=@(() => SetIngest(true))>Mark Tagging Incomplete</button>
                        }
                    </div>
                </div>
            </TabPane>
        </TabContainer>
    </div>
</div>

<Dialog Title="Delete this media?" @ref=deleteDialog>
    <div class="button-container">
        <button class="secondary" @onclick=@(() => deleteDialog.Hide())>Cancel</button>
        <button onclick="deleteMedia()" class="warning">Confirm</button>
    </div>
</Dialog>

<TagSelectDialog
    Title="Select one or more tag(s) to add"
    OnSubmit=AddTags
    @ref=tagDialog/>

@code {
    [Parameter]
    [SupplyParameterFromQuery(Name = "m")]
    public Guid MediaId { get; set; }

    private Media media;

    private string title;

    private bool infoEditMode = false;

    private Dialog          deleteDialog;
    private TagSelectDialog tagDialog;
    private MediaTagTable   mediaTagTable;

    protected override void OnInitialized() {
        using var db = dbFactory.CreateDbContext();
        media = db.Media.AsNoTracking().First(m => m.Guid == MediaId);
        if(media is null)
            throw new ArgumentException("Media not found!");

        title = media.DisplayName ?? "Media View";
    }

    private void AddTags(TagDefinition[] tagDefs) {
        Console.WriteLine($"Adding tags: {string.Join(", ", tagDefs.Select(td => td.Name))}");
        foreach(var tagDef in tagDefs)
            tagService.AddTag(media, tagDef);
        mediaTagTable.Refresh();
    }

    private void SetIngest(bool ingest) {
        StateHasChanged();
    }
}