Skip to content

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 state observable; once the parent form is available it triggers loadAnalytics().
  • Fetches results via FormResultControllerService.find({ where: { form_id: object.id } }) and segregates them by status (1=in progress, 2=completed).

Aggregation Pipeline

For each form definition group:

  1. Builds a list of fields.
  2. Runs type-specific aggregators:
    • buildRadioChart / buildMeasurementChart / buildMatrixChart / buildInputTableStats / buildTextStats.
  3. Each aggregator returns chartOptions and chartSeries objects compatible with <hc-chart> plus helper stats (pass/fail counts, min/max/avg, filled percentages, etc.).
  4. 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 AuthState roles before enabling the action.

Syneo/Barcoding Documentation