Track and untrack refs

This commit is contained in:
Joscha 2023-08-18 01:03:14 +02:00
parent 4af950b6a4
commit 7e0bf21223
10 changed files with 134 additions and 25 deletions

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE refs SET tracked = 1 WHERE name = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 1
},
"nullable": []
},
"hash": "3f51c3b54edbb7c4819ecdcfe396059750c9b841a54effa4a5ef63b43f1b1a94"
}

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE refs SET tracked = 0 WHERE name = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 1
},
"nullable": []
},
"hash": "c0f80f2907ea00edd35207fb72b591eaa895db06c585e7f4355a3c5b5461acd6"
}

View file

@ -17,6 +17,7 @@ use self::{
post_admin_queue_add, post_admin_queue_add_batch, post_admin_queue_decrease, post_admin_queue_add, post_admin_queue_add_batch, post_admin_queue_decrease,
post_admin_queue_delete, post_admin_queue_increase, post_admin_queue_delete, post_admin_queue_increase,
}, },
refs::{post_admin_refs_track, post_admin_refs_untrack},
repo::post_admin_repo_update, repo::post_admin_repo_update,
}, },
api::worker::{ api::worker::{
@ -59,6 +60,8 @@ pub async fn run(server: Server) -> somehow::Result<()> {
.typed_post(post_admin_queue_decrease) .typed_post(post_admin_queue_decrease)
.typed_post(post_admin_queue_delete) .typed_post(post_admin_queue_delete)
.typed_post(post_admin_queue_increase) .typed_post(post_admin_queue_increase)
.typed_post(post_admin_refs_track)
.typed_post(post_admin_refs_untrack)
.typed_post(post_admin_repo_update) .typed_post(post_admin_repo_update)
.merge(post_api_worker_status) .merge(post_api_worker_status)
.fallback(get(r#static::static_handler)) .fallback(get(r#static::static_handler))

View file

@ -1,2 +1,3 @@
pub mod queue; pub mod queue;
pub mod refs;
pub mod repo; pub mod repo;

View file

@ -0,0 +1,58 @@
use axum::{
extract::State,
response::{IntoResponse, Redirect},
Form,
};
use log::info;
use serde::Deserialize;
use sqlx::SqlitePool;
use crate::{
config::ServerConfig,
server::web::{
base::Base,
paths::{PathAdminRefsTrack, PathAdminRefsUntrack, PathIndex},
},
somehow,
};
#[derive(Deserialize)]
pub struct FormAdminRefsTrack {
r#ref: String,
}
pub async fn post_admin_refs_track(
_path: PathAdminRefsTrack,
State(config): State<&'static ServerConfig>,
State(db): State<SqlitePool>,
Form(form): Form<FormAdminRefsTrack>,
) -> somehow::Result<impl IntoResponse> {
let result = sqlx::query!("UPDATE refs SET tracked = 1 WHERE name = ?", form.r#ref)
.execute(&db)
.await?;
if result.rows_affected() > 0 {
info!("Admin tracked {}", form.r#ref);
}
let link = Base::link_with_config(config, PathIndex {});
Ok(Redirect::to(&link.to_string()))
}
pub async fn post_admin_refs_untrack(
_path: PathAdminRefsUntrack,
State(config): State<&'static ServerConfig>,
State(db): State<SqlitePool>,
Form(form): Form<FormAdminRefsTrack>,
) -> somehow::Result<impl IntoResponse> {
let result = sqlx::query!("UPDATE refs SET tracked = 0 WHERE name = ?", form.r#ref)
.execute(&db)
.await?;
if result.rows_affected() > 0 {
info!("Admin untracked {}", form.r#ref);
}
let link = Base::link_with_config(config, PathIndex {});
Ok(Redirect::to(&link.to_string()))
}

View file

@ -8,7 +8,7 @@ use crate::{
server::web::{ server::web::{
base::{Base, Link, Tab}, base::{Base, Link, Tab},
link::LinkCommit, link::LinkCommit,
paths::{PathAdminRepoUpdate, PathIndex}, paths::{PathAdminRefsTrack, PathAdminRefsUntrack, PathAdminRepoUpdate, PathIndex},
}, },
somehow, somehow,
}; };
@ -22,6 +22,8 @@ struct Ref {
#[derive(Template)] #[derive(Template)]
#[template(path = "pages/index.html")] #[template(path = "pages/index.html")]
struct IndexTemplate { struct IndexTemplate {
link_admin_refs_track: Link,
link_admin_refs_untrack: Link,
link_admin_repo_update: Link, link_admin_repo_update: Link,
base: Base, base: Base,
@ -64,6 +66,8 @@ pub async fn get_index(
} }
Ok(IndexTemplate { Ok(IndexTemplate {
link_admin_refs_track: base.link(PathAdminRefsTrack {}),
link_admin_refs_untrack: base.link(PathAdminRefsUntrack {}),
link_admin_repo_update: base.link(PathAdminRepoUpdate {}), link_admin_repo_update: base.link(PathAdminRepoUpdate {}),
base: Base::new(config, Tab::Index), base: Base::new(config, Tab::Index),

View file

@ -53,6 +53,14 @@ pub struct PathWorkerByName {
// Admin actions // // Admin actions //
/////////////////// ///////////////////
#[derive(Deserialize, TypedPath)]
#[typed_path("/admin/refs/track")]
pub struct PathAdminRefsTrack {}
#[derive(Deserialize, TypedPath)]
#[typed_path("/admin/refs/untrack")]
pub struct PathAdminRefsUntrack {}
#[derive(Deserialize, TypedPath)] #[derive(Deserialize, TypedPath)]
#[typed_path("/admin/repo/update")] #[typed_path("/admin/repo/update")]
pub struct PathAdminRepoUpdate {} pub struct PathAdminRepoUpdate {}

View file

@ -29,9 +29,18 @@ a:hover {
} }
button { button {
font-size: inherit;
padding: 0 .5ch; padding: 0 .5ch;
} }
button.linkish {
background-color: unset;
border: unset;
text-decoration: underline;
padding: 0;
cursor: pointer;
}
details { details {
padding: .3em 1ch; padding: .3em 1ch;
background-color: #ddd; background-color: #ddd;
@ -145,15 +154,6 @@ nav a:hover {
display: inline; display: inline;
} }
.queue-commits button {
font-size: inherit;
background-color: unset;
border: unset;
text-decoration: underline;
padding: 0;
cursor: pointer;
}
.queue-commits button:hover { .queue-commits button:hover {
font-weight: bold; font-weight: bold;
} }

View file

@ -8,22 +8,32 @@
<details open> <details open>
<summary>Tracked ({{ tracked_refs.len() }})</summary> <summary>Tracked ({{ tracked_refs.len() }})</summary>
<form method="post" action="{{ link_admin_refs_untrack }}">
<dl> <dl>
{% for ref in tracked_refs %} {% for ref in tracked_refs %}
<dt>{{ ref.name }}</dt> <dt>
{{ ref.name }}
[<button class="linkish" name="ref" value="{{ ref.name }}">untrack</button>]
</dt>
<dd>{{ ref.commit|safe }}</dd> <dd>{{ ref.commit|safe }}</dd>
{% endfor %} {% endfor %}
</dl> </dl>
</form>
</details> </details>
<details> <details>
<summary>Untracked ({{ untracked_refs.len() }})</summary> <summary>Untracked ({{ untracked_refs.len() }})</summary>
<form method="post" action="{{ link_admin_refs_track }}">
<dl> <dl>
{% for ref in untracked_refs %} {% for ref in untracked_refs %}
<dt>{{ ref.name }}</dt> <dt>
{{ ref.name }}
[<button class="linkish" name="ref" value="{{ ref.name }}">track</button>]
</dt>
<dd>{{ ref.commit|safe }}</dd> <dd>{{ ref.commit|safe }}</dd>
{% endfor %} {% endfor %}
</dl> </dl>
</form>
</details> </details>
<form method="post" action="{{ link_admin_repo_update }}"> <form method="post" action="{{ link_admin_repo_update }}">

View file

@ -50,9 +50,10 @@
</td> </td>
<td> <td>
{{ task.priority }} {{ task.priority }}
[<button title="Increase priority by 1" formaction="{{ task.link_increase }}" name="hash" [<button class="linkish" title="Increase priority by 1" formaction="{{ task.link_increase }}"
value="{{ task.hash }}">inc</button>/<button title="Decrease priority by 1" name="hash" value="{{ task.hash }}">inc</button>/<button class="linkish"
formaction="{{ task.link_decrease }}" name="hash" value="{{ task.hash }}">dec</button>] title="Decrease priority by 1" formaction="{{ task.link_decrease }}" name="hash"
value="{{ task.hash }}">dec</button>]
</td> </td>
{% if task.workers.is_empty() %} {% if task.workers.is_empty() %}
<td>-</td> <td>-</td>