breaking up widgets into small chunks
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 26 Sep 2005 20:36:11 +0000 (20:36 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 26 Sep 2005 20:36:11 +0000 (20:36 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1874 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/reporter/tables.example.xml
Open-ILS/src/reporter/templates/login.ttk
Open-ILS/src/reporter/templates/stage1.ttk

index 6ec6b07..65b3f39 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <tables>
 
-       <table id="silly.fact" partition="true">
-               <name>Silly Fact table</name>
+       <table id="silly.fact" partition="true" fact-table="true">
+               <label>Silly Fact table</label>
                <description>Silly Fact table</description>
                <tablename>stats.silly_fact</tablename>
 
@@ -62,7 +62,7 @@
        </table>
 
        <table id="silly.word_dim">
-               <name>Silly word list</name>
+               <label>Silly word list</label>
                <description>Silly word list</description>
                <tablename>stats.words</tablename>
                <fields>
                          name="id"
                          primary="true"
                          create-type="serial"
-                         datatype="int"/>
+                         datatype="int">
+                               <label>Silly word id</label>
+                       </field>
                        <field
                          name="word"
                          datatype="text"
                          indexed="true"
-                         index-type="BTREE"/>
+                         index-type="BTREE">
+                               <label>Silly word</label>
+                       </field>
                </fields>
        </table>
 
        <table id="silly.sayer_dim">
-               <name>Silly word sayer list</name>
+               <label>Silly word sayer list</label>
                <description>Silly word sayer list</description>
                <tablename>stats.silly_sayers</tablename>
                <fields>
                          name="id"
                          primary="true"
                          create-type="serial"
-                         datatype="int"/>
+                         datatype="int">
+                               <label>Silly person id</label>
+                       </field>
                        <field
                          name="sayer"
                          widget-family="string-choose"
                          datatype="text"
                          indexed="true"
-                         index-type="BTREE"/>
+                         index-type="BTREE">
+                               <label>Silly person</label>
+                       </field>
                </fields>
        </table>
 
index 82f6e2d..5ccef68 100644 (file)
                                <td><input type='submit' value='Login' onclick='doLogin();'/></td>
                        </tr>
                </table>
+
+               <br/><br/>
+               <span> Org Test </span>
+               <br/><br/>
+               [% INCLUDE orgtree.ttk %]
+
        </body>
 
        [% INCLUDE footer.ttk %]
index dba9c83..b9242a6 100644 (file)
@@ -6,60 +6,59 @@ END;
 
 MACRO logme(a) PROCESS logme_block x = a.list.join(', ');
 
-%]
-
-[%
-       USE CGI;
-       USE DBI;
-       USE WebSession;
-       USE utils = WebUtils;
-       USE config = XML.LibXML(config_xml);
+USE CGI;
+USE DBI;
+USE WebSession;
+USE utils = WebUtils;
+USE config = XML.LibXML(config_xml, expand_xinclude => 1);
 
-       dir = '/reporter/setup/files/' _ stage_dir;
-       dir = config.findvalue(dir);
+dir = '/reporter/setup/files/' _ stage_dir;
+dir = config.findvalue(dir);
 
-       dbname = config.findvalue('/reporter/setup/database/name');
-       dbhost = config.findvalue('/reporter/setup/database/host');
-       d_u = config.findvalue('/reporter/setup/database/user');
-       d_p = config.findvalue('/reporter/setup/database/password');
+dbname = config.findvalue('/reporter/setup/database/name');
+dbhost = config.findvalue('/reporter/setup/database/host');
+d_u = config.findvalue('/reporter/setup/database/user');
+d_p = config.findvalue('/reporter/setup/database/password');
 
-       dsn = "dbi:Pg:dbname=" _ dbname _';host=' _ dbhost;
+dsn = "dbi:Pg:dbname=" _ dbname _';host=' _ dbhost;
 
-       logme([dsn,d_u,d_p]);
+logme([dsn,d_u,d_p]);
        
-       DBI.connect(dsn,d_u,d_p);
-%]
-
-
-<html>
-       [% INCLUDE header.ttk title="Basic Report Types" %]     
-       <body>
-               [% INCLUDE logout.ttk %]
-               [% IF !CGI.param('id') %]
-                       [%      IF CGI.param('detail') %]
-                               |<a href="?detail=0">No Details (All)</a>
-                       [% ELSE %]
-                               |<a href="?detail=1">Details (All)</a>
-                       [% END %]
-                       [% PROCESS all_stage1 %]
-               [% END %]
-               [% PROCESS one_stage1 IF CGI.param('id') %]
-       </body>
-       [% INCLUDE footer.ttk %]        
-</html>
+DBI.connect(dsn,d_u,d_p);
+
+
+WRAPPER html/html;
+       INCLUDE header.ttk title="Basic Report Types";
+       WRAPPER html/body;
+               INCLUDE logout.ttk;
+               IF !CGI.param('id');
+                       IF CGI.param('detail');
+                               %]|<a href="?detail=0">No Details (All)</a>[%
+                       ELSE;
+                               %]|<a href="?detail=1">Details (All)</a>[%
+                       END;
+                       PROCESS all_stage1;
+               ELSE;
+                       PROCESS one_stage1;
+               END;
+       END;
+       INCLUDE footer.ttk;
+END;
 
 
 
 
+#=============================================================================
 
 
+BLOCK one_stage1;
+       %]|<a href="[%
+       CGI.url('-absolute',1,'-path_info',1,'-query',1).replace('&?id=\d+','');
+       %]">Show all</a>[%
 
