183 lines
11 KiB
Plaintext
183 lines
11 KiB
Plaintext
@using PlotLine.Data
|
|
@using PlotLine.Services
|
|
@model StoryElementReferenceWorkspace
|
|
@{
|
|
var references = Model.References;
|
|
var scope = references.Scope;
|
|
var routes = new Dictionary<string, string>
|
|
{
|
|
["entityType"] = scope.EntityType.ToString(),
|
|
["entityId"] = scope.EntityID.ToString()
|
|
};
|
|
var refreshUrl = scope.EntityType == StoryElementType.Character && Model.CharacterGallery is not null
|
|
? Url.Action("Tab", "CharacterWorkspace", new { id = scope.EntityID, tab = "reference" })
|
|
: Url.Action("List", "StoryElementReferences", new { entityType = scope.EntityType, entityId = scope.EntityID });
|
|
string? FileUrl(StoryElementReference item, bool save = false) => Url.Action("Download", "StoryElementReferences",
|
|
new { entityType = scope.EntityType, entityId = scope.EntityID, referenceId = item.ReferenceID, save });
|
|
var editable = references.Access.CanEdit;
|
|
var attachmentsOnly = scope.AttachmentsOnly;
|
|
var attachmentId = $"reference-attachments-{scope.EntityType}-{scope.EntityID}";
|
|
var tabs = new[] { "Images", "Audio", "Documents" };
|
|
var primary = references.Items.FirstOrDefault(item => item.IsPrimary);
|
|
}
|
|
<section id="@(scope.EntityType is StoryElementType.Chapter or StoryElementType.Scene ? $"intent-references-{scope.EntityType}-{scope.EntityID}" : "story-element-references")" class="reference-workspace"
|
|
data-story-element-references data-project-id="@references.Access.ProjectID"
|
|
data-reference-key="@scope.EntityType-@scope.EntityID" data-refresh-url="@refreshUrl"
|
|
data-primary-image="@(primary is null ? null : FileUrl(primary))"
|
|
aria-label="Reference workspace">
|
|
@if (TempData["ReferenceSaved"] is string saved)
|
|
{
|
|
<span hidden data-toast-message="success">@saved</span>
|
|
}
|
|
@if (scope.EntityType == StoryElementType.Asset && TempData["AssetImageSaved"] is string legacySaved)
|
|
{
|
|
<span hidden data-toast-message="success">@legacySaved</span>
|
|
}
|
|
@if (scope.EntityType == StoryElementType.Asset && TempData["ImageError"] is string legacyError)
|
|
{
|
|
<p class="alert alert-warning" role="alert">@legacyError</p>
|
|
}
|
|
<p class="alert alert-warning" role="alert" data-reference-error hidden="@(TempData.Peek("ReferenceError") is null)">@TempData["ReferenceError"]</p>
|
|
<div class="@(attachmentsOnly ? "mt-3" : "reference-workspace__panes")">
|
|
@if (!attachmentsOnly)
|
|
{
|
|
<section class="reference-workspace__pane" data-reference-scroll aria-labelledby="reference-characteristics">
|
|
<h2 id="reference-characteristics">Key characteristics</h2>
|
|
@if (editable)
|
|
{
|
|
<form asp-controller="StoryElementReferences" asp-action="Add" asp-all-route-data="routes" method="post"
|
|
data-story-reference-form class="reference-workspace__quick-add">
|
|
<input type="hidden" name="kind" value="Characteristic" />
|
|
<input class="form-control form-control-sm" name="note" placeholder="Add a characteristic"
|
|
aria-label="New characteristic" maxlength="500" required />
|
|
<button class="btn btn-primary btn-sm">Add</button>
|
|
</form>
|
|
}
|
|
@foreach (var item in references.Items.Where(item => item.Kind == "Characteristic"))
|
|
{
|
|
<article class="reference-workspace__row">
|
|
<span class="text-break">@item.Note</span>
|
|
@if (editable)
|
|
{
|
|
<partial name="Components/StoryElementReferences/_ReferenceActions" model="(item, routes)" />
|
|
}
|
|
</article>
|
|
}
|
|
@if (!references.Items.Any(item => item.Kind == "Characteristic"))
|
|
{
|
|
<p class="muted small">No characteristics yet.</p>
|
|
}
|
|
</section>
|
|
<div class="reference-workspace__divider" role="separator" aria-label="Resize characteristics"
|
|
aria-orientation="vertical" tabindex="0" aria-valuemin="25" aria-valuemax="70"
|
|
aria-valuenow="40" data-reference-divider></div>
|
|
}
|
|
<section class="reference-workspace__pane" data-reference-scroll aria-labelledby="@attachmentId">
|
|
<div class="d-flex flex-wrap align-items-baseline justify-content-between gap-2">
|
|
<h2 id="@attachmentId">Attachments</h2>
|
|
@if (Model.Storage is not null)
|
|
{
|
|
<small class="muted" title="Account storage used and subscription allowance">Storage @Model.Storage.DisplayLabel</small>
|
|
}
|
|
</div>
|
|
<div class="reference-workspace__tabs" role="tablist" aria-label="Attachment type">
|
|
@foreach (var tab in tabs)
|
|
{
|
|
<button type="button" class="btn btn-sm" role="tab" id="@(attachmentId + "-tab-" + tab)"
|
|
aria-controls="@(attachmentId + "-panel-" + tab)" aria-selected="@(tab == "Images" ? "true" : "false")"
|
|
tabindex="@(tab == "Images" ? 0 : -1)" data-reference-tab="@tab">@tab</button>
|
|
}
|
|
</div>
|
|
@foreach (var tab in tabs)
|
|
{
|
|
var items = references.Items.Where(item => item.Kind != "Characteristic" &&
|
|
tab == (item.Kind == "Image" ? "Images" :
|
|
StoryElementAttachmentPolicy.AudioType(item.OriginalFileName ?? "") is not null ? "Audio" : "Documents")).ToList();
|
|
<section role="tabpanel" id="@(attachmentId + "-panel-" + tab)" aria-labelledby="@(attachmentId + "-tab-" + tab)"
|
|
data-reference-tab-panel="@tab" hidden="@(tab != "Images")">
|
|
@if (editable)
|
|
{
|
|
<form asp-controller="StoryElementReferences" asp-action="Add" asp-all-route-data="routes" method="post"
|
|
enctype="multipart/form-data" class="reference-workspace__drop" data-story-reference-form data-reference-upload>
|
|
<label class="form-label mb-0">
|
|
Drop files here or browse <small class="muted">(up to 10 MB each)</small>
|
|
<input class="form-control form-control-sm" type="file" name="upload"
|
|
accept="@StoryElementAttachmentPolicy.AcceptedExtensions" required />
|
|
</label>
|
|
<button class="btn btn-primary btn-sm">Upload</button>
|
|
</form>
|
|
}
|
|
@if (tab == "Images" && Model.CharacterGallery is not null)
|
|
{
|
|
<div id="character-gallery" data-workspace-gallery data-gallery-content>
|
|
<partial name="/Views/Characters/_WorkspaceGallery.cshtml" model="Model.CharacterGallery" />
|
|
@if (Model.GalleryPages > 1)
|
|
{
|
|
<button type="button" class="btn btn-outline-secondary btn-sm" data-gallery-page="2">More gallery images</button>
|
|
}
|
|
</div>
|
|
}
|
|
@if (tab == "Images" && references.Access.LegacyImagePath is string legacyImage)
|
|
{
|
|
<article class="reference-workspace__row">
|
|
<a href="@legacyImage" target="_blank" rel="noopener">
|
|
<img class="reference-workspace__preview" src="@legacyImage" alt="Existing asset image" loading="lazy" />
|
|
</a>
|
|
<span>@(primary is null ? "Primary image" : "Previous asset image")</span>
|
|
@if (editable)
|
|
{
|
|
<form asp-controller="StoryAssets" asp-action="SaveImage" asp-route-id="@scope.EntityID" method="post">
|
|
<button class="btn btn-outline-danger btn-sm" name="operation" value="remove">Remove</button>
|
|
</form>
|
|
}
|
|
</article>
|
|
}
|
|
@if (items.Count == 0 && (tab != "Images" || Model.CharacterGallery is null && references.Access.LegacyImagePath is null))
|
|
{
|
|
<p class="muted small mt-2">No @tab.ToLowerInvariant() yet.</p>
|
|
}
|
|
<div class="@(tab == "Images" ? "reference-workspace__gallery" : null)">
|
|
@foreach (var item in items)
|
|
{
|
|
var url = FileUrl(item);
|
|
<article class="reference-workspace__file">
|
|
@if (tab == "Images")
|
|
{
|
|
<a href="@url" target="_blank" rel="noopener">
|
|
<img class="reference-workspace__preview" src="@url" alt="@(item.Note.Length > 0 ? item.Note : item.OriginalFileName)" loading="lazy" />
|
|
</a>
|
|
}
|
|
<strong class="text-break">@(item.Title ?? item.OriginalFileName)</strong>
|
|
@if (item.IsPrimary)
|
|
{
|
|
<small class="muted">Primary image</small>
|
|
}
|
|
@if (item.Note.Length > 0)
|
|
{
|
|
<p class="mb-1 text-break">@item.Note</p>
|
|
}
|
|
@if (tab == "Audio")
|
|
{
|
|
<audio controls preload="none" src="@url">Use Download to play this file.</audio>
|
|
}
|
|
<div class="d-flex align-items-center flex-wrap gap-2">
|
|
@if (tab == "Documents")
|
|
{
|
|
<a href="@url" target="_blank" rel="noopener">Open</a>
|
|
}
|
|
<a href="@FileUrl(item, true)">Download</a>
|
|
<button type="button" class="btn btn-outline-secondary btn-sm" data-reference-copy="@url" hidden>Copy link</button>
|
|
@if (editable)
|
|
{
|
|
<partial name="Components/StoryElementReferences/_ReferenceActions" model="(item, routes)" />
|
|
}
|
|
</div>
|
|
</article>
|
|
}
|
|
</div>
|
|
</section>
|
|
}
|
|
</section>
|
|
</div>
|
|
</section>
|