Skip to content

Commit db2fdab

Browse files
committed
[IMP] runbot: stats - disable/enable filters by their relations
1 parent 6b02187 commit db2fdab

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

runbot/controllers/frontend.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from odoo.http import Controller, Response, request
1616
from odoo.http import route as o_route
1717
from odoo.fields import Domain
18+
from odoo.tools.json import json_default
1819

1920
from odoo.addons.website.controllers.main import QueryURL
2021

@@ -63,6 +64,13 @@ def response_wrap(*args, **kwargs):
6364
return response_wrap
6465
return decorator
6566

67+
68+
def json_default_set(obj):
69+
if isinstance(obj, set):
70+
return list(obj)
71+
return json_default(obj)
72+
73+
6674
class Runbot(Controller):
6775

6876
def _pending(self):
@@ -596,8 +604,7 @@ def modules_stats(self, bundle, search=None, **post):
596604
all_builds |= bundle.with_context(category_id=request.env.ref('runbot.nightly_category').id).last_done_batch.slot_ids.build_id
597605
all_builds = request.env['runbot.build'].search([('id', 'child_of', all_builds.ids)])
598606
all_stats = all_builds.sudo().stat_ids
599-
category_per_trigger = {}
600-
step_per_trigger_category = {}
607+
triggers_relations = {}
601608
all_categories = set()
602609
all_steps = set()
603610
all_triggers = set()
@@ -608,21 +615,20 @@ def modules_stats(self, bundle, search=None, **post):
608615
all_categories.add(stat.category)
609616
all_steps.add(stat.dynamic_step_name or stat.config_step_id.name)
610617
all_triggers.add(stat_trigger)
611-
category_per_trigger.setdefault(stat_trigger, set()).add(stat.category)
612-
step_per_trigger_category.setdefault((stat_trigger, stat.category), set()).add(stat.dynamic_step_name or stat.config_step_id.name)
618+
triggers_relations.setdefault(stat_trigger.id, dict()).setdefault(stat.category, set()).add(stat.dynamic_step_name or stat.config_step_id.name)
613619
all_triggers = sorted(all_triggers, key=lambda t: (t.category_id.id, t.sequence, t.id))
614620
context = {
615-
'category_per_trigger': category_per_trigger,
616-
'step_per_trigger_category': step_per_trigger_category,
617621
'bundle': bundle,
618622
'project': bundle.project_id,
619623
'triggers_data': {
620624
'bundle_id': bundle.id,
621625
'trigger_id': all_triggers[0].id if all_triggers else None,
626+
'relations': triggers_relations,
622627
},
623628
'all_categories': sorted(all_categories),
624629
'all_steps': sorted(all_steps),
625630
'all_triggers': all_triggers,
631+
'json_default': json_default_set,
626632
}
627633
return request.render("runbot.modules_stats", context)
628634

runbot/static/src/public/interactions/stats.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ export class Stats extends Interaction {
9999
return String(el.value) === String(this.params[filterName]) ? "selected" : undefined;
100100
},
101101
},
102+
"select#trigger_id_selector option": {
103+
"t-att-class": (el) => {
104+
const categories = Object.keys(this.triggersData.relations[el.value] || {});
105+
return { "text-secondary": !categories.find((category) => category === this.params.key_category) };
106+
},
107+
},
108+
"select#key_category_selector option": {
109+
"t-att-class": (el) => {
110+
const trigger = this.triggersData.relations[String(this.params.trigger_id)] || {};
111+
return { "text-secondary": !Object.keys(trigger).includes(el.value) };
112+
},
113+
},
114+
"select#key_step_selector option": {
115+
"t-att-class": (el) => {
116+
const trigger = this.triggersData.relations[String(this.params.trigger_id)] || {};
117+
const steps = trigger[this.params.key_category] || [];
118+
return { "text-secondary": !steps.includes(el.value) };
119+
},
120+
},
102121
"#js-chart": {
103122
"t-component": () => [StatsChart, { config: this.chartConfig, data: this.chartData, loader: this.loader }],
104123
},

runbot/templates/build_stats.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<template id="runbot.modules_stats">
55
<t t-call='runbot.layout'>
66
<div class="runbot-stats container-fluid py-4">
7-
<script id="triggers_data" type="application/json" t-out="json.dumps(triggers_data, indent=4)"/>
7+
<script id="triggers_data" type="application/json" t-out="json.dumps(triggers_data, indent=4, default=json_default)"/>
88
<nav class="row row-cols-auto mb-4">
99
<h1 class="h2" t-out="bundle.name"/>
1010
<div class="d-flex gap-3 ms-auto">

0 commit comments

Comments
 (0)