115 lines
5.8 KiB
Plaintext
115 lines
5.8 KiB
Plaintext
@using PlotLine.Data
|
|
@model StoryElementReferenceList
|
|
@{
|
|
var scope = Model.Scope;
|
|
var routes = new Dictionary<string, string>
|
|
{
|
|
["entityType"] = scope.EntityType.ToString(),
|
|
["entityId"] = scope.EntityID.ToString()
|
|
};
|
|
var isCharacter = scope.EntityType == StoryElementType.Character;
|
|
}
|
|
<section id="story-element-references" class="list-section mt-3" aria-labelledby="story-element-reference-title"
|
|
data-story-element-references data-project-id="@Model.Access.ProjectID"
|
|
data-refresh-url="@Url.Action("List", "StoryElementReferences", new { entityType = scope.EntityType, entityId = scope.EntityID })">
|
|
<div class="d-flex flex-wrap align-items-center justify-content-between gap-2">
|
|
<h2 id="story-element-reference-title">References</h2>
|
|
<a class="btn btn-outline-secondary btn-sm" asp-controller="@scope.DetailsController" asp-action="Details"
|
|
asp-route-id="@scope.EntityID" asp-fragment="story-element-references">Refresh references</a>
|
|
</div>
|
|
@if (TempData["ReferenceSaved"] is string saved)
|
|
{
|
|
<span hidden data-toast-message="success">@saved</span>
|
|
}
|
|
@if (TempData["ReferenceError"] is string error)
|
|
{
|
|
<p class="alert alert-warning" role="alert">@error</p>
|
|
}
|
|
|
|
@foreach (var kind in new[] { "Characteristic", "Image", "Attachment" })
|
|
{
|
|
var label = kind switch { "Characteristic" => "Key characteristics", "Image" => "Images", _ => "Attachments" };
|
|
if (kind == "Image" && isCharacter)
|
|
{
|
|
<div class="mt-3">
|
|
<h3>@label</h3>
|
|
<a asp-controller="Characters" asp-action="Details" asp-route-id="@scope.EntityID"
|
|
asp-fragment="character-gallery" asp-route-tab="overview" data-open-reference-gallery>Open character gallery</a>
|
|
</div>
|
|
continue;
|
|
}
|
|
|
|
var items = Model.Items.Where(item => item.Kind == kind).ToList();
|
|
<div class="mt-3">
|
|
<h3>@label</h3>
|
|
@if (items.Count == 0)
|
|
{
|
|
<p class="muted">No @label.ToLowerInvariant() yet.</p>
|
|
}
|
|
@foreach (var item in items)
|
|
{
|
|
<article class="border rounded p-2 mb-2">
|
|
@if (item.OriginalFileName is not null)
|
|
{
|
|
var fileUrl = Url.Action("Download", "StoryElementReferences",
|
|
new { entityType = scope.EntityType, entityId = scope.EntityID, referenceId = item.ReferenceID });
|
|
<a href="@fileUrl">
|
|
@if (kind == "Image")
|
|
{
|
|
<img class="d-block rounded" src="@fileUrl" alt="@(item.Note.Length > 0 ? item.Note : item.OriginalFileName)"
|
|
loading="lazy" width="180" />
|
|
}
|
|
@item.OriginalFileName
|
|
</a>
|
|
}
|
|
@if (item.Note.Length > 0)
|
|
{
|
|
<p class="mb-2 text-break">@item.Note</p>
|
|
}
|
|
@if (Model.Access.CanEdit)
|
|
{
|
|
<details>
|
|
<summary>Edit or remove</summary>
|
|
<form asp-controller="StoryElementReferences" asp-action="Change" asp-all-route-data="routes" method="post" data-story-reference-form
|
|
class="mt-2">
|
|
<input type="hidden" name="referenceId" value="@item.ReferenceID" />
|
|
<input type="hidden" name="version" value="@Convert.ToBase64String(item.Version)" />
|
|
<label class="form-label d-block">
|
|
@(kind == "Characteristic" ? "Characteristic" : "Caption")
|
|
<textarea class="form-control" name="note" maxlength="500" rows="2">@item.Note</textarea>
|
|
</label>
|
|
<button class="btn btn-primary btn-sm" name="operation" value="edit">Save</button>
|
|
<button class="btn btn-outline-danger btn-sm" name="operation" value="delete">Remove</button>
|
|
</form>
|
|
</details>
|
|
}
|
|
</article>
|
|
}
|
|
|
|
@if (Model.Access.CanEdit)
|
|
{
|
|
<details>
|
|
<summary>Add @kind.ToLowerInvariant()</summary>
|
|
<form asp-controller="StoryElementReferences" asp-action="Add" asp-all-route-data="routes" method="post" data-story-reference-form
|
|
enctype="multipart/form-data" class="mt-2">
|
|
<input type="hidden" name="kind" value="@kind" />
|
|
@if (kind != "Characteristic")
|
|
{
|
|
<label class="form-label d-block">
|
|
File up to 10 MB
|
|
<input class="form-control" type="file" name="upload" required
|
|
accept="@(kind == "Image" ? "image/png,image/jpeg,image/webp" : null)" />
|
|
</label>
|
|
}
|
|
<label class="form-label d-block">
|
|
@(kind == "Characteristic" ? "Characteristic" : "Caption (optional)")
|
|
<textarea class="form-control" name="note" maxlength="500" rows="2" required="@(kind == "Characteristic")"></textarea>
|
|
</label>
|
|
<button class="btn btn-primary btn-sm">Add @kind.ToLowerInvariant()</button>
|
|
</form>
|
|
</details>
|
|
}
|
|
</div>
|
|
}
|
|
</section>
|