No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
You create a viewmodel that extracts the data you need from your model. Each attribute in this viewmodel can replace one or more "tags" in the source template. Note that the viewmodel also defines where the template can be found. | You create a viewmodel that extracts the data you need from your model. Each attribute in this viewmodel can replace one or more "tags" in the source template. Note that the viewmodel also defines where the template can be found. | ||
Example of a viewmodel that extracts two attributes to be used, "String" and "Text". | |||
[[File:ReportingTemplate.png|none|thumb|417x417px]] | |||
==== | ==== Ways to retrieve the template ==== | ||
The templates is can be accessed in several different ways; | The templates is can be accessed in several different ways; | ||
*From an String attribute in a modeled class | *From an String attribute in a modeled class | ||
*From a BLOB attribute in a modeled class (base64 encoded) | |||
*From an URL | *From an URL | ||
*From the local filesystem | *From the local filesystem | ||
{| class="wikitable" | {| class="wikitable" | ||
|'''Attribute name''' | |'''Attribute name''' | ||
|'''Attribute should evaluate to''' | |'''Attribute should evaluate to''' | ||
|'''Value type and content''' | |'''Value type and content''' | ||
|- | |||
|TemplateHtml | |||
|A string that contains Html | |||
|Not encoded in any special way. | |||
|- | |- | ||
|TemplateUrl | |TemplateUrl | ||
Line 39: | Line 37: | ||
|TemplateBlob | |TemplateBlob | ||
|A class attribute containing the template | |A class attribute containing the template | ||
|Blob with an uploaded document template, value is expected to be | |Blob with an uploaded document template, value is expected to be Base64 | ||
|- | |||
|ReportFileName | |||
|A string with a filename | |||
|Not used by XHtmlReportAsString but needed for opendocumentreportasblob | |||
|} | |} | ||
==== Methods ==== | |||
Depending on your input format, you can use either of these two functions; | |||
ResultHtmlAsString := self.XHtmlReportAsString(ReportRoot.ViewModels.ReportingViewmodel) | |||
ResultHtmlAsBlob := self.opendocumentreportasblob(ReportRoot.ViewModels.ReportingViewmodel) | |||
* '''self''' here will become the root object of the reporting viewmodel. | |||
* '''ReportRoot''' is the class | |||
* '''Viewmodels''' is a method that retrieves all the viewmodels of the class. See [[OCLOperators ViewModels|ViewModels]] | |||
* '''ReportingViewmodel''' is the name of the reporting viewmodel used in this example | |||
==== XML documents ==== | |||
XML is just the more generic case of html. They are treated by the same logic. You can from 20190919 use any xml-tag as row builder. Example<pre> | |||
<SomeXml attrib='%SomeVMColumnAsAttributeresult%'> %SomeOtherVMColumnAsXMLTextresult% <Items> <Item>%%+TheVMNestingColumn% <ContentInItem someattrib='%VMColInNesting%'> %StuffFromViewModelNesting% </ContentInItem> </Item> </Items> </SomeXml> </pre> | |||
When creating OpenDocument documents, consider using the tag '''%meta%''' in your document to get the exact tag list for your document. | When creating OpenDocument documents, consider using the tag '''%meta%''' in your document to get the exact tag list for your document. | ||
Copy the tag name including the percent signs from the generated meta tag information (preferable without style). The %meta% must be first string in element in order to be recognized - it is also case sensitive. | Copy the tag name including the percent signs from the generated meta tag information (preferable without style). The %meta% must be first string in element in order to be recognized - it is also case sensitive. | ||
Revision as of 10:09, 19 June 2020
Background
The HtmlReport functionality takes an XHTML string, processes it adding data from a viewmodel and outputs the resulting XHTML.
XHTML is a strict version of HTML that is XML compatible. Most important is that it always have one, and only one, root node. Read more here https://en.wikipedia.org/wiki/XHTML
All the functionality of the HtmlReport functionality also applies to XML if you need that.
The HTML generating functions share most of it's code with the OpenDocument functionality. The OpenDocument format uses XML for storing the document content.
How it works
- Viewmodel that defines data to insert
- Template to insert data into
You create a viewmodel that extracts the data you need from your model. Each attribute in this viewmodel can replace one or more "tags" in the source template. Note that the viewmodel also defines where the template can be found.
Example of a viewmodel that extracts two attributes to be used, "String" and "Text".
Ways to retrieve the template
The templates is can be accessed in several different ways;
- From an String attribute in a modeled class
- From a BLOB attribute in a modeled class (base64 encoded)
- From an URL
- From the local filesystem
Attribute name | Attribute should evaluate to | Value type and content |
TemplateHtml | A string that contains Html | Not encoded in any special way. |
TemplateUrl | The URL or local filename | String with for example http://www.mdriven.net/templates/report.odt or for prototyping c:\\temp\\mytemplate.odt |
TemplateBlob | A class attribute containing the template | Blob with an uploaded document template, value is expected to be Base64 |
ReportFileName | A string with a filename | Not used by XHtmlReportAsString but needed for opendocumentreportasblob |
Methods
Depending on your input format, you can use either of these two functions;
ResultHtmlAsString := self.XHtmlReportAsString(ReportRoot.ViewModels.ReportingViewmodel) ResultHtmlAsBlob := self.opendocumentreportasblob(ReportRoot.ViewModels.ReportingViewmodel)
- self here will become the root object of the reporting viewmodel.
- ReportRoot is the class
- Viewmodels is a method that retrieves all the viewmodels of the class. See ViewModels
- ReportingViewmodel is the name of the reporting viewmodel used in this example
XML documents
XML is just the more generic case of html. They are treated by the same logic. You can from 20190919 use any xml-tag as row builder. Example
<SomeXml attrib='%SomeVMColumnAsAttributeresult%'> %SomeOtherVMColumnAsXMLTextresult% <Items> <Item>%%+TheVMNestingColumn% <ContentInItem someattrib='%VMColInNesting%'> %StuffFromViewModelNesting% </ContentInItem> </Item> </Items> </SomeXml>
When creating OpenDocument documents, consider using the tag %meta% in your document to get the exact tag list for your document.
Copy the tag name including the percent signs from the generated meta tag information (preferable without style). The %meta% must be first string in element in order to be recognized - it is also case sensitive.