Skip to content

Commit a61b462

Browse files
handle case where all columns are excluded
1 parent b985ed0 commit a61b462

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ private function _handleDataAndSettingsPage() {
690690
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
691691
'loading' => esc_html__( 'Loading...', 'visualizer' ),
692692
'json_error' => esc_html__( 'An error occured in fetching data.', 'visualizer' ),
693+
'select_columns' => esc_html__( 'Please select a few columns to include in the chart.', 'visualizer' ),
693694
),
694695
'charts' => array(
695696
'canvas' => $data,

classes/Visualizer/Render/Layout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public static function _renderEditorTable( $args ) {
408408
echo '<select name="type[]">';
409409
} else {
410410
echo '<input name="header[]" type="hidden" value="' . $header . '">';
411-
echo '<select name="type[' . $header . ']">';
411+
echo '<select name="type[' . $header . ']" class="viz-select-data-type">';
412412
}
413413
echo '<option value="" title="' . __( 'Exclude from chart', 'visualizer' ) . '">' . __( 'Exclude', 'visualizer' ) . '</option>';
414414
echo '<option value="0" disabled title="' . __( 'Include in chart and select data type', 'visualizer' ) . '">--' . __( 'OR', 'visualizer' ) . '--</option>';

classes/Visualizer/Render/Page/Data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class="visualizer-select">
222222
?>
223223
</div>
224224

225-
<p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Save & Show Chart\' on the left before you click \'Show Chart\' below.', 'visualizer' ) ); ?></p>
225+
<p class="viz-group-description viz-info-msg json-chart-msg" style="display: none"><?php echo sprintf( __( 'Please make sure you click \'Save & Show Chart\' on the left before you click \'Show Chart\' below.', 'visualizer' ) ); ?></p>
226226
<input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
227227
value="<?php echo $bttn_label; ?>" data-current="chart"
228228
data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"

js/frame.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
$(this).attr( 'data-current', 'filter' );
386386
$( '.visualizer-editor-lhs' ).hide();
387387
$( '#visualizer-json-screen' ).css("z-index", "9999").show();
388+
$('.json-chart-msg').show();
388389
$( '#canvas' ).hide();
389390
}else{
390391
var filter_button = $(this);
@@ -393,6 +394,7 @@
393394
filter_button.val( filter_button.attr( 'data-t-chart' ) );
394395
filter_button.html( filter_button.attr( 'data-t-chart' ) );
395396
filter_button.attr( 'data-current', 'chart' );
397+
$('.json-chart-msg').hide();
396398
$( '#canvas' ).css("z-index", "1").show();
397399
$('#canvas').unlock();
398400
}
@@ -476,6 +478,17 @@
476478

477479
// when the data is set and the chart is updated, toggle the screen so that the chart is shown
478480
$('#json-conclude-form').on( 'submit', function(e){
481+
// at least one column has to be selected as non-excluded.
482+
var count_selected = 0;
483+
$('select.viz-select-data-type').each(function(i, element){
484+
if($(element).prop('selectedIndex') > 0){
485+
count_selected++;
486+
}
487+
});
488+
if(count_selected === 0){
489+
alert(visualizer.l10n.select_columns);
490+
return false;
491+
}
479492
// populate the form elements that are in the other tabs.
480493
$('#json-conclude-form-helper .json-form-element, #json-endpoint-form .json-form-element, #json-root-form .json-form-element').each(function(x, y){
481494
$('#json-conclude-form').append('<input type="hidden" name="' + y.name + '" value="' + y.value + '">');

0 commit comments

Comments
 (0)