-[% BLOCK one_stage1 %]
-       |<a href="[% CGI.
-                                               url('-absolute',1,'-path_info',1,'-query',1).
-                                               replace('&?id=\d+','') %]">Show all</a>
-[%     uid = DBI.quote(user.id());
+       uid = DBI.quote(user.id());
        rid = DBI.quote(CGI.param('id'));
+
        q = "select * from reporter.stage1 where (pub is true or owner = $uid) and id = $rid;";
        FOR s1 IN DBI.query(q);
                file = dir _ '/' _ s1.filename;
@@ -73,12 +72,15 @@ MACRO logme(a) PROCESS logme_block x = a.list.join(', ');
 
        END;
 END;
-%]
 
-[%
+
+
+
 BLOCK all_stage1;
+       '<ul>';
        uid = DBI.quote(user.id());
        FOR s1 IN DBI.query("select * from reporter.stage1 where pub is true or owner = $uid;");
+               '<li>';
                file = dir _ '/' _ s1.filename;
                USE doc = XML.LibXML(file);
 
@@ -91,168 +93,324 @@ BLOCK all_stage1;
                        '<hr>';
                END;
        END;
+       '</ul>';
 END;
-%]
 
-[% BLOCK stage1_summary  links=0 %]
-<table width="100%">
-       <tr>
-               <td align="right">
-                       <b>Name:</b>
-               </td>
-               <td>
-                       [%doc.findvalue('/reporter/report/@name')%]
-               </td>
-       </tr>
-       <tr>
-               <td align="right">
-                       <b>Description:</b>
-               </td>
-               <td>
-                       [%doc.findvalue('/reporter/report/description')%]
-               </td>
-       </tr>
-       <tr>
-               <td align="right">
-                       <b>Actions:</b>
-               </td>
-               <td>
-                       [% IF CGI.param('detail') %]
-                               <a href="?detail=0&id=[% s1.id %]">No Details</a>
-                       [% ELSE %]
-                               <a href="?detail=1&id=[% s1.id %]">Details</a>
-                       [% END %]
-                       |<a href="?create_stage2=1&id=[% s1.id %]">New Report Template</a>
-               </td>
-       </tr>
-[%     PROCESS stage1_detail IF CGI.param('detail') == 1 %]
-</table>
-[%     END %]
 
 
-[%
+
+BLOCK stage1_summary links=0;
+       WRAPPER html/table width="100%";
+               WRAPPER html/row;
+                       WRAPPER html/cell align="right";
+                               %]<b>Name:</b>[%
+                       END;
+                       WRAPPER html/cell;
+                               doc.findvalue('/reporter/report/@name');
+                       END;
+               END;
+               WRAPPER html/row;
+                       WRAPPER html/cell align="right";
+                               %]<b>Description:</b>[%
+                       END;
+                       WRAPPER html/cell;
+                               doc.findvalue('/reporter/report/description');
+                       END;
+               END;
+               WRAPPER html/row;
+                       WRAPPER html/cell align="right";
+                               %]<b>Actions:</b>[%
+                       END;
+                       WRAPPER html/cell;
+                               IF CGI.param('detail');
+                                       %]<a href="?detail=0&id=[% s1.id %]">No Details</a>[%
+                               ELSE;
+                                       %]<a href="?detail=1&id=[% s1.id %]">Details</a>[%
+                               END;
+                               %]|<a href="?create_stage2=1&id=[% s1.id %]">New Report Template</a>[%
+                       END;
+               END;
+               PROCESS stage1_detail IF CGI.param('detail') == 1;
+       END;
+END;
+
+
+%][%
+
 BLOCK stage2_new;
        col_xpath = "/reporter/tables/table[@id='" _ fact_table _ "']/fields/field[@core='true']";
        logme(col_xpath);
 
-       '<h3><u>Core report limiters</u></h3>';
+       WRAPPER html/table width="100%" border=1;
+               WRAPPER html/row;
+                       WRAPPER html/cell colspan=2;
+                               # hidden input here ...
+                               table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
+                               INCLUDE hidden name="filtertable" value=fact_table;
+                               table.findvalue('label');
+                               ' Core Columns';
+                       END;
+               END;
+               INCLUDE widget_selector tableid=fact_table columns=config.findnodes(col_xpath) force=1;
+       END;
 
-       FOR col IN config.findnodes(col_xpath);
-               logme(col.findvalue('@name'));
-               widget = col.findvalue('@widget') or col.findvalue('@datatype');
-               INCLUDE "draw_$widget" column = col; 
+       dim_xpath = "/reporter/tables/table[@id='$fact_table']/links/link/@table";
+       FOR dim_table IN config.findnodes(dim_xpath);
+               dim_table = dim_table.value();
+               dimension = config.findnodes("/reporter/tables/table[@id='$dim_table']");
+
+               WRAPPER html/table width="100%" border=1;
+                       WRAPPER html/row;
+                               WRAPPER html/cell colspan=2;
+                                       # checkbox input here ...
+                                       INCLUDE checkbox name="filtertable" value=dim_table checked=1;
+                                       dimension.findvalue('label');
+                                       ' Dimension';
+                               END;
+                       END;
+                       INCLUDE widget_selector tableid=dim_table;
+               END;
        END;
 
 END;
-%]
+
+
+BLOCK widget_selector;
+
+       logme("widget_selector called for table $tableid");
+
+       #   if we got some columns, use them. if not, get all non-primary columns
+       IF ! columns;
+               columns_xpath =
+                       '/reporter/tables/table[@id="' _ tableid _
+                       '"]/fields/field[not(@primary) or @primary!="true"]'
+               columns = config.findnodes(columns_xpath);
+               logme("widget_selector had to grab columns for table $tableid!");
+       END;
+
+       column_input_type="checkbox";
+       IF force;
+               column_input_type="hidden";
+       END;
+
+       FOR column IN columns;
+               column_name=column.findvalue('@name');
+
+               WRAPPER html/row;
+                       WRAPPER html/cell valign='top';
+                               # checkbox for column filter here ...
+                               INCLUDE $column_input_type
+                                       name="filtercolumn:$tableid"
+                                       value=column_name
+                                       checked=1; 
+                               column.findvalue('label');
+                       END;
+                       WRAPPER html/cell;
+
+                               col_widget_fams_xpath =
+                                       '/reporter/widgets/widget-family[@datatype="' _
+                                       column.findvalue('@datatype') _ '"]';
+
+                               IF column.findnodes('@widget-family');
+                                       col_widget_fams_xpath =
+                                               '/reporter/widgets/widget-family[@name="' _
+                                               column.findvalue('@widget-family') _ '"]';
+                               END;
+
+                               logme("finding widget families using $col_widget_fams_xpath");
+
+                               widget_fams = config.findnodes(col_widget_fams_xpath);
+
+                               '<UL>';
+                               FOR fam IN widget_fams;
+
+                                       fam_input = 'radio';
+                                       IF loop.size == 1;
+                                               fam_input = 'hidden';
+                                       END;
+
+                                       checked = 0;
+                                       IF loop.count == 1;
+                                               checked = 1;
+                                       END;
+
+                                       fam_name = fam.findvalue('@name');
+                                       # radio for widget family here ...
+                                       '<LI>';
+                                       INCLUDE $fam_input
+                                               name="filterfamily:$tableid:$column_name"
+                                               value= fam_name;
+                                       fam.findvalue('label');
+                                       '<UL>';
+                                       
+                                       FOR widget IN fam.findnodes('widget');
+
+                                               fam_input = 'radio';
+                                               IF loop.size == 1;
+                                                       fam_input = 'hidden';
+                                               END;
+
+                                               checked = 0;
+                                               IF loop.count == 1;
+                                                       checked = 1;
+                                               END;
+
+                                               widget_name = widget.findvalue('@name');
+                                               # radio for widget here ...
+                                               '<LI>';
+                                               INCLUDE $fam_input
+                                                       name="filter:$tableid:$column_name:$fam_name"
+                                                       value= widget_name;
+                                               widget.findvalue('label');
+                                               '</LI>';
+                                       END;
+                                       '</UL>';
+                                       '</LI>';
+                               END;
+                               '</UL>';
+                       END;
+               END;
+       END;
+END;
 
 
 
 
-[% BLOCK draw_timestamptz %]
-[% varname = column.parentNode.parentNode.findvalue('tablename') _ '.' _ column.findvalue('@name') %]
 
