Skip to content

Commit

Permalink
Add simple package page
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Feb 23, 2024
1 parent b42211b commit 00b012e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"RepoPath": "src/PackageRegistryService/StagingArea/invenio/[email protected]",
"FileName": "[email protected]",
"LastUpdated": "2024-02-23T16:27:27+01:00",
"LastUpdated": "2024-02-23T16:27:26+01:00",
"Metadata": {
"Name": "invenio",
"Description": "Validates if the ARC contains the necessary metadata to be publishable via Invenio.\nThe following metadata is required:\n - Investigation has title and description\n - All persons in Investigation Contacts must have a name, last name, affiliation and valid email\n",
Expand Down
2 changes: 1 addition & 1 deletion src/PackageRegistryService/Pages/Components/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static string Render(string activeNavbarItem, string title, string conten
<meta charset=""utf-8"">
<meta name=""viewport"" content=""width=device-width, initial-scale=1"">
<meta name=""color-scheme"" content=""light dark"" />
<link rel=""stylesheet"" href=""css/pico.cyan.min.css"" />
<link rel=""stylesheet"" href=""/css/pico.cyan.min.css"" />
<title>{title}</title>
</head>
<body>
Expand Down
15 changes: 13 additions & 2 deletions src/PackageRegistryService/Pages/Components/PackageSummary.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
namespace PackageRegistryService.Pages.Components
using YamlDotNet.Core.Tokens;

namespace PackageRegistryService.Pages.Components
{
public record PackageSummary(string Name, string Description, string [] Tags, string LatestVersion, DateOnly ReleaseDate)
{
public static string RenderDescription(string description)
{
return String.Join(
System.Environment.NewLine,
description
.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)
.Select(l => $@"<small style=""display:block"">{l}</small>")
);
}
public static string Render(PackageSummary summary)
{
return $@"<tr>
<th scope=""row""><a href=""/package/{summary.Name}"">{summary.Name}</a></th>
<td>{summary.Description}</td>
<td>{RenderDescription(summary.Description)}</td>
<td><a href=""/package/{summary.Name}/{summary.LatestVersion}"">{summary.LatestVersion}</a></td>
<td>{summary.ReleaseDate}</td>
<td>{string.Join("; ", summary.Tags.Select(t => $@"<a href=""/packages?tag={t}"">{t}</a>"))}</td>
Expand Down
37 changes: 36 additions & 1 deletion src/PackageRegistryService/Pages/Package.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
namespace PackageRegistryService.Pages
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;
using PackageRegistryService.Models;
using PackageRegistryService.Pages.Components;

namespace PackageRegistryService.Pages
{
public static class Package
{
public static async Task<ContentHttpResult> Render(string packageName, ValidationPackageDb database)
{
var packages = await
database.ValidationPackages
.Where(p => p.Name == packageName)
.ToArrayAsync();

var latestPackage =
packages
.OrderByDescending(p => p.MajorVersion)
.ThenByDescending(p => p.MinorVersion)
.ThenByDescending(p => p.PatchVersion)
.FirstOrDefault();

var content = Layout.Render(
activeNavbarItem: "",
title: $"Package {packageName} - ARC validation package registry API",
content: $@"<h1>Validation Package <mark>{packageName}</mark></h1>
<pre>
<code>
arc-validate package install {packageName}
arc-validate package install {packageName} --package-version {latestPackage.GetSemanticVersionString()}
</code>
</pre>
"
);

return TypedResults.Text(content: content, contentType: "text/html");
}
}
}
2 changes: 2 additions & 0 deletions src/PackageRegistryService/Pages/PageEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public static RouteGroupBuilder MapPageEndpoints(this RouteGroupBuilder group)

group.MapGet("packages", Packages.Render);

group.MapGet("package/{packageName}", Package.Render);

return group;
}
}
Expand Down

0 comments on commit 00b012e

Please sign in to comment.