Changes between Version 15 and Version 16 of S3XRC/ResourceReport


Ignore:
Timestamp:
08/28/10 19:37:54 (14 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • S3XRC/ResourceReport

    v15 v16  
     1[[TOC]]
    12= S3XRC Mini-Tutorial =
    23
    34  - [wiki:S3XRC_Recipes S3XRC Recipes and Tutorials]
    4 == Report Function for your Resource ==
    5 
    6 === The idea ===
     5
     6== A Report function for your resource ==
     7
     8=== Use-case ===
    79
    810You have a module {{{xxx}}} and within it a resource {{{yyy}}}, which has a number of components. You're providing CRUD functions for the resource and its components using {{{shn_rest_controller()}}}.
     
    1012Now you want to provide a reporting function for this resource, where the user can select records using a search form and then generate a summary report that can be exported in various formats, among others XLS, PDF and SVG.
    1113
     14  Our example: Your resource contains a "timestmp" field (type datetime) and a field "cost" (type double), and now the user shall select a time interval in aform, and your report function shall provide the sum of all "cost" for those records with a timestmp within the selected time interval.
     15
    1216This tutorial shows you how this can be integrated in the REST interface of your resource.
    1317
    14 === Techniques to use ===
    15 
    16 ==== Creating a custom method handler ====
     18=== Techniques ===
     19
     20==== Create a custom method handler ====
    1721
    1822Reporting is a method of your resource, the reporting function will therefore be implemented as a custom method handler.
     
    4953meaning, it already implements a RESTful API for your reporting function, e.g. does the parsing/validating of the URL for you, implements the full range of URL queries for your resource and so forth. Nothing you need to care about now.
    5054
    51 ==== Providing different Report Formats ====
     55==== Provide different report formats ====
    5256
    5357You want to provide the report in various formats, hence you need to know what format the user has requested. The best way is to check for the format that has been specified in the URL.
     
    99103}}}
    100104
    101 ==== How to get at the data ====
     105==== Get at the data ====
    102106
    103107How can you find out which data have to be processed by your reporting function, and yet more important: how can you get at them?
     
    149153
    150154
    151 === The concrete case: Total costs within a time interval ===
     155=== Step by step: total costs within a time interval ===
    152156
    153157Your resource contains a "timestmp" field (type datetime) and a field "cost" (type double), and now the user shall select a time interval in aform, and your report function shall provide the sum of all "cost" for those records with a timestmp within the selected time interval.
    154158
    155159Let's go:
     160
     161==== 1. Create a method handler ====
     162
    156163First of all, we implement our method handler as before:
    157164
     
    163170s3xrc.model.set_method("xxx", "yyy", method="report", action=s3_xxx_yyy_report)
    164171}}}
     172
     173
     174==== 2. Add representations ====
    165175
    166176Then we add the HTML representation:
     
    175185s3xrc.model.set_method("xxx", "yyy", method="report", action=s3_xxx_yyy_report)
    176186}}}
     187
     188==== 3. Add the form ====
    177189
    178190The next step would be to provide a form to select the first and the last date of the interval. This would look like that:
     
    202214}}}
    203215
     216==== 4. Process the form data ====
     217
    204218From this, we need to process the form data into two dates. We use {{{datetime}}} for that:
    205219
     
    218232
    219233}}}
     234
     235==== 5. Extend the resource query ====
    220236
    221237To select the corresponding records, we need to extend our query:
     
    252268}}}
    253269
     270==== 6. Retrieve the sum of costs ====
     271
    254272From there, it is easy to select the sum of the "cost" field:
    255273
     
    292310            output.update(result=result)
    293311}}}
     312
     313==== 7. Add a view ====
    294314
    295315Done with the method handler! Here at a glance:
     
    375395}}}
    376396
    377 ...and that's all.
    378 
    379 ...to be continued...
    380 ...to be continued...
     397...and that's it.