Skip to content

Commit

Permalink
add UI for marking graphs as vintage
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Sep 16, 2024
1 parent 15dd5d0 commit edbae77
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
3 changes: 3 additions & 0 deletions Sources/UnidocAPI/Building/Unidoc.LinkerRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ extension Unidoc
case uplink
case unlink
case delete
/// This is not really a linker action, but it is related closely enough to piggyback
/// on the same route.
case vintage
}
}
extension Unidoc.LinkerRoute:CustomStringConvertible
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extension Unidoc.LinkerOperation
{
enum Update
{
case action(Unidoc.LinkerAction)
case vintage(Bool)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,37 @@ extension Unidoc
/// Queues one or more editions for uplinking. The uplinking process itself is asynchronous.
struct LinkerOperation:Sendable
{
let action:LinkerAction
let update:Update
let scope:Edition?
let back:String?

init(action:Unidoc.LinkerAction, scope:Unidoc.Edition?, back:String? = nil)
init(update:Update, scope:Unidoc.Edition?, back:String? = nil)
{
self.action = action
self.update = update
self.scope = scope
self.back = back
}
}
}
extension Unidoc.LinkerOperation
{
init(action:Unidoc.LinkerAction, form:Unidoc.LinkerForm)
{
self.init(action: action, scope: form.edition, back: form.back)
}
}
extension Unidoc.LinkerOperation:Unidoc.AdministrativeOperation
{
func load(from server:Unidoc.Server,
db:Unidoc.DB,
as _:Unidoc.RenderFormat) async throws -> HTTP.ServerResponse?
{
if let scope:Unidoc.Edition = self.scope
switch (self.scope, self.update)
{
try await db.snapshots.queue(id: scope, for: self.action)
}
else
{
try await db.snapshots.queueAll(for: self.action)
case (nil, .action(let action)):
try await db.snapshots.queueAll(for: action)

case (let scope?, .action(let action)):
try await db.snapshots.queue(id: scope, for: action)

case (let scope?, .vintage(let vintage)):
try await db.snapshots.mark(id: scope, vintage: vintage)

default:
return nil
}

return .redirect(.seeOther(self.back ?? "/admin"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ extension Unidoc.BuilderUploadOperation:Unidoc.BlockingOperation
case .failure:
// Mark the snapshot as unbuildable, so that automated plugins don’t try to
// build it again.
let _:Unidoc.Snapshot? = try await db.snapshots.modify(
existing: complete.id.edition)
{
$0[.set] { $0[Unidoc.Snapshot[.vintage]] = true }
}
try await db.snapshots.mark(id: complete.id.edition, vintage: true)
}

case .labeling:
Expand Down
18 changes: 12 additions & 6 deletions Sources/UnidocServer/Requests/Unidoc.Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,21 +525,25 @@ extension Unidoc.Router
case .uplink: return nil
case .unlink: page = .unlink(uri)
case .delete: page = .delete(uri)
case .vintage: return nil
}

return .syncHTML(page)
}

let action:Unidoc.LinkerAction
let update:Unidoc.LinkerOperation.Update

switch route
{
case .uplink: action = .uplinkRefresh
case .unlink: action = .unlink
case .delete: action = .delete
case .uplink: update = .action(.uplinkRefresh)
case .unlink: update = .action(.unlink)
case .delete: update = .action(.delete)
case .vintage: update = .vintage(true)
}

return .unordered(Unidoc.LinkerOperation.init(action: action, form: form))
return .unordered(Unidoc.LinkerOperation.init(update: update,
scope: form.edition,
back: form.back))
}

private mutating
Expand Down Expand Up @@ -646,7 +650,9 @@ extension Unidoc.Router
}

case .uplinkAll:
return .unordered(Unidoc.LinkerOperation.init(action: .uplinkRefresh, scope: nil))
return .unordered(Unidoc.LinkerOperation.init(
update: .action(.uplinkRefresh),
scope: nil))

case .userConfig:
if let account:Unidoc.Account = self.authorization.account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ extension Unidoc.RefsTable.Row.Graph:HTML.OutputStreamable
("Uplink", .uplink),
("Unlink", .unlink),
("Delete", .delete),
("Mark vintage", .vintage)
]
{
$0[.li]
Expand All @@ -173,6 +174,8 @@ extension Unidoc.RefsTable.Row.Graph:HTML.OutputStreamable
case .uplink: break
case .unlink: action["y"] = "false"
case .delete: action["y"] = "false"
// Mark vintage does not require confirmation.
case .vintage: break
}

$0[.form]
Expand Down

0 comments on commit edbae77

Please sign in to comment.