Skip to content

Commit

Permalink
renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
vadosnaprimer committed Jan 20, 2024
1 parent e28ccec commit 12a618c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 57 deletions.
2 changes: 1 addition & 1 deletion TASVideos/Pages/Publications/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<th>URL</th>
<th>Name</th>
</tr>
@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))
{
<tr>
<td>@url.Type</td>
Expand Down
14 changes: 7 additions & 7 deletions TASVideos/Pages/Publications/Urls/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@page "/Publications/{id}/Urls/Edit/{publicationUrlId?}/{handler?}"
@page "/Publications/{publicationId}/Urls/Edit/{urlId?}/{handler?}"
@model EditUrlsModel
@{
string saveBtnName;
string iconClass;
if (Model.publicationUrlId.HasValue)
if (Model.UrlId.HasValue)
{
ViewData.SetTitle($"Editing URL #{Model.publicationUrlId} for {Model.Title}");
ViewData.SetTitle($"Editing URL #{Model.UrlId} for {Model.Title}");
saveBtnName = "Save";
iconClass = "fa fa-save";
}
Expand All @@ -27,9 +27,9 @@
<span asp-validation-for="UrlType" class="text-danger"></span>
</fieldset>
<fieldset>
<label asp-for="PublicationUrl"></label>
<input type="text" asp-for="PublicationUrl" class="form-control" />
<span asp-validation-for="PublicationUrl" class="text-danger"></span>
<label asp-for="CurrentUrl"></label>
<input type="text" asp-for="CurrentUrl" class="form-control" />
<span asp-validation-for="CurrentUrl" class="text-danger"></span>
</fieldset>
<fieldset>
<label asp-for="DisplayName"></label>
Expand All @@ -38,7 +38,7 @@
</fieldset>
<div class="text-center mt-3">
<submit-button class="btn btn-primary"><span class="@iconClass"></span> @saveBtnName</submit-button>
<a asp-page="List" asp-route-id="@Model.Id" class="btn btn-secondary"><span class="fa fa-times"></span> Cancel</a>
<a asp-page="List" asp-route-PublicationId="@Model.PublicationId" class="btn btn-secondary"><span class="fa fa-times"></span> Cancel</a>
</div>
</column>
</row>
Expand Down
56 changes: 28 additions & 28 deletions TASVideos/Pages/Publications/Urls/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public EditUrlsModel(
});

[FromRoute]
public int Id { get; set; }
public int PublicationId { get; set; }

[FromRoute]
public int? publicationUrlId { get; set; }
public int? UrlId { get; set; }

[BindProperty]
public string Title { get; set; } = "";
Expand All @@ -69,7 +69,7 @@ public EditUrlsModel(
[BindProperty]
[Url]
[Display(Name = "URL")]
public string PublicationUrl { get; set; } = "";
public string CurrentUrl { get; set; } = "";

[Required]
[BindProperty]
Expand All @@ -79,7 +79,7 @@ public EditUrlsModel(
public async Task<IActionResult> OnGet()
{
var title = await _db.Publications
.Where(p => p.Id == Id)
.Where(p => p.Id == PublicationId)
.Select(p => p.Title)
.SingleOrDefaultAsync();

Expand All @@ -90,35 +90,35 @@ public async Task<IActionResult> OnGet()

Title = title;
CurrentUrls = await _db.PublicationUrls
.Where(u => u.PublicationId == Id)
.Where(u => u.PublicationId == PublicationId)
.ToListAsync();

if (!publicationUrlId.HasValue)
if (!UrlId.HasValue)
{
return Page();
}

var url = CurrentUrls
.Where(u => u.Id == publicationUrlId.Value)
.Where(u => u.Id == UrlId.Value)
.SingleOrDefault();

if (url is null || url.Url is null)
{
return NotFound();
}

Id = url.PublicationId;
PublicationId = url.PublicationId;
DisplayName = url.DisplayName;
UrlType = url.Type;
PublicationUrl = url.Url;
CurrentUrl = url.Url;

return Page();
}

public async Task<IActionResult> OnPost()
{
var publication = await _db.Publications
.Where(p => p.Id == Id)
.Where(p => p.Id == PublicationId)
.Select(p => new
{
Title,
Expand All @@ -135,13 +135,13 @@ public async Task<IActionResult> OnPost()
return NotFound();
}

var publicationWiki = await _wikiPages.PublicationPage(Id);
var publicationWiki = await _wikiPages.PublicationPage(PublicationId);

CurrentUrls = publication.PublicationUrls;

if (!publicationUrlId.HasValue && CurrentUrls.Any(u => u.Type == UrlType && u.Url == PublicationUrl))
if (!UrlId.HasValue && CurrentUrls.Any(u => u.Type == UrlType && u.Url == CurrentUrl))
{
ModelState.AddModelError($"{nameof(PublicationUrl)}", $"The {UrlType} URL: {PublicationUrl} already exists");
ModelState.AddModelError($"{nameof(CurrentUrl)}", $"The {UrlType} URL: {CurrentUrl} already exists");
}

if (!ModelState.IsValid)
Expand All @@ -151,49 +151,49 @@ public async Task<IActionResult> OnPost()

string[] logwording;

if (publicationUrlId.HasValue)
if (UrlId.HasValue)
{
var url = CurrentUrls
.Where(u => u.Id == publicationUrlId.Value)
.Where(u => u.Id == UrlId.Value)
.Single();

url.PublicationId = Id;
url.PublicationId = PublicationId;
url.DisplayName = DisplayName;
url.Type = UrlType;
url.Url = PublicationUrl;
url.Url = CurrentUrl;

logwording = new string[2] { "Add", "add" };
}
else
{
_db.PublicationUrls.Add(new PublicationUrl
{
PublicationId = Id,
Url = PublicationUrl,
PublicationId = PublicationId,
Url = CurrentUrl,
Type = UrlType,
DisplayName = DisplayName
});

logwording = new string[2] { "Change", "change" };
}

string log = $"{logwording[0]}ed {DisplayName} {UrlType} URL {PublicationUrl}";
await _publicationMaintenanceLogger.Log(Id, User.GetUserId(), log);
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()}",
$"{PublicationId}M edited by {User.Name()}",
$"[{PublicationId}M]({{0}}) edited by {User.Name()}",
$"{logwording[0]}ed {UrlType} URL | {Title}",
$"{Id}M");
$"{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!,
Expand All @@ -204,6 +204,6 @@ await _publisher.SendPublicationEdit(
}
}

return RedirectToPage("List", new { Id });
return RedirectToPage("List", new { PublicationId });
}
}
26 changes: 14 additions & 12 deletions TASVideos/Pages/Publications/Urls/List.cshtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@page "/Publications/{id}/Urls/List/{publicationUrlId?}/{handler?}"
@page "/Publications/{publicationId}/Urls/List/{urlId?}/{handler?}"
@model ListUrlsModel
@{
ViewData.SetTitle($"URLs for {Model.Title}");
}

