Skip to content

Commit

Permalink
Define Chart.js constants in MantisGraph plugin
Browse files Browse the repository at this point in the history
The library is only used by the MantisGraph plugin, so it makes more
sense to define the related constants within the plugin's class, instead
of doing it in constants_inc.php.

Fixes #25952
  • Loading branch information
dregad committed Aug 8, 2019
1 parent a02680d commit 5d9a4f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 0 additions & 5 deletions core/constant_inc.php
Expand Up @@ -656,11 +656,6 @@
define( 'DATETIME_PICKER_VERSION', '4.17.47' );
define( 'DATETIME_PICKER_HASH', 'sha256-5YmaxAwMjIpMrVlK84Y/+NjCpKnFYa8bWWBbUHSBGfU=' );

# Chart JS
define( 'CHARTJS_VERSION', '2.7.3' );
define( 'CHARTJS_HASH', 'sha384-WJu6cbQvbPRsw+66L1nOomDAZzhTALnUlpchFlWHimhJ9o95CMue7xEZXXDRKV2S' );
define( 'CHARTJSBUNDLE_HASH', 'sha384-e4YKd0O/y4TmH7qskMQzKnOrqN83RJ7TmJ4RsBLHodJ6jHOE30I7J1uZfLdvybhc' );

# Tyeahead JS
define( 'TYPEAHEAD_VERSION', '1.1.1' );
define( 'TYPEAHEAD_HASH', 'sha256-qZIhMVBV4/crmcmYXNq5ZE5gPRiiPPMKVYbapf5HDBs=' );
Expand Down
17 changes: 13 additions & 4 deletions plugins/MantisGraph/MantisGraph.php
Expand Up @@ -23,6 +23,15 @@
*/
class MantisGraphPlugin extends MantisPlugin {

/**
* Chart JS
* @see https://www.chartjs.org/ Home page
* @see https://www.jsdelivr.com/package/npm/chart.js CDN
*/
const CHARTJS_VERSION = '2.7.3';
const CHARTJS_HASH = 'sha384-WJu6cbQvbPRsw+66L1nOomDAZzhTALnUlpchFlWHimhJ9o95CMue7xEZXXDRKV2S';
const CHARTJSBUNDLE_HASH = 'sha384-e4YKd0O/y4TmH7qskMQzKnOrqN83RJ7TmJ4RsBLHodJ6jHOE30I7J1uZfLdvybhc';

/**
* ChartJS colorschemes plugin
* @see https://nagix.github.io/chartjs-plugin-colorschemes/
Expand Down Expand Up @@ -140,12 +149,12 @@ function graph_filter_menu() {
function resources() {
if( current( explode( '/', gpc_get_string( 'page', '' ) ) ) === $this->basename ) {
if( config_get_global( 'cdn_enabled' ) == ON ) {
html_javascript_cdn_link('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/' . CHARTJS_VERSION . '/Chart.min.js', CHARTJS_HASH);
html_javascript_cdn_link('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/' . CHARTJS_VERSION . '/Chart.bundle.min.js', CHARTJSBUNDLE_HASH);
html_javascript_cdn_link('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/' . self::CHARTJS_VERSION . '/Chart.min.js', self::CHARTJS_HASH);
html_javascript_cdn_link('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/' . self::CHARTJS_VERSION . '/Chart.bundle.min.js', self::CHARTJSBUNDLE_HASH);
html_javascript_cdn_link('https://cdn.jsdelivr.net/npm/chartjs-plugin-colorschemes@' . self::CHARTJS_COLORSCHEMES_VERSION . '/dist/chartjs-plugin-colorschemes.min.js', self::CHARTJS_COLORSCHEMES_HASH );
} else {
echo '<script type="text/javascript" src="' . plugin_file('Chart-' . CHARTJS_VERSION . '.min.js') . '"></script>';
echo '<script type="text/javascript" src="' . plugin_file('Chart.bundle-' . CHARTJS_VERSION . '.min.js') . '"></script>';
echo '<script type="text/javascript" src="' . plugin_file( 'Chart-' . self::CHARTJS_VERSION . '.min.js' ) . '"></script>';
echo '<script type="text/javascript" src="' . plugin_file( 'Chart.bundle-' . self::CHARTJS_VERSION . '.min.js' ) . '"></script>';
echo '<script type="text/javascript" src="' . plugin_file( 'chartjs-plugin-colorschemes.min.js' ) . '"></script>';
}
echo '<script type="text/javascript" src="' . plugin_file("MantisGraph.js") . '"></script>';
Expand Down

0 comments on commit 5d9a4f3

Please sign in to comment.