From 513da570e27e481cd4e392b6409fb475759bf3bc Mon Sep 17 00:00:00 2001 From: Jon Herron Date: Fri, 18 Nov 2022 14:29:04 -0500 Subject: [PATCH] Accept report_identifier --- .../models/process_instance_report.py | 1 + .../routes/process_api_blueprint.py | 2 +- .../process_instance_report_service.py | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) 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 1425d69f5..ea85a23ec 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 deb347076..dd4037e72 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -739,7 +739,7 @@ def process_instance_list( 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 e90120d86..541bdee22 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,63 @@ class ProcessInstanceReportFilter: class ProcessInstanceReportService: """ProcessInstanceReportService.""" + @classmethod + def report_with_identifier( + cls, + user: UserModel, + report_identifier: Optional[str] = None + ) -> ProcessInstanceReportModel: + if report_identifier is None: + return ProcessInstanceReportModel.default_report(user) + + # TODO replace with system reports that are loaded on launch (or similar) + temp_system_metdata_map = { + "system_report_instances_initiated_by_me": { + "columns": [ + {"Header": "id", "accessor": "id"}, + { + "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"}, + ], + }, + "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 = cls( + identifier=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