Skip to content

Commit

Permalink
#15 Added confirmation card
Browse files Browse the repository at this point in the history
  • Loading branch information
ellinge committed Feb 9, 2023
1 parent 377b3f8 commit 65ab75f
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
<nav aria-label="Table pagination">
<ul class="pagination">
<li class="page-item @(Model.HasPreviousPage ? string.Empty : "disabled")">
<button type="submit" class="page-link" name="page" value="@(Model.PageNumber-1)" aria-label="Previous">
<button type="submit" class="page-link" name="page" value="@(Model.PageNumber-1)" aria-label="Previous" asp-page-handler="">
<span aria-hidden="true">&laquo;</span>
</button>
</li>

@for (int i = 1; i <= Model.PageCount; i++)
{
<li class="page-item">
<button type="submit" class="page-link" name="page" value="@i">
<button type="submit" class="page-link" name="page" value="@i" asp-page-handler="">
@i
</button>
</li>
}
<li class="page-item @(Model.HasNextPage ? string.Empty : "disabled")">
<button type="submit" class="page-link" name="page" value="@(Model.PageNumber+1)" aria-label="Next">
<button type="submit" class="page-link" name="page" value="@(Model.PageNumber+1)" aria-label="Next" asp-page-handler="">
<span aria-hidden="true">&raquo;</span>
</button>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<th class="sortable-header@(isCurrent ? " current" : "")@(Model.AdditionalClass != null ? $" {Model.AdditionalClass}" : "")"
data-sort-by="@sortBy" data-sort-direction="@nextSortDirection">
<a role="button" title="Sort @Model.DisplayName @nextSortDirection.ToString().ToLower()">
<button type="button" title="Sort @Model.DisplayName @nextSortDirection.ToString().ToLower()" asp-page-handler="">
@Model.DisplayName

@if (isCurrent && nextSortDirection == SortOrder.Ascending)
Expand All @@ -20,5 +20,5 @@
{
<span data-feather="arrow-down"></span>
}
</a>
</button>
</th>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@page
@using Geta.NotFoundHandler.Core.Redirects;
@model Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.DeletedModel
@model DeletedModel

@await Component.InvokeAsync("Card", new { message = Model.Message })
@await Component.InvokeAsync("Card", new { message = Model.OperationMessage, cardType = CardType.Success })

<form method="post">
<div class="table-responsive mt-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public IActionResult OnPostCreate()
if (ModelState.IsValid)
{
RedirectsService.AddDeletedRedirect(DeletedRedirect.OldUrl);
OperationMessage = $"Added delete redirect for {DeletedRedirect.OldUrl}";
DeletedRedirect = new DeletedRedirectModel();
return LoadPage(true);
}

