SysDoc: Sys = system i.e. MDriven built-in feature. Doc = document.
Together: a system pattern for how to handle documents in batches.
SysDocBatch is a model pattern recognized by TurnkeyServer and WPF-Wecpof (MDrivenServer can zip and convert).
We suggest you keep the SysDocBatch and SysDoc classes transient.
This Pattern is mergable from the GitHub repository: supportMDriven/MDrivenComponents (github.com)
The problem it solves is document collections, conversions, zipping and controlled download of reports and other documents.
Normally when you generate a report, it will directly download as an odt or ods formated file. What the SysDocBatch-functionality changes to this behavior is that If a SysSingleton.oclSingleton.CurrentSysDocBatch object is set, we now instead add a SysDoc-object to the SysSingleton.oclSingleton.CurrentSysDocBatch.SysDocs association, thus not triggering the download immediately - but rather build up a batch of documents that may be zipped or converted prior to a later download triggered by the developer or the user.
On the first added SysDoc, we will show the SysDocBatchView ViewModel (rooted in SysDocBatch) as a Modal window.
This will enable you to collect a list of many possible documents that you need to print (if your action generates multiple reports, multiple SysDoc objects are created).
The SysDocBatchView ViewModel is a good place to possibly offer to convert documents to pdf or docx (read more on Using LibreOffice for this task).
You can also make use of the new selfVM operators for Zipping and Downloading:
vData:=selfVM.SysDocBatchZip( self ) selfVM.Download( 'Somefile.zip' , vData )
SysDoc
Attributes
ConversionLog
: Text
Message log from LibreOffice on the document conversion
DocData
: Blob
Document data required for conversion
DocDirectory
: String
Name of the folder to be used when organizing files in zip document.
DocName
: String
Name to be assigned to file including file extension for example .odt for open text document.
InfoOnFailed
: String
Exception message when file conversion fails.
Methods
ConvertToMSOfficeWithLibreOffice
: Converts .ods document to .docx Microsoft office document and .ods document to .xlsx Microsoft Office document.
ConvertToPDFWithLibreOffice
: Converts .odt to .pdf document.
How To Use SysDocBatch Pattern
a) In an Existing Model as a Document Converter
- Merge the pattern into your model from TK Live View
- Set the SysMDrivenMiscSettingsSingleton.oclSingleton.LibreOfficeInstallPathandExe attribute value to Libre office path after installation.
- Create a Template ViewModel that will be used to generate text documents.
- Create a Class Action on the ViewModel that will be used to generate the text documents.
Execute Expression to create the text document and navigate to SysDocBatchView for pdf conversion.
let doc=SysDoc.Create in
(
doc.DocData:=self.opendocumentreportasblob(Order.ViewModels.OrderReceiptViewModel);
doc.DocName:='order-receipt.odt';
doc.DocDirectory:='order-docs';
let sysDocBatch=SysDocBatch.Create in
(
sysDocBatch.SysDocs.add(doc);
SysSingleton.oclSingleton.currentSysDocBatch:=sysDocBatch
)
)
To zip many documents together, attach all the SysDoc(s) to a single SysDocBatch.
let doc=SysDoc.Create in
(
doc.DocData:=self.opendocumentreportasblob(Order.ViewModels.OrderReceiptViewModel);
doc.DocName:='order-receipt.odt';
doc.DocDirectory:='order-docs';
let sys=SysSingleton.oclSingleton in
(
(sys.CurrentSysDocBatch.isNull).whentrue(sys.CurrentSysDocBatch:=SysDocBatch.Create);
sys.CurrentSysDocBatch.SysDocs.add(doc)
)
)
SysDocBatch will only be created the first time and used for subsequent executions.
b) As an Independent Document Converter
- Merge the pattern from TK Live View
- Set the SysMDrivenMiscSettingsSingleton.oclSingleton.LibreOfficeInstallPathandExe attribute value to Libre office path after installation.
- Create Autoforms.
- Use the SysDoc View to Upload text documents to convert and set the DocName attribute with the full file name (including extension).
- Navigate to the SysDocBatchView to convert documents.
- Click on PDF to convert document to PDF.
- Create Zip below downloading Zip.