-<b>[% column.findvalue('label') %]</b><br/><br/>
-<table border=1 width="100%">
-       <tr>
-               <td colspan=2>
-                       <b>[% column.findvalue('description') %]</b>
-               </td>
-       </tr>
-       <tr>
-               <td>
-                       Report Range Size:
-               </td>
-               <td>
-                       <select
-                               name="range_size" >
-                               <option value="[% varname %]:">Any</option>
-                               <option value="[% varname %]:hour">Hour</option>
-                               <option value="[% varname %]:day">Day</option>
-                               <option value="[% varname %]:week">Week</option>
-                               <option value="[% varname %]:month">Month</option>
-                               <option value="[% varname %]:year">Year</option>
-                               <option value="[% varname %]:decade">Decade</option>
-                       </select>
-               </td>
-       </tr>
-</table>
-[% END %]
+%][%
 
 
 
 
-[% BLOCK dim_description %]
-<tr>
-       <td align="right">Name:</td>
-       <td>[% dim.findvalue('name') %]</td>
-</tr>
-[% PROCESS table_fields table = dim %]
-[% END %]
+BLOCK text;
+       %]<INPUT TYPE="text" NAME="[%
+               name;
+               %]" VALUE="[%
+               value;
+               %]" [%
+               IF sz;
+                       %]SIZE="[% sz %]" [%
+               END;
+               IF mx;
+                       %]MAXLENGTH="[% mx %]" [%
+               END;
+               %]>[%
+END;
 
+BLOCK textarea;
+       %]<TEXTAREA NAME="[% name %]">[% value %]</TEXTAREA>[%
+END;
 
+BLOCK hidden;
+       %]<INPUT TYPE="hidden" NAME="[% name %]" VALUE="[% value %]">[%
+END;
 
+BLOCK radio;
+       %]<INPUT TYPE="radio" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
+END;
 
