Wiki source for StructDataActionInfo


Show raw source

=====Structdata Action Documentation=====
//Not Included in official Wikka version//

>>==See also:==
Development: StructDataAction>>This is the documentation page for the Structdata action.::c::
===Documentation===

==Short description==
Enables to embed structured (or "semantically tagged", somehow like a database) data items in a page. You can then:
~- use a specific visual rendering (including [[http://www.microformats.org | microformats]]) to format and display only key informations of each data item
~- call predefined requests (a la SQL) to select and process data items across all wiki pages

This is by essence ''not a turnkey tool'', as you have to define your data items and the requests to be performed upon them.

Two examples are provided :
~- a "To Do" list
~- a contact card

==Parameters==
Parameters shall be of either of two (exclusive) types:
~- either a pair (//type//, //data//), if you want to define a data item

""<table class="data" cellspacing="0" cellpadding="2" border="1">
<thead>
<tr><th scope="col">name</th><th scope="col">type</th><th scope="col">required?</th><th scope="col">default</th><th scope="col">description</th></tr>
</thead>
<tbody>
<tr><td>type</td><td>string</td><td>required</td><td></td><td>The data item type. Predefined types are ToDo and Card (see explanation in the 'Long description' paragraph below)</td></tr>
<tr><td>data</td><td>string</td><td>required</td><td></td><td>field1='value1' field2='value2' etc. Optionality and allowed values depend on value of the 'type' parameter</td></tr>
<tr><td>print</td><td>string</td><td>optional</td><td></td><td>The display mode for the data item. Predefined types are false (no display), basic (inline of the type name), table (one-row table with one column per field) and list (table with one row per field)</td></tr>
</tbody>
</table>""
~- or //req// with context-dependent //p1//, //p2// and //p3//, if you want to perform a request

""<table class="data" cellspacing="0" cellpadding="2" border="1">
<thead>
<tr><th scope="col">name</th><th scope="col">type</th><th scope="col">required?</th><th scope="col">default</th><th scope="col">description</th></tr>
</thead>
<tbody>
<tr><td>req</td><td>string</td><td>required</td><td></td><td>The request id. Predefined generic types are ItemTable, ToDos and Cards (see explanation in the 'Long description' paragraph below)</td></tr>
<tr><td>p1</td><td>string</td><td>optional</td><td></td><td>The request's first parameter.Typically used to filter or sort, but actual semantics are request-specific</td></tr>
<tr><td>p2</td><td>string</td><td>optional</td><td></td><td>The request's second parameter.Typically used to filter or sort, but actual semantics are request-specific</td></tr>
<tr><td>p3</td><td>string</td><td>optional</td><td></td><td>The request's third parameter.Typically used to filter or sort, but actual semantics are request-specific</td></tr>
<tr><td>help</td><td>string</td><td>optional</td><td></td><td>If this parameter is present, a one line description of the request and its parameters is displayed</td></tr>
</tbody>
</table>""
__Notes:__
~- If you pass ''both'' a //type// and a //req// parameter, the //req// parameter will be ignored

==Long description==
Didn't you ''ever'' think: "these wikis are great, but if only I had a way to tag a chunk of page as containing the data for a contact card, a customer call or a calendar entry, in order to perform some database-style request on these data items?"

Well, here is a solution. With the Structdata action you can do four things:
~1) embed in any page a "structured data item" which is defined by a type (e.g. a To-Do list entry) and a list of parameters (or fields, in the database terminology). Note that fields are not typed;
~1) validate the list of parameters. You can:
~~ - check for the presence of a mandatory parameter; and
~~ - perform any data validation desired.
~~ An error message will indicate failure to validate a given data item. Note that this requires you to provide the corresponding code.
~1) control the visual rendering of each data item. You can choose:
~~ - to make it invisible; or
~~ - to display it as a list, a table or an inline text by using predefined display modes; or
~~ - to display it as a [[http://www.microformats.org | microformat]], where applicable
~~ - to display it in any custom way you may provide code for.
~1) perform any selection, processing and aggregation request you wish (example: display all the open To-Do list entries with priority levels of 1 or 2). Of course, here again you have to provide some code.

==Usage==
%%{{structdata (type="datatype" data="fieldslist" [print="printmode"] | req="reqname" [p1="val1"][p2="val2"][p3="val3"] [help]) }}%%

===Examples===

== Example 1: To-Do list structured data item==
__Definition of two To-Do list items. The second one will not be displayed__
%%{{structdata type="ToDo" print="table" data="date_open='2006-10-3' owner='jdoe' status='open' date_due='2007/11/13' desc='Complete logo design'"}}%%
%%{{structdata type="ToDo" print="false" data=" owner='kbill' status='open' desc='Book flight to Lake Tahoe' priority='2' date_open='2006-10-4' date_due='2006-12-2' "}}%%
Comments:
~1) four fields are mandatory: owner, desc (description of the task), date_open and date_due. Dates shall follow the 'yyyy-mm-dd' format.
~1) date existence check is performed for date_open and date_due.
~1) no specific visual rendering has been defined. print='table' usually gives good results:

