Skip to content

Commit

Permalink
Finish latest package page, wip versioned display
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Feb 24, 2024
1 parent 00b012e commit c6caaf3
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using PackageRegistryService.Models;

namespace PackageRegistryService.Pages.Components
{
public class PackageAvailableVersion
{
public static string Render(string packageName, string version) => $@"<a href=""/package/{packageName}/{version}"">{version}</a>";

public static string RenderVersionTable(ValidationPackage[] packages)
{

var content = $@"<table>
<thead>
<tr>
<th scope=""col"">Version</th>
<th scope=""col"">Released on</th>
</tr>
</thead>
<tbody>
{string.Join(
System.Environment.NewLine,
packages
.OrderByDescending(p => p.MajorVersion)
.ThenByDescending(p => p.MinorVersion)
.ThenByDescending(p => p.PatchVersion)
.Select(p => $@" <tr>
<td>{Render(p.Name, p.GetSemanticVersionString())}</td>
<td>{p.ReleaseDate}</td>
</tr>"))}
</tbody>
";
return content;

}
}
}
26 changes: 26 additions & 0 deletions src/PackageRegistryService/Pages/Components/PackageDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace PackageRegistryService.Pages.Components
{
public class PackageDescription
{
public static string Render(string description)
{
return String.Join(
System.Environment.NewLine,
description
.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)
.Select(l => $@"<p style=""display:block"">{l}</p>")
);

}
public static string RenderSmall(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>")
);

}
}
}
39 changes: 39 additions & 0 deletions src/PackageRegistryService/Pages/Components/PackageReleaseNotes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace PackageRegistryService.Pages.Components
{
public class PackageReleaseNotes
{
public static string Render(string? releaseNotes)
{
if (releaseNotes == null)
{
return "<p>No release notes available for this version</p>";
}
else
{
return String.Join(
System.Environment.NewLine,
releaseNotes
.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)
.Select(l => $@"<p style=""display:block"">{l}</p>")
);
}
}
public static string RenderSmall(string? releaseNotes)
{
if (releaseNotes == null)
{
return "<p>No release notes available for this version</p>";
}
else
{
return String.Join(
System.Environment.NewLine,
releaseNotes
.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None)
.Select(l => $@"<small style=""display:block"">{l}</small>")
);

}
}
}
}
13 changes: 2 additions & 11 deletions src/PackageRegistryService/Pages/Components/PackageSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@ 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>{RenderDescription(summary.Description)}</td>
<td>{PackageDescription.RenderSmall(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>
<td>{string.Join("; ", summary.Tags.Select(PackageTag.Render))}</td>
</tr>";
}

Expand Down
19 changes: 19 additions & 0 deletions src/PackageRegistryService/Pages/Components/PackageTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace PackageRegistryService.Pages.Components
{
public class PackageTag
{
public static string Render(string tagName) => $@"<a href=""/packages?tag={tagName}"">{tagName}</a>";

public static string RenderAllInline(string[]? tags)
{
if (tags == null)
{
return "";
}
else
{
return String.Join("; ", tags.Select(t => Render(t)));
}
}
}
}
64 changes: 52 additions & 12 deletions src/PackageRegistryService/Pages/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
using Microsoft.EntityFrameworkCore;
using PackageRegistryService.Models;
using PackageRegistryService.Pages.Components;
using System.Text;

namespace PackageRegistryService.Pages
{
public static class Package
{
public static async Task<ContentHttpResult> Render(string packageName, ValidationPackageDb database)
public static async Task<Results<ContentHttpResult, NotFound>> Render(string packageName, string version, ValidationPackageDb database)
{
var content = $"{packageName}, {version}";
return TypedResults.Text(content: content, contentType: "text/html");
}
public static async Task<Results<ContentHttpResult, NotFound>> RenderLatest(string packageName, ValidationPackageDb database)
{
var packages = await
database.ValidationPackages
Expand All @@ -21,21 +27,55 @@ public static async Task<ContentHttpResult> Render(string packageName, Validatio
.ThenByDescending(p => p.PatchVersion)
.FirstOrDefault();

var content = Layout.Render(
if (latestPackage == null)
{
return TypedResults.NotFound();
}

var content = $@"<section>
<hgroup>
<h1>Validation Package <mark>{packageName}</mark></h1>
<p>{PackageTag.RenderAllInline(latestPackage.Tags)}</p>
<p>v{latestPackage.GetSemanticVersionString()}</p>
</hgroup>
</section>
<hr />
<section>
<h4>Install with <a href=""a"">arc-validate</a></h3>
<pre><code> arc-validate package install {packageName} --package-version {latestPackage.GetSemanticVersionString()}</code></pre>
</section>
<hr />
<section>
<h2>Description</h2>
{PackageDescription.Render(latestPackage.Description)}
</section>
<hr />
<section>
<details>
<summary role=""button"" class=""primary"">Release notes</summary>
{PackageReleaseNotes.Render(latestPackage.ReleaseNotes)}
</details>
<hr />
<details>
<summary role=""button"" class=""primary"">Browse code (v{latestPackage.GetSemanticVersionString()})</summary>
<pre><code>{Encoding.UTF8.GetString(latestPackage.PackageContent)}</code></pre>
</details>
<hr />
<details>
<summary role=""button"" class=""primary"">Available versions</summary>
{PackageAvailableVersion.RenderVersionTable(packages)}
</details>
</section>
<hr />
";

var page = 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>
"
content: content
);

return TypedResults.Text(content: content, contentType: "text/html");
return TypedResults.Text(content: page, contentType: "text/html");
}
}
}
4 changes: 3 additions & 1 deletion src/PackageRegistryService/Pages/PageEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public static RouteGroupBuilder MapPageEndpoints(this RouteGroupBuilder group)

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

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

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

return group;
}
Expand Down

0 comments on commit c6caaf3

Please sign in to comment.