Skip to content

Commit

Permalink
Fix/retrieve new filters update (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori committed Mar 16, 2022
1 parent 59d1a4b commit 74b40a5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
18 changes: 18 additions & 0 deletions ckanext/querytool/controllers/querytool.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,28 @@ def querytool_public_read(self, name):
image['url'] = '{0}/uploads/vs/{1}'.format(
toolkit.request.host_url, image['url'])

# Default to first new filter after updating visualizations
for vis in q_item.get('visualizations', []):
resource_id = q_item.get('chart_resource')
filter_name = vis.get('filter_name')
visibility = vis.get('filter_visibility')
filter_value = vis.get('filter_value')

if resource_id and filter_name and \
visibility == 'public':
updated_filters = helpers.get_filter_values(
resource_id, filter_name, new_filters
)

if filter_value and filter_value not in \
updated_filters and len(updated_filters) > 0:
vis['filter_value'] = updated_filters[0]

related_sql_string = helpers.create_query_str(
q_item.get('chart_resource'),
new_filters
)

q_item['public_filters'] = new_filters
q_item['public_filters'].sort(key=itemgetter('order'))
q_item['sql_string'] = related_sql_string
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions ckanext/querytool/fanstatic/javascript/vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,11 @@ $(document).ready(function(){
}

if(selected=='pie' || selected=='donut') {
$(`#donut_hole_${chart_number}`).removeClass("hidden");
$(`#chart_donut_hole_${chart_number}`).removeClass("hidden");
$(`#chart_field_donut_hole_${chart_number}`).removeProp("disabled");
} else {
$(`#donut_hole_${chart_number}`).addClass("hidden");
$(`#chart_donut_hole_${chart_number}`).addClass("hidden");
$(`#chart_field_donut_hole_${chart_number}`).prop("disabled", true);
}

})
Expand Down
7 changes: 5 additions & 2 deletions ckanext/querytool/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,12 @@ def get_querytool_get_chart_colors(data):
return data


def convert_bar_width(bar_width, convert=True):
def convert_bar_width(bar_width, convert=True, type='bar'):
if not bar_width or bar_width == 'None':
return
if type == 'donut':
return 4.0
else:
return 5.0

if convert:
return str(round(float(bar_width) * 10, 2))
Expand Down
6 changes: 3 additions & 3 deletions ckanext/querytool/templates/ajax_snippets/chart_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@
{% set hide_donut = '' %}
{% endif %}

<div class="control-group {{hide_donut}}" id="donut_hole_{{n}}">
<div class="control-group {{hide_donut}}" id="chart_donut_hole_{{n}}">
<label class="control-label" for="chart_field_donut_hole_{{ n }}">{{ _('Donut hole') }}</label>
<div class="controls ">
<input id="chart_field_donut_hole_{{ n }}" type="text" name="chart_field_donut_hole_{{ n }}" value="{{ h.convert_bar_width(donut_hole, True)|default (4.0) }}" placeholder="{{ _('Donut hole, default 4.0') }}" {{'' if donut_option else 'disabled'}}>
<input id="chart_field_donut_hole_{{ n }}" type="text" name="chart_field_donut_hole_{{ n }}" value="{{ h.convert_bar_width(donut_hole, True, 'donut')|default (4.0) }}" placeholder="{{ _('Donut hole, default 4.0') }}">
{{ form.info(_('An integer or decimal between 0.1-10.')) }}
</div>
</div>
Expand All @@ -612,7 +612,7 @@
<div class="control-group {{ hide_bar_width }}" id="chart_bar_width_{{n}}">
<label class="control-label" for="chart_field_bar_width_{{ n }}">{{ _('Bar width') }}</label>
<div class="controls ">
<input id="chart_field_bar_width_{{ n }}" type="text" name="chart_field_bar_width_{{ n }}" value="{{ h.convert_bar_width(bar_width, True)|default (5.0)}}" placeholder="{{ _('Width of bar, default 5.0') }}" {{'' if bar_width_option else 'disabled'}}>
<input id="chart_field_bar_width_{{ n }}" type="text" name="chart_field_bar_width_{{ n }}" value="{{ h.convert_bar_width(bar_width, True)|default (5.0)}}" placeholder="{{ _('Width of bar, default 5.0') }}">
{{ form.info(_('An integer or decimal between 0.1-10.')) }}
</div>
</div>
Expand Down

0 comments on commit 74b40a5

Please sign in to comment.