mirror of
https://github.com/miawinter98/just-short-it.git
synced 2024-11-22 08:19:54 +00:00
Implemented Inspect on Urls
This commit is contained in:
parent
89cce362f6
commit
2290099f45
|
@ -6,6 +6,7 @@
|
|||
|
||||
- Page Titles to Login, Logout and Urls Page
|
||||
- Added Inspect Page, which displays information about a URL and allows to delete it
|
||||
- Added Inspect Form group to Urls that redirects to Inspect Page
|
||||
|
||||
## [1.1.0] - 2023-04-17
|
||||
|
||||
|
|
|
@ -16,48 +16,70 @@
|
|||
<h1 class="title is-2">Urls Administration</h1>
|
||||
</div>
|
||||
|
||||
<form class="column is-half-desktop is-two-thirds-tablet is-full-mobile" method="post">
|
||||
<h2 class="title is-3">New URL</h2>
|
||||
<div class="column is-half-desktop is-two-thirds-tablet is-full-mobile">
|
||||
<form class="mb-6" method="post" asp-page="Urls" asp-page-handler="Inspect">
|
||||
<h2 class="title is-3">Inspect URL</h2>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" asp-for="Model!.Id">ID</label>
|
||||
<div class="control">
|
||||
<input required class="input" type="text" asp-for="Model!.Id" />
|
||||
</div>
|
||||
<span class="help is-danger" asp-validation-for="Model!.Id"></span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" asp-for="Model!.Target">Target</label>
|
||||
<div class="control">
|
||||
<input required class="input" type="text" asp-for="Model!.Target" />
|
||||
</div>
|
||||
<span class="help is-danger" asp-validation-for="Model!.Target"></span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" asp-for="Model!.ExpirationDate">Expiration</label>
|
||||
<div class="control">
|
||||
<div class="select">
|
||||
@Html.DropDownListFor(m => m.Model!.ExpirationDate, new List<SelectListItem> {
|
||||
new("1 Day", DateTime.UtcNow.AddDays(1).ToBinary().ToString()),
|
||||
new("1 Week", DateTime.UtcNow.AddDays(7).ToBinary().ToString()),
|
||||
new("4 Weeks", DateTime.UtcNow.AddDays(4 * 7).ToBinary().ToString()),
|
||||
new("1 Year", DateTime.UtcNow.AddYears(1).ToBinary().ToString()),
|
||||
new("Never", DateTime.UtcNow.AddYears(1000).ToBinary().ToString())
|
||||
}, "Select Expiration")
|
||||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
<label class="button is-static">ID</label>
|
||||
</div>
|
||||
<div class="control is-expanded">
|
||||
<input required type="text" class="input" name="Inspect_Id"/>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button is-primary" type="submit">Inspect</button>
|
||||
</div>
|
||||
</div>
|
||||
<span class="help is-danger" asp-validation-for="Model!.ExpirationDate"></span>
|
||||
</div>
|
||||
|
||||
<div class="has-text-danger" asp-validation-summary="ModelOnly"></div>
|
||||
|
||||
<div class="field is-grouped is-grouped-right">
|
||||
<div class="control">
|
||||
<button class="button is-primary" type="submit">Create</button>
|
||||
<div class="field">
|
||||
<span class="help is-danger">@ModelState["Inspect_Id"]?.Errors.FirstOrDefault()?.ErrorMessage</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<form method="post">
|
||||
<h2 class="title is-3">New URL</h2>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" asp-for="Model!.Id">ID</label>
|
||||
<div class="control">
|
||||
<input required class="input" type="text" asp-for="Model!.Id" />
|
||||
</div>
|
||||
<span class="help is-danger" asp-validation-for="Model!.Id"></span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" asp-for="Model!.Target">Target</label>
|
||||
<div class="control">
|
||||
<input required class="input" type="text" asp-for="Model!.Target" />
|
||||
</div>
|
||||
<span class="help is-danger" asp-validation-for="Model!.Target"></span>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" asp-for="Model!.ExpirationDate">Expiration</label>
|
||||
<div class="control">
|
||||
<div class="select">
|
||||
@Html.DropDownListFor(m => m.Model!.ExpirationDate, new List<SelectListItem> {
|
||||
new("1 Day", DateTime.UtcNow.AddDays(1).ToBinary().ToString()),
|
||||
new("1 Week", DateTime.UtcNow.AddDays(7).ToBinary().ToString()),
|
||||
new("4 Weeks", DateTime.UtcNow.AddDays(4 * 7).ToBinary().ToString()),
|
||||
new("1 Year", DateTime.UtcNow.AddYears(1).ToBinary().ToString()),
|
||||
new("Never", DateTime.UtcNow.AddYears(1000).ToBinary().ToString())
|
||||
}, "Select Expiration")
|
||||
</div>
|
||||
</div>
|
||||
<span class="help is-danger" asp-validation-for="Model!.ExpirationDate"></span>
|
||||
</div>
|
||||
|
||||
<div class="has-text-danger" asp-validation-summary="ModelOnly"></div>
|
||||
|
||||
<div class="field is-grouped is-grouped-right">
|
||||
<div class="control">
|
||||
<button class="button is-primary" type="submit">Create</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
|
||||
namespace JustShortIt.Pages;
|
||||
|
@ -28,7 +29,20 @@ public class UrlsModel : PageModel {
|
|||
Db = db;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostInspectAsync() {
|
||||
string? id = Request.Form["Inspect_Id"];
|
||||
if (id is null || string.IsNullOrEmpty(id)) {
|
||||
ModelState.AddModelError("Inspect_Id", "ID is a required field");
|
||||
return Page();
|
||||
}
|
||||
|
||||
if (await Db.GetAsync(id) is null) {
|
||||
ModelState.AddModelError("Inspect_Id", "ID does not exist");
|
||||
return Page();
|
||||
}
|
||||
|
||||
return RedirectToPage("Inspect", new { Id = id });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync() {
|
||||
if (!ModelState.IsValid) return Page();
|
||||
|
|
Loading…
Reference in a new issue