""<table class='data' cellpadding='2' cellspacing='1' border='2'><thead><tr><th class='comment'>date_open</th><th class='comment'>owner</th><th class='comment'>status</th><th class='comment'>date_due</th><th class='comment'>desc</th></tr></thead><tbody><tr><td>2006-10-3</td><td>jdoe</td><td>open</td><td>2007/11/13</td><td>Complete logo design </td></tr></tbody></table>""
__Predefined requests__
A request called ""ToDos"" is predefined. It displays all To-Do list items in a table, sorted in reverse order of date_open. If parameter p1 is present, only data items whose owner equals p1 are selected. If parameter p2 is present, only data items whose status is equal to p2 are selected. With the two To-do list items defined above, ""{{structdata req="ToDos"}}"" would display the following:

""<table class='data' cellpadding='2' cellspacing='1' border='2'><thead><tr class='comment'><th>owner</th><th>description</th><th>due date</th><th>page link</th></tr></thead><tbody><tr><td>kbill</td><td>Book flight to Lake Tahoe</td><td style='background-color:red; color:white; '>2006-12-2</td><td align='center'><a href='./StructDataActionInfo'>StructDataActionInfo</a></td></tr><tr><td>jdoe</td><td>Complete logo design</td><td>2007/11/13</td><td align='center'><a href='./StructDataActionInfo'>StructDataActionInfo</a></td></tr></tbody></table>""

==Example 2: Contact card structured data item==
__Definition of a contact card__
%%{{structdata type="Card" data="n='DOE;John' email='jdoe@his_organization.org' fax='(123) 654-898' tel='(+41) 123 4567' org='His_org'"}}%%
Comments:
>>//Sample stylesheet for hCard microformat rendering//

%%
.vcard .additional-name { display: none; }
.vcard .tel, .vcard .email { font-size: smaller; }
.vcard .org { display: inline; font-style: italic; margin-left: 0.5em; }
.vcard span.n .org { margin: 0; }
%%
This stylesheet will render the example card as :