return LoadPage();
Expand All @@ -30,6 +33,7 @@ public IActionResult OnPostCreate()
public IActionResult OnPostDelete(string oldUrl)
{
RedirectsService.DeleteByOldUrl(oldUrl);
OperationMessage = $"Removed {oldUrl}";
return LoadPage(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@page
@using Geta.NotFoundHandler.Core.Redirects;
@model Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.IgnoredModel
@model IgnoredModel

@await Component.InvokeAsync("Card", new { message = Model.Message })
@await Component.InvokeAsync("Card", new { message = Model.OperationMessage, cardType = CardType.Success })

<form method="post">
<div class="table-responsive mt-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public IgnoredModel(IRedirectsService redirectsService) : base(redirectsService,
public IActionResult OnPostUnignore(string oldUrl)
{
RedirectsService.DeleteByOldUrl(oldUrl);
OperationMessage = $"Removed {oldUrl} from the ignore list";
return LoadPage(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@page
@using Geta.NotFoundHandler.Core.Redirects
@model Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.IndexModel
@model IndexModel

@await Component.InvokeAsync("Card", new { message = Model.Message })
@await Component.InvokeAsync("Card", new { message = Model.OperationMessage, cardType = CardType.Success })

<form method="post">
<div class="search-container input-group flex-nowrap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public IActionResult OnPostCreate()
CustomRedirect.RedirectType);

RedirectsService.AddOrUpdate(customRedirect);
OperationMessage = $"Added/updated redirect from {CustomRedirect.OldUrl} to {CustomRedirect.NewUrl}";
CustomRedirect = new RedirectModel();
return LoadPage(true);
}

return LoadPage();
Expand All @@ -36,6 +38,7 @@ public IActionResult OnPostCreate()
public IActionResult OnPostDelete(string oldUrl)
{
RedirectsService.DeleteByOldUrl(oldUrl);
OperationMessage = $"Removed redirect for {oldUrl}";
return LoadPage(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin;
public abstract class BaseRedirectPageModel : PageModel
{
public string Message { get; set; }
public string OperationMessage { get; set; }

[BindProperty(SupportsGet = true)]
public QueryParams Params { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@page
@using Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.Models;
@model Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.SuggestionsModel
@model SuggestionsModel

@await Component.InvokeAsync("Card", new { message = Model.Message })
@await Component.InvokeAsync("Card", new { message = Model.OperationMessage, cardType = CardType.Success })

<form method="post">
<div class="table-responsive mt-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public IActionResult OnPostCreate(Dictionary<int, SuggestionRedirectModel> items
if (TryValidateModel(item, $"{nameof(items)}[{index}]"))
{
_suggestionService.AddRedirect(new SuggestionRedirect(item.OldUrl, item.NewUrl));
OperationMessage = $"Added redirect from {item.OldUrl} to {item.NewUrl}";
}
}

Expand All @@ -41,6 +42,7 @@ public IActionResult OnPostCreate(Dictionary<int, SuggestionRedirectModel> items
public IActionResult OnPostIgnore(string oldUrl)
{
_suggestionService.IgnoreSuggestion(oldUrl);
OperationMessage = $"Added {oldUrl} to ignore list";
return LoadPage(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Geta.NotFoundHandler.Admin
@using Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.Components.Card;
@using Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin.Models;
@using Geta.NotFoundHandler.Admin.Pages.Geta.NotFoundHandler.Admin;
@using Geta.NotFoundHandler.Core.Redirects
@addTagHelper *, Geta.NotFoundHandler.Admin
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,19 @@
white-space: nowrap;
}

.sortable-header button {
padding: 0;
margin: 0;
border: none;
background-color: transparent;
font-weight: bold;
}

.sortable-header svg {
color: lightgray;
}

.sortable-header.current, .sortable-header:hover {
.sortable-header.current button, .sortable-header:hover button {
text-decoration: underline;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* globals feather:false */

(function() {
(function () {
'use strict';

feather.replace();


function clearInput() {
var initiators = document.querySelectorAll('[data-clear]');
initiators.forEach(function(initiator) {
initiators.forEach(function (initiator) {
initiator.addEventListener('click',
function(e) {
function (e) {
var target = e.currentTarget;
var selector = target.getAttribute('data-clear');
var input = document.querySelector(selector);
Expand All @@ -21,7 +20,7 @@

function confirmSubmit() {
var initiators = document.querySelectorAll('[data-confirm]');
initiators.forEach(function(initiator) {
initiators.forEach(function (initiator) {
var form = initiator.form;
form.addEventListener('submit',
function (e) {
Expand All @@ -37,7 +36,7 @@
}

function addSortableHeaders() {
var buttons = document.querySelectorAll('form .sortable-header a');
var buttons = document.querySelectorAll('form .sortable-header button');
buttons.forEach(function (button) {
button.addEventListener('click',
function (e) {
Expand All @@ -48,6 +47,7 @@
var sortDirection = form.querySelector("input[name='sort-direction']");
if (sortBy) sortBy.value = header.dataset.sortBy;
if (sortDirection) sortDirection.value = header.dataset.sortDirection;
form.action = button.formAction;
form.submit();
});
});
Expand All @@ -56,4 +56,4 @@
clearInput();
confirmSubmit();
addSortableHeaders();
})()
})()

0 comments on commit 65ab75f

Please sign in to comment.