Skip to content

Commit 438b8f6

Browse files
authored
CRM: Update Chart.js dependency to 4.5.0 (#43990)
* Clean up enqueues * Bump chart.js to v4.5.0 and more enqueue cleanup * Move funnel JS to JS file * Move chart JS to JS file * Add changelog * Ensure chart buttons indicate which is selected * Slight style cleanup
1 parent 237e060 commit 438b8f6

File tree

11 files changed

+237
-239
lines changed

11 files changed

+237
-239
lines changed

pnpm-lock.yaml

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/plugins/crm/admin/dashboard/main.page.php

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -406,57 +406,15 @@ function jpcrm_render_dashboard_page() {
406406
$tracking->track_specific_pageview( 'first-use-dashboard' );
407407
}
408408
}
409-
?>
410409

411-
<script>
412-
413-
// set default color for charts
414-
Chart.defaults.defaultColor = zbs_root['jp_green']['40'];
415-
// build sales funnel
416-
let funnel_element = document.getElementById('jpcrm_sales_funnel');
417-
let funnel_data = <?php echo wp_json_encode( $funnel_data ); ?>;
418-
jpcrm_build_funnel(funnel_data,funnel_element);
419-
420-
421-
// draw revenue chart
422-
if (document.getElementById('bar-chart')) {
423-
424-
new Chart(
425-
document.getElementById("bar-chart"),
426-
{
427-
type: 'bar',
428-
data: {
429-
labels: <?php echo wp_json_encode( $labels ); ?>,
430-
datasets: [
431-
{
432-
label: '',
433-
backgroundColor: Chart.defaults.defaultColor,
434-
data: <?php echo wp_json_encode( $chartdata ); ?>
435-
}
436-
]
437-
},
438-
options: {
439-
responsive: true,
440-
maintainAspectRatio: false,
441-
plugins: {
442-
legend: { display: false },
443-
title: {
444-
display: false,
445-
text: '',
446-
},
447-
},
448-
scales: {
449-
y: {
450-
display: true,
451-
beginAtZero: true // minimum value will be 0.
452-
}
453-
}
454-
}
455-
}
456-
);
457-
}
458-
</script>
459-
<?php
410+
$jpcrm_dash_data = 'const jpcrm_funnel_data = ' . wp_json_encode( $funnel_data ) . ';';
411+
$jpcrm_dash_data .= 'const jpcrm_revenue_chart_data = ' . wp_json_encode(
412+
array(
413+
'labels' => $labels,
414+
'data' => $chartdata,
415+
)
416+
);
417+
wp_add_inline_script( 'jpcrm-dash', $jpcrm_dash_data, 'before' );
460418
}
461419

462420
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Update package dependencies.

projects/plugins/crm/includes/ZeroBSCRM.Core.Menus.WP.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function zeroBSCRM_menu_buildMenu() {
104104
'wpposition' => $menu_position,
105105
'subitems' => array(),
106106
'callback' => 'zeroBSCRM_pages_dash',
107-
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_chartjs', 'zeroBSCRM_admin_styles_homedash' ),
107+
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_homedash' ),
108108
);
109109

