From 48233b601e0606b553c9cf9e863e4c11180b26ab Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Thu, 9 Jan 2025 17:53:36 +0100 Subject: [PATCH] [IMP] runbot: allow changing trigger from stat page Adds a new selection field to change trigger directly from the stat page. --- runbot/controllers/frontend.py | 18 ++++++++++++++ runbot/static/src/stats/stats_config.js | 31 ++++++++++++++++++++++++ runbot/static/src/stats/stats_config.xml | 7 +++++- runbot/static/src/stats/stats_root.js | 14 +++++++++++ runbot/static/src/stats/use_config.js | 18 ++++++++++++++ runbot/templates/build_stats.xml | 1 + 6 files changed, 88 insertions(+), 1 deletion(-) diff --git a/runbot/controllers/frontend.py b/runbot/controllers/frontend.py index 9058a4301..a7551cf0b 100644 --- a/runbot/controllers/frontend.py +++ b/runbot/controllers/frontend.py @@ -3,6 +3,7 @@ import werkzeug import logging import functools +import itertools import werkzeug.utils import werkzeug.urls @@ -620,10 +621,27 @@ def list_config_categories(config): categories = sorted(categories) + triggers = bundle.project_id.trigger_ids.filtered( + lambda t: t.has_stats and not t.manual + ).sorted( + lambda t: (t.category_id.id, t.sequence, t.id) + ) + triggers_by_category = defaultdict(list) + slug = request.env['ir.http']._slug + for trig in triggers: + triggers_by_category[trig.category_id.name].append( + { + 'id': trig.id, + 'slug': slug(trig), + 'name': trig.name, + }, + ) context = { 'stats_categories': categories, 'bundle': bundle, 'trigger': trigger, + # Category name -> List of trigger name + id + 'triggers_by_category': triggers_by_category } return request.render("runbot.modules_stats", context) diff --git a/runbot/static/src/stats/stats_config.js b/runbot/static/src/stats/stats_config.js index a74290583..ee3dc04d9 100644 --- a/runbot/static/src/stats/stats_config.js +++ b/runbot/static/src/stats/stats_config.js @@ -24,6 +24,20 @@ export class StatsConfig extends Component { }, }, stats_categories: { type: Array, element: String }, + triggers_by_category: { + type: Object, + values: { + type: Array, + element: { + type: Object, + shape: { + id: { type: Number }, + slug: { type: String }, + name: { type: String }, + } + } + } + }, }; setup() { @@ -43,4 +57,21 @@ export class StatsConfig extends Component { onClickNext() { this.env.bus.trigger('click-next', {}); } + + /** + * Called when the trigger selection is changed. + * This changes the config a bit and redirects the user towards the same page with the new trigger. + * + * @param {Event} event the event + */ + onChangeTrigger(event) { + const { origin, pathname, search } = window.location; + const [_, bundle] = /\/runbot\/stats\/(.+)\/.+/.exec(pathname); + const newParams = this.config.asSearchParams(); + this.config.getTriggerSpecificKeys().forEach( + (key) => newParams.delete(key) + ); + console.log( `${origin}/runbot/stats/${bundle}/${event.target.value}${search}#${newParams.toString()}`); + window.location.href = `${origin}/runbot/stats/${bundle}/${event.target.value}${search}#${newParams.toString()}`; + } }; diff --git a/runbot/static/src/stats/stats_config.xml b/runbot/static/src/stats/stats_config.xml index 4e8478828..cc7439595 100644 --- a/runbot/static/src/stats/stats_config.xml +++ b/runbot/static/src/stats/stats_config.xml @@ -4,7 +4,12 @@