@@ -137,7 +137,11 @@ public static function _renderJsonScreen( $args ) {
137
137
$ url = get_post_meta ( $ id , Visualizer_Plugin::CF_JSON_URL , true );
138
138
$ root = get_post_meta ( $ id , Visualizer_Plugin::CF_JSON_ROOT , true );
139
139
$ paging = get_post_meta ( $ id , Visualizer_Plugin::CF_JSON_PAGING , true );
140
-
140
+ $ headers = get_post_meta ( $ id , Visualizer_Plugin::CF_JSON_HEADERS , true );
141
+ if ( empty ( $ headers ['method ' ] ) ) {
142
+ $ headers ['method ' ] = 'get ' ;
143
+ }
144
+ $ methods = apply_filters ( 'visualizer_json_request_methods ' , array ( 'GET ' , 'POST ' ) );
141
145
?>
142
146
<div id="visualizer-json-screen" style="display: none">
143
147
<div class="visualizer-json-form">
@@ -146,7 +150,7 @@ public static function _renderJsonScreen( $args ) {
146
150
<form id="json-endpoint-form">
147
151
<div class="json-wizard-hints">
148
152
<ul class="info">
149
- <li><?php echo sprintf ( __ ( 'If you want to add authentication, add headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s. ' , 'visualizer ' ), '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank"> ' , '</a> ' ); ?> </li>
153
+ <li><?php echo sprintf ( __ ( 'If you want to add authentication or headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s. ' , 'visualizer ' ), '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank"> ' , '</a> ' ); ?> </li>
150
154
</ul>
151
155
</div>
152
156
@@ -156,15 +160,67 @@ public static function _renderJsonScreen( $args ) {
156
160
name="url"
157
161
value="<?php echo esc_url ( $ url ); ?> "
158
162
placeholder="<?php esc_html_e ( 'Please enter the URL ' , 'visualizer ' ); ?> "
159
- class="visualizer-input">
163
+ class="visualizer-input json-form-element ">
160
164
<button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e ( 'Fetch Endpoint ' , 'visualizer ' ); ?> </button>
165
+
166
+ <div class="visualizer-json-subform">
167
+ <h3 class="viz-substep"><?php _e ( 'Headers ' , 'visualizer ' ); ?> </h3>
168
+ <div class="json-wizard-headers">
169
+ <div class="json-wizard-header">
170
+ <div><?php _e ( 'Request Type ' , 'visualizer ' ); ?> </div>
171
+ <div>
172
+ <select name="method" class="json-form-element">
173
+ <?php foreach ( $ methods as $ method ) { ?>
174
+ <option value="<?php echo $ method ; ?> " <?php selected ( $ headers ['method ' ], $ method ); ?> ><?php echo $ method ; ?> </option>
175
+ <?php } ?>
176
+ </select>
177
+ </div>
178
+ </div>
179
+ <div class="json-wizard-header">
180
+ <div><?php _e ( 'Credentials ' , 'visualizer ' ); ?> </div>
181
+ <div>
182
+ <input
183
+ type="text"
184
+ id="vz-import-json-username"
185
+ name="username"
186
+ value="<?php echo ( array_key_exists ( 'auth ' , $ headers ) && array_key_exists ( 'username ' , $ headers ['auth ' ] ) ? $ headers ['auth ' ]['username ' ] : '' ); ?> "
187
+ placeholder="<?php esc_html_e ( 'Username/Access Key ' , 'visualizer ' ); ?> "
188
+ class="json-form-element">
189
+ &
190
+ <input
191
+ type="password"
192
+ id="vz-import-json-password"
193
+ name="password"
194
+ value="<?php echo ( array_key_exists ( 'auth ' , $ headers ) && array_key_exists ( 'password ' , $ headers ['auth ' ] ) ? $ headers ['auth ' ]['password ' ] : '' ); ?> "
195
+ placeholder="<?php esc_html_e ( 'Password/Secret Key ' , 'visualizer ' ); ?> "
196
+ class="json-form-element">
197
+ </div>
198
+ </div>
199
+ <div class="json-wizard-header">
200
+ <div></div>
201
+ <div><?php esc_html_e ( 'OR ' , 'visualizer ' ); ?> </div>
202
+ </div>
203
+ <div class="json-wizard-header">
204
+ <div><?php esc_html_e ( 'Authorization ' , 'visualizer ' ); ?> </div>
205
+ <div>
206
+ <input
207
+ type="text"
208
+ id="vz-import-json-auth"
209
+ name="auth"
210
+ value="<?php echo ( ! empty ( $ headers ) && array_key_exists ( 'auth ' , $ headers ) ? $ headers ['auth ' ]['auth ' ] : '' ); ?> "
211
+ placeholder="<?php esc_html_e ( 'e.g. SharedKey <AccountName>:<Signature> ' , 'visualizer ' ); ?> "
212
+ class="visualizer-input json-form-element">
213
+ </div>
214
+ </div>
215
+ </div>
216
+ </div>
161
217
</form>
162
218
</div>
163
219
<h3 class="viz-step step2 <?php echo empty ( $ url ) ? 'ui-state-disabled ' : '' ; ?> json-root-form"><?php _e ( 'STEP 2: Choose the JSON root ' , 'visualizer ' ); ?> </h3>
164
220
<div>
165
221
<form id="json-root-form">
166
222
<input type="hidden" name="chart" value="<?php echo $ id ; ?> ">
167
- <select name="root" id="vz-import-json-root">
223
+ <select name="root" id="vz-import-json-root" class="json-form-element" >
168
224
<?php
169
225
if ( ! empty ( $ root ) ) {
170
226
?>
@@ -173,7 +229,6 @@ class="visualizer-input">
173
229
}
174
230
?>
175
231
</select>
176
- <input type="hidden" name="url" value="<?php echo $ url ; ?> ">
177
232
<button class="button button-secondary button-small" id="visualizer-json-parse"><?php esc_html_e ( 'Parse Endpoint ' , 'visualizer ' ); ?> </button>
178
233
</form>
179
234
</div>
@@ -182,12 +237,12 @@ class="visualizer-input">
182
237
<form id="json-conclude-form-helper">
183
238
<div class="<?php echo apply_filters ( 'visualizer_pro_upsell_class ' , 'only-pro-feature ' ); ?> ">
184
239
<div class="json-pagination">
185
- <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf ( 'Get first %d pages using %s ' , apply_filters ( 'visualizer_json_fetch_pages ' , 5 , $ url ), '? ' ); ?> '>
186
- <option value="0" class="static"><?php _e ( 'Don \' t use pagination ' , 'visualizer ' ); ?> </option>
240
+ <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf ( 'Get results from the first %d pages using %s ' , apply_filters ( 'visualizer_json_fetch_pages ' , 5 , $ url ), '? ' ); ?> '>
241
+ <option value="0" class="static"><?php _e ( 'Get results from the first page only ' , 'visualizer ' ); ?> </option>
187
242
<?php
188
243
if ( ! empty ( $ paging ) ) {
189
244
?>
190
- <option value="<?php echo esc_attr ( $ paging ); ?> "><?php echo sprintf ( 'Get first %d pages using %s ' , apply_filters ( 'visualizer_json_fetch_pages ' , 5 , $ url ), str_replace ( Visualizer_Source_Json::TAG_SEPARATOR , Visualizer_Source_Json::TAG_SEPARATOR_VIEW , $ paging ) ); ?> </option>
245
+ <option value="<?php echo esc_attr ( $ paging ); ?> "><?php echo sprintf ( 'Get results from the first %d pages using %s ' , apply_filters ( 'visualizer_json_fetch_pages ' , 5 , $ url ), str_replace ( Visualizer_Source_Json::TAG_SEPARATOR , Visualizer_Source_Json::TAG_SEPARATOR_VIEW , $ paging ) ); ?> </option>
191
246
<?php
192
247
}
193
248
?>
@@ -210,10 +265,6 @@ class="visualizer-input">
210
265
<h3 class="viz-step step4 ui-state-disabled"><?php _e ( 'STEP 4: Select the data to display in the chart ' , 'visualizer ' ); ?> </h3>
211
266
<div>
212
267
<form id="json-conclude-form" action="<?php echo $ action ; ?> " method="post" target="thehole">
213
- <input type="hidden" name="url">
214
- <input type="hidden" name="root">
215
- <input type="hidden" name="chart" value="<?php echo $ id ; ?> ">
216
-
217
268
<div class="json-wizard-hints html-table-editor-hints">
218
269
<ul class="info">
219
270
<li><?php _e ( 'Select whether to include the data in the chart. Each column selected will form one series. ' , 'visualizer ' ); ?> </li>
@@ -357,7 +408,7 @@ public static function _renderEditorTable( $args ) {
357
408
echo '<select name="type[]"> ' ;
358
409
} else {
359
410
echo '<input name="header[]" type="hidden" value=" ' . $ header . '"> ' ;
360
- echo '<select name="type[ ' . $ header . ']"> ' ;
411
+ echo '<select name="type[ ' . $ header . ']" class="viz-select-data-type" > ' ;
361
412
}
362
413
echo '<option value="" title=" ' . __ ( 'Exclude from chart ' , 'visualizer ' ) . '"> ' . __ ( 'Exclude ' , 'visualizer ' ) . '</option> ' ;
363
414
echo '<option value="0" disabled title=" ' . __ ( 'Include in chart and select data type ' , 'visualizer ' ) . '">-- ' . __ ( 'OR ' , 'visualizer ' ) . '--</option> ' ;
@@ -376,10 +427,15 @@ public static function _renderEditorTable( $args ) {
376
427
if ( array_key_exists ( 'data ' , $ data ) ) {
377
428
$ data = $ data ['data ' ];
378
429
}
430
+
379
431
foreach ( $ data as $ row ) {
380
432
echo '<tr> ' ;
381
433
echo '<th> ' . __ ( 'Value ' , 'visualizer ' ) . '</th> ' ;
382
434
$ index = 0 ;
435
+ if ( empty ( $ row ) ) {
436
+ echo '<td></td> ' ;
437
+ continue ;
438
+ }
383
439
foreach ( array_values ( $ row ) as $ value ) {
384
440
if ( $ editable_data ) {
385
441
echo '<td><input type="text" name="data ' . $ index ++ . '[]" value=" ' . esc_attr ( $ value ) . '"></td> ' ;
0 commit comments