implement renaming feature for vorgang

UI and backend logic
make ´NameItemEditor´ reusable to be able to use with Vorgang
This commit is contained in:
2025-11-20 09:46:28 +01:00
parent b3ba6256e0
commit b6996902cc
4 changed files with 139 additions and 30 deletions

View File

@@ -13,7 +13,8 @@
// props, old syntax
export let list: ListItem[] = [];
export let currentName: string;
export let onSave: (n: string, o: string) => unknown = () => {};
export let vorgangToken: string | null;
export let onSave: (n: string, o: string, t?: string) => unknown = () => {};
export let onDelete: (n: string) => unknown = () => {};
let localName = currentName;
@@ -43,8 +44,10 @@
}
function commitEdit() {
if (!error && localName != currentName) onSave(localName, currentName);
if (!error && localName != currentName) onSave(localName, currentName, vorgangToken);
// restore original value
if (error) { localName = currentName }
isEditing = false;
}
@@ -54,7 +57,8 @@
}
function handleDeleteClick() {
onDelete(currentName);
// vorgangToken defined when deleting Vorgang, otherwise Crime
onDelete(vorgangToken || currentName);
}
</script>

View File

@@ -234,3 +234,25 @@ export const vorgangPINValidation = function (vorgangToken: string, vorgangPIN:
return true;
};
/**
* Rename Vorgang
* @param vorgangToken
* @param newName
* @returns {int} number of affected lines
*/
export const renameVorgangByToken = function (vorgangToken: string, newName: string) {
const renameSQLStmt = 'UPDATE cases set name = ? WHERE token = ?';
const statement = db.prepare(renameSQLStmt);
let info;
try {
info = statement.run(newName, vorgangToken);
} catch (err) {
console.log(`error: ${err}`)
return 0;
}
return info.changes;
};