Skip to content

Commit d68b621

Browse files
authored
Feature/textbox templates (#495)
1 parent 7ac0af8 commit d68b621

File tree

8 files changed

+124
-17
lines changed

8 files changed

+124
-17
lines changed

ckanext/querytool/fanstatic/css/main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/javascript/dist/visualizations_settings.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/javascript/vitals.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,3 +1035,44 @@ $("#field-ckan-homepage-style").closest('.control-group').hide();
10351035
$("#field-ckan-site-intro-text").closest('.control-group').hide();
10361036
$("#field-ckan-site-about").closest('.control-group').hide();
10371037

1038+
1039+
//Render chart title for textbox
1040+
$(document).ready(function(){
1041+
$('.textbox').each(function(){
1042+
var content = $(this).html();
1043+
var measure = $(this).attr("data-measure");
1044+
var queryFilters = $(this).attr("data-filters");
1045+
queryFilters = JSON.parse(queryFilters);
1046+
var optionalFilter = undefined;
1047+
1048+
console.log(queryFilters);
1049+
1050+
//var dynamicTitle = this.options.map_custom_title_field;
1051+
var dynamicTitle = renderChartTitle(content,{
1052+
measure: {name: measure, alias: measure},
1053+
filters: queryFilters,
1054+
optionalFilter: optionalFilter,
1055+
});
1056+
$(this).html(dynamicTitle);
1057+
})
1058+
});
1059+
1060+
1061+
function renderChartTitle (title, options) {
1062+
1063+
// Configure nunjucks
1064+
var env = nunjucks.configure({tags: {variableStart: '{', variableEnd: '}'}});
1065+
1066+
// Prepare data
1067+
var data = {measure: options.measure.alias};
1068+
for (let filter of options.filters) data[filter.slug] = filter.value;
1069+
console.log(options);
1070+
if (options.optionalFilter) data.optional_filter = options.optionalFilter.value.toString();
1071+
1072+
// Render and return
1073+
try {
1074+
return env.renderString(title, data);
1075+
} catch (error) {
1076+
return title;
1077+
}
1078+
}

ckanext/querytool/fanstatic/less/main.less

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,16 @@ body {
224224
margin-top:10px !important;
225225
padding:12px 15px !important;
226226
float:right !important;
227+
}
228+
229+
.textbox_desc {
230+
width: 400px;
231+
}
232+
233+
.textbox_dropdown {
234+
width: 415px;
235+
}
236+
237+
.textbox_info {
238+
width:393px !important;
227239
}

ckanext/querytool/templates/ajax_snippets/chart_item.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,19 @@
629629
</div>
630630
{# {% endif %} #}
631631

632+
{# X sorting #}
633+
{% set sort_options = h.querytool_get_chart_sort() %}
634+
<div id="chart_field_sort_div_{{ n }}" class="control-group control-select {% if chart and chart.category_name %}hidden{% endif %}">
635+
<label class="control-label" for="chart_field_sort_{{ n }}">{{ _('Data sorting') }}</label>
636+
<div class="controls ">
637+
<select id="chart_field_sort_{{ n }}" name="chart_field_sort_{{ n }}" >
638+
{% for sort in sort_options %}
639+
<option value="{{ sort.value }}" {% if chart %}{{ 'selected' if sort.value == chart.sort }}{% endif %} >{{ sort.text }}</option>
640+
{% endfor %}
641+
</select>
642+
</div>
643+
</div>
644+
632645
</div>
633646
</div>
634647
</div>
Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
1-
{% import 'macros/form.html' as form %}
2-
{% if box %}
3-
{% set text_description = box.description %}
4-
{% set column_width = box.column_width %}
5-
{% endif %}
6-
<div id="text_box_{{ n }}" class="item text-boxs-section text_box visualization-fields-section">
7-
<div class="item-wrapper">
1+
{% import 'macros/form.html' as form %}
2+
{% if box %}
3+
{% set text_description = box.description %}
4+
{% set column_width = box.column_width %}
5+
{% endif %}
86

9-
{{ form.markdown('text_box_description_' ~ n, id='text_box_description_' ~ n, label=_('Content'), placeholder=_('Description'), value=text_description) }}
10-
{{ form.select('text_box_column_width_' ~ n, id='text_box_column_width_' ~ n, label=_('Column Width'), options=[{'text':_('Half'), 'value': 'Half'},{'text': _('Full'), 'value': 'Full'}], selected=column_width) }}
7+
<div id="text_box_{{ n }}" class="item text-boxs-section text_box visualization-fields-section">
8+
<div class="item-wrapper">
119

12-
<ul class="inline text-right chart-actions">
13-
<li class="remove"><a class="btn delete-item-btn">{% block delete_button_text %}<span class="fa fa-trash-o" aria-hidden="true"></span> {{ _('Delete') }}{% endblock %}</a></li>
14-
</ul>
15-
<span class="grippy"></span>
10+
<div class="control-group title">
11+
<label class="control-label" for="text_box_description_1">Content</label>
12+
<div class="controls editor">
13+
14+
<textarea id="text_box_description_{{ n }}" class="textbox_desc" name="text_box_description_{{ n }}" cols="20" rows="5" placeholder="Description">{{ text_description }}</textarea>
15+
<div class="control-group title-vars">
16+
<div class=" ">
17+
{% set filters = h.querytool_parse_json(info_query_filters or main_filters or '[]') %}
18+
{% set filters = filters|sort(attribute='order') %}
19+
<select class="textbox_dropdown">
20+
<option value="" disabled selected>{{_('Add variable to title')}}</option>
21+
<optgroup label="{{_('Capitalized')}}">
22+
<option value="{measure|capitalize}">{{_('Measure')}}</option>
23+
{% for filter in filters %}
24+
<option value="{{'{%s|capitalize}' % filter.slug}}">{{ filter.alias }}</option>
25+
{% endfor %}
26+
</optgroup>
27+
<optgroup label="{{_('lowercase')}}" class='text-lowercase'>
28+
<option value="{measure|lower}">{{_('Measure')}}</option>
29+
{% for filter in filters %}
30+
<option value="{{'{%s|lower}' % filter.slug}}">{{ filter.alias }}</option>
31+
{% endfor %}
32+
</optgroup>
33+
</select>
34+
35+
</div>
36+
</div>
37+
<div class="control-group title-help">
38+
<div class=" ">
39+
{% set template_tooltip = "<pre><p>" + _('Variables') + "<br>---<br>{measure}<br>{optional_filter}<br>*" + _('use drop-down list to select variables based on application filters') + "</p><p>" + _('Processed variables') + "<br>---<br>{measure|capitalize}<br>{measure|lower}<br>{measure|upper}<br>" + _('etc') + "</p></pre><p><b><a href='https://mozilla.github.io/nunjucks/templating.html#variables' target='_blank'>" + _('Full templates syntax') + "</a></b></p><p class='muted'><b>" + _('Please note:') + " " + "</b>" + _('Single braces \'{}\' are used for variables') + "</p>" %}
40+
<span class="editor-info-block textbox_info">{{_('You can use')}} <a href="#templates" title="" data-trigger="focus" data-target="popover" data-content="{{ template_tooltip }}" data-html="true" data-original-title="{{_('Templates quick reference')}}" data-container="body">{{_('Templates')}}</a> {{_('here')}}</span>
41+
</div>
42+
</div>
43+
44+
</div>
1645
</div>
46+
47+
48+
49+
{{ form.select('text_box_column_width_' ~ n, id='text_box_column_width_' ~ n, label=_('Column Width'), options=[{'text':_('Half'), 'value': 'Half'},{'text': _('Full'), 'value': 'Full'}], selected=column_width) }}
50+
51+
<ul class="inline text-right chart-actions">
52+
<li class="remove"><a class="btn delete-item-btn">{% block delete_button_text %}<span class="fa fa-trash-o" aria-hidden="true"></span> {{ _('Delete') }}{% endblock %}</a></li>
53+
</ul>
54+
<span class="grippy"></span>
1755
</div>
56+
</div>

ckanext/querytool/templates/querytool/admin/snippets/edit_visualizations_form.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
measure_label, info_query_filters = data.main_filters, bar_width = data.bar_width,
104104
donut_hole = data.donut_hole %} {% endif %} {% if
105105
item.type == 'text_box' %} {% snippet 'ajax_snippets/text_box_item.html', n
106-
= item.order, box = item %} {% endif %} {% if item.type == 'image' %} {%
106+
= item.order, box = item, main_filters =
107+
data.main_filters %} {% endif %} {% if item.type == 'image' %} {%
107108
snippet 'ajax_snippets/image_item.html', n = item.order, data = item %} {%
108109
endif %} {% if item.type == 'map' %} {% snippet
109110
'ajax_snippets/map_item.html', n = item.order, map = item, sql_string =

ckanext/querytool/templates/querytool/public/read.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ <h3 id="item-title-{{chart_id}}">{{ item.map_custom_title_field }}</h3>
279279
%}
280280
{% endif %}
281281
{% if item.type == 'text_box' %}
282-
<div class="item-content" >
282+
<div class="item-content textbox" data-filters="{{ querytool.public_main_filters }}" data-measure="{{ measure_label }}" id="textbox-{{chart_id}}">
283283
{{ h.render_markdown(h.get_translated(item, 'description'), True, True) }}
284284
</div>
285285
{% endif %}

0 commit comments

Comments
 (0)