Wednesday, January 30, 2008

Upcoming Andromeda Feature

About three weeks ago I was working on a project for work, that is using Andromeda and for some reason got to thinking about reports. And I thought to myself why couldn't we use YAML to define reports. So I sent an email to Ken Downs and suggested that we should get together and hash this idea out. So we got together about two weekends ago, and I presented this idea to him, and then showed him Smarty and showed him a couple of things that could be done with it.

Basically the whole "concept" comes down to the following
  • We already have our tables defined in the application YAML file
  • A report is just how to display the data
  • Smarty Gives us a way to have some logic (Looping, Alternating Row Color)
  • WE just need a filter for the data to display (WHERE CLAUSE)
So over the course of the rest of the weekend Ken coded up the concept of an AndroPage, which literally passes off the data to a another class that handles either turning the data into a Report(PDF) or a page(Smarty). After he was done with that I put into place the code that loops through the sections, and assigned the row(s) to the appropriate Smarty Variables named after the section they are in.

The definition of page looks like this:
options:
title: Reviews

section review:
onerow: "Y"
table reviews:
column name_book:
compare: = @book
column review:
column ts_ins:
column ts_upd:
column uid_ins:
column uid_upd:

uifilter book:
description: Book Title
type_id: vchar
colprec: 50

template: p_review.tpl

options: Allows us to set things such as page title.

section: Allows us to litterally pull as much data as we want and place it in different sections around the page, such as maybe client information in one area and then ads pertaining to this clients industry in another area.

onerow: Specified that we only expect one row back for this page(This is done so that we do not need a foreach loop in the smarty template)

table: Refer to tables that are specified in the application YAML file. Multiple tables can be specified and Andromeda will attempt to join the tables based on primary_keys

column: The columns to be used for display from the tables.

uifilter: Tells Andromeda that we need to filter on something, and if its not specified display a page so the user can enter it.

template: Tells Andromeda that this is a Smarty Page and to use the specified template.

Each section get assigned to a Smarty variable with the same name, then you just have to create the Smarty template.

An example of a Smarty template is this:

{* Smarty *}
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><h3>{$review.name_book}</h3></td>
</tr>
<tr>
<td>Review:</td>
</tr>
<tr>
<td>{$review.review}</td>
</tr>
<tr>
<td>Reviewed by: {$review.uid_ins} on {$review.ts_ins}</td>
</tr>
</tbody>
</table>
There as still a couple of minor bugs which should be fixed shortly and then there will be a release.

2 comments:

Unknown said...

That sounds like what django has with generic views...

Donald J Organ IV said...

yeah i guess they are similiar