Overview
TheReportController extends BaseController and is specifically designed for handling report-type documents. It enforces view-only access by automatically redirecting all non-view actions to the view action, making it ideal for report generation and display.
Class Definition
packages/loopar/core/controller/report-controller.js:6
When to Use
- For generating and displaying reports
- When you need to present aggregated data or analytics
- For financial reports, sales reports, or business intelligence dashboards
- When you want to prevent report modification through the UI
- For data visualization and analysis pages
Key Features
- Automatic redirection of all actions to ‘view’
- View-only access enforcement for reports
- Inherits all BaseController functionality (available programmatically)
- Simplified report rendering
- Ideal for data presentation without edit capabilities
Constructor
Configuration object containing controller initialization parameters:
action: The current action being performed (will be redirected if not ‘view’)document: The document type being controlled (typically a Report)name: The name/identifier of the specific reportdata: Request data, often containing report parameters and filtersreq: HTTP request objectres: HTTP response object- Other inherited controller properties
Methods
actionView()
Handles the view action by loading and rendering the report document.Promise<object> - Rendered report response with report data and metadata
Implementation:
- Loads the report document using
loopar.getDocument() - Renders the report with appropriate metadata
- Returns the rendered response for display
packages/loopar/core/controller/report-controller.js:13
Properties
Current action being executed - always ‘view’ due to automatic redirection
Document type name being controlled (e.g., ‘Sales Report’, ‘Analytics Dashboard’)
The name/identifier of the specific report instance
Request data object, typically containing report filters and parameters
Default action inherited from BaseController (redirected to ‘view’)
Whether to display sidebar navigation (inherited from BaseController)
Inherited Methods
ReportController inherits all methods from:- BaseController - Full CRUD operations (programmatic access only)
- CoreController - Rendering, error handling, authentication
- AuthController - User authentication and authorization
Available Inherited Methods
While UI access is restricted to ‘view’, these methods are available programmatically:render(meta)
render(meta)
Promise<object> - Rendered report responsesuccess(message, options)
success(message, options)
Promise<object> - Success response with notificationerror(message, options, status)
error(message, options, status)
Promise<object> - Error response with notificationactionList()
actionList()
Promise<object> - List of reports with paginationUsage Examples
Creating a Sales Report Controller
Financial Report with Export
Analytics Dashboard Report
Best Practices
Report Generation: Generate report data in
actionView() and cache results when appropriate to improve performance.Do’s
- Cache report data when possible to reduce database load
- Implement filters and parameters for flexible reporting
- Provide export functionality (PDF, Excel, CSV)
- Use database indexes on fields used in report queries
- Show loading indicators for long-running reports
- Implement real-time refresh options when needed
- Add date range selectors for time-based reports
Don’ts
- Don’t run expensive queries without optimization
- Don’t load all data at once for large datasets
- Don’t skip input validation on report parameters
- Don’t expose raw database queries to users
- Avoid generating reports synchronously for very large datasets
Performance Optimization
Comparison with Other Controllers
| Feature | ReportController | ViewController | FormController | BaseController |
|---|---|---|---|---|
| Multiple instances | Yes | Yes | Yes | Yes |
| List view | Redirected | Redirected | Redirected | Yes |
| Edit capability | No | No | No | Yes |
| Best for | Reports | Read-only docs | Forms | Full CRUD |
| Action restriction | View only | View only | View only | All actions |
| Data aggregation | Yes | Optional | No | No |
Related Controllers
- BaseController - Parent class with full CRUD
- ViewController - Similar view-only behavior
- FormController - For form handling
- SingleController - For single-instance documents
Common Use Cases
- Sales Reports: Revenue, orders, and sales performance
- Financial Statements: Income statements, balance sheets, cash flow
- Analytics Dashboards: KPIs, trends, and business intelligence
- Inventory Reports: Stock levels, movements, valuations
- User Activity Reports: Engagement, retention, behavior analysis
- Performance Reports: Employee, department, or project performance
- Compliance Reports: Regulatory and audit reports
Troubleshooting
Report generation is slow
Report generation is slow
- Optimize database queries with proper indexes
- Implement caching for frequently accessed reports
- Use pagination for large datasets
- Consider pre-generating reports asynchronously
Cannot edit or create reports
Cannot edit or create reports
This is by design. ReportController restricts actions to ‘view’ only. If you need to create or edit report definitions, access them through BaseController or implement custom actions.
Report shows outdated data
Report shows outdated data
If caching is enabled, implement a cache refresh mechanism:
Export functionality not working
Export functionality not working
Implement custom export actions: