Skip to content

Commit

Permalink
Finish AG creation demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcrane committed Jan 28, 2024
1 parent e25fb07 commit 256526d
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 73 deletions.
2 changes: 1 addition & 1 deletion LeedsExperiment/Dashboard/Controllers/BrowseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task<IActionResult> IndexAsync(
ViewBag.Parent = "/browse/" + parentPath;


ViewBag.Result = $"Container created at path {path}";
ViewBag.CreateResult = $"Container created at path {path}";
return View("Container", newContainer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,20 @@ public async Task<IActionResult> ImportStartAsync(
var existingAg = await preservation.GetArchivalGroup(path, null);
model.ArchivalGroup = existingAg;
}
else if(resourceInfo.StatusCode == 404)
{
model.NewName = name;
}
else
else if (resourceInfo.StatusCode != 404)
{
ViewBag.Problem = "Invalid Status code: " + resourceInfo.StatusCode;
return View("ImportStart", model);
}
model.Name = name;
if (!string.IsNullOrWhiteSpace(source))
{
// we already know where the update file are
// This is only for synchronising with S3; There'll need to be a different route
// for ad hoc construction of an ImportJob (e.g., it's just one deletion).
var importJob = await preservation.GetUpdateJob(path, source);
model.ImportJob = importJob;
importJob.ArchivalGroupName = name;
importJob.ArchivalGroupName = model.ArchivalGroup?.Name ?? model.Name;
return View("ImportJob", model);
}
// else render a view that asks for the S3 source then resubmits
Expand Down
17 changes: 4 additions & 13 deletions LeedsExperiment/Dashboard/Models/ImportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@ namespace Dashboard.Models;

public class ImportModel
{
public string DisplayName
{
get
{
if(ArchivalGroup == null)
{
return "[New Archival Group]";
}
return ArchivalGroup.GetDisplayName();
}
}
public string DisplayName => ArchivalGroup?.GetDisplayName() ?? Name!;
public required string Path { get; set; }
public ArchivalGroup? ArchivalGroup { get; set; }
public ResourceInfo? ResourceInfo { get; set; }
public ImportJob? ImportJob { get; set; }

/// <summary>
/// The name to give a new ArchivalGroup on creation
/// The name to give a new Archival Group on creation, or the name of the current
/// Archival Group.
/// </summary>
public string? NewName { get; internal set; }
public string? Name { get; internal set; }
}
128 changes: 79 additions & 49 deletions LeedsExperiment/Dashboard/Views/Browse/Container.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,99 @@
@model Fedora.Abstractions.Container

<div>
@if(ViewBag.Result != null)
@if(ViewBag.CreateResult != null)
{
<div class="alert alert-success" role="alert">
<p>@ViewBag.Result</p>
<p>@ViewBag.CreateResult</p>
</div>
}

@if (ViewBag.Problem != null)
{
<div class="alert alert-danger" role="alert">
<p>@ViewBag.Problem</p>
</div>
<partial name="_ParentLink" />
}
else
{
@if (ViewBag.Problem != null)
{
<div class="alert alert-danger" role="alert">
<p>@ViewBag.Problem</p>
</div>
}

<partial name="_ArchivalGroupHeader" />
<partial name="_ArchivalGroupHeader" />

@if (Model.Type == "RepositoryRoot")
{
<h1 class="display-4">🏠 @Model.GetDisplayName()</h1>
}
else
{
<partial name="_ParentLink" />
@if (Model.Type == "RepositoryRoot")
{
<h1 class="display-4">🏠 @Model.GetDisplayName()</h1>
}
else
{
<partial name="_ParentLink" />

<h1 class="display-4">📁 @Model.GetDisplayName()</h1>
<partial name="_CommonMetadata" model="Model" />
}
<h1 class="display-4">📁 @Model.GetDisplayName()</h1>
<partial name="_CommonMetadata" model="Model" />
}

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

@if (ViewBag.ArchivalGroupPath == null)
{
<form action="/create/@ViewBag.Path" method="post">
<div class="mb-3">
<label for="childContainerName" class="form-label">Add a child container:</label>
<input type="text" class="form-control" id="childContainerName" name="name" placeholder="(📁 path-safe name of child container)">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
}
@if (ViewBag.ArchivalGroupPath == null)
{
<form id="childContainerForm" action="/create/@ViewBag.Path" method="post">
<div class="mb-3">
<label for="childContainerName" class="form-label">Add a child container:</label>
<input type="text" class="form-control" id="childContainerName" name="name" placeholder="(📁 path-safe name of child container)">
</div>
<button type="submit" class="btn btn-primary">Create container</button>
</form>

@if (ViewBag.ArchivalGroupPath == null && Model.Type != "RepositoryRoot")
{
<form id="newAgForm" action="/import/@ViewBag.Path/NEW-AG" method="get">
<div class="mb-3">
<label for="agName" class="form-label">Create an Archival Group:</label>
<input type="text" class="form-control" id="agName" name="name" placeholder="(📦 path-safe name of archival group)">

<script type="text/javascript">
const childContainerForm = document.getElementById("childContainerForm");
childContainerForm.addEventListener("submit", function (ev) {
ev.preventDefault();
const slug = document.getElementById("childContainerName").value;
if (encodeURIComponent(slug) != slug) {
alert("slug must only contain characters that won't be URI-encoded");
} else {
childContainerForm.submit();
}
});
</script>
}

@if (ViewBag.ArchivalGroupPath == null && Model.Type != "RepositoryRoot")
{
<!-- -->
<div class="alert alert-primary mt-4" role="alert">
<form id="newAgForm" action="/import/@ViewBag.Path/NEW-AG" method="get">
<div class="mb-3">
<label for="agName" class="form-label"><strong>Create a new Archival Group under @ViewBag.Path:</strong></label>
<input type="text" class="form-control" id="agName" name="name" placeholder="(📦 Name of archival group)">
</div>
<div class="mb-3">
<label for="agSlug" class="form-label">with path element (slug):</label>
<input type="text" class="form-control" id="agSlug" name="slug" placeholder="(📦 path-safe slug of archival group)">
</div>
<button type="submit" id="btnAgSubmit" class="btn btn-primary">Select source files...</button>
</form>
</div>
<button type="submit" id="btnAgSubmit" class="btn btn-primary">Submit</button>
</form>

<script type="text/javascript">
<script type="text/javascript">
const prefix = "/import/@(ViewBag.Path)/";
const agForm = document.getElementById("newAgForm");
agForm.addEventListener("submit", function (ev) {
ev.preventDefault();
const name = document.getElementById("agName").value;
agForm.action = prefix + name;
agForm.submit();
});
const prefix = "/import/@(ViewBag.Path)/";
const agForm = document.getElementById("newAgForm");
agForm.addEventListener("submit", function (ev) {
ev.preventDefault();
const slug = document.getElementById("agSlug").value;
if (encodeURIComponent(slug) != slug) {
alert("slug must only contain characters that won't be URI-encoded");
} else {
agForm.action = prefix + slug;
agForm.submit();
}
});
</script>
</script>
}
}

</div>
4 changes: 2 additions & 2 deletions LeedsExperiment/Dashboard/Views/ImportExport/ImportJob.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@if(Model.ArchivalGroup == null)
{
<p>This import will create a new Archival Group at @Model.Path with name <b>@Model.NewName</b></p>
<p>This import will create a new Archival Group at @Model.Path with name <b>@Model.Name</b></p>
}
else
{
Expand All @@ -40,7 +40,7 @@
</tr>
<tr>
<th scope="row">Name</th>
<td>@(Model.ArchivalGroup?.Name ?? Model.NewName)</td>
<td>@(Model.ArchivalGroup?.Name ?? Model.Name)</td>
</tr>
<tr>
<th scope="row">Diff duration</th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<div>
<h1 class="display-4">Import 📦 - @Model.DisplayName</h1>
<p>Path: @Model.Path</p>
<p><a href="/ocfl/@Model.Path">View storage (OCFL)</a></p>

@if(Model.ArchivalGroup == null)
{
<p>Specify a source location to create a new Archival Group at @Model.Path</p>
}
else
{
<p><a href="/ocfl/@Model.Path">View storage (OCFL)</a></p>
<p>Specify a source for updating the existing Archival Group at @Model.Path</p>
<p>The existing Archival Group <em>@Model.ArchivalGroup.Name</em> is at version @Model.ArchivalGroup.Version</p>
}
Expand All @@ -29,7 +29,7 @@
{
<div class="mb-3">
<label for="newName" class="form-label">Name</label>
<input type="text" class="form-control" id="newName" name="name" aria-describedby="nameHelp" value="@Model.NewName" />
<input type="text" class="form-control" id="newName" name="name" aria-describedby="nameHelp" value="@Model.Name" />
<div id="nameHelp" class="form-text">The name of the new Archival Group</div>
</div>
}
Expand Down

0 comments on commit 256526d

Please sign in to comment.