Skip to content

armgit / kanzo

Public Imported from GitHub
0

Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.

Rename projects

emanuele-em1dd160b5a424
diff --git a/src/app.js b/src/app.js
index 45a0d19..b48a4f7 100644
--- a/src/app.js
+++ b/src/app.js
@@ -66,6 +66,7 @@ const ICONS = {
plus: '<path d="M5 12h14M12 5v14"/>',
trash: '<path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6M10 11v6M14 11v6"/>',
check: '<path d="M20 6 9 17l-5-5"/>',
+ rename: '<path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/>',
update: '<circle cx="12" cy="12" r="9"/><path d="M12 7v9M8 12l4 4 4-4"/>',
send: '<path d="M12 19V5M5 12l7-7 7 7"/>',
};
@@ -286,6 +287,8 @@ function render() {
}
function renderNav() {
+ // Redrawing would take the field away from someone renaming a project.
+ if (renaming && document.contains(renaming.input)) return;
const { projects } = state.board;
const open = projects.reduce((n, p) => n + p.open, 0);
const link = (slug, name, count, glyph) =>
@@ -294,7 +297,9 @@ function renderNav() {
glyph,
el("span", { class: "name" }, name),
el("span", { class: "count" }, String(count)));
- const item = (p) => el("div", { class: "item" + (state.menu === p.slug ? " menu-open" : "") },
+ const item = (p) => renaming && renaming.slug === p.slug
+ ? el("div", { class: "item renaming" }, icon("folder", projectColor(p.slug)), renaming.input)
+ : el("div", { class: "item" + (state.menu === p.slug ? " menu-open" : "") },
link(p.slug, p.name, p.open, icon("folder", projectColor(p.slug))),
el("button", { class: "more", title: "More", "aria-label": `More for ${p.name}`, "aria-haspopup": "menu",
onclick: (e) => toggleProjectMenu(p, e.currentTarget) }, icon("more")));
@@ -340,11 +345,12 @@ function toggleProjectMenu(p, button) {
if (focus) input.focus();
};
drawRepos(p.repos);
+ const rename = el("button", { onclick: () => startRename(p) }, icon("rename"), "Rename");
const remove = el("button", { class: "danger", onclick: () => { closeMenu(); deleteProject(p); } },
icon("trash"), "Delete project");
const menu = el("div", { class: "menu", role: "menu", tabindex: "-1" },
el("div", { class: "label" }, "Color"), swatches, el("div", { class: "label" }, "Repos"), repos,
- el("div", { class: "sep" }), remove);
+ el("div", { class: "sep" }), rename, remove);
document.body.append(menu);
const r = button.getBoundingClientRect();
const below = r.bottom + 4 + menu.offsetHeight <= innerHeight;
@@ -354,6 +360,36 @@ function toggleProjectMenu(p, button) {
menu.focus();
}
+// Renaming a project, as in ChatGPT: its sidebar row becomes a field. Enter or leaving it
+// saves, Esc cancels. The slug, and so the task keys, stay.
+let renaming = null; // { slug, input }
+
+function startRename(p) {
+ closeMenu();
+ const input = el("input", { class: "field", "aria-label": `Rename ${p.name}`, spellcheck: "false", autocomplete: "off" });
+ input.value = p.name;
+ renaming = { slug: p.slug, input };
+ let finished = false;
+ const finish = async (save) => {
+ if (finished) return;
+ finished = true;
+ const name = input.value.trim();
+ renaming = null;
+ if (save && name && name !== p.name) {
+ try { await api("PATCH", `/projects/${encodeURIComponent(p.slug)}`, { name }); } catch (err) { toast(err.message); }
+ }
+ loadBoard();
+ };
+ input.addEventListener("keydown", (e) => {
+ if (e.key === "Enter") { e.preventDefault(); finish(true); }
+ else if (e.key === "Escape") { e.stopPropagation(); finish(false); }
+ });
+ input.addEventListener("blur", () => finish(true));
+ renderNav();
+ input.focus();
+ input.select();
+}
+
// Links (POST) or unlinks (DELETE) a repo; returns the project, or null after showing the error.
async function changeRepo(slug, method, repo) {
try {
diff --git a/src/index.html b/src/index.html
index 81e0a99..8803230 100644
--- a/src/index.html
+++ b/src/index.html
@@ -69,6 +69,8 @@ aside {
.nav .item:hover .more, .nav .item:focus-within .more, .nav .item.menu-open .more { display: block; }
.nav .item:hover .count, .nav .item:focus-within .count, .nav .item.menu-open .count { visibility: hidden; }
.nav .item.menu-open a { background: var(--hover); }
+.nav .item.renaming { display: flex; align-items: center; gap: 10px; padding: 3px 6px 3px 10px; }
+.nav .item.renaming .field { padding: 5px 8px; border-radius: 8px; }
@media (hover: none) { .nav .more { display: block; } .nav .item .count { visibility: hidden; } }
.menu {
position: fixed; z-index: 30; min-width: 190px; padding: 6px; background: var(--menu);
diff --git a/src/store.rs b/src/store.rs
index 87a3d14..2e0ce46 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -399,6 +399,17 @@ impl Store {
}
}
+ /// Renames a project. Its slug, and so its task keys like api#12, stay.
+ pub fn rename_project(&self, slug: &str, name: &str) -> Result<Project> {
+ let name = name.split_whitespace().collect::<Vec<_>>().join(" ");
+ if name.is_empty() {
+ return Err(Error::Invalid("project name is empty".into()));
+ }
+ let project = self.find_project(slug)?;
+ self.conn.execute("UPDATE projects SET name = ?1 WHERE id = ?2", params![name, project.id])?;
+ self.find_project(&project.slug)
+ }
+
pub fn set_project_color(&self, slug: &str, color: &str) -> Result<Project> {
if !PROJECT_COLORS.contains(&color) {
return Err(Error::Invalid(format!("unknown color {color:?}; use one of: {}", PROJECT_COLORS.join(", "))));
@@ -922,6 +933,9 @@ mod tests {
assert_eq!((web.name.as_str(), web.color.as_deref()), ("web", None));
assert_eq!(s.set_project_color("web", "teal").unwrap().color.as_deref(), Some("teal"));
assert!(s.set_project_color("web", "#ff0000").is_err());
+ let renamed = s.rename_project("web", " Web site ").unwrap();
+ assert_eq!((renamed.slug.as_str(), renamed.name.as_str()), ("web", "Web site"));
+ assert!(s.rename_project("web", " ").is_err());
assert!(s.find_project("nope").unwrap_err().to_string().contains("api, web"));
}
diff --git a/src/web.rs b/src/web.rs
index f097bbc..b2d1dac 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -322,11 +322,22 @@ async fn create_project(State(home): Shared, Json(p): Json<NewProject>) -> Respo
#[derive(Deserialize)]
struct ProjectPatch {
- color: String,
+ name: Option<String>,
+ color: Option<String>,
}
async fn update_project(State(home): Shared, Path(slug): Path<String>, Json(p): Json<ProjectPatch>) -> Response {
- with_store(home, move |_, s| s.set_project_color(&slug, &p.color)).await
+ with_store(home, move |_, s| {
+ let mut project = s.find_project(&slug)?;
+ if let Some(name) = &p.name {
+ project = s.rename_project(&slug, name)?;
+ }
+ if let Some(color) = &p.color {
+ project = s.set_project_color(&slug, color)?;
+ }
+ Ok(project)
+ })
+ .await
}
#[derive(Deserialize)]