1
0
Fork 0
mirror of https://github.com/miawinter98/just-short-it.git synced 2024-11-22 16:29:53 +00:00

Implemented Inspect on Urls

This commit is contained in:
Mia Rose Winter 2023-04-19 16:42:24 +02:00
parent 89cce362f6
commit 2290099f45
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 78 additions and 41 deletions

View file

@ -6,6 +6,7 @@
- Page Titles to Login, Logout and Urls Page - Page Titles to Login, Logout and Urls Page
- Added Inspect Page, which displays information about a URL and allows to delete it - 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 ## [1.1.0] - 2023-04-17

View file

@ -16,48 +16,70 @@
<h1 class="title is-2">Urls Administration</h1> <h1 class="title is-2">Urls Administration</h1>
</div> </div>
<form class="column is-half-desktop is-two-thirds-tablet is-full-mobile" method="post"> <div class="column is-half-desktop is-two-thirds-tablet is-full-mobile">
<h2 class="title is-3">New URL</h2> <form class="mb-6" method="post" asp-page="Urls" asp-page-handler="Inspect">
<h2 class="title is-3">Inspect URL</h2>
<div class="field"> <div class="field has-addons">
<label class="label" asp-for="Model!.Id">ID</label> <div class="control">
<div class="control"> <label class="button is-static">ID</label>
<input required class="input" type="text" asp-for="Model!.Id" /> </div>
</div> <div class="control is-expanded">
<span class="help is-danger" asp-validation-for="Model!.Id"></span> <input required type="text" class="input" name="Inspect_Id"/>
</div> </div>
<div class="control">
<div class="field"> <button class="button is-primary" type="submit">Inspect</button>
<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>
</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">
<span class="help is-danger">@ModelState["Inspect_Id"]?.Errors.FirstOrDefault()?.ErrorMessage</span>
<div class="field is-grouped is-grouped-right">
<div class="control">
<button class="button is-primary" type="submit">Create</button>
</div> </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> </div>

View file

@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Web; using System.Web;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
namespace JustShortIt.Pages; namespace JustShortIt.Pages;
@ -28,7 +29,20 @@ public class UrlsModel : PageModel {
Db = db; 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() { public async Task<IActionResult> OnPostAsync() {
if (!ModelState.IsValid) return Page(); if (!ModelState.IsValid) return Page();