diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml index 068efa2f..1f3e7971 100755 --- a/spiffworkflow-backend/src/spiffworkflow_backend/api.yml +++ b/spiffworkflow-backend/src/spiffworkflow_backend/api.yml @@ -445,6 +445,12 @@ paths: description: For filtering - indicates the user has manually entered a query schema: type: boolean + - name: report_identifier + in: query + required: false + description: Specifies the identifier of a report to use, if any + schema: + type: string get: operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_list summary: Returns a list of process instances for a given process model diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py index 1425d69f..ea85a23e 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py @@ -79,6 +79,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel): identifier=identifier, created_by_id=user.id ).first() + # TODO replace with system report that is loaded on launch (or similar) if process_instance_report is None: report_metadata = { "columns": [ diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index b3d5ec02..307daa8c 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -736,9 +736,12 @@ def process_instance_list( end_to: Optional[int] = None, process_status: Optional[str] = None, user_filter: Optional[bool] = False, + report_identifier: Optional[str] = None, ) -> flask.wrappers.Response: """Process_instance_list.""" - process_instance_report = ProcessInstanceReportModel.default_report(g.user) + process_instance_report = ProcessInstanceReportService.report_with_identifier( + g.user, report_identifier + ) if user_filter: report_filter = ProcessInstanceReportFilter( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py index e90120d8..a521c1a3 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py @@ -5,6 +5,7 @@ from typing import Optional from spiffworkflow_backend.models.process_instance_report import ( ProcessInstanceReportModel, ) +from spiffworkflow_backend.models.user import UserModel @dataclass @@ -41,6 +42,62 @@ class ProcessInstanceReportFilter: class ProcessInstanceReportService: """ProcessInstanceReportService.""" + @classmethod + def report_with_identifier( + cls, user: UserModel, report_identifier: Optional[str] = None + ) -> ProcessInstanceReportModel: + """Report_with_filter.""" + if report_identifier is None: + return ProcessInstanceReportModel.default_report(user) + + # TODO replace with system reports that are loaded on launch (or similar) + temp_system_metadata_map = { + "system_report_instances_initiated_by_me": { + "columns": [ + { + "Header": "process_model_identifier", + "accessor": "process_model_identifier", + }, + {"Header": "start_in_seconds", "accessor": "start_in_seconds"}, + {"Header": "id", "accessor": "id"}, + {"Header": "end_in_seconds", "accessor": "end_in_seconds"}, + {"Header": "status", "accessor": "status"}, + ], + }, + "system_report_instances_with_tasks_completed_by_me": { + "columns": [ + {"Header": "start_in_seconds", "accessor": "start_in_seconds"}, + {"Header": "end_in_seconds", "accessor": "end_in_seconds"}, + {"Header": "status", "accessor": "status"}, + {"Header": "id", "accessor": "id"}, + { + "Header": "process_model_identifier", + "accessor": "process_model_identifier", + }, + ], + }, + "system_report_instances_with_tasks_completed_by_my_groups": { + "columns": [ + { + "Header": "process_model_identifier", + "accessor": "process_model_identifier", + }, + {"Header": "start_in_seconds", "accessor": "start_in_seconds"}, + {"Header": "end_in_seconds", "accessor": "end_in_seconds"}, + {"Header": "status", "accessor": "status"}, + {"Header": "id", "accessor": "id"}, + ], + }, + } + + process_instance_report = ProcessInstanceReportModel( + identifier=report_identifier, + created_by_id=user.id, + report_metadata=temp_system_metadata_map[report_identifier], + ) + + return process_instance_report + @classmethod def filter_by_to_dict( cls, process_instance_report: ProcessInstanceReportModel