Skip to content

Commit

Permalink
User interface start
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrane committed Jan 10, 2024
1 parent a45cd03 commit 6620a38
Show file tree
Hide file tree
Showing 40 changed files with 843 additions and 638 deletions.
45 changes: 45 additions & 0 deletions LeedsExperiment/Dashboard/Controllers/BrowseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Fedora.Abstractions;
using Microsoft.AspNetCore.Mvc;
using Preservation;

namespace Dashboard.Controllers;

public class BrowseController : Controller
{
private readonly ILogger<BrowseController> logger;
private readonly IPreservation preservation;

public BrowseController(
IPreservation preservation,
ILogger<BrowseController> logger)
{
this.preservation = preservation;
this.logger = logger;
}

[Route("browse/{*path}")]
public async Task<IActionResult> IndexAsync(string? path = null)
{
var resource = await preservation.GetResource(path);
if (resource == null)
{
return NotFound();
}
if(resource.PreservationApiPartOf != null)
{
ViewBag.ArchivalGroupPath = preservation.GetInternalPath(resource.PreservationApiPartOf);
}
switch(resource.Type)
{
case "Container":
case "RepositoryRoot":
return View("Container", resource as Container);
case "Binary":
return View("Binary", resource as Binary);
case "ArchivalGroup":
return View("ArchivalGroup", resource as ArchivalGroup);
default:
return Problem("Unknown Preservation type");
}
}
}
67 changes: 31 additions & 36 deletions LeedsExperiment/Dashboard/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
using Dashboard.Models;
using Microsoft.AspNetCore.Mvc;
using Preservation.API;
using Preservation;
using System.Diagnostics;

namespace Dashboard.Controllers
namespace Dashboard.Controllers;

