Skip to content

Commit bd4df83

Browse files
1 parent 0de23fa commit bd4df83

File tree

5 files changed

+70
-7
lines changed

5 files changed

+70
-7
lines changed

classes/Visualizer/Module.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,24 @@ private function handle_css_property( $property, $value ) {
519519
return $property . ': ' . $value;
520520
}
521521

522+
/**
523+
* Determines if charts have been created of the particular chart type.
524+
*/
525+
protected static function hasChartType( $type ) {
526+
$args = array(
527+
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
528+
'fields' => 'ids',
529+
'post_status' => 'publish',
530+
'meta_query' => array(
531+
array(
532+
'key' => Visualizer_Plugin::CF_CHART_TYPE,
533+
'value' => $type,
534+
),
535+
),
536+
);
537+
538+
$q = new WP_Query( $args );
539+
return $q->found_posts > 0;
540+
}
541+
522542
}

classes/Visualizer/Module/Admin.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
5353
parent::__construct( $plugin );
5454
$this->_addAction( 'load-post.php', 'enqueueMediaScripts' );
5555
$this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' );
56-
$this->_addAction( 'admin_footer', 'renderTempaltes' );
56+
$this->_addAction( 'admin_footer', 'renderTemplates' );
5757
$this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 8 );
5858
$this->_addAction( 'admin_menu', 'registerAdminMenu' );
5959
$this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
@@ -278,7 +278,7 @@ public function setupMediaViewStrings( $strings ) {
278278
* @access private
279279
* @return array The associated array of chart types with localized names.
280280
*/
281-
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false ) {
281+
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false, $where = null ) {
282282
$additional = array();
283283
if ( $add_select ) {
284284
$additional['select'] = array(
@@ -372,6 +372,45 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
372372
$types = $doubleD;
373373
}
374374

375+
return self::handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where );
376+
}
377+
378+
/**
379+
* Handle (soon-to-be) deprecated charts.
380+
*/
381+
private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darray, $where ) {
382+
$deprecated = array();
383+
384+
switch ( $where ) {
385+
case 'library':
386+
// if the user has a Google Table chart, show it as deprecated otherwise remove the option from the library.
387+
if ( ! self::hasChartType( 'table' ) ) {
388+
$deprecated[] = 'table';
389+
if ( $get2Darray ) {
390+
$types['dataTable'] = esc_html__( 'Table', 'visualizer' );
391+
} else {
392+
$types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' );
393+
}
394+
}
395+
break;
396+
default:
397+
// remove the option to create a Google Table chart.
398+
if ( self::hasChartType( 'table' ) ) {
399+
$deprecated[] = 'table';
400+
if ( $get2Darray ) {
401+
$types['dataTable'] = esc_html__( 'Table', 'visualizer' );
402+
} else {
403+
$types['dataTable']['name'] = esc_html__( 'Table', 'visualizer' );
404+
}
405+
}
406+
}
407+
408+
if ( $deprecated ) {
409+
foreach ( $deprecated as $type ) {
410+
unset( $types[ $type ] );
411+
}
412+
}
413+
375414
return $types;
376415
}
377416

@@ -383,7 +422,7 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
383422
*
384423
* @access public
385424
*/
386-
public function renderTempaltes() {
425+
public function renderTemplates() {
387426
global $pagenow;
388427
if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
389428
return;
@@ -628,7 +667,7 @@ public function renderLibraryPage() {
628667
$render = new Visualizer_Render_Library();
629668
$render->charts = $charts;
630669
$render->type = $filter;
631-
$render->types = self::_getChartTypesLocalized();
670+
$render->types = self::_getChartTypesLocalized( false, false, false, true );
632671
$render->custom_css = $css;
633672
$render->pagination = paginate_links(
634673
array(

css/frame.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ div.viz-group-content .viz-group-description {
484484
background-position: -600px -225px;
485485
}
486486

487-
.type-box-htmltable .type-label {
487+
.type-box-dataTable .type-label {
488488
background-position: -301px -670px;
489489
}
490490

js/render-datatables.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@
7373
};
7474
$.extend( settings, { select } ); // jshint ignore:line
7575

76+
var stripe = ['', ''];
77+
7678
// in preview mode, cssClassNames will not exist when a color is changed.
7779
if(typeof chart.settings['cssClassNames'] !== 'undefined'){
7880
if(typeof chart.settings['cssClassNames']['oddTableRow'] !== 'undefined'){
79-
$.extend($.fn.dataTable.ext.classes, { sStripeOdd: chart.settings['cssClassNames']['oddTableRow'] } );
81+
stripe[0] = chart.settings['cssClassNames']['oddTableRow'];
8082
}
8183

8284
if(typeof chart.settings['cssClassNames']['evenTableRow'] !== 'undefined'){
83-
$.extend($.fn.dataTable.ext.classes, { sStripeEven: chart.settings['cssClassNames']['evenTableRow'] } );
85+
stripe[1] = chart.settings['cssClassNames']['evenTableRow'];
8486
}
8587

8688
if(typeof chart.settings['cssClassNames']['selectedTableItem'] !== 'undefined'){
@@ -123,7 +125,9 @@
123125
table.DataTable( {
124126
data: rows,
125127
columns: cols,
128+
stripeClasses: stripe,
126129
} );
130+
127131
}
128132

129133
function render(v) {
File renamed without changes.

0 commit comments

Comments
 (0)