974d5f3
use axum::extract::{Path, State};
use axum::response::Response;
use maud::html;
use crate::handler::html::{HtmlRepoPath, archived_class, resolve, response_html};
use crate::service::GitService;
use crate::share::access::BasicAuth;
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/html/refs-dropdown",
tag = "html",
params(HtmlRepoPath),
responses(
(status = 200, description = "refs dropdown html fragment", content_type = "text/html"),
(status = 404, description = "repo not found")
)
)]
pub async fn render(
State(service): State<GitService>,
Path(path): Path<HtmlRepoPath>,
auth: BasicAuth,
) -> Response {
let ctx = match resolve(service, path, auth).await {
Ok(c) => c,
Err(resp) => return resp,
};
let base = "git-refs-dropdown relative inline-flex w-full max-w-xs";
let cls = archived_class(&ctx.dto, base);
let default = ctx.dto.default_branch.clone();
let space = ctx.space_name.clone();
let repo = ctx.repo_name.clone();
let markup = html! {
div class=(cls)
data-component="git-refs-dropdown"
data-space=(space)
data-repo=(repo)
data-default-branch=(default)
data-archived=(if ctx.dto.is_archived { "true" } else { "false" }) {
label class="mb-1 block text-xs font-medium text-zinc-600" { "Branch" }
select class="w-full rounded border border-zinc-200 bg-white px-2 py-1 text-sm"
data-action="switch-ref" {
option value=(ctx.dto.default_branch) selected[true] {
(ctx.dto.default_branch) " (default)"
}
@if ctx.dto.nums_branches > 1 {
option disabled="true" value="" { "—" }
option value="__tags__" disabled="true" { "tags: " (ctx.dto.nums_tags) }
}
}
p class="mt-1 text-xs text-zinc-500" {
(ctx.dto.nums_branches) " branches · " (ctx.dto.nums_tags) " tags"
}
}
};
response_html(markup, 30)
}