+BLOCK checkbox;
+       %]<INPUT TYPE="checkbox" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
+END;
 
 
-[% BLOCK table_fields %]
-[%             FOR f IN table.findnodes('fields/field') %]
-<tr>
-       <td align="right">Field:</td>
-       <td>[% f.findvalue('@name') %] ([% f.findvalue('@datatype') %])</td>
-</tr>
-[%             END %]
-[% END %]
 
 
+BLOCK render_dimension;
+       INCLUDE checkbox checked = 1 name = 's2_dim_table' value = dim_object.findvalue('@id');
+       %]<b>[% dim_object.findvalue('name') %]</b><br>[%
+       
+       WRAPPER html/table width="100%" ;
+               WRAPPER html/row;
+                       WRAPPER html/cell align="right";
+                       END;
+               END;
+       END;
+END;
 
 
 
 
-[% BLOCK stage1_detail %]
-                               <tr>
-                                       <td align="right">
-                                               Visible Stage2 reports:
-                                       </td>
-                                       <td>
-                                               [% q = 'select count(*) as x from reporter.stage2 ' _
-                                                               'where pub is true or owner = ' _ DBI.quote(user.id());
-                                               FOR r IN DBI.query(q);
-                                                       r.x;
-                                               END %]
-                                       </td>
-                               </tr>
 
-[% PROCESS table_fields table = config.findnodes("/reporter/tables/table[@id='$fact_table']") %]
+BLOCK dim_description;
+       WRAPPER html/row;
+               WRAPPER html/cell align="right";
+                       %]Name:[%
+               END;
+               WRAPPER html/cell;
+                       dim.findvalue('name');
+               END;
+       END;
+       PROCESS table_fields table = dim;
+END; 
 
-                               <tr>
-                                       <td align="right">
-                                               Report Attributes<br/>(dimensions):
-                                       </td>
-                                       <td>
-[%
-                                               incs = doc.findnodes('//report/dims/dim/@include');
 
-                                               FOR dim IN incs;
-                                                       '<table border=1 width="100%">';
 
-                                                       link_xpath = '/reporter/tables/table[@id="' _ fact_table _'"]'_
-                                                                                               '/links/link[@field="' _ dim.value() _ '"]/@table';
-                                                       logme(link_xpath);
 
-                                                       dim_table = config.findvalue(link_xpath);
 
-                                                       dim_xpath = '/reporter/tables/table[@id="' _ dim_table _'"]';
-                                                       logme(dim_xpath);
+
+BLOCK table_fields;
+       FOR f IN table.findnodes('fields/field');
+               WRAPPER html/row;
+                       WRAPPER html/cell align="right";
+                               %]Field:[%
+                       END;
+                       WRAPPER html/cell;
+                               f.findvalue('@name');
+                               %] ([% f.findvalue('@datatype') %])[%
+                       END;
+               END;
+       END;
+END;
+
+
+
+
+
+
+BLOCK stage1_detail;
+       WRAPPER html/row;
+               WRAPPER html/cell align="right";
+                       %]Visible Stage2 reports:[%
+               END;
+               WRAPPER html/cell;
+                       q = 'select count(*) as x from reporter.stage2 ' _
+                               'where pub is true or owner = ' _ DBI.quote(user.id());
+                       FOR r IN DBI.query(q);
+                               r.x;
+                       END;
+               END;
+       END;
+
+       PROCESS table_fields table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
+
+       WRAPPER html/row;
+               WRAPPER html/cell align="right";
+                       %]Report Attributes<br/>(dimensions):[%
+               END;
+               WRAPPER html/cell;
+                       incs = doc.findnodes('//report/dims/dim/@include');
+
+                       FOR dim IN incs;
+                               %]<table border=1 width="100%">[%
+
+                               link_xpath = '/reporter/tables/table[@id="' _ fact_table _'"]'_
+                                                                       '/links/link[@field="' _ dim.value() _ '"]/@table';
+                               logme(link_xpath);
+
+                               dim_table = config.findvalue(link_xpath);
+
+                               dim_xpath = '/reporter/tables/table[@id="' _ dim_table _'"]';
+                               logme(dim_xpath);
                                                        
-                                                       dim_def = config.findnodes(dim_xpath);
+                               dim_def = config.findnodes(dim_xpath);
 
-                                                       PROCESS dim_description dim = dim_def;
-                                                       '</table>';
-                                               END
-%]
-                                       </td>
-                               </tr>
-[%                     END %]
+                               PROCESS dim_description dim = dim_def;
+                               %]</table>[%
+                       END;
+               END;
+       END;
+END;
 
+%]