Skip to content
Permalink
Browse files

Removing moment from codebase. Chartjs includes it bundled as a dep

  • Loading branch information
CorWatts committed Aug 23, 2017
1 parent ace19a1 commit 8dcccb70a1a25ccc40b68840cc182484f7221c92
@@ -18,8 +18,6 @@ class AppAsset extends AssetBundle
// we disable all the css in the bootstrap asset here. But we pull the css into the main appasset css at the top.
// however, the bootstrap fonts are still pulled in here in this bootstrap asset. The url is different, because the css (pulled in via appasset) is looking for the fonts in its same asset directory.
'yii\bootstrap\BootstrapAsset',
'yii\bootstrap\BootstrapPluginAsset',
'site\assets\MomentAsset',
'site\assets\ChartjsAsset',
'yii\bootstrap\BootstrapPluginAsset'
];
}
@@ -8,10 +8,7 @@ class ChartjsAsset extends AssetBundle
{
public $sourcePath = '@bower/chartjs/dist';
public $js = [
'Chart.min.js',
];
public $depends = [
'yii\web\JqueryAsset',
'Chart.bundle.min.js',
];
}

This file was deleted.

@@ -18,15 +18,13 @@
'cssCompressor' => 'uglifycss --debug --ugly-comments {from} > {to}',
// The list of asset bundles to compress:
'bundles' => [
'yii\web\JqueryAsset',
'site\assets\AppAsset',
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
'yii\bootstrap\BootstrapPluginAsset',
'yii\widgets\ActiveFormAsset',
'yii\validators\ValidationAsset',
'yii\captcha\CaptchaAsset',
'site\assets\MomentAsset',
'site\assets\ChartjsAsset',
'site\assets\PickadateAsset',
'yii\grid\GridViewAsset',
@@ -43,26 +41,32 @@
],
// Asset bundle for compression output:
'targets' => [
'all' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'common' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'sourcePath' => '@web/assets',
'baseUrl' => '@web',
'js' => 'js/all-{hash}.js',
'css' => 'css/all-{hash}.css',
'depends' => [], // Include all remaining assets
'baseUrl' => '@web',
'js' => 'js/common-{hash}.js',
'css' => 'css/common-{hash}.css',
],
'chartjs' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'sourcePath' => '@web/assets',
'baseUrl' => '@web',
'js' => 'js/chartjs-{hash}.js',
'css' => 'css/chartjs-{hash}.css',
'depends' => [ 'site\assets\ChartjsAsset' ]
],
'pickadate' => [
'class' => 'yii\web\AssetBundle',
'basePath' => '@webroot',
'sourcePath' => '@web/assets',
'baseUrl' => '@web',
'js' => 'js/pickadate-{hash}.js',
'depends' => [
'site\assets\PickadateAsset',
]
],
],
'depends' => [ 'site\assets\PickadateAsset' ]
]
],
// Asset manager configuration:
'assetManager' => [
'basePath' => '@webroot/assets',
@@ -2,6 +2,7 @@
/**
* @var yii\web\View $this
*/
\site\assets\ChartjsAsset::register($this);

$this->title = "The Faster Scale App | Report";
$this->registerJsFile('/js/checkin/report.js', ['depends' => [\site\assets\AppAsset::class]]);
@@ -11,6 +11,7 @@
* @var yii\web\View $this
*/
\site\assets\PickadateAsset::register($this);
\site\assets\ChartjsAsset::register($this);

$this->title = "The Faster Scale App | Previous Check-ins";
$time = Yii::$container->get('common\interfaces\TimeInterface');
@@ -1 +1,2 @@
all*
common*
@@ -1,2 +1,4 @@
all*
pickadate*
common*
moment*
@@ -29,8 +29,6 @@
/* Event Listeners */
$('.date-period-switcher').on('click', 'label', function(e) {
var period = this.getAttribute('data-period');
console.log('clicked', this, period)

$.ajax({
url: '/checkin/history/'+period,
dataType: 'json'
@@ -43,11 +41,26 @@


function buildChart(labels, datasets) {
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
return new Chart(bar_ctx, {
type: 'bar',
data: {labels: labels, datasets: datasets},
options: {
tooltips: { mode: 'index', intersect: false },
tooltips: {
mode: 'index',
intersect: false,
callbacks: {
title: function(tooltipItem, data) {
// format tooltip title
var d = new Date(tooltipItem[0].xLabel)
return months[d.getUTCMonth()]+" "+d.getUTCDate()+", "+d.getUTCFullYear()
},
label: function(tooltipItem, data) {
// format tooltip label
return "Score: " + tooltipItem.yLabel;
}
}
},
responsive: true,
maintainAspectRatio: false,
legend: {
@@ -68,6 +81,5 @@
}
});
}

});
})(jQuery, Chart)
@@ -1,44 +1,111 @@
(function($, moment) {
$.ajax({
type: 'GET',
url: 'https://api.github.com/repos/CorWatts/emotionalcheckin/commits?per_page=10',
dataType: 'json',
success: function(data) {
$('#spinner').remove();
$.each(data, function(key, commit) {
$('#commits').append("<tr>"+
"<td class='text-nowrap'>"+moment(commit.commit.committer.date).fromNow()+"</td>"+
"<td><a href='"+commit.html_url+"'>Commit</a></td>"+
"<td><a href='"+commit.author.html_url+"'>"+commit.author.login+"</a></td>"+
"<td>"+escape(commit.commit.message)+"</td>"+
"</tr>");
});
}
});
})(jQuery, moment)

// Stole this HTML escaping code from the UnderscoreJS source
var escapeMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'`': '&#x60;'
};

var createEscaper = function(map) {
var escaper = function(match) {
return map[match];
(function($) {
/**
* Ripped from Stack Overflow
* Thanks to Caio Tarifa via https://stackoverflow.com/a/37802747
* MIT Licensed
*/
var TimeAgo = (function() {
var self = {};

// Public Methods
self.locales = {
prefix: '',
sufix: 'ago',

seconds: 'less than a minute',
minute: 'about a minute',
minutes: '%d minutes',
hour: 'about an hour',
hours: 'about %d hours',
day: 'a day',
days: '%d days',
month: 'about a month',
months: '%d months',
year: 'about a year',
years: '%d years'
};

self.inWords = function(timeAgo) {
var seconds = Math.floor((new Date() - parseInt(timeAgo)) / 1000),
separator = this.locales.separator || ' ',
words = this.locales.prefix + separator,
interval = 0,
intervals = {
year: seconds / 31536000,
month: seconds / 2592000,
day: seconds / 86400,
hour: seconds / 3600,
minute: seconds / 60
};

var distance = this.locales.seconds;

for (var key in intervals) {
interval = Math.floor(intervals[key]);

if (interval > 1) {
distance = this.locales[key + 's'];
break;
} else if (interval === 1) {
distance = this.locales[key];
break;
}
}

distance = distance.replace(/%d/i, interval);
words += distance + separator + this.locales.sufix;

return words.trim();
};

return self;
}());
/* end Caio Tarifa's code */

/**
* Taken from the UnderscoreJS source
* MIT Licensed
*/
var escapeMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'`': '&#x60;'
};

var source = '(?:' + Object.keys(escapeMap).join('|') + ')';
var testRegexp = RegExp(source);
var replaceRegexp = RegExp(source, 'g');
return function(string) {
string = string == null ? '' : '' + string;
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
var createEscaper = function(map) {
var escaper = function(match) {
return map[match];
};

var source = '(?:' + Object.keys(escapeMap).join('|') + ')';
var testRegexp = RegExp(source);
var replaceRegexp = RegExp(source, 'g');
return function(string) {
string = string == null ? '' : '' + string;
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
};
};
};
/* End UnderscoreJS code */

var escape = createEscaper(escapeMap);

var escape = createEscaper(escapeMap);
$.ajax({
type: 'GET',
url: 'https://api.github.com/repos/CorWatts/emotionalcheckin/commits?per_page=10',
dataType: 'json',
success: function(data) {
$('#spinner').remove();
$.each(data, function(key, data) {
$('#commits').append("<tr>"+
"<td class='text-nowrap'>"+TimeAgo.inWords(new Date(data.commit.committer.date).getTime())+"</td>"+
"<td><a href='"+data.html_url+"'>Commit</a></td>"+
"<td><a href='"+data.author.html_url+"'>"+data.author.login+"</a></td>"+
"<td>"+escape(data.commit.message)+"</td>"+
"</tr>");
});
}
});
})(jQuery)

0 comments on commit 8dcccb7

Please sign in to comment.
You can’t perform that action at this time.