Commit 9765d07ffd84e0c1dab282f51108b29883a4d76d
1 parent
e331f7fc
Exists in
master
and in
4 other branches
New period widget selector on Agents/stats
Showing
4 changed files
with
61 additions
and
11 deletions
Show diff stats
app/main/routes.py
... | ... | @@ -79,7 +79,9 @@ def agents(): |
79 | 79 | @role_required('project') |
80 | 80 | def agents_stats(): |
81 | 81 | num_agents = len(Agent.query.all()) |
82 | - return render_template('agents_stats.html', subtitle="Statistiques des agents ({})".format(num_agents)) | |
82 | + all_periods = Period.query.order_by(Period.name).all() | |
83 | + return render_template('agents_stats.html', subtitle="Statistiques des agents ({})".format(num_agents), | |
84 | + periods=all_periods) | |
83 | 85 | |
84 | 86 | |
85 | 87 | @bp.route('/capacities') | ... | ... |
app/main/static/js/charges.js
... | ... | @@ -153,7 +153,6 @@ function build_chart(div_selector, data_url, entity_name, category_type) { |
153 | 153 | let category_name = d3.select(this.parentNode).datum().key; |
154 | 154 | let category_charge = d.data[category_name]; |
155 | 155 | show_tooltip(e, category_name, category_charge); |
156 | - console.log("HELLO"); | |
157 | 156 | }; |
158 | 157 | |
159 | 158 | let mouseovergrouped = function (e, d) { |
... | ... | @@ -657,6 +656,7 @@ function build_pie_chart(div_selector, data_url, entity_name) { |
657 | 656 | // height = width * 0.8; |
658 | 657 | height = 400; |
659 | 658 | |
659 | + d3.selectAll('svg.svg_chart').remove(); | |
660 | 660 | let svg = make_svg(div_selector, width, height, margin); |
661 | 661 | let radius = Math.min(height, width) / 2, |
662 | 662 | radius_width = 90; |
... | ... | @@ -667,7 +667,7 @@ function build_pie_chart(div_selector, data_url, entity_name) { |
667 | 667 | }); |
668 | 668 | |
669 | 669 | let arc = d3.arc() |
670 | - .innerRadius(radius - radius_width) | |
670 | + .innerRadius(0 ) | |
671 | 671 | .outerRadius(radius); |
672 | 672 | |
673 | 673 | d3.csv(data_url).then(data => { |
... | ... | @@ -704,7 +704,7 @@ function build_pie_chart(div_selector, data_url, entity_name) { |
704 | 704 | .attr("y", 0 - (margin.top / 2) ) |
705 | 705 | .attr("text-anchor", "middle") |
706 | 706 | .style("font-size", "12px") |
707 | - .text("Période: "); | |
707 | + .text("Période: "+entity_name); | |
708 | 708 | |
709 | 709 | }); |
710 | 710 | |
... | ... | @@ -715,6 +715,5 @@ function build_line_chart(div_selector, data_url, entity_name) { |
715 | 715 | let main_elt = document.querySelector(div_selector); |
716 | 716 | let width = main_elt.offsetWidth, |
717 | 717 | height = 500; |
718 | - console.log(main_elt); | |
719 | 718 | let svg = make_svg(div_selector, width, height, margin); |
720 | 719 | } | ... | ... |
app/main/templates/agents_stats.html
... | ... | @@ -9,6 +9,21 @@ |
9 | 9 | <!-- Invisible span to definte wich ul and a in the navbar are actived --> |
10 | 10 | <span id="nav_actived" style="display: none">agent,agents_stats</span> |
11 | 11 | |
12 | + <h3 class="sub-header">Sélectionner la période</h3> | |
13 | + | |
14 | + <div class="row pdc-controls"> | |
15 | + <select title="Choisir la période" id="period_id_select" name="period_id_select" class="form-control col-1"> | |
16 | + {% for p in periods %} | |
17 | + <option value="{{ p.id }}" {{ "selected" if p.id == 1 }}>{{ p.name }}</option> | |
18 | + {% endfor %} | |
19 | + </select> | |
20 | + <div class="col-1"> | |
21 | + <button id='prev_period' title="Période précédente"><span data-feather="chevron-left"></span></button> | |
22 | + <button id='next_period' title="Période suivante"><span data-feather="chevron-right"></span></button> | |
23 | + </div> | |
24 | + | |
25 | + </div> | |
26 | + | |
12 | 27 | <h3 class="sub-header">Tout le laboratoire</h3> |
13 | 28 | |
14 | 29 | <div class="row"> |
... | ... | @@ -33,12 +48,42 @@ |
33 | 48 | |
34 | 49 | <script> |
35 | 50 | {#TODO: get current period id from session#} |
36 | - build_pie_chart("#agents_by_status_chart", | |
37 | - "{{url_for('main.rest_agents_status_count', period_id=1)}}", | |
38 | - "Charge des agents par statut"); | |
39 | - build_line_chart("#charge_by_status_chart", | |
40 | - "{{url_for('main.rest_agents_status_count', period_id=1)}}", | |
41 | - "Charge des agents par statut"); | |
51 | + $('#period_id_select').on('change', function () { | |
52 | + let period_id = $(this).find(':selected').val(); | |
53 | + let period_name = $(this).find(':selected').text(); | |
54 | + build_all(period_id, period_name); | |
55 | + }); | |
56 | + document.getElementById('next_period').onclick = function () { | |
57 | + period_select_update(1); | |
58 | + }; | |
59 | + document.getElementById('prev_period').onclick = function () { | |
60 | + period_select_update(-1); | |
61 | + }; | |
62 | + | |
63 | + let period_select_update = function (step) { | |
64 | + let select_elemnt = $('#period_id_select'); | |
65 | + let selectoptions_length = $('#period_id_select option').length; | |
66 | + let next_step = +select_elemnt.val() + step; | |
67 | + if (next_step <= 0 || next_step > selectoptions_length) { | |
68 | + return; | |
69 | + } | |
70 | + select_elemnt.val(next_step); | |
71 | + select_elemnt.trigger('change'); | |
72 | + }; | |
73 | + | |
74 | + let build_all = function (period_id, period_name) { | |
75 | + let agent_status_url = "{{url_for('main.rest_agents_status_count', period_id='PERIOD_ID')}}" | |
76 | + .replace("PERIOD_ID", period_id); | |
77 | + | |
78 | + build_pie_chart("#agents_by_status_chart", | |
79 | + agent_status_url, | |
80 | + period_name); | |
81 | + | |
82 | + build_line_chart("#charge_by_status_chart", | |
83 | + "{{url_for('main.rest_agents_status_count', period_id=1)}}", | |
84 | + "Charge des agents par statut"); | |
85 | + | |
86 | + }; | |
42 | 87 | |
43 | 88 | {# {% for c in categories %}#} |
44 | 89 | {# build_chart("#labels_stats_chart_{{ c.id }}",#} | ... | ... |
app/static/css/style.css