forms
struct ExistingLink
pub(crate) struct ExistingLinkA pre-populated relationship link used by edit forms.
| Field | Type | Description |
|---|---|---|
rel |
String | The relationship as seen from the edited entity, such as blocks; inverted when the entity is the target. |
ref_ |
String | The other entity as <tasks|artifacts|iterations>/<id>, the form’s link_ref[] value. |
struct NoteFormData
pub(crate) struct NoteFormDataShared form body for note-add endpoints.
| Field | Type | Description |
|---|---|---|
body |
String | The note’s Markdown text. |
Implements Deserialize<'de>.
fn build_existing_links_for_entity
pub(crate) fn build_existing_links_for_entity(
entity_id: &Id,
entity_type: EntityType,
rels: &[relationship::Model],
) -> Vec<ExistingLink>Build existing link items for edit form pre-population.
| Parameter | Type | Description |
|---|---|---|
entity_id |
&Id | the entity being edited |
entity_type |
EntityType | the kind of the entity being edited |
rels |
&[relationship::Model] | the relationships in which the entity is the source or the target |
| returns | Vec<ExistingLink> | One link for each relationship, in the order of rels. |
fn seen_from
fn seen_from(
entity_type: EntityType,
entity_id: &Id,
rel: &relationship::Model,
) -> (RelationshipType, EntityType, Id)A link as the edit form shows it from one entity: its relationship and the other end.
A link that starts at the entity reads as it is stored. A link that ends at the entity reads from the other side,
with the inverse relationship: A blocks B reads from B as blocked-by A.
| Parameter | Type | Description |
|---|---|---|
entity_type |
EntityType | the kind of the entity the link is seen from |
entity_id |
&Id | the entity the link is seen from |
rel |
&relationship::Model | a link that starts or ends at the entity |
| returns | (RelationshipType, EntityType, Id) | The relationship, and the kind and ID of the other end. |
fn extract_link_fields
pub(crate) fn extract_link_fields(bytes: &[u8]) -> (Vec<String>, Vec<String>)Extract repeated link_rel[] and link_ref[] fields from a url-encoded form body.
| Parameter | Type | Description |
|---|---|---|
bytes |
&[u8] | the raw application/x-www-form-urlencoded body |
| returns | (Vec<String>, Vec<String>) | The link_rel[] values and the link_ref[] values, each in form order. |
fn sync_form_links
pub(crate) async fn sync_form_links(
conn: &Connection,
transaction_id: &Id,
entity_type: EntityType,
entity_id: &Id,
link_rels: &[String],
link_refs: &[String],
) -> Result<(), String>Make the entity’s links match the form’s link rows, recording each change in transaction_id.
The form shows every link that starts or ends at the entity, each as seen_from reads it, so the rows are
matched the same way. Each link matches at most one row. A link with a matching row is kept as it is, whichever
way it points; a link with no row is deleted. A row that matches no link is created as a link from the entity, and
equal new rows make one link. A row with an unknown relationship, ref kind or ID is ignored. Each deletion and
creation is recorded, so gest undo restores the links as they were.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
transaction_id |
&Id | the transaction the changes belong to |
entity_type |
EntityType | the kind of the entity whose links these are |
entity_id |
&Id | the entity |
link_rels |
&[String] | the relationship of each form row |
link_refs |
&[String] | the target of each form row, as <kind>/<id> |
| returns | Result<(), String> | Ok(()) once the links match, or the store error as text. |
fn begin
pub(crate) async fn begin(
state: &crate::web::AppState,
conn: &Connection,
command: &str,
) -> Result<crate::store::model::transaction::Model, crate::store::Error>Open a transaction for a write from the web UI, under the server’s author when it has one.
| Parameter | Type | Description |
|---|---|---|
state |
&crate::web::AppState | the shared server state, for the project and the author |
conn |
&Connection | the database connection |
command |
&str | the command name that gest undo shows, such as task update |
| returns | Result<crate::store::model::transaction::Model, crate::store::Error> | The new transaction, or the store error. |