110110
/**
@@ -118,7 +118,7 @@ function zeroBSCRM_menu_buildMenu() {
118118
'order' => 1,
119119
'wpposition' => 1,
120120
'callback' => 'zeroBSCRM_pages_dash',
121-
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_chartjs', 'zeroBSCRM_admin_styles_homedash' ),
121+
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_homedash' ),
122122
);
123123

124124
if ( apply_filters( 'jetpack_crm_automations_load_ui', false ) ) {
@@ -341,7 +341,7 @@ function zeroBSCRM_menu_buildMenu() {
341341
'wpposition' => 2,
342342
'subitems' => array(),
343343
'callback' => 'zeroBSCRM_pages_dash',
344-
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_chartjs', 'zeroBSCRM_admin_styles_homedash' ),
344+
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_homedash' ),
345345
);
346346

347347
/**
@@ -355,7 +355,7 @@ function zeroBSCRM_menu_buildMenu() {
355355
'order' => 1,
356356
'wpposition' => 1,
357357
'callback' => 'zeroBSCRM_pages_dash',
358-
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_chartjs', 'zeroBSCRM_admin_styles_homedash' ),
358+
'stylefuncs' => array( 'zeroBSCRM_global_admin_styles', 'zeroBSCRM_admin_styles_homedash' ),
359359
);
360360

361361
if ( apply_filters( 'jetpack_crm_automations_load_ui', false ) ) {

projects/plugins/crm/includes/ZeroBSCRM.DashboardBoxes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function zeroBS_dashboard_crm_list_growth(){
4848
</div>
4949
</div>
5050
<div class="day-or-month">
51-
<div class="button" data-range="daily"><?php esc_html_e( 'Day', 'zero-bs-crm' ); ?></div>
52-
<div class="button" data-range="weekly"><?php esc_html_e( 'Week', 'zero-bs-crm' ); ?></div>
53-
<div class="button selected" data-range="monthly"><?php esc_html_e( 'Month', 'zero-bs-crm' ); ?></div>
54-
<div class="button" data-range="yearly"><?php esc_html_e( 'Year', 'zero-bs-crm' ); ?></div>
51+
<div class="ui button small white" data-range="daily"><?php esc_html_e( 'Day', 'zero-bs-crm' ); ?></div>
52+
<div class="ui button small white" data-range="weekly"><?php esc_html_e( 'Week', 'zero-bs-crm' ); ?></div>
53+
<div class="ui button small black" data-range="monthly"><?php esc_html_e( 'Month', 'zero-bs-crm' ); ?></div>
54+
<div class="ui button small white" data-range="yearly"><?php esc_html_e( 'Year', 'zero-bs-crm' ); ?></div>
5555
</div>
5656
<?php
5757
}

projects/plugins/crm/includes/ZeroBSCRM.ScriptsStyles.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function zeroBSCRM_scriptStyles_initStyleRegister(){
102102
wp_register_style( 'jpcrm-fontawesome', plugins_url( '/build/lib/font-awesome/css/font-awesome.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
103103

104104
// chart.js
105-
wp_register_script( 'zerobscrmchartjs', plugins_url( '/build/lib/chart.js/chart.min.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs::VERSION );
105+
wp_register_script( 'jpcrm-chartjs', plugins_url( '/build/lib/chart.js/chart.umd.min.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs::VERSION, true );
106106

107107
// SweetAlert2
108108
wp_register_style( 'zerobscrmswa', plugins_url( '/build/lib/sweetalert2/sweetalert2.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
@@ -480,9 +480,6 @@ function zeroBSCRM_admin_styles_ui2_semantic_settingspage(){
480480
wp_enqueue_style( 'zerobscrmsettings' );
481481
}
482482

483-
function zeroBSCRM_admin_styles_chartjs(){
484-
wp_enqueue_script( 'zerobscrmchartjs' );
485-
}
486483
function zeroBSCRM_admin_styles_singleview(){
487484

488485
// single item view
@@ -499,14 +496,13 @@ function jpcrm_admin_scripts_systems_page(){
499496

500497
function zeroBSCRM_admin_styles_homedash(){
501498
global $zbs;
502-
//home dashboard styles and script
499+
// home dashboard styles and script
503500
wp_enqueue_style( 'zerobscrmhomedash' );
501+
wp_enqueue_style( 'jpcrm-funnel', ZEROBSCRM_URL . 'css/jpcrm-admin-funnel' . wp_scripts_get_suffix() . '.css', array(), $zbs::VERSION );
502+
wp_enqueue_script( 'jpcrm-funnel', ZEROBSCRM_URL . 'js/jpcrm-admin-funnel' . wp_scripts_get_suffix() . '.js', array(), $zbs::VERSION, true );
503+
wp_enqueue_script( 'jpcrm-chartjs' );
504504
zeroBSCRM_enqueue_libs_js_momentdatepicker();
505-
wp_register_script( 'zerobscrmjs-dash', ZEROBSCRM_URL . 'js/ZeroBSCRM.admin.dash' . wp_scripts_get_suffix() . '.js', array( 'jquery' ), $zbs::VERSION );
506-
wp_enqueue_script( 'zerobscrmjs-dash' );
507-
508-
wp_enqueue_script( 'jpcrm-funnel-js', ZEROBSCRM_URL . 'js/jpcrm-admin-funnel' . wp_scripts_get_suffix() . '.js', array(), $zbs::VERSION, false );
509-
wp_enqueue_style( 'jpcrm-funnel-css', ZEROBSCRM_URL . 'css/jpcrm-admin-funnel' . wp_scripts_get_suffix() . '.css', array(), $zbs::VERSION );
505+
wp_enqueue_script( 'jpcrm-dash', ZEROBSCRM_URL . 'js/ZeroBSCRM.admin.dash' . wp_scripts_get_suffix() . '.js', array( 'jquery' ), $zbs::VERSION, true );
510506
}
511507

512508
function zeroBSCRM_admin_scripts_editcust(){

0 commit comments

Comments
 (0)