widget-form-results-analytics
App: Backend
Source: web/projects/backend/src/widgets/widget-form-results-analytics
Purpose
Provides a dashboard-level analytics view for a single form. Summarizes counts of total/completed/in-progress results and renders charts for each field type. Also exposes a shortcut to the form_summary_report generator.
Loading & State
- Subscribes to the widget
stateobservable; once the parent form is available it triggersloadAnalytics(). - Fetches results via
FormResultControllerService.find({ where: { form_id: object.id } })and segregates them bystatus(1=in progress, 2=completed).
Aggregation Pipeline
For each form definition group:
- Builds a list of fields.
- Runs type-specific aggregators:
buildRadioChart/buildMeasurementChart/buildMatrixChart/buildInputTableStats/buildTextStats.
- Each aggregator returns
chartOptionsandchartSeriesobjects compatible with<hc-chart>plus helper stats (pass/fail counts, min/max/avg, filled percentages, etc.). - The template renders stats plus optional conditional comment lists for radio-conditional fields.
Summary Report Action
generateSummaryReport() calls:
ts
reportService.generateReport({
controller: 'form_summary_report',
params: { form_id: this.object.id },
options_interface: {
to: { user_id: [currentUser.id] },
output: { html_content: true },
delivery: { instant: true },
},
}, true);This uses the backend reporting worker to produce the same stats in PDF/HTML.
Extension Tips
- Plug in additional chart builders (e.g., time-series) by extending the aggregation switch statement.
- Gate the summary report button on permissions by injecting
AuthStateroles before enabling the action.