Beispiel #1
0
    def get_dashboard_resource(self, resource_id, today=None):
        project = Project.find()
        reports_service = ReportsService(project)
        dashboards_service = DashboardsService(project)

        dashboard = dashboards_service.get_dashboard(resource_id)
        reports = [
            reports_service.get_report(report_id)
            for report_id in dashboard["report_ids"]
        ]
        dashboards_helper = DashboardsHelper()
        reports_with_query_results = dashboards_helper.get_dashboard_reports_with_query_results(
            reports, today=today)
        return {
            "dashboard": dashboard,
            "reports_with_query_results": reports_with_query_results,
        }
Beispiel #2
0
class DashboardImporter(RecordImporter):
    RECORD_TYPE = M5oCollectionParserTypes.Dashboard
    ALREADY_EXISTS_ERROR = DashboardAlreadyExistsError
    UPDATABLE_ATTRIBUTES = ["name", "description", "report_ids"]

    def __init__(self, *args):
        super().__init__(*args)

        self.dashboards_service = DashboardsService(self.project)

    def import_record(self, dashboard):
        original_report_ids = dashboard["report_ids"]

        super().import_record(dashboard)

        self.add_reports_to_dashboard(dashboard, original_report_ids)

    def add_reports_to_dashboard(self, dashboard, report_ids):
        for report_id in report_ids:
            self.dashboards_service.add_report_to_dashboard({
                "dashboard_id":
                dashboard["id"],
                "report_id":
                report_id
            })

            logger.debug(
                f"Added report with ID '{report_id}' to dashboard with ID '{dashboard['id']}'"
            )

    def _get_record(self, id):
        return self.dashboards_service.get_dashboard(id)

    def _save_record(self, dashboard):
        return self.dashboards_service.save_dashboard(dashboard)

    def _update_record(self, dashboard):
        return self.dashboards_service.update_dashboard({
            "dashboard": {
                "id": dashboard["id"]
            },
            "new_settings":
            dashboard
        })
Beispiel #3
0
    def test_add_dashboard(self, project, cli_runner):
        def install():
            return cli_runner.invoke(
                cli, ["add", "dashboard", "dashboard-google-analytics"])

        res = install()
        assert res.exit_code == 0

        dashboards_service = DashboardsService(project)
        dashboards_count = len(dashboards_service.get_dashboards())

        assert dashboards_count > 0

        reports_service = ReportsService(project)
        reports_count = len(reports_service.get_reports())
        assert reports_count > 0

        # Verify that reinstalling doesn't duplicate dashboards and reports
        res = install()
        assert res.exit_code == 0

        assert len(dashboards_service.get_dashboards()) == dashboards_count
        assert len(reports_service.get_reports()) == reports_count
Beispiel #4
0
    def __init__(self, *args):
        super().__init__(*args)

        self.dashboards_service = DashboardsService(self.project)
Beispiel #5
0
def dashboards_service():
    project = Project.find()
    return DashboardsService(project)