Jump to content

ICT:Automatic IDs: Difference between revisions

From Costa Sano MediaWiki
No edit summary
No edit summary
Line 1: Line 1:
'''Description:''' Documentation for generating and querying automatic IDs using Page Forms and Cargo.
'''Description:''' Documentation for generating and querying automatic IDs using Page Forms and Cargo, including Protected Namespace management.


= Automatic ID Generation for Cargo Tables =
= Automatic ID Generation & Namespace Control =


This page documents the workflow for generating automatic, composite IDs using the [[Extension:Page Forms|Page Forms]] and [[Extension:Cargo|Cargo]] extensions.
This page documents the workflow for creating unique, automatic IDs and ensuring pages are saved within a specific Protected Namespace using [[Extension:Page Forms|Page Forms]] and [[Extension:Cargo|Cargo]].


== Overview ==
== 1. Template Logic (Automatic ID Generation) ==
While Page Forms does not have a "native" ID generator button, unique IDs can be constructed by:
The best practice is to construct your ID inside the storage template. This allows you to combine multiple attributes and system values (like timestamps) before storing them in Cargo.
# Combining user-input attributes in the storage template.
# Using the form's '''page name''' formula to ensure uniqueness.
# Enforcing uniqueness via form validation.
 
== 1. Template Logic (The "Store" Method) ==
To create an ID from a combination of attributes, logic is placed inside the <nowiki>{{#cargo_store}}</nowiki> function.
 
=== Example Cargo Declaration ===
Define your table in your Schema template:
<pre>
<nowiki>
{{#cargo_declare:
_table = Projects
|ProjectID = String
|Category = String
|Year = Integer
}}
</nowiki>
</pre>


=== Example Cargo Store ===
=== Example Cargo Store ===
In your data template, concatenate the fields to create the `ProjectID`:
In your data template's `<includeonly>` section:
<pre>
<pre>
<nowiki>
<nowiki>
<includeonly>
{{#cargo_store:
{{#cargo_store:
_table = Projects
_table = Projects
Line 38: Line 18:
|Year = {{{Year|}}}
|Year = {{{Year|}}}
}}
}}
</includeonly>
</nowiki>
</nowiki>
</pre>
</pre>


== 2. Form Definition ==
== 2. Form Definition (Namespace & Page Naming) ==
To ensure the user doesn't create a duplicate ID, use the `unique` and `page name` parameters in [[Extension:Page Forms|Page Forms]].
By defining the `page name` formula in the form, you can force all new pages into a specific namespace and ensure the URL itself acts as a unique identifier.
 
=== Forcing a Protected Namespace ===
In the <nowiki>{{{info}}}</nowiki> tag, prefix your formula with the name of your protected namespace.
* '''Note:''' Use the exact name of the namespace (e.g., `Archive:`, `Internal:`, or `Data:`).


=== Page Name Formula ===
In the <nowiki>{{{info}}}</nowiki> tag, define how the page is named automatically:
<pre>
<pre>
<nowiki>
<nowiki>
{{{info|page name=<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}}
{{{info|page name=Archive:<Projects[Category]>-<Projects[Year]>-<unique number;start=001>}}}
</nowiki>
</nowiki>
</pre>
</pre>


=== Field Validation ===
=== Validation for Uniqueness ===
Force the form to check if an ID already exists:
To prevent manual ID collisions, use the `unique` parameter on a hidden field in your form definition:
<pre>
<pre>
<nowiki>
<nowiki>
Line 61: Line 42:
</pre>
</pre>


== 3. Querying Records ==
== 3. Querying Protected Data ==
To retrieve data using your custom ID, use the <nowiki>{{#cargo_query:...}}</nowiki> parser function.
When querying pages in a specific namespace, Cargo's `_pageName` will include the namespace prefix (e.g., `Archive:Project-101`).


=== Filter by Composite ID ===
=== Query Example ===
<pre>
<pre>
<nowiki>
<nowiki>
{{#cargo_query:
{{#cargo_query:
|tables = Projects
|tables = Projects
|fields = _pageName=Page, Category, Year
|fields = _pageName=ID, Category
|where = ProjectID = 'Hardware-2024-171523421'
|where = _pageNamespace = 102 <!-- Use the ID of your Protected Namespace -->
|format = table
|format = table
}}
}}
Line 76: Line 57:
</pre>
</pre>


== Extensions Used ==
== Comparison: Page Forms vs. Page Schemas ==
* [[Extension:Page Forms|Page Forms]]: Handles the user interface and page naming.
| Feature | Page Schemas | Manual Page Forms |
* [[Extension:Cargo|Cargo]]: Handles data storage and querying.
| :--- | :--- | :--- |
* [[Extension:ParserFunctions|ParserFunctions]]: Used for string manipulation and date formatting.
| **Ease of Use** | High (Visual) | Medium (Markup) |
| **Namespace Control** | Limited / Hardcoded | Full (Dynamic via `page name`) |
| **Custom ID Logic** | Difficult to customize | Unlimited (via ParserFunctions) |
| **Maintenance** | Auto-generates code | Manual template updates |


[[Category:Help]]
[[Category:Help]]
[[Category:Cargo]]
[[Category:Cargo]]

Revision as of 09:01, 28 January 2026

Description: Documentation for generating and querying automatic IDs using Page Forms and Cargo, including Protected Namespace management.

Automatic ID Generation & Namespace Control

This page documents the workflow for creating unique, automatic IDs and ensuring pages are saved within a specific Protected Namespace using Page Forms and Cargo.

1. Template Logic (Automatic ID Generation)

The best practice is to construct your ID inside the storage template. This allows you to combine multiple attributes and system values (like timestamps) before storing them in Cargo.

Example Cargo Store

In your data template's `