""<div class="vcard"><span class="n"><span class="fn"><span class="given-name">John</span> <span class="family-name">Doe</span></span></span><div class="org" style="display: inline; font-style: italic; margin-left: 0.5em;">His_org</div><div class="email" style="font-size: smaller; "><a href="mailto:jdoe@his_organization.org">jdoe@his_organization.org</a></div><div class="tel" style="font-size: smaller; "><span class="value">(+41) 123 4567</span></div><div class="tel" style="font-size: smaller; "><span class="type">fax</span> <span class="value">(123) 654-898</span></div></div>""
>>
~1) one field is mandatory: n, containing the name of the contact, formatted as 'last_name[;given_name[;middle_name]]'
~1) optional fields are:
~~2.1. org (organization): use the same value as the 'n' field if the contact is an organization instead of a person
~~2.2. email
~~2.3. tel and/or fax
~~2.4. adr (address), formatted as 'street_adress;[city_name];[postal_code];[region_or_state];[country_name]'
~~2.5. title
~~2.6. url (personal or organizational web address)
~~2.7. note (any further information)
~1) no data validation is performed.
~1) a contact card is rendered by default as an inline text displaying the contact's name and (if any) organization, with a 'mailto' hyperlink to the contact's email address and a tooltip showing his/her phone and fax numbers. Example: ""<a href='mailto:jdoe@his_organization.org' title='phone:(+41) 123 4567 / fax: (123) 654-898'>John Doe (His_org)</a>"".
~1) optionally, a contact card can be displayed as a [[http://www.microformats.org/wiki/hcard | hCard microformat]]. Just add the ##print="hCard"## parameter. The visual rendering of the hCard can be customized by adding classes to the wikka.css stylesheet (an example is given in the right-hand side box.)

__Predefined requests__
A request called Cards is predefined. It displays all contact cards in a table, sorted by name. If parameter p1 is present, only contacts whose organization equals p1 are selected. If parameter p2 is present, its value is used as the name of the field to sort on. As an example, ""{{structdata req="Cards"}}"" yields the following table:

""<table class='data' cellpadding='2' cellspacing='1' border='2'><thead><tr><th class='comment'>Last name</th><th class='comment'>Given name</th><th class='comment'>Email</th><th class='comment'>Phone</th><th class='comment'>Fax</th><th class='comment'>Organization</th></tr></thead><tbody><tr><td>Doe</td><td>John</td><td>jdoe@his_organization.org</td><td>(+41) 123 4567</td><td>(123) 654-898</td><td>His_org</td></tr></tbody></table>""
Finally, parameter p3 controls the way the contact cards are formatted:
~ - if p3 is absent or p3="table", the cards are displayed in a table as shown above
~ - if p3="vCard", a download button is displayed, which allows to grab a file containing the contact cards in the [[http://en.wikipedia.org/wiki/VCard | vCard]] format (which can be imported into a Personal Information Manager or a phone). In this example, ""{{structdata req="Cards" p3="vCard"}}"" displays a button giving access to a file containing:
%%BEGIN:VCARD
VERSION:2.1
N:DOE;John
FN:John Doe
ORG:His_org
TEL:(+41) 123 4567
TEL;FAX:(123) 654-898
EMAIL;INTERNET:jdoe@his_organization.org
END:VCARD
%%

== Example 3: ""ItemTable"" request==
This is a predefined request which can be used with any type of data item. What it does is displaying in a single table all the data items of a given type (passed as parameter p1) present on the page. This allows a more compact rendering compared to displaying each data item as an independent table. Usually, data items are entered with the print='false' parameter; otherwise they will be displayed twice.
As an example, ""{{structdata req="ItemTable" p1="ToDo"}}"" groups the two data items defined in example 1 in the following table:

""<table class='data' cellpadding='2' cellspacing='1' border='2'><thead><tr class='comment'><th>date_open</th><th>owner</th><th>status</th><th>date_due</th><th>desc</th><th>priority</th></tr></thead>
<tbody><tr><td>2006-10-3</td><td>jdoe</td><td>open</td><td>2007/11/13</td><td>Complete logo design</td><td>2</td></tr>
<tr><td>2006-10-4</td><td>kbill</td><td>open</td><td>2006-12-2</td><td>Book flight to Lake Tahoe</td></tr>
</tbody></table>""
If you want to control the column order, you can optionally provide a (comma-separated) column list as the p2 parameter.
Thus, ""{{structdata req="ItemTable" p1="ToDo" p2="owner,desc,status"}}"" displays:

""<table class='data' cellpadding='2' cellspacing='1' border='2'><thead><tr class='comment'><th>owner</th><th>desc</th><th>status</th><th>date_open</th><th>date_due</th><th>priority</th></tr></thead>
<tbody><tr><td>jdoe</td><td>Complete logo design</td><td>open</td><td>2006-10-3</td><td>2007/11/13</td><td>2</td></tr>
<tr><td>kbill</td><td>Book flight to Lake Tahoe</td><td>open</td><td>2006-10-4</td><td>2006-12-2</td></tr>
</tbody></table>""
Finally, you can control the request's scope (the set of pages whose data items will be listed) with the p3 parameter. Possible values are:
~ - "page" (default value; only items from current page are displayed)
~ - "user" (all pages owned by current user)
~ - "all" (all pages to which current user has read-access)

===To-do, bugs and limitations===
~- Double and single quotes around parameters and values shall be used in the same way as in the examples.
~- A field can not be multi-line (should be fixed in release 1.1.7.)
~- A possible path of development would be to provide dynamic edition/validation capabilities for data items by embedding a HTML/Javascript form into the page.
~- Possible refactoring: use an object approach to dynamically extend a base class with new structured data item types, each packaged in its own file.

===Other considerations===
~- A nice feature of this action is that it is possible to freely mix regular wiki page content and structured data items, without any change to the database structure. However, this approach relies on regular expressions and is probably not very scalable in terms of the performance achieved when processing requests.
~- One could wish, instead of having pre-cooked requests, to be able to run SQL-style SELECT statements. This would require a syntactic parser and is currently beyond my resources.
~- Other wikis have developed the notion of structured data items, most notably (to my knowledge) [[http://twiki.org | twiki]] and [[http://www.xwiki.org | xwiki]], as well as the interesting [[http://projects.nickblundell.org.uk/wikidbase | wikidbase]].

==Author==
DomBonj

----
CategoryDocumentation
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki