How Dialog Forms Work

From truxwiki.com
Revision as of 11:37, 22 November 2021 by Adrian (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

This page documents how the Dialog Forms in Truxton work, or forms that pop up in a modal window work.

UI Guide Menu

  1. Entry Point
  2. Navigation and Routing
  3. Databinding
  4. Dependency Injection
  5. Task Bar Icon
  6. Truxton CLI options
  7. How Reports are Displayed
  8. How Dialog Forms Work

Overview

In the Truxton Analyst App, there are a few pages that have forms to add or update data related to that page. A few examples include: Subjects, Media, and Investigator.
Generally, to change data related to those models, you would go to that page, click a button that opens a form, change the data, and click the button when you are done. When this happens, there are a lot of things happening behind the scenes. A lot of it abstracted out so that there is a centralized code for the common functionality.
For each model, there is a "-PageViewModel", "-Form", "-ViewModel", "-.xaml".
Resource Summary
PageViewModel.cs This class loads and manages the data on the page, the view that you look at when you navigate using the navigation menu.
Form.cs This class loads and manages the data on the Dialog Form, the form that you see when you're on the page and you click the "add" or "new" button. The xaml bindings are here mostly. The FormItems properties are loaded here but they are not defined here.
ViewModelRegistrar.cs Registers the ViewModels so that the WorkspaceFactory can associate the View with the ViewModel \Truxton\Client\TruxtonClient\TruxtonClient\PresentationCore\ViewModelRegistrar.cs
ViewModel.cs Contains the various Views
Templates Directory Contains Templates which are additional XAML that may be used in each Views \Truxton\Client\TruxtonClient\TruxtonClient\Templates\
ViewModel Directory Contains the various ViewModels for each view \Truxton\Client\TruxtonClient\TruxtonClient\ViewModels\

Main Files

File Summary Path
ReportSection.xaml This view has a WebBrowser element that displays the HTML. It's loaded using the Binding HTMLReport.Stream \Truxton\Client\TruxtonClient\TruxtonClient\Templates\ReportSection.xaml
ReportSectionViewModel.cs This is the ViewModel for the ReportSection \Truxton\Client\TruxtonClient\TruxtonClient\ViewModels\Reports\ReportSectionViewModel.cs
HTMLReportViewModel.cs This is where the report-generating functions are called in loadReportContent \Truxton\Client\TruxtonClient\TruxtonClient\ViewModels\Reports\HTMLReportViewModel.cs


HTMLReportViewModel.cs

In the loadReportContent function,
the relevant reportFactory is selected.
loadReportContent
  var reportFactory = _ctx.ReportService.GetReportFactory(req.ReporterID);
Then, the report is generated resulting in a ITruxtonReport.
loadReportContent
  var report = await reportFactory.GenerateAsync(req.ReportConfig, req.CTS.Token);
Next, the reportContent(HTML) is generated resulting in a string that contains the HTML.
loadReportContent
  string reportContent = await report.GetReportContentAsync(req.CTS.Token);
Eventually, the string is converted into a stream then assigned so that it's available for dataBinding.
loadReportContent
  Stream = req.Stream;
For quick reference, the databinding can be found in ReportSection.xaml.
ReportSection.xaml
  <controls:WebBrowser x:Name="WebBrowser" Stream="{Binding HTMLReport.Stream}" />
Here's the full snippet of loadReportConent with the relevant code..
loadReportContent
  var reportFactory = _ctx.ReportService.GetReportFactory(req.ReporterID);
   if (reportFactory != null)
   {
       var report = await reportFactory.GenerateAsync(req.ReportConfig, req.CTS.Token);
       report.ReportFormatter = ReportFormatter;
       string reportContent = await report.GetReportContentAsync(req.CTS.Token);
       if (!req.CTS.Token.IsCancellationRequested)
       {
           var bytes = Encoding.UTF8.GetBytes(reportContent);
           req.Stream = new CancellableStream(bytes);
           Stream = req.Stream;
   
           string message = getActionMessage(req, reportFactory.Name);
           await _ctx.InvestigationContext.AddActionAsync(message, CancellationToken.None);
       }
   }