Skip to content

Commit

Permalink
Changes for table view
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Lekich committed Dec 6, 2019
1 parent 69ecb85 commit e72f319
Show file tree
Hide file tree
Showing 4 changed files with 9,041 additions and 15 deletions.
9,013 changes: 9,012 additions & 1 deletion ckanext/knowledgehub/fanstatic/css/main.css

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions ckanext/knowledgehub/fanstatic/javascript/modules/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ ckan.module('table', function () {
var category_name = (this.options.category_name === true) ? '' : this.options.category_name;
var title = (this.options.table_title === true) ? '' : this.options.table_title;
var subtitle = (this.options.table_subtitle === true) ? '' : this.options.table_subtitle;
subtitle.length > 30 ? subtitle = subtitle.substring(0,30) + "..." : null;
subtitle.length > 30 ? subtitle = subtitle.substring(0, 30) + "..." : null;
var description = (this.options.table_description === true) ? '' : this.options.table_description;
description.length > 50 ? description = description.substring(0,50) + "..." : null;
description.length > 50 ? description = description.substring(0, 50) + "..." : null;
var filename_export = (title === '') ? this.options.resource_name : title;



filename_export = filename_export.split('.').slice(0, 1).join('.');

this.el.text('');
Expand All @@ -225,7 +227,7 @@ ckan.module('table', function () {
} else {
html = module.render_data_table(rows, main_value, y_axis);
}
// var table = module.el.next('#table-item-' + module.options.resource_id);
// var table = module.el.next('#table-item-' + module.options.resource_id);
var table = $('#table-item-' + module.options.resource_id);
// Enable jquery.datatable
if ($.fn.DataTable.isDataTable(table)) table.DataTable().destroy();
Expand All @@ -245,7 +247,8 @@ ckan.module('table', function () {
'className': 'btn btn-default',
'title': filename_export
},
{ 'extend': 'pdf',
{
'extend': 'pdf',
'className': 'btn btn-default',
'title': filename_export
},
Expand All @@ -254,7 +257,7 @@ ckan.module('table', function () {
});

// Set title value
$("div.dt-header").html(`<div></div><div>${title} <p>${subtitle}</p> <p>${description}</p><div>`);
$("div.dt-header").html(`<div>${title} <p>${subtitle}</p> <p>${description}</p><div>`);
} else {
this.el.text(this._('Table could not be created!'));
}
Expand All @@ -269,21 +272,21 @@ ckan.module('table', function () {
var sqlStringExceptSelect = parsedSqlString[1];
var tableField = this.el.closest('.table_item');

var y_operation_selected = tableField.find('[name*=table_y_axis_operation]');
var y_operation_selected = tableField.find('[name*=table_y_axis_operation]');
var y_operation_value = y_operation_selected.val();

// If category is set
// we need the first column as a pivot column
// see comments inside this.render_data_table_with_category
if (category_name) {
if(y_operation_value == "MAX") {
if (y_operation_value == "MAX") {
return 'SELECT ' + '"' + category_name + '", "' + main_value + '", MAX("' + y_axis + '") as ' + '"' + y_axis + '"' + sqlStringExceptSelect + ' GROUP BY "' + category_name + '", "' + main_value + '"';
}
else {
return 'SELECT ' + '"' + category_name + '", "' + main_value + '", SUM("' + y_axis + '") as ' + '"' + y_axis + '"' + sqlStringExceptSelect + ' GROUP BY "' + category_name + '", "' + main_value + '"';
}
} else {
if(y_operation_value == "MAX") {
if (y_operation_value == "MAX") {
return 'SELECT ' + '"' + main_value + '", MAX("' + y_axis + '") as ' + '"' + y_axis + '"' + sqlStringExceptSelect + ' GROUP BY "' + main_value + '"';
}
else {
Expand All @@ -296,7 +299,7 @@ ckan.module('table', function () {

// default tables
render_data_table: function (rows, main_value, y_axis) {
main_value = typeof main_value === 'string' ? main_value.toLowerCase(): main_value;
main_value = typeof main_value === 'string' ? main_value.toLowerCase() : main_value;
y_axis = typeof y_axis === 'string' ? y_axis.toLowerCase() : y_axis;

// Prepare data
Expand Down Expand Up @@ -455,7 +458,7 @@ ckan.module('table', function () {
this.createTable(yVal, xVal, true);
},

capitalize: function(s) {
capitalize: function (s) {
if (typeof s !== 'string') return s
return s.charAt(0).toUpperCase() + s.slice(1)
},
Expand Down
7 changes: 7 additions & 0 deletions ckanext/knowledgehub/fanstatic/less/_visualizations.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
height: 100px;
}

#table_field_description {
height: 100px;
}

#downloadImageButton {
text-align: center;
Expand Down Expand Up @@ -86,4 +89,8 @@
padding: 3px;
border-radius: 2px;
padding-bottom: 4px;
}

.dt-header {
font-size: 200px;
}
13 changes: 9 additions & 4 deletions ckanext/knowledgehub/templates/view/table/table_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@
<div class="control-group ">
<label class="control-label" for="table_field_title">{{ _('Title') }}</label>
<div class="controls input-controls">
<input id="table_field_title" name="table_field_title" value="{{ table_title }}"
<input class="inputs" id="table_field_title" name="table_field_title" value="{{ table_title }}"
placeholder="{{ _('Table title') }}" type="text" required>
</div>
</div>

<div class="control-group title">
<label class="control-label" for="table_field_subtitle">{{ _('Subtitle') }}</label>
<div class="controls input-controls">
<input id="table_field_subtitle" type="text" name="table_field_subtitle" value="{{ table.table_subtitle }}" placeholder="{{ _('Table subtitle') }}" maxlength="100" required="required">
<input class="inputs" id="table_field_subtitle" type="text" name="table_field_subtitle"
value="{{ table.table_subtitle }}" placeholder="{{ _('Table subtitle') }}" maxlength="100"
required="required">
</div>
</div>

<div class="control-group title">
<label class="control-label" for="table_field_description">{{ _('Description') }}</label>
<div class="controls input-controls">
<input id="table_field_description" type="text" name="table_field_description" value="{{ table.table_description }}" placeholder="{{ _('Table description') }}" maxlength="100" required="required">
<textarea class="inputs" id="table_field_description" type="text" name="table_field_description"
value="{{ table.table_description }}" placeholder="{{ _('Table description') }}" maxlength="100"
required="required"></textarea>

</div>
</div>

Expand Down Expand Up @@ -111,7 +116,7 @@
</select>
</div>
</div>
{# Y operation #}
{# Y operation #}
<div class="control-group control-select">
<label class="control-label" for="table_y_axis_operation">{{ _('Y Axis Operation') }}</label>
<div class="controls input-controls">
Expand Down

0 comments on commit e72f319

Please sign in to comment.