diff --git a/argus/backend/controller/view_api.py b/argus/backend/controller/view_api.py index d1dca588..55b1d191 100644 --- a/argus/backend/controller/view_api.py +++ b/argus/backend/controller/view_api.py @@ -7,6 +7,7 @@ ) from argus.backend.controller.views_widgets.highlights import bp as highlights_bp from argus.backend.controller.views_widgets.summary import bp as summary_bp +from argus.backend.controller.views_widgets.graphs import bp as graphs_bp from argus.backend.error_handlers import handle_api_exception from argus.backend.models.web import User from argus.backend.service.stats import ViewStatsCollector @@ -18,6 +19,7 @@ LOGGER = logging.getLogger(__name__) bp.register_blueprint(highlights_bp) bp.register_blueprint(summary_bp) +bp.register_blueprint(graphs_bp) bp.register_error_handler(Exception, handle_api_exception) diff --git a/argus/backend/controller/views_widgets/graphs.py b/argus/backend/controller/views_widgets/graphs.py new file mode 100644 index 00000000..33b94f41 --- /dev/null +++ b/argus/backend/controller/views_widgets/graphs.py @@ -0,0 +1,66 @@ +from uuid import UUID +from datetime import datetime, timezone + +from flask import Blueprint, request + +from argus.backend.models.web import ArgusUserView, ArgusTest +from argus.backend.service.results_service import ResultsService +from argus.backend.service.user import api_login_required +bp = Blueprint("graphs", __name__, url_prefix="/widgets") + +@bp.route("/graphs/graph_views", methods=["GET"]) +@api_login_required +def get_graph_views(): + view_id = UUID(request.args.get("view_id")) + view: ArgusUserView = ArgusUserView.get(id=view_id) + start_date = request.args.get("start_date") + end_date = request.args.get("end_date") + service = ResultsService() + response = {} + tests_details = {} + + for test_id in view.tests: + test_uuid = test_id + graph_views = service.get_argus_graph_views(test_uuid) + if graph_views: + test_name = ArgusTest.get(id=test_uuid).name + tests_details[str(test_id)] = {"name": test_name} + view_data = [] + + for graph_view in graph_views: + # Get unique table names from all graphs in the view + table_names = set() + for graph_name in graph_view.graphs.keys(): + table_name = graph_name.rsplit(" - ", 1)[0] + table_names.add(table_name) + + # Get graphs data for these tables + start_dt = datetime.fromisoformat(start_date).astimezone(timezone.utc) if start_date else None + end_dt = datetime.fromisoformat(end_date).astimezone(timezone.utc) if end_date else None + graphs, ticks, releases_filters = service.get_test_graphs( + test_id=test_uuid, + start_date=start_dt, + end_date=end_dt, + table_names=list(table_names) + ) + + # filter out graphs that are not in the graph views + graphs = [graph for graph in graphs if graph["options"]["plugins"]["title"]["text"] in graph_view.graphs.keys()] + + if graphs: + view_data.append({ + "id": str(graph_view.id), + "name": graph_view.name, + "description": graph_view.description, + "graphs": graphs, + "ticks": ticks, + "releases_filters": releases_filters + }) + + response[str(test_id)] = view_data + + return { + "status": "ok", + "response": response, + "tests_details": tests_details + } diff --git a/frontend/Common/ViewTypes.js b/frontend/Common/ViewTypes.js index f0fcd042..ceae36c5 100644 --- a/frontend/Common/ViewTypes.js +++ b/frontend/Common/ViewTypes.js @@ -10,6 +10,8 @@ import {subUnderscores, titleCase} from "./TextUtils"; import ViewHighlights from "../Views/Widgets/ViewHighlights/ViewHighlights.svelte"; import IntegerValue from "../Views/WidgetSettingTypes/IntegerValue.svelte"; import SummaryWidget from "../Views/Widgets/SummaryWidget/SummaryWidget.svelte"; +import GraphWidget from "../Views/Widgets/GraphsWidget/GraphsWidget.svelte"; + export class Widget { constructor(position = -1, type = "testDashboard", settings = {}) { @@ -120,6 +122,11 @@ export const WIDGET_TYPES = { } }, }, + graphs: { + type: GraphWidget, + friendlyName: "Graphs Views", + settingDefinitions: {} + }, }; diff --git a/frontend/Views/Widgets/GraphsWidget/GraphsWidget.svelte b/frontend/Views/Widgets/GraphsWidget/GraphsWidget.svelte new file mode 100644 index 00000000..3992ea08 --- /dev/null +++ b/frontend/Views/Widgets/GraphsWidget/GraphsWidget.svelte @@ -0,0 +1,259 @@ + + +