revamp
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
}
|
||||
|
||||
<h1>Create Page From Template</h1>
|
||||
<p>Creates a new managed page by copying content and schedule fields from an existing page.</p>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
@@ -14,15 +15,15 @@
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.NewName" class="form-label"></label>
|
||||
<input asp-for="Input.NewName" class="form-control" />
|
||||
<span asp-validation-for="Input.NewName" class="text-danger"></span>
|
||||
<label asp-for="Input.NewKey" class="form-label"></label>
|
||||
<input asp-for="Input.NewKey" class="form-control" />
|
||||
<span asp-validation-for="Input.NewKey" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.NewTitle" class="form-label"></label>
|
||||
<input asp-for="Input.NewTitle" class="form-control" />
|
||||
<span asp-validation-for="Input.NewTitle" class="text-danger"></span>
|
||||
<label asp-for="Input.DisplayName" class="form-label"></label>
|
||||
<input asp-for="Input.DisplayName" class="form-control" />
|
||||
<span asp-validation-for="Input.DisplayName" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Create</button>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using maintenance.Data;
|
||||
using maintenance.Data.Entities;
|
||||
using maintenance.Services.Pages;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
@@ -30,15 +32,15 @@ public sealed class CreateModel : PageModel
|
||||
public Guid SourceTemplateId { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(50, MinimumLength = 2)]
|
||||
[StringLength(100, MinimumLength = 3)]
|
||||
[RegularExpression("^[a-z0-9-]+$")]
|
||||
[Display(Name = "New Template Name")]
|
||||
public string NewName { get; set; } = string.Empty;
|
||||
[Display(Name = "Page Key")]
|
||||
public string NewKey { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[StringLength(200)]
|
||||
[Display(Name = "New Template Title")]
|
||||
public string NewTitle { get; set; } = string.Empty;
|
||||
[Display(Name = "Display Name")]
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
@@ -55,38 +57,45 @@ public sealed class CreateModel : PageModel
|
||||
return Page();
|
||||
}
|
||||
|
||||
var source = await _dbContext.Templates
|
||||
var source = await _dbContext.ManagedPages
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == Input.SourceTemplateId, HttpContext.RequestAborted);
|
||||
|
||||
if (source is null)
|
||||
{
|
||||
ModelState.AddModelError(nameof(Input.SourceTemplateId), "Source template was not found.");
|
||||
ModelState.AddModelError(nameof(Input.SourceTemplateId), "Source page was not found.");
|
||||
return Page();
|
||||
}
|
||||
|
||||
var normalizedName = Input.NewName.Trim().ToLowerInvariant();
|
||||
var exists = await _dbContext.Templates
|
||||
.AnyAsync(t => t.Name == normalizedName, HttpContext.RequestAborted);
|
||||
var normalizedKey = Input.NewKey.Trim().ToLowerInvariant();
|
||||
var exists = await _dbContext.ManagedPages
|
||||
.AnyAsync(t => t.Key == normalizedKey, HttpContext.RequestAborted);
|
||||
|
||||
if (exists)
|
||||
{
|
||||
ModelState.AddModelError(nameof(Input.NewName), "A template with this name already exists.");
|
||||
ModelState.AddModelError(nameof(Input.NewKey), "A page with this key already exists.");
|
||||
return Page();
|
||||
}
|
||||
|
||||
var clone = new TemplateEntity
|
||||
var clone = new ManagedPageEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = normalizedName,
|
||||
Title = Input.NewTitle.Trim(),
|
||||
Body = source.Body,
|
||||
SupportContactBlock = source.SupportContactBlock,
|
||||
Key = normalizedKey,
|
||||
DisplayName = Input.DisplayName.Trim(),
|
||||
PageKind = source.PageKind,
|
||||
IsDefaultFallback = false,
|
||||
IsEnabled = false,
|
||||
OverrideWindow = false,
|
||||
Priority = source.Priority,
|
||||
StartUtc = source.StartUtc,
|
||||
EndUtc = source.EndUtc,
|
||||
RecurrenceRule = source.RecurrenceRule,
|
||||
ContentJson = CloneJson(source.ContentJson),
|
||||
LastUpdatedBy = User.Identity?.Name ?? "unknown",
|
||||
LastUpdatedAtUtc = DateTime.UtcNow
|
||||
};
|
||||
|
||||
_dbContext.Templates.Add(clone);
|
||||
_dbContext.ManagedPages.Add(clone);
|
||||
await _dbContext.SaveChangesAsync(HttpContext.RequestAborted);
|
||||
|
||||
return RedirectToPage("./Edit", new { id = clone.Id });
|
||||
@@ -94,14 +103,28 @@ public sealed class CreateModel : PageModel
|
||||
|
||||
private async Task LoadSourcesAsync()
|
||||
{
|
||||
SourceTemplates = await _dbContext.Templates
|
||||
SourceTemplates = await _dbContext.ManagedPages
|
||||
.AsNoTracking()
|
||||
.OrderBy(t => t.Name)
|
||||
.OrderBy(t => t.PageKind)
|
||||
.ThenBy(t => t.Key)
|
||||
.Select(t => new SelectListItem
|
||||
{
|
||||
Value = t.Id.ToString(),
|
||||
Text = $"{t.Name} ({t.Title})"
|
||||
Text = $"{t.PageKind} - {t.Key}"
|
||||
})
|
||||
.ToListAsync(HttpContext.RequestAborted);
|
||||
}
|
||||
|
||||
private static string CloneJson(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var model = JsonSerializer.Deserialize<PageContentModel>(json) ?? new PageContentModel();
|
||||
return JsonSerializer.Serialize(model);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return JsonSerializer.Serialize(new PageContentModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,120 @@
|
||||
@page "{id:guid}"
|
||||
@model maintenance.Pages.Admin.Templates.EditModel
|
||||
@{
|
||||
ViewData["Title"] = "Edit Template";
|
||||
ViewData["Title"] = "Edit Page";
|
||||
}
|
||||
|
||||
<h1>Edit Template</h1>
|
||||
<h1>Edit Page</h1>
|
||||
<p><a href="@Model.PreviewUrl" target="_blank" rel="noopener">Preview this page</a></p>
|
||||
|
||||
<form method="post">
|
||||
<input asp-for="Input.Id" type="hidden" />
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.Name" class="form-label"></label>
|
||||
<input asp-for="Input.Name" class="form-control" readonly />
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label asp-for="Input.Key" class="form-label"></label>
|
||||
<input asp-for="Input.Key" class="form-control" readonly />
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label asp-for="Input.DisplayName" class="form-label"></label>
|
||||
<input asp-for="Input.DisplayName" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.Title" class="form-label"></label>
|
||||
<input asp-for="Input.Title" class="form-control" />
|
||||
<span asp-validation-for="Input.Title" class="text-danger"></span>
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label asp-for="Input.PageKind" class="form-label"></label>
|
||||
<select asp-for="Input.PageKind" class="form-select">
|
||||
<option value="maintenance">maintenance</option>
|
||||
<option value="error">error</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label asp-for="Input.Priority" class="form-label"></label>
|
||||
<input asp-for="Input.Priority" class="form-control" type="number" />
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label asp-for="Input.RecurrenceRule" class="form-label"></label>
|
||||
<input asp-for="Input.RecurrenceRule" class="form-control" placeholder="cron-like (future)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.Body" class="form-label"></label>
|
||||
<textarea asp-for="Input.Body" class="form-control" rows="5"></textarea>
|
||||
<span asp-validation-for="Input.Body" class="text-danger"></span>
|
||||
<div class="row">
|
||||
<div class="col-md-3 form-check mb-3">
|
||||
<input asp-for="Input.IsEnabled" class="form-check-input" />
|
||||
<label asp-for="Input.IsEnabled" class="form-check-label"></label>
|
||||
</div>
|
||||
<div class="col-md-3 form-check mb-3">
|
||||
<input asp-for="Input.IsDefaultFallback" class="form-check-input" />
|
||||
<label asp-for="Input.IsDefaultFallback" class="form-check-label"></label>
|
||||
</div>
|
||||
<div class="col-md-3 form-check mb-3">
|
||||
<input asp-for="Input.OverrideWindow" class="form-check-input" />
|
||||
<label asp-for="Input.OverrideWindow" class="form-check-label"></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label asp-for="Input.StartUtc" class="form-label"></label>
|
||||
<input asp-for="Input.StartUtc" class="form-control" type="datetime-local" />
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label asp-for="Input.EndUtc" class="form-label"></label>
|
||||
<input asp-for="Input.EndUtc" class="form-control" type="datetime-local" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
<h4>Page Content (Template Slots)</h4>
|
||||
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.SupportContactBlock" class="form-label"></label>
|
||||
<textarea asp-for="Input.SupportContactBlock" class="form-control" rows="6"></textarea>
|
||||
<span asp-validation-for="Input.SupportContactBlock" class="text-danger"></span>
|
||||
<label asp-for="Input.ErrorName" class="form-label"></label>
|
||||
<input asp-for="Input.ErrorName" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.ShortDescription" class="form-label"></label>
|
||||
<input asp-for="Input.ShortDescription" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.Description" class="form-label"></label>
|
||||
<textarea asp-for="Input.Description" class="form-control" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.InstructionsHeader" class="form-label"></label>
|
||||
<input asp-for="Input.InstructionsHeader" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.InstructionSteps" class="form-label"></label>
|
||||
<input asp-for="Input.InstructionSteps" class="form-control" placeholder="step 1|step 2|step 3" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-3 form-check mb-3">
|
||||
<input asp-for="Input.ShowInstructions" class="form-check-input" />
|
||||
<label asp-for="Input.ShowInstructions" class="form-check-label"></label>
|
||||
</div>
|
||||
<div class="col-md-3 form-check mb-3">
|
||||
<input asp-for="Input.ShowSupport" class="form-check-input" />
|
||||
<label asp-for="Input.ShowSupport" class="form-check-label"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label asp-for="Input.SupportEmail" class="form-label"></label>
|
||||
<input asp-for="Input.SupportEmail" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label asp-for="Input.SupportPhone" class="form-label"></label>
|
||||
<input asp-for="Input.SupportPhone" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label asp-for="Input.ErrorCode" class="form-label"></label>
|
||||
<input asp-for="Input.ErrorCode" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Input.SupportHours" class="form-label"></label>
|
||||
<input asp-for="Input.SupportHours" class="form-control" />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json;
|
||||
using maintenance.Data;
|
||||
using maintenance.Services.Pages;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
@@ -20,46 +22,90 @@ public sealed class EditModel : PageModel
|
||||
[BindProperty]
|
||||
public InputModel Input { get; set; } = new();
|
||||
|
||||
public string PreviewUrl { get; private set; } = "/errors/template";
|
||||
public string PreviewUrl { get; private set; } = "/errors/maintenance";
|
||||
|
||||
public sealed class InputModel
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[StringLength(200)]
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
[RegularExpression("^(maintenance|error)$")]
|
||||
public string PageKind { get; set; } = "maintenance";
|
||||
|
||||
public string? SupportContactBlock { get; set; }
|
||||
public bool IsDefaultFallback { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public bool OverrideWindow { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public DateTime? StartUtc { get; set; }
|
||||
public DateTime? EndUtc { get; set; }
|
||||
public string? RecurrenceRule { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(200)]
|
||||
public string ErrorName { get; set; } = string.Empty;
|
||||
public string? ShortDescription { get; set; }
|
||||
[Required]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string? InstructionsHeader { get; set; }
|
||||
public string? InstructionSteps { get; set; }
|
||||
public bool ShowInstructions { get; set; } = true;
|
||||
public bool ShowSupport { get; set; } = true;
|
||||
[Required]
|
||||
public string SupportEmail { get; set; } = "maxsupport@max.gov";
|
||||
[Required]
|
||||
public string SupportPhone { get; set; } = "202-395-6860";
|
||||
[Required]
|
||||
public string SupportHours { get; set; } = "8:00AM - 8:00PM Weekdays, 9:00AM - 6:00PM Weekends (ET)";
|
||||
[Required]
|
||||
public string ErrorCode { get; set; } = "eag";
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(Guid id)
|
||||
{
|
||||
var template = await _dbContext.Templates
|
||||
var page = await _dbContext.ManagedPages
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == id, HttpContext.RequestAborted);
|
||||
|
||||
if (template is null)
|
||||
if (page is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var content = Deserialize(page.ContentJson);
|
||||
|
||||
Input = new InputModel
|
||||
{
|
||||
Id = template.Id,
|
||||
Name = template.Name,
|
||||
Title = template.Title,
|
||||
Body = template.Body,
|
||||
SupportContactBlock = template.SupportContactBlock
|
||||
Id = page.Id,
|
||||
Key = page.Key,
|
||||
DisplayName = page.DisplayName,
|
||||
PageKind = page.PageKind,
|
||||
IsDefaultFallback = page.IsDefaultFallback,
|
||||
IsEnabled = page.IsEnabled,
|
||||
OverrideWindow = page.OverrideWindow,
|
||||
Priority = page.Priority,
|
||||
StartUtc = page.StartUtc,
|
||||
EndUtc = page.EndUtc,
|
||||
RecurrenceRule = page.RecurrenceRule,
|
||||
ErrorName = content.ErrorName,
|
||||
ShortDescription = content.ShortDescription,
|
||||
Description = content.Description,
|
||||
InstructionsHeader = content.InstructionsHeader,
|
||||
InstructionSteps = content.InstructionSteps.Count == 0 ? null : string.Join('|', content.InstructionSteps),
|
||||
ShowInstructions = content.ShowInstructions,
|
||||
ShowSupport = content.ShowSupport,
|
||||
SupportEmail = content.SupportEmail,
|
||||
SupportPhone = content.SupportPhone,
|
||||
SupportHours = content.SupportHours,
|
||||
ErrorCode = content.ErrorCode
|
||||
};
|
||||
|
||||
PreviewUrl = BuildPreviewUrl(template.Name);
|
||||
|
||||
PreviewUrl = BuildPreviewUrl(page.PageKind, page.Key);
|
||||
return Page();
|
||||
}
|
||||
|
||||
@@ -67,42 +113,75 @@ public sealed class EditModel : PageModel
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
PreviewUrl = BuildPreviewUrl(Input.PageKind, Input.Key);
|
||||
return Page();
|
||||
}
|
||||
|
||||
var template = await _dbContext.Templates
|
||||
var page = await _dbContext.ManagedPages
|
||||
.FirstOrDefaultAsync(t => t.Id == Input.Id, HttpContext.RequestAborted);
|
||||
|
||||
if (template is null)
|
||||
if (page is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
template.Title = Input.Title.Trim();
|
||||
template.Body = Input.Body.Trim();
|
||||
template.SupportContactBlock = string.IsNullOrWhiteSpace(Input.SupportContactBlock)
|
||||
? null
|
||||
: Input.SupportContactBlock.Trim();
|
||||
template.LastUpdatedAtUtc = DateTime.UtcNow;
|
||||
template.LastUpdatedBy = User.Identity?.Name ?? "unknown";
|
||||
page.DisplayName = Input.DisplayName.Trim();
|
||||
page.PageKind = Input.PageKind.Trim().ToLowerInvariant();
|
||||
page.IsDefaultFallback = Input.IsDefaultFallback;
|
||||
page.IsEnabled = Input.IsEnabled;
|
||||
page.OverrideWindow = Input.OverrideWindow;
|
||||
page.Priority = Input.Priority;
|
||||
page.StartUtc = Input.StartUtc;
|
||||
page.EndUtc = Input.EndUtc;
|
||||
page.RecurrenceRule = string.IsNullOrWhiteSpace(Input.RecurrenceRule) ? null : Input.RecurrenceRule.Trim();
|
||||
page.ContentJson = JsonSerializer.Serialize(new PageContentModel
|
||||
{
|
||||
ErrorName = Input.ErrorName.Trim(),
|
||||
ShortDescription = string.IsNullOrWhiteSpace(Input.ShortDescription) ? null : Input.ShortDescription.Trim(),
|
||||
Description = Input.Description.Trim(),
|
||||
InstructionsHeader = string.IsNullOrWhiteSpace(Input.InstructionsHeader) ? null : Input.InstructionsHeader.Trim(),
|
||||
InstructionSteps = ParseSteps(Input.InstructionSteps),
|
||||
ShowInstructions = Input.ShowInstructions,
|
||||
ShowSupport = Input.ShowSupport,
|
||||
SupportEmail = Input.SupportEmail.Trim(),
|
||||
SupportPhone = Input.SupportPhone.Trim(),
|
||||
SupportHours = Input.SupportHours.Trim(),
|
||||
ErrorCode = Input.ErrorCode.Trim()
|
||||
});
|
||||
page.LastUpdatedAtUtc = DateTime.UtcNow;
|
||||
page.LastUpdatedBy = User.Identity?.Name ?? "unknown";
|
||||
|
||||
await _dbContext.SaveChangesAsync(HttpContext.RequestAborted);
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
|
||||
private static string BuildPreviewUrl(string templateName)
|
||||
private static PageContentModel Deserialize(string json)
|
||||
{
|
||||
if (templateName.Equals("generic", StringComparison.OrdinalIgnoreCase))
|
||||
try
|
||||
{
|
||||
return "/errors/generic";
|
||||
return JsonSerializer.Deserialize<PageContentModel>(json) ?? new PageContentModel();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new PageContentModel();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> ParseSteps(string? steps)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(steps))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
if (templateName.Equals("unavailable", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "/errors/unavailable";
|
||||
}
|
||||
return steps.Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return $"/errors/template?template={Uri.EscapeDataString(templateName)}";
|
||||
private static string BuildPreviewUrl(string kind, string key)
|
||||
{
|
||||
return $"/errors/{kind}?page={Uri.EscapeDataString(key)}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
ViewData["Title"] = "Templates";
|
||||
}
|
||||
|
||||
<h1>Templates</h1>
|
||||
<p>Manage error template content used by user-facing pages.</p>
|
||||
<h1>Manage Pages</h1>
|
||||
<p>Create and schedule maintenance/error pages while keeping the visual template fixed.</p>
|
||||
<p><a asp-page="./Create" class="btn btn-primary">Create page from template</a></p>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Title</th>
|
||||
<th>Key</th>
|
||||
<th>Kind</th>
|
||||
<th>Default</th>
|
||||
<th>Enabled</th>
|
||||
<th>Window</th>
|
||||
<th>Updated</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
@@ -21,12 +24,15 @@
|
||||
@foreach (var item in Model.Templates)
|
||||
{
|
||||
<tr>
|
||||
<td>@item.Name</td>
|
||||
<td>@item.Title</td>
|
||||
<td>@item.Key</td>
|
||||
<td>@item.PageKind</td>
|
||||
<td>@item.IsDefaultFallback</td>
|
||||
<td>@item.IsEnabled</td>
|
||||
<td>@(item.StartUtc?.ToString("u") ?? "-") to @(item.EndUtc?.ToString("u") ?? "-")</td>
|
||||
<td>@item.LastUpdatedAtUtc.ToString("u")</td>
|
||||
<td>
|
||||
<a asp-page="./Edit" asp-route-id="@item.Id">Edit</a> |
|
||||
<a href="@Model.GetPreviewUrl(item.Name)" target="_blank" rel="noopener">Preview</a>
|
||||
<a href="@Model.GetPreviewUrl(item)" target="_blank" rel="noopener">Preview</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -16,28 +16,20 @@ public sealed class IndexModel : PageModel
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public IReadOnlyList<TemplateEntity> Templates { get; private set; } = [];
|
||||
public IReadOnlyList<ManagedPageEntity> Templates { get; private set; } = [];
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
Templates = await _dbContext.Templates
|
||||
Templates = await _dbContext.ManagedPages
|
||||
.AsNoTracking()
|
||||
.OrderBy(t => t.Name)
|
||||
.OrderBy(t => t.PageKind)
|
||||
.ThenByDescending(t => t.IsDefaultFallback)
|
||||
.ThenBy(t => t.Key)
|
||||
.ToListAsync(HttpContext.RequestAborted);
|
||||
}
|
||||
|
||||
public string GetPreviewUrl(string templateName)
|
||||
public string GetPreviewUrl(ManagedPageEntity page)
|
||||
{
|
||||
if (templateName.Equals("generic", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "/errors/generic";
|
||||
}
|
||||
|
||||
if (templateName.Equals("unavailable", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "/errors/unavailable";
|
||||
}
|
||||
|
||||
return $"/errors/template?template={Uri.EscapeDataString(templateName)}";
|
||||
return $"/errors/{page.PageKind}?page={Uri.EscapeDataString(page.Key)}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user