<h4>Movie: <pub-link id="Model.Id">@Model.Title</pub-link></h4>
<h4>Movie: <pub-link id="Model.PublicationId">@Model.Title</pub-link></h4>
<a asp-page="Edit"
permission="EditPublicationFiles"
asp-route-Id="@Model.Id"
asp-route-publicationId="@Model.PublicationId"
class="btn btn-primary"><i class="fa fa-plus"></i> Add</a>
<hr />
<row condition="Model.CurrentUrls.Any()">
Expand All @@ -18,23 +18,25 @@
<th>Name</th>
<th>Actions</th>
</tr>
@foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type))
@foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type).ThenBy(u => u.DisplayName))
{
<tr>
<td>@url.Type</td>
<td>@url.Url</td>
<td>@url.DisplayName</td>
<td>
<a asp-page="Edit"
<a asp-page="Edit"
permission="EditPublicationFiles"
asp-route-publicationUrlId="@url.Id"
asp-route-Id="@Model.Id"
class="btn btn-primary">
asp-route-urlId="@url.Id"
asp-route-publicationId="@Model.PublicationId"
class="btn btn-primary btn-sm mb-1">
<i class="fa fa-pencil"></i> Edit
</a>
</a>
<delete-button warning-message="Are you sure you want to remove this URL?"
asp-href="/Publications/@Model.Id/Urls/List/@url.Id/Delete">
<span class="fa fa-times"></span> Delete
permission="EditPublicationFiles"
asp-href="/Publications/@Model.PublicationId/Urls/List/@url.Id/Delete"
class="btn-sm mb-1">
<span class="fa fa-times"></span> Delete
</delete-button>
</td>
</tr>
Expand All @@ -44,7 +46,7 @@
<div class="text-center mt-3">
<a permission="EditPublicationMetaData"
asp-page="/Publications/Edit"
asp-route-id="@Model.Id"
asp-route-id="@Model.PublicationId"
class="btn btn-secondary">
<span class="fa fa-arrow-left"></span> Back To Edit
</a>
Expand Down
18 changes: 9 additions & 9 deletions TASVideos/Pages/Publications/Urls/List.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ListUrlsModel(
}

[FromRoute]
public int Id { get; set; }
public int PublicationId { get; set; }

[BindProperty]
public string Title { get; set; } = "";
Expand All @@ -57,7 +57,7 @@ public ListUrlsModel(
public async Task<IActionResult> OnGet()
{
var title = await _db.Publications
.Where(p => p.Id == Id)
.Where(p => p.Id == PublicationId)
.Select(p => p.Title)
.SingleOrDefaultAsync();

Expand All @@ -68,16 +68,16 @@ public async Task<IActionResult> OnGet()

Title = title;
CurrentUrls = await _db.PublicationUrls
.Where(u => u.PublicationId == Id)
.Where(u => u.PublicationId == PublicationId)
.ToListAsync();

return Page();
}

public async Task<IActionResult> OnPostDelete(int publicationUrlId)
public async Task<IActionResult> OnPostDelete(int urlId)
{
var url = await _db.PublicationUrls
.SingleOrDefaultAsync(pf => pf.Id == publicationUrlId);
.SingleOrDefaultAsync(pf => pf.Id == urlId);

if (url != null)
{
Expand All @@ -88,15 +88,15 @@ public async Task<IActionResult> OnPostDelete(int publicationUrlId)
if (result)
{
await _publisher.SendPublicationEdit(
$"{Id}M edited by {User.Name()}",
$"[{Id}M]({{0}}) edited by {User.Name()}",
$"{PublicationId}M edited by {User.Name()}",
$"[{PublicationId}M]({{0}}) edited by {User.Name()}",
$"Deleted {url.Type} URL",
$"{Id}M");
$"{PublicationId}M");

await _youtubeSync.UnlistVideo(url.Url!);
}
}

return RedirectToPage("List", new { Id });
return RedirectToPage("List", new { PublicationId });
}
}

0 comments on commit 12a618c

Please sign in to comment.