Skip to content

Commit f0e7944

Browse files
Merge pull request #563 from contactashish13/issue-481
use Show Chart button to trigger submit
2 parents 18136bb + 4bbe8b2 commit f0e7944

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,29 @@ public function setJsonData() {
213213
add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] );
214214
}
215215

216+
$time = filter_input(
217+
INPUT_POST,
218+
'time',
219+
FILTER_VALIDATE_INT,
220+
array(
221+
'options' => array(
222+
'min_range' => -1,
223+
),
224+
)
225+
);
226+
227+
delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE );
228+
229+
if ( -1 < $time ) {
230+
add_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, $time );
231+
}
232+
233+
// delete other source specific parameters.
234+
delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY );
235+
delete_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE );
236+
delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_URL );
237+
delete_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE );
238+
216239
$render = new Visualizer_Render_Page_Update();
217240
$render->id = $chart->ID;
218241
$render->data = json_encode( $source->getRawData() );

classes/Visualizer/Render/Layout.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,16 @@ class="visualizer-input json-form-element">
270270
<form id="json-conclude-form" action="<?php echo $action; ?>" method="post" target="thehole">
271271
<div class="json-wizard-hints html-table-editor-hints">
272272
<ul class="info">
273+
<li><?php _e( 'If you see Invalid Data in the table, you may have selected the wrong root to fetch data from. Please select an alternative from the JSON root dropdown.', 'visualizer' ); ?></li>
273274
<li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
274275
<li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
275276
<li><?php _e( 'You can use drag/drop to reorder the columns but this column position is not saved. So when you reload the table, you may have to reorder again.', 'visualizer' ); ?></li>
276277
<li><?php _e( 'You can select any number of columns but the chart type selected will determine how many will display in the chart.', 'visualizer' ); ?></li>
278+
<li><?php _e( 'Once you have made your selection, click \'Show Chart\' on the right to view the chart.', 'visualizer' ); ?></li>
277279
</ul>
278280
</div>
279281
<div class="json-table"></div>
280-
<button class="button button-primary" id="visualizer-json-conclude"><?php esc_html_e( 'Save &amp; Show Chart', 'visualizer' ); ?></button>
282+
<button class="button button-primary" style="display: none" id="visualizer-json-conclude"></button>
281283
</form>
282284
</div>
283285
</div>
@@ -443,7 +445,7 @@ public static function _renderEditorTable( $args ) {
443445
if ( $editable_data ) {
444446
echo '<td><input type="text" name="data' . $index++ . '[]" value="' . esc_attr( $value ) . '"></td>';
445447
} else {
446-
echo '<td>' . $value . '</td>';
448+
echo '<td>' . ( is_array( $value ) ? __( 'Invalid Data', 'visualizer' ) : $value ) . '</td>';
447449
}
448450
}
449451

classes/Visualizer/Render/Page/Data.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected function _renderSidebarContent() {
175175
if ( Visualizer_Module::is_pro() ) {
176176
?>
177177
<p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
178-
<select name="vz-json-time" id="vz-json-time" class="visualizer-select" data-chart="<?php echo $this->chart->ID; ?>">
178+
<select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $this->chart->ID; ?>">
179179
<?php
180180
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
181181
$schedules = apply_filters(
@@ -200,7 +200,6 @@ protected function _renderSidebarContent() {
200200
?>
201201
</div>
202202

203-
<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>
204203
<input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
205204
value="<?php echo $bttn_label; ?>" data-current="chart"
206205
data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"

css/frame.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,11 +1387,14 @@ span.viz-section-error {
13871387
min-width: 10px !important;
13881388
}
13891389

1390-
#json-conclude-form .json-table,
1390+
#json-conclude-form .json-table {
1391+
width: 85%;
1392+
}
1393+
13911394
#vz-import-json-url,
13921395
#vz-import-json-root,
13931396
#vz-import-json-paging {
1394-
width: 85%;
1397+
width: 75%;
13951398
}
13961399

13971400
#json-conclude-form .json-table,

js/frame.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,25 +390,29 @@
390390

391391
// toggle between chart and create/modify parameters
392392
$( '#json-chart-button' ).on( 'click', function(){
393-
$('#content').css('width', 'calc(100% - 300px)');
393+
var $bttn = $(this);
394+
$('#content').css('width', 'calc(100% - 100px)');
394395
if( $(this).attr( 'data-current' ) === 'chart'){
396+
// toggle from chart to LHS form
395397
$(this).val( $(this).attr( 'data-t-filter' ) );
396398
$(this).html( $(this).attr( 'data-t-filter' ) );
397399
$(this).attr( 'data-current', 'filter' );
398400
$( '.visualizer-editor-lhs' ).hide();
399401
$( '#visualizer-json-screen' ).css("z-index", "9999").show();
400-
$('.json-chart-msg').show();
401402
$( '#canvas' ).hide();
402403
}else{
403-
var filter_button = $(this);
404-
$( '#visualizer-json-screen' ).css("z-index", "-1").hide();
405-
$('#canvas').lock();
406-
filter_button.val( filter_button.attr( 'data-t-chart' ) );
407-
filter_button.html( filter_button.attr( 'data-t-chart' ) );
408-
filter_button.attr( 'data-current', 'chart' );
409-
$('.json-chart-msg').hide();
410-
$( '#canvas' ).css("z-index", "1").show();
411-
$('#canvas').unlock();
404+
// toggle from LHS form to chart
405+
$( '#json-conclude-form' ).trigger('submit');
406+
$('body').on('visualizer:json:form:submit', function() {
407+
var filter_button = $bttn;
408+
$( '#visualizer-json-screen' ).css("z-index", "-1").hide();
409+
$('#canvas').lock();
410+
filter_button.val( filter_button.attr( 'data-t-chart' ) );
411+
filter_button.html( filter_button.attr( 'data-t-chart' ) );
412+
filter_button.attr( 'data-current', 'chart' );
413+
end_ajax( $( '#visualizer-json-screen' ) );
414+
$( '#canvas' ).css("z-index", "1").show();
415+
});
412416
}
413417
} );
414418

@@ -501,12 +505,13 @@
501505
alert(visualizer.l10n.select_columns);
502506
return false;
503507
}
508+
504509
// populate the form elements that are in the other tabs.
505-
$('#json-conclude-form-helper .json-form-element, #json-endpoint-form .json-form-element, #json-root-form .json-form-element').each(function(x, y){
510+
$('#json-conclude-form-helper .json-form-element, #json-endpoint-form .json-form-element, #json-root-form .json-form-element, #vz-import-json .json-form-element').each(function(x, y){
506511
$('#json-conclude-form').append('<input type="hidden" name="' + y.name + '" value="' + y.value + '">');
507512
});
508-
$( '#json-chart-button' ).trigger('click');
509-
$('#canvas').lock();
513+
514+
$('body').trigger('visualizer:json:form:submit');
510515
});
511516

512517
// update the schedule

0 commit comments

Comments
 (0)