diff --git a/TASVideos/Pages/Games/Index.cshtml b/TASVideos/Pages/Games/Index.cshtml
index a18735cf0..65cfc2335 100644
--- a/TASVideos/Pages/Games/Index.cshtml
+++ b/TASVideos/Pages/Games/Index.cshtml
@@ -167,7 +167,7 @@
No records.
-
+
Type |
Name |
diff --git a/TASVideos/Pages/Games/Models/GameEditModel.cs b/TASVideos/Pages/Games/Models/GameEditModel.cs
index a86a49d5c..c883de6da 100644
--- a/TASVideos/Pages/Games/Models/GameEditModel.cs
+++ b/TASVideos/Pages/Games/Models/GameEditModel.cs
@@ -17,7 +17,7 @@ public class GameEditModel
public string? Aliases { get; set; }
[StringLength(250)]
- [Display(Name = "Screenshot Url")]
+ [Display(Name = "Screenshot URL")]
public string? ScreenshotUrl { get; set; }
[StringLength(300)]
diff --git a/TASVideos/Pages/Publications/Edit.cshtml b/TASVideos/Pages/Publications/Edit.cshtml
index ea1a0be65..2360b4de0 100644
--- a/TASVideos/Pages/Publications/Edit.cshtml
+++ b/TASVideos/Pages/Publications/Edit.cshtml
@@ -44,19 +44,22 @@
}
- Edit
+ Edit
- Name |
- Url |
Type |
+ URL |
+ Name |
- @foreach (var url in Model.Publication.Urls.OrderBy(f => f.Type))
+ @foreach (var url in Model.Publication.Urls.OrderBy(f => f.Type).ThenBy(f => f.DisplayName))
{
- @url.DisplayName |
- @url.Url |
@url.Type |
+ @url.Url |
+ @url.DisplayName |
}
diff --git a/TASVideos/Pages/Publications/EditFiles.cshtml b/TASVideos/Pages/Publications/EditFiles.cshtml
index 92b51a04b..e4b493357 100644
--- a/TASVideos/Pages/Publications/EditFiles.cshtml
+++ b/TASVideos/Pages/Publications/EditFiles.cshtml
@@ -8,7 +8,7 @@
- Url |
+ URL |
Type |
Description |
|
diff --git a/TASVideos/Pages/Publications/EditUrls.cshtml b/TASVideos/Pages/Publications/EditUrls.cshtml
deleted file mode 100644
index 3bbdc23c3..000000000
--- a/TASVideos/Pages/Publications/EditUrls.cshtml
+++ /dev/null
@@ -1,62 +0,0 @@
-@page "{id}/{handler?}/{publicationUrlId?}"
-@model EditUrlsModel
-@{
- ViewData.SetTitle($"Edit Urls for {Model.Title}");
-}
-
-Urls
-
-
-
- Name |
- Url |
- Type |
- |
-
- @foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type))
- {
-
- @url.DisplayName |
- @url.Url |
- @url.Type |
-
-
- Delete
-
- |
-
- }
-
-
-
-
-
-@section Scripts {
-
-}
diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml b/TASVideos/Pages/Publications/Urls/Edit.cshtml
new file mode 100644
index 000000000..e8b4c1ec4
--- /dev/null
+++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml
@@ -0,0 +1,49 @@
+@page "/Publications/{publicationId}/Urls/Edit/{urlId?}/{handler?}"
+@model EditUrlsModel
+@{
+ string saveBtnName;
+ string iconClass;
+ if (Model.UrlId.HasValue)
+ {
+ ViewData.SetTitle($"Editing URL #{Model.UrlId} for {Model.Title}");
+ saveBtnName = "Save";
+ iconClass = "fa fa-save";
+ }
+ else
+ {
+ ViewData.SetTitle("Add A New URL");
+ saveBtnName = "Add";
+ iconClass = "fa fa-plus";
+ }
+}
+
+
+
+@section Scripts {
+
+}
diff --git a/TASVideos/Pages/Publications/EditUrls.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs
similarity index 61%
rename from TASVideos/Pages/Publications/EditUrls.cshtml.cs
rename to TASVideos/Pages/Publications/Urls/Edit.cshtml.cs
index 33212fcb3..10428054a 100644
--- a/TASVideos/Pages/Publications/EditUrls.cshtml.cs
+++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs
@@ -8,7 +8,7 @@
using TASVideos.Data;
using TASVideos.Data.Entity;
-namespace TASVideos.Pages.Publications;
+namespace TASVideos.Pages.Publications.Urls;
[RequirePermission(PermissionTo.EditPublicationFiles)]
public class EditUrlsModel : BasePageModel
@@ -47,7 +47,10 @@ public EditUrlsModel(
});
[FromRoute]
- public int Id { get; set; }
+ public int PublicationId { get; set; }
+
+ [FromRoute]
+ public int? UrlId { get; set; }
[BindProperty]
public string Title { get; set; } = "";
@@ -62,8 +65,8 @@ public EditUrlsModel(
[Required]
[BindProperty]
[Url]
- [Display(Name = "Url")]
- public string PublicationUrl { get; set; } = "";
+ [Display(Name = "URL")]
+ public string CurrentUrl { get; set; } = "";
[Required]
[BindProperty]
@@ -73,7 +76,7 @@ public EditUrlsModel(
public async Task OnGet()
{
var title = await _db.Publications
- .Where(p => p.Id == Id)
+ .Where(p => p.Id == PublicationId)
.Select(p => p.Title)
.SingleOrDefaultAsync();
@@ -84,16 +87,34 @@ public async Task OnGet()
Title = title;
CurrentUrls = await _db.PublicationUrls
- .Where(u => u.PublicationId == Id)
+ .Where(u => u.PublicationId == PublicationId)
.ToListAsync();
+ if (!UrlId.HasValue)
+ {
+ return Page();
+ }
+
+ var url = CurrentUrls
+ .SingleOrDefault(u => u.Id == UrlId.Value);
+
+ if (url is null || url.Url is null)
+ {
+ return NotFound();
+ }
+
+ PublicationId = url.PublicationId;
+ DisplayName = url.DisplayName;
+ UrlType = url.Type;
+ CurrentUrl = url.Url;
+
return Page();
}
public async Task OnPost()
{
var publication = await _db.Publications
- .Where(p => p.Id == Id)
+ .Where(p => p.Id == PublicationId)
.Select(p => new
{
Title,
@@ -110,13 +131,13 @@ public async Task OnPost()
return NotFound();
}
- var publicationWiki = await _wikiPages.PublicationPage(Id);
+ var publicationWiki = await _wikiPages.PublicationPage(PublicationId);
CurrentUrls = publication.PublicationUrls;
- if (CurrentUrls.Any(u => u.Type == UrlType && u.Url == PublicationUrl))
+ if (CurrentUrls.Any(u => u.Type == UrlType && u.Url == CurrentUrl && u.Id != UrlId))
{
- ModelState.AddModelError($"{nameof(PublicationUrl)}", $"The {UrlType} url: {PublicationUrl} already exists");
+ ModelState.AddModelError($"{nameof(CurrentUrl)}", $"The {UrlType} URL: {CurrentUrl} already exists");
}
if (!ModelState.IsValid)
@@ -124,33 +145,50 @@ public async Task OnPost()
return Page();
}
- var publicationUrl = new PublicationUrl
+ string[] logWording;
+
+ if (UrlId.HasValue)
+ {
+ var url = CurrentUrls
+ .Single(u => u.Id == UrlId.Value);
+
+ url.PublicationId = PublicationId;
+ url.DisplayName = DisplayName;
+ url.Type = UrlType;
+ url.Url = CurrentUrl;
+
+ logWording = new[] { "Chang", "chang" };
+ }
+ else
{
- PublicationId = Id,
- Url = PublicationUrl,
- Type = UrlType,
- DisplayName = DisplayName
- };
+ _db.PublicationUrls.Add(new PublicationUrl
+ {
+ PublicationId = PublicationId,
+ Url = CurrentUrl,
+ Type = UrlType,
+ DisplayName = DisplayName
+ });
- _db.PublicationUrls.Add(publicationUrl);
+ logWording = new[] { "Add", "add" };
+ }
- string log = $"Added {DisplayName} {UrlType} url {PublicationUrl}";
- await _publicationMaintenanceLogger.Log(Id, User.GetUserId(), log);
- var result = await ConcurrentSave(_db, log, "Unable to add url.");
+ string log = $"{logWording[0]}ed {DisplayName} {UrlType} URL {CurrentUrl}";
+ await _publicationMaintenanceLogger.Log(PublicationId, User.GetUserId(), log);
+ var result = await ConcurrentSave(_db, log, $"Unable to {logWording[1]} URL.");
if (result)
{
await _publisher.SendPublicationEdit(
- $"{Id}M edited by {User.Name()}",
- $"[{Id}M]({{0}}) edited by {User.Name()}",
- $"Added {UrlType} url | {Title}",
- $"{Id}M");
+ $"{PublicationId}M edited by {User.Name()}",
+ $"[{PublicationId}M]({{0}}) edited by {User.Name()}",
+ $"{logWording[0]}ed {UrlType} URL | {Title}",
+ $"{PublicationId}M");
- if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(PublicationUrl))
+ if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(CurrentUrl))
{
YoutubeVideo video = new(
- Id,
+ PublicationId,
publication.CreateTimestamp,
- PublicationUrl,
+ CurrentUrl,
DisplayName,
publication.Title,
publicationWiki!,
@@ -161,32 +199,6 @@ await _publisher.SendPublicationEdit(
}
}
- return RedirectToPage("EditUrls", new { Id });
- }
-
- public async Task OnPostDelete(int publicationUrlId)
- {
- var url = await _db.PublicationUrls
- .SingleOrDefaultAsync(pf => pf.Id == publicationUrlId);
-
- if (url != null)
- {
- _db.PublicationUrls.Remove(url);
- string log = $"Deleted {url.DisplayName} {url.Type} url {url.Url}";
- await _publicationMaintenanceLogger.Log(url.PublicationId, User.GetUserId(), log);
- var result = await ConcurrentSave(_db, log, "Unable to remove url.");
- if (result)
- {
- await _publisher.SendPublicationEdit(
- $"{Id}M edited by {User.Name()}",
- $"[{Id}M]({{0}}) edited by {User.Name()}",
- $"Deleted {url.Type} url",
- $"{Id}M");
-
- await _youtubeSync.UnlistVideo(url.Url!);
- }
- }
-
- return RedirectToPage("EditUrls", new { Id });
+ return RedirectToPage("List", new { PublicationId });
}
}
diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml b/TASVideos/Pages/Publications/Urls/List.cshtml
new file mode 100644
index 000000000..0a9a475c4
--- /dev/null
+++ b/TASVideos/Pages/Publications/Urls/List.cshtml
@@ -0,0 +1,53 @@
+@page "/Publications/{publicationId}/Urls/List/{urlId?}/{handler?}"
+@model ListUrlsModel
+@{
+ ViewData.SetTitle($"URLs for {Model.Title}");
+}
+
+Movie: @Model.Title
+ Add
+
+
+
+
+ Type |
+ URL |
+ Name |
+ Actions |
+
+ @foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type).ThenBy(u => u.DisplayName))
+ {
+
+ @url.Type |
+ @url.Url |
+ @url.DisplayName |
+
+
+ Edit
+
+
+ Delete
+
+ |
+
+ }
+
+
+
diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml.cs b/TASVideos/Pages/Publications/Urls/List.cshtml.cs
new file mode 100644
index 000000000..56d128687
--- /dev/null
+++ b/TASVideos/Pages/Publications/Urls/List.cshtml.cs
@@ -0,0 +1,82 @@
+using Microsoft.AspNetCore.Mvc;
+using TASVideos.Core.Services;
+using TASVideos.Core.Services.ExternalMediaPublisher;
+using TASVideos.Core.Services.Youtube;
+using TASVideos.Data;
+using TASVideos.Data.Entity;
+
+namespace TASVideos.Pages.Publications.Urls;
+
+[RequirePermission(PermissionTo.EditPublicationFiles)]
+public class ListUrlsModel : BasePageModel
+{
+ private readonly ApplicationDbContext _db;
+ private readonly ExternalMediaPublisher _publisher;
+ private readonly IYoutubeSync _youtubeSync;
+ private readonly IPublicationMaintenanceLogger _publicationMaintenanceLogger;
+
+ public ListUrlsModel(
+ ApplicationDbContext db,
+ ExternalMediaPublisher publisher,
+ IYoutubeSync youtubeSync,
+ IPublicationMaintenanceLogger publicationMaintenanceLogger)
+ {
+ _db = db;
+ _publisher = publisher;
+ _youtubeSync = youtubeSync;
+ _publicationMaintenanceLogger = publicationMaintenanceLogger;
+ }
+
+ [FromRoute]
+ public int PublicationId { get; set; }
+
+ public string Title { get; set; } = "";
+
+ public ICollection CurrentUrls { get; set; } = new List();
+
+ public async Task OnGet()
+ {
+ var title = await _db.Publications
+ .Where(p => p.Id == PublicationId)
+ .Select(p => p.Title)
+ .SingleOrDefaultAsync();
+
+ if (title is null)
+ {
+ return NotFound();
+ }
+
+ Title = title;
+ CurrentUrls = await _db.PublicationUrls
+ .Where(u => u.PublicationId == PublicationId)
+ .ToListAsync();
+
+ return Page();
+ }
+
+ public async Task OnPostDelete(int urlId)
+ {
+ var url = await _db.PublicationUrls
+ .SingleOrDefaultAsync(pf => pf.Id == urlId);
+
+ if (url != null)
+ {
+ _db.PublicationUrls.Remove(url);
+ string log = $"Deleted {url.DisplayName} {url.Type} URL {url.Url}";
+ await _publicationMaintenanceLogger.Log(url.PublicationId, User.GetUserId(), log);
+ var result = await ConcurrentSave(_db, log, "Unable to remove URL.");
+ if (result)
+ {
+ await _publisher.SendPublicationEdit(
+ $"{PublicationId}M edited by {User.Name()}",
+ $"[{PublicationId}M]({{0}}) edited by {User.Name()}",
+ $"Deleted {url.Type} URL",
+ $"{PublicationId}M");
+
+ await _youtubeSync.UnlistVideo(url.Url!);
+ }
+ }
+
+ return RedirectToPage("List", new { PublicationId });
+ }
+}