311 lines
20 KiB
Plaintext
311 lines
20 KiB
Plaintext
@model StoryIntelligenceProgressViewModel
|
|
@{
|
|
ViewData["Title"] = "Review locations";
|
|
const int previewLimit = 25;
|
|
var locationCandidates = Model.LocationReview.Candidates.Take(previewLimit).ToList();
|
|
var hiddenCandidateCount = Math.Max(0, Model.LocationReview.PendingCandidateCount - locationCandidates.Count);
|
|
}
|
|
|
|
<section class="onboarding-shell" aria-labelledby="story-location-title">
|
|
<div class="onboarding-panel onboarding-review-panel story-review-page">
|
|
<div class="onboarding-copy story-review-heading">
|
|
<p class="eyebrow">Story Intelligence</p>
|
|
<h1 id="story-location-title">Review Locations</h1>
|
|
<p>Review place suggestions that need a create, same-location, or ignore decision.</p>
|
|
</div>
|
|
|
|
@if (TempData["OnboardingStoryIntelligenceError"] is string error)
|
|
{
|
|
<div class="alert alert-danger">@error</div>
|
|
}
|
|
@if (TempData["OnboardingStoryIntelligenceMessage"] is string message)
|
|
{
|
|
<div class="alert alert-success">@message</div>
|
|
}
|
|
|
|
<section class="story-review-chapter-list" aria-label="Location review">
|
|
@if (Model.LocationReview.Candidates.Count == 0)
|
|
{
|
|
<div class="story-review-note">
|
|
<strong>No location decisions are waiting.</strong>
|
|
<p class="mb-0">Locations are already up to date, or there were no location suggestions ready to import.</p>
|
|
</div>
|
|
<div class="onboarding-actions">
|
|
<a class="btn btn-outline-secondary" asp-action="StoryIntelligenceReviewCentre" asp-route-batchId="@Model.BatchID">Back to Review Centre</a>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="story-review-card-actions">
|
|
<button class="btn btn-outline-secondary btn-sm" type="button" data-location-bulk="link-existing">Use exact matches</button>
|
|
<button class="btn btn-outline-secondary btn-sm" type="button" data-location-bulk="expand">Expand all</button>
|
|
<button class="btn btn-outline-secondary btn-sm" type="button" data-location-bulk="collapse">Collapse all</button>
|
|
@if (hiddenCandidateCount > 0)
|
|
{
|
|
<span class="story-review-page-status">Showing @locationCandidates.Count.ToString("N0") of @Model.LocationReview.PendingCandidateCount.ToString("N0") pending</span>
|
|
}
|
|
</div>
|
|
|
|
<form asp-action="ImportStoryIntelligenceLocations" method="post" data-location-review-form data-story-review-form>
|
|
<input type="hidden" name="BatchID" value="@Model.BatchID" />
|
|
<div class="story-character-card-grid">
|
|
@for (var i = 0; i < locationCandidates.Count; i++)
|
|
{
|
|
var candidate = locationCandidates[i];
|
|
var status = candidate.IsExistingMatch ? "existing" : "new";
|
|
var proposedParentLabel = candidate.ProposedParentLocationName ?? candidate.ParentLocationHint;
|
|
var searchText = string.Join(" ", new[] { candidate.LocationName, candidate.ExistingLocationName, candidate.Category, candidate.ParentLocationHint, candidate.ProposedParentLocationName });
|
|
<details class="story-character-card" open data-location-card data-location-status="@status" data-location-existing-match="@candidate.IsExistingMatch.ToString().ToLowerInvariant()" data-location-search-text="@searchText">
|
|
<summary>
|
|
<span>
|
|
<strong>@candidate.LocationName</strong>
|
|
<small>@candidate.Category · @candidate.AppearsInScenes.ToString("N0") scene@(candidate.AppearsInScenes == 1 ? string.Empty : "s")</small>
|
|
</span>
|
|
<em>@candidate.Confidence</em>
|
|
</summary>
|
|
|
|
<input type="hidden" name="Locations[@i].Key" value="@candidate.Key" />
|
|
|
|
<div class="story-character-card__body" data-location-key="@candidate.Key" data-location-name="@candidate.LocationName">
|
|
<dl>
|
|
<div><dt>First appearance</dt><dd>@Display(candidate.ExampleFirstAppearance)</dd></div>
|
|
<div><dt>Proposed parent</dt><dd>@Display(proposedParentLabel)</dd></div>
|
|
<div><dt>Existing match</dt><dd>@(candidate.ExistingLocationName ?? "None")</dd></div>
|
|
</dl>
|
|
|
|
@if (!string.IsNullOrWhiteSpace(candidate.ExampleContext))
|
|
{
|
|
<div class="story-review-note">
|
|
<strong>Scene context</strong>
|
|
<p>@candidate.ExampleContext</p>
|
|
</div>
|
|
}
|
|
|
|
@if (candidate.EvidenceSummaries.Any())
|
|
{
|
|
<details class="story-review-note">
|
|
<summary>Evidence from @candidate.AppearsInScenes.ToString("N0") scene@(candidate.AppearsInScenes == 1 ? string.Empty : "s")</summary>
|
|
<ul class="mb-0">
|
|
@foreach (var evidence in candidate.EvidenceSummaries)
|
|
{
|
|
<li>@evidence</li>
|
|
}
|
|
</ul>
|
|
</details>
|
|
}
|
|
|
|
@if (candidate.IsExistingMatch)
|
|
{
|
|
<div class="story-review-note">
|
|
<strong>Existing location matched</strong>
|
|
<p>@candidate.LocationName is linked to @candidate.ExistingLocationName. Review only the parent location if needed.</p>
|
|
</div>
|
|
}
|
|
|
|
@if (candidate.IsExistingMatch)
|
|
{
|
|
<input type="hidden" name="Locations[@i].Action" value="@StoryIntelligenceLocationImportActions.LinkExisting" data-location-action />
|
|
<input type="hidden" name="Locations[@i].ExistingLocationID" value="@candidate.ExistingLocationID" />
|
|
}
|
|
else
|
|
{
|
|
<fieldset class="story-character-actions">
|
|
<legend>Decision</legend>
|
|
<label>
|
|
<input type="radio" name="Locations[@i].Action" value="@StoryIntelligenceLocationImportActions.CreateNew" checked="@(candidate.DefaultAction == StoryIntelligenceLocationImportActions.CreateNew)" data-location-action />
|
|
Create new location
|
|
</label>
|
|
<label>
|
|
<input type="radio" name="Locations[@i].Action" value="@StoryIntelligenceLocationImportActions.LinkExisting" checked="@(candidate.DefaultAction == StoryIntelligenceLocationImportActions.LinkExisting)" data-location-action />
|
|
Same location as
|
|
</label>
|
|
<label>
|
|
<input type="radio" name="Locations[@i].Action" value="@StoryIntelligenceLocationImportActions.Ignore" data-location-action />
|
|
Ignore
|
|
</label>
|
|
</fieldset>
|
|
|
|
<div data-location-import-name-panel>
|
|
<label class="form-label" for="location-import-name-@i">Import name</label>
|
|
<input id="location-import-name-@i" class="form-control" name="Locations[@i].ImportName" value="@candidate.ImportName" />
|
|
</div>
|
|
}
|
|
|
|
<div data-location-parent-panel>
|
|
<label class="form-label" for="location-parent-@i">Parent location</label>
|
|
<select id="location-parent-@i" class="form-select" name="Locations[@i].ParentSelection">
|
|
@if (!string.IsNullOrWhiteSpace(proposedParentLabel))
|
|
{
|
|
<option value="__proposed__" selected>Use proposed: @proposedParentLabel</option>
|
|
}
|
|
@if (string.IsNullOrWhiteSpace(proposedParentLabel))
|
|
{
|
|
<option value="__none__" selected>Not determined</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="__none__">Not determined</option>
|
|
}
|
|
@foreach (var parent in Model.LocationReview.ParentLocationOptions)
|
|
{
|
|
@if (candidate.ProposedParentLocationID == parent.LocationID)
|
|
{
|
|
<option value="@parent.LocationID" selected>@parent.DisplayName</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="@parent.LocationID">@parent.DisplayName</option>
|
|
}
|
|
}
|
|
</select>
|
|
</div>
|
|
|
|
@if (!candidate.IsExistingMatch)
|
|
{
|
|
<div data-location-same-panel hidden>
|
|
<label class="form-label" for="location-same-existing-@i">Same location as existing</label>
|
|
<select id="location-same-existing-@i" class="form-select" name="Locations[@i].ExistingLocationID" data-location-existing-target>
|
|
<option value="">Choose existing location...</option>
|
|
@foreach (var target in Model.LocationReview.SameLocationOptions)
|
|
{
|
|
var isSelected = candidate.ExistingLocationID == target.LocationID;
|
|
<option value="@target.LocationID" selected="@isSelected">@target.LocationName@(string.IsNullOrWhiteSpace(target.AliasSummary) ? string.Empty : $" ({target.AliasSummary})")</option>
|
|
}
|
|
</select>
|
|
|
|
<label class="form-label mt-3" for="location-alias-target-@i">Same location as pending candidate</label>
|
|
<select id="location-alias-target-@i" class="form-select" name="Locations[@i].AliasTargetKey" data-location-alias-target>
|
|
<option value="">Choose pending location...</option>
|
|
@foreach (var target in locationCandidates
|
|
.Where(target => !string.Equals(target.Key, candidate.Key, StringComparison.OrdinalIgnoreCase))
|
|
.OrderBy(target => target.LocationName, NaturalStringComparer.OrdinalIgnoreCase))
|
|
{
|
|
<option value="@target.Key">@target.LocationName@(target.IsExistingMatch ? $" -> {target.ExistingLocationName}" : string.Empty)</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
}
|
|
</div>
|
|
</details>
|
|
}
|
|
</div>
|
|
|
|
<div class="onboarding-actions">
|
|
@if (hiddenCandidateCount > 0)
|
|
{
|
|
<span class="text-muted">Save this batch to continue with @hiddenCandidateCount.ToString("N0") more location decision@(hiddenCandidateCount == 1 ? string.Empty : "s").</span>
|
|
}
|
|
<a class="btn btn-outline-secondary" asp-action="StoryIntelligenceReviewCentre" asp-route-batchId="@Model.BatchID">Back to Review Centre</a>
|
|
@if (Model.LocationReview.HasPreviousPage)
|
|
{
|
|
<a class="btn btn-outline-secondary" asp-action="StoryIntelligenceLocations" asp-route-batchId="@Model.BatchID" asp-route-page="@(Model.LocationReview.PageNumber - 1)">Previous</a>
|
|
}
|
|
@if (Model.LocationReview.HasNextPage)
|
|
{
|
|
<a class="btn btn-outline-secondary" asp-action="StoryIntelligenceLocations" asp-route-batchId="@Model.BatchID" asp-route-page="@(Model.LocationReview.PageNumber + 1)">Next</a>
|
|
}
|
|
<button class="btn btn-primary" type="submit" data-busy-label="Saving locations...">Save location decisions</button>
|
|
</div>
|
|
</form>
|
|
}
|
|
</section>
|
|
</div>
|
|
</section>
|
|
|
|
@section Scripts {
|
|
<script>
|
|
(() => {
|
|
const form = document.querySelector("[data-location-review-form]");
|
|
if (!form) return;
|
|
|
|
const cards = () => Array.from(form.querySelectorAll("[data-location-card]"));
|
|
const setAction = (card, action) => {
|
|
const input = card.querySelector(`[data-location-action][value="${action}"]`);
|
|
if (input) {
|
|
input.checked = true;
|
|
updateCard(card);
|
|
}
|
|
};
|
|
const actionFor = (card) => card.querySelector("[data-location-action]:checked")?.value || "@StoryIntelligenceLocationImportActions.CreateNew";
|
|
const isCanonicalTarget = (card) => {
|
|
const action = actionFor(card);
|
|
const pendingTarget = card.querySelector("[data-location-alias-target]")?.value || "";
|
|
return action !== "@StoryIntelligenceLocationImportActions.Ignore"
|
|
&& !pendingTarget;
|
|
};
|
|
const updateAliasTargets = () => {
|
|
const allCards = cards();
|
|
for (const card of allCards) {
|
|
const body = card.querySelector("[data-location-key]");
|
|
const ownKey = body?.getAttribute("data-location-key") || "";
|
|
const select = card.querySelector("[data-location-alias-target]");
|
|
if (!select) continue;
|
|
|
|
const previous = select.value;
|
|
for (const option of Array.from(select.options)) {
|
|
if (!option.value) continue;
|
|
const targetCard = allCards.find(item => item.querySelector("[data-location-key]")?.getAttribute("data-location-key") === option.value);
|
|
option.disabled = option.value === ownKey || !targetCard || !isCanonicalTarget(targetCard);
|
|
}
|
|
if (select.selectedOptions[0]?.disabled) {
|
|
select.value = "";
|
|
} else {
|
|
select.value = previous;
|
|
}
|
|
}
|
|
};
|
|
const updateCard = (card) => {
|
|
const action = actionFor(card);
|
|
const isExistingMatch = card.getAttribute("data-location-existing-match") === "true";
|
|
const namePanel = card.querySelector("[data-location-import-name-panel]");
|
|
const samePanel = card.querySelector("[data-location-same-panel]");
|
|
if (namePanel) namePanel.hidden = action === "@StoryIntelligenceLocationImportActions.Ignore" || action === "@StoryIntelligenceLocationImportActions.LinkExisting";
|
|
const parentPanel = card.querySelector("[data-location-parent-panel]");
|
|
if (parentPanel) parentPanel.hidden = action === "@StoryIntelligenceLocationImportActions.Ignore" || (action === "@StoryIntelligenceLocationImportActions.LinkExisting" && !isExistingMatch);
|
|
if (samePanel) samePanel.hidden = action !== "@StoryIntelligenceLocationImportActions.LinkExisting";
|
|
updateAliasTargets();
|
|
};
|
|
document.querySelectorAll("[data-location-bulk]").forEach(button => {
|
|
button.addEventListener("click", () => {
|
|
const action = button.getAttribute("data-location-bulk");
|
|
if (action === "link-existing") cards().forEach(card => {
|
|
if (card.querySelector("[data-location-existing-target]")?.value) {
|
|
setAction(card, "@StoryIntelligenceLocationImportActions.LinkExisting");
|
|
}
|
|
});
|
|
if (action === "expand") cards().forEach(card => card.open = true);
|
|
if (action === "collapse") cards().forEach(card => card.open = false);
|
|
});
|
|
});
|
|
form.querySelectorAll("[data-location-action]").forEach(input => {
|
|
input.addEventListener("change", () => updateCard(input.closest("[data-location-card]")));
|
|
});
|
|
form.querySelectorAll("[data-location-existing-target]").forEach(select => {
|
|
select.addEventListener("change", () => {
|
|
if (select.value) {
|
|
const card = select.closest("[data-location-card]");
|
|
const pending = card?.querySelector("[data-location-alias-target]");
|
|
if (pending) pending.value = "";
|
|
}
|
|
});
|
|
});
|
|
form.querySelectorAll("[data-location-alias-target]").forEach(select => {
|
|
select.addEventListener("change", () => {
|
|
if (select.value) {
|
|
const card = select.closest("[data-location-card]");
|
|
const existing = card?.querySelector("[data-location-existing-target]");
|
|
if (existing) existing.value = "";
|
|
}
|
|
cards().forEach(updateCard);
|
|
});
|
|
});
|
|
cards().forEach(updateCard);
|
|
})();
|
|
</script>
|
|
<script src="~/js/story-review-actions.js" asp-append-version="true"></script>
|
|
}
|
|
|
|
@functions {
|
|
private static string Display(string? value) => string.IsNullOrWhiteSpace(value) ? "Not detected" : value;
|
|
}
|