public class HomeController : Controller
{
public class HomeController : Controller
private readonly ILogger<HomeController> logger;
private readonly IPreservation preservation;

public HomeController(
IPreservation preservation,
ILogger<HomeController> logger)
{
this.preservation = preservation;
this.logger = logger;
}

public IActionResult Index()
{
return View();
}


//public async Task<IActionResult> ForecastAsync()
//{
// var forecasts = await preservation.Test();
// return View(forecasts[0]);
//}


[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
private readonly ILogger<HomeController> logger;
private readonly IPreservation preservation;

public HomeController(
IPreservation preservation,
ILogger<HomeController> logger)
{
this.preservation = preservation;
this.logger = logger;
}

public IActionResult Index()
{
return View();
}


public async Task<IActionResult> ForecastAsync()
{
var forecasts = await preservation.Test();
return View(forecasts[0]);
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
1 change: 1 addition & 0 deletions LeedsExperiment/Dashboard/Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\Fedora\Fedora.csproj" />
<ProjectReference Include="..\PreservationApiClient\PreservationApiClient.csproj" />
<ProjectReference Include="..\Preservation\Preservation.csproj" />
</ItemGroup>

Expand Down
19 changes: 19 additions & 0 deletions LeedsExperiment/Dashboard/Helpers/ResourceX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Fedora.Abstractions;

namespace Dashboard.Helpers;

public static class ResourceX
{
public static string GetDisplayName(this Resource resource)
{
if(!string.IsNullOrWhiteSpace(resource.Name)) return resource.Name;

if (resource.Type == "RepositoryRoot") return "(Root of repository)";

var slug = resource.GetSlug();
if(!string.IsNullOrWhiteSpace(slug)) return slug;

return $"[{resource.GetType().Name}]";
}

}
4 changes: 2 additions & 2 deletions LeedsExperiment/Dashboard/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Preservation.API;
using Preservation;
using PreservationApiClient;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -8,7 +9,6 @@
// https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests
builder.Services.AddHttpClient<IPreservation, PreservationService>(client =>
{
// client.BaseAddress = new Uri("http://host.docker.internal:8801/");
client.BaseAddress = new Uri(builder.Configuration["ApiBaseAddress"]!);
client.DefaultRequestHeaders.Add("Accept", "application/json");
});
Expand Down
10 changes: 10 additions & 0 deletions LeedsExperiment/Dashboard/Views/Browse/ArchivalGroup.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@using Dashboard.Helpers
@model Fedora.Abstractions.ArchivalGroup

<div>
<div class="alert alert-primary" role="alert">
<h1 class="display-4">📦 @Model.GetDisplayName()</h1>
</div>

<partial name="_CommonMetadata" model="Model" />
</div>
15 changes: 15 additions & 0 deletions LeedsExperiment/Dashboard/Views/Browse/Binary.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@using Dashboard.Helpers
@model Fedora.Abstractions.Binary

<div>
@if (ViewBag.ArchivalGroupPath != null)
{
<div class="alert alert-primary" role="alert">
Part of an <i>Archival Group</i>: <a href="/browse/@ViewBag.ArchivalGroupPath">@ViewBag.ArchivalGroupPath</a>
</div>
}

<h1 class="display-4">📄 @Model.GetDisplayName()</h1>

<partial name="_CommonMetadata" model="Model" />
</div>
25 changes: 25 additions & 0 deletions LeedsExperiment/Dashboard/Views/Browse/Container.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@using Dashboard.Helpers
@model Fedora.Abstractions.Container

<div>
@if (ViewBag.ArchivalGroupPath != null)
{
<div class="alert alert-primary" role="alert">
Part of an <i>Archival Group</i>: <a href="/browse/@ViewBag.ArchivalGroupPath">@ViewBag.ArchivalGroupPath</a>
</div>
}

<h1 class="display-4">@(Model.Type == "RepositoryRoot") ? "🏠" : "📁") @Model.GetDisplayName()</h1>

<partial name="_CommonMetadata" model="Model" />

@foreach(var container in Model.Containers)
{
<partial name="_SimpleContainer" model="container" />
}

@foreach (var binary in Model.Binaries)
{
<partial name="_SimpleBinary" model="binary" />
}
</div>
7 changes: 7 additions & 0 deletions LeedsExperiment/Dashboard/Views/Browse/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@{
ViewData["Title"] = "Home Page";
}

<div class="text-center">
<h1 class="display-4">@ViewBag.Path</h1>
</div>
36 changes: 0 additions & 36 deletions LeedsExperiment/Dashboard/Views/Home/Forecast.cshtml

This file was deleted.

6 changes: 0 additions & 6 deletions LeedsExperiment/Dashboard/Views/Home/Privacy.cshtml

This file was deleted.

19 changes: 19 additions & 0 deletions LeedsExperiment/Dashboard/Views/Shared/_CommonMetadata.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@model Fedora.Abstractions.Resource
<table class="table">
<tr>
<th scope="row">Created</th>
<td>@Model.Created</td>
</tr>
<tr>
<th scope="row">Created by</th>
<td>@Model.CreatedBy</td>
</tr>
<tr>
<th scope="row">Last modified</th>
<td>@Model.LastModified</td>
</tr>
<tr>
<th scope="row">Last modified by</th>
<td>@Model.LastModifiedBy</td>
</tr>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using Fedora.Storage;
using System.Text.Json.Serialization;

namespace Fedora;
namespace Fedora.Abstractions;

public class ArchivalGroup : Container
{
public ArchivalGroup() { }

public ArchivalGroup(FedoraJsonLdResponse fedoraResponse) : base(fedoraResponse)
{
Type = "ArchivalGroup";
Expand All @@ -29,11 +31,11 @@ public Uri GetResourceUri(string path)
// we can't do:
// new Uri(Location, "foo/bar.xml");
// and nor can we use "./foo/bar.xml" or "/foo/bar.xml"
if(Location == null)
if (Location == null)
{
throw new InvalidOperationException("Needs a location");
}
if(Location.AbsolutePath.EndsWith("/"))
if (Location.AbsolutePath.EndsWith("/"))
{
// I'm pretty sure this will never be the case
return new Uri(Location, path);
Expand Down
43 changes: 43 additions & 0 deletions LeedsExperiment/Fedora/Abstractions/Binary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Fedora.ApiModel;
using System.Text.Json.Serialization;

namespace Fedora.Abstractions;

public class Binary : Resource
{
public Binary() { }

public Binary(FedoraJsonLdResponse jsonLdResponse) : base(jsonLdResponse)
{
Type = "Binary";
var binaryresp = jsonLdResponse as BinaryMetadataResponse;
if (binaryresp != null)
{
FileName = binaryresp.FileName;
ContentType = binaryresp.ContentType;
Size = Convert.ToInt64(binaryresp.Size);
Digest = binaryresp.Digest?.Split(':')[^1];
}
}

[JsonPropertyName("filename")]
[JsonPropertyOrder(21)]
public string? FileName { get; set; }

[JsonPropertyName("contentType")]
[JsonPropertyOrder(22)]
public string? ContentType { get; set; }

[JsonPropertyName("size")]
[JsonPropertyOrder(23)]
public long Size { get; set; }

[JsonPropertyName("digest")]
[JsonPropertyOrder(24)]
public string? Digest { get; set; }

public override string ToString()
{
return $"🗎 {Name ?? GetType().Name}";
}
}
Loading

0 comments on commit 6620a38

Please sign in to comment.