-
-
Notifications
You must be signed in to change notification settings - Fork 968
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run
prettier
on JavaScript via pre-commit
This patch removes the global `djangoproject/static/*` exclude rule in `.pre-commit-config.yaml` to enable `prettier` to run on this project's JavaScript files. The `djangoproject/static/js/lib/` directory is now excluded in the `prettier` hook because there is no value in reformatting a minified JavaScript file. I also added a `.prettierrc` file to the root of the project to control JavaScript formatting. Refs #1827
- Loading branch information
Showing
22 changed files
with
913 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.js", | ||
"options": { | ||
"tabWidth": 2, | ||
"singleQuote": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,89 @@ | ||
define('dashboard/detail', ['jquery', 'jquery.flot', 'dashboard/utils'], function ($, plot, utils) { | ||
$(function () { | ||
var element = $("#graph"); | ||
var url = element.data('path') + element.data('metric') + ".json?days=365"; | ||
var hover = { | ||
show: function (x, y, message) { | ||
$('<div id="hover">').html(message) | ||
.css({top: y, left: x}) | ||
.appendTo('body') | ||
.show(); | ||
}, | ||
hide: function () { | ||
$("#hover").remove(); | ||
} | ||
}; | ||
define('dashboard/detail', [ | ||
'jquery', | ||
'jquery.flot', | ||
'dashboard/utils', | ||
], function ($, plot, utils) { | ||
$(function () { | ||
var element = $('#graph'); | ||
var url = element.data('path') + element.data('metric') + '.json?days=365'; | ||
var hover = { | ||
show: function (x, y, message) { | ||
$('<div id="hover">') | ||
.html(message) | ||
.css({ top: y, left: x }) | ||
.appendTo('body') | ||
.show(); | ||
}, | ||
hide: function () { | ||
$('#hover').remove(); | ||
}, | ||
}; | ||
|
||
$.getJSON(url, function (response) { | ||
for (var i = 0; i < response.data.length; i++) { | ||
response.data[i][0] = response.data[i][0] * 1000; | ||
} | ||
var options = { | ||
xaxis: { | ||
mode: "time", | ||
tickColor: "rgba(0,0,0,0)", | ||
minTickSize: [1, "day"] | ||
}, | ||
yaxis: {min: 0, ticks: 4}, | ||
grid: {borderWidth: 0, hoverable: true, color: "#0C3C26"}, | ||
colors: ["#0C4B33"] | ||
}; | ||
if (response.period == "daily") { | ||
options.bars = { | ||
show: true, | ||
barWidth: 22 * 60 * 60 * 1000, | ||
align: "center" | ||
}; | ||
} else if (response.period == 'weekly') { | ||
options.bars = { | ||
show: true, | ||
barWidth: 22 * 60 * 60 * 7 * 1000, | ||
align: "center" | ||
}; | ||
} | ||
var plot = $.plot(element, [response.data], options); | ||
$.getJSON(url, function (response) { | ||
for (var i = 0; i < response.data.length; i++) { | ||
response.data[i][0] = response.data[i][0] * 1000; | ||
} | ||
var options = { | ||
xaxis: { | ||
mode: 'time', | ||
tickColor: 'rgba(0,0,0,0)', | ||
minTickSize: [1, 'day'], | ||
}, | ||
yaxis: { min: 0, ticks: 4 }, | ||
grid: { borderWidth: 0, hoverable: true, color: '#0C3C26' }, | ||
colors: ['#0C4B33'], | ||
}; | ||
if (response.period == 'daily') { | ||
options.bars = { | ||
show: true, | ||
barWidth: 22 * 60 * 60 * 1000, | ||
align: 'center', | ||
}; | ||
} else if (response.period == 'weekly') { | ||
options.bars = { | ||
show: true, | ||
barWidth: 22 * 60 * 60 * 7 * 1000, | ||
align: 'center', | ||
}; | ||
} | ||
var plot = $.plot(element, [response.data], options); | ||
|
||
var format_message = function (timestamp, measurement) { | ||
var unit = measurement == 1 ? response.unit : response.unit_plural; | ||
return utils.formatTimestamp(timestamp, response.period) + '<br>' + measurement + ' ' + unit; | ||
}; | ||
var format_message = function (timestamp, measurement) { | ||
var unit = measurement == 1 ? response.unit : response.unit_plural; | ||
return ( | ||
utils.formatTimestamp(timestamp, response.period) + | ||
'<br>' + | ||
measurement + | ||
' ' + | ||
unit | ||
); | ||
}; | ||
|
||
var previousPoint = null; | ||
element.bind("plothover", function (event, pos, item) { | ||
if (item) { | ||
if (previousPoint != item.dataIndex) { | ||
previousPoint = item.dataIndex; | ||
hover.hide(); | ||
var x, y; | ||
var message = format_message.apply(null, item.datapoint); | ||
if (response.period == 'instant') { | ||
x = item.pageX + 10; | ||
y = item.pageY + 10; | ||
} else { | ||
// I'd like this hover to be centered over the bar. This | ||
// simple math sorta works, but it assumes a *lot* about | ||
// the plot and basically won't scale. Grr. | ||
x = item.pageX - 40; | ||
y = item.pageY - 50; | ||
} | ||
hover.show(x, y, message); | ||
} | ||
} else { | ||
hover.hide(); | ||
previousPoint = null; | ||
} | ||
}); | ||
}); | ||
var previousPoint = null; | ||
element.bind('plothover', function (event, pos, item) { | ||
if (item) { | ||
if (previousPoint != item.dataIndex) { | ||
previousPoint = item.dataIndex; | ||
hover.hide(); | ||
var x, y; | ||
var message = format_message.apply(null, item.datapoint); | ||
if (response.period == 'instant') { | ||
x = item.pageX + 10; | ||
y = item.pageY + 10; | ||
} else { | ||
// I'd like this hover to be centered over the bar. This | ||
// simple math sorta works, but it assumes a *lot* about | ||
// the plot and basically won't scale. Grr. | ||
x = item.pageX - 40; | ||
y = item.pageY - 50; | ||
} | ||
hover.show(x, y, message); | ||
} | ||
} else { | ||
hover.hide(); | ||
previousPoint = null; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,48 @@ | ||
define('dashboard/index', ['jquery', 'jquery.flot', 'dashboard/utils'], function ($, flot, utils) { | ||
$(function () { | ||
$(".metric .sparkline").each(function (index, elem) { | ||
var element = $(elem); | ||
var valueElement = element.parent().find('.value a'); | ||
var timestampElement = element.parent().find('.timestamp'); | ||
var originalValue = valueElement.html(); | ||
var green = '#93D7B7'; | ||
define('dashboard/index', [ | ||
'jquery', | ||
'jquery.flot', | ||
'dashboard/utils', | ||
], function ($, flot, utils) { | ||
$(function () { | ||
$('.metric .sparkline').each(function (index, elem) { | ||
var element = $(elem); | ||
var valueElement = element.parent().find('.value a'); | ||
var timestampElement = element.parent().find('.timestamp'); | ||
var originalValue = valueElement.html(); | ||
var green = '#93D7B7'; | ||
|
||
var url = element.data('path') + element.data('metric') + ".json"; | ||
$.getJSON(url, function (response) { | ||
response.data = utils.convertSecondsToMilliseconds(response.data); | ||
$.plot(element, [response.data], { | ||
xaxis: {show: false, mode: "time"}, | ||
yaxis: {show: false, min: 0}, | ||
grid: {borderWidth: 0, hoverable: true}, | ||
colors: [green], | ||
bars: { | ||
show: true, | ||
barWidth: (response.period == 'daily' ? 24 * 60 * 60 * 1000 : 24 * 60 * 60 * 7 * 1000), | ||
fillColor: green, | ||
lineWidth: 1, | ||
align: "center" | ||
} | ||
}); | ||
var url = element.data('path') + element.data('metric') + '.json'; | ||
$.getJSON(url, function (response) { | ||
response.data = utils.convertSecondsToMilliseconds(response.data); | ||
$.plot(element, [response.data], { | ||
xaxis: { show: false, mode: 'time' }, | ||
yaxis: { show: false, min: 0 }, | ||
grid: { borderWidth: 0, hoverable: true }, | ||
colors: [green], | ||
bars: { | ||
show: true, | ||
barWidth: | ||
response.period == 'daily' | ||
? 24 * 60 * 60 * 1000 | ||
: 24 * 60 * 60 * 7 * 1000, | ||
fillColor: green, | ||
lineWidth: 1, | ||
align: 'center', | ||
}, | ||
}); | ||
|
||
element.bind('plothover', function (event, pos, item) { | ||
if (item) { | ||
valueElement.html(item.datapoint[1]); | ||
timestampElement.html( | ||
utils.formatTimestamp( | ||
item.datapoint[0], | ||
response.period | ||
) | ||
); | ||
} else { | ||
valueElement.html(originalValue); | ||
timestampElement.html(' '); | ||
} | ||
}); | ||
}); | ||
element.bind('plothover', function (event, pos, item) { | ||
if (item) { | ||
valueElement.html(item.datapoint[1]); | ||
timestampElement.html( | ||
utils.formatTimestamp(item.datapoint[0], response.period), | ||
); | ||
} else { | ||
valueElement.html(originalValue); | ||
timestampElement.html(' '); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
define('dashboard/utils', ['jquery'], function ($) { | ||
return { | ||
formatTimestamp: function formatTimestamp(timestamp, period) { | ||
var d = new Date(timestamp); | ||
if (period == 'instant') { | ||
return $.plot.formatDate(d, "%b %d, %h:%M %p"); | ||
} else if (period == 'daily') { | ||
return $.plot.formatDate(d, "%b %d"); | ||
} else if (period == 'weekly') { | ||
// A bit more complicated than the above: the timestamp is in the | ||
// middle of the week, so we have to bracket the date. This is | ||
// something of a fudge here, but it works well enough. | ||
var start = new Date(d.getTime() - (3 * 24 * 60 * 60 * 1000)); | ||
var end = new Date(d.getTime() + (3 * 24 * 60 * 60 * 1000)); | ||
return $.plot.formatDate(start, "%b %d") + ' - ' + $.plot.formatDate(end, "%b %d"); | ||
} | ||
}, | ||
convertSecondsToMilliseconds: function convertSecondsToMilliseconds(data) { | ||
for (var i = 0; i < data.length; i++) { | ||
data[i][0] = data[i][0] * 1000; | ||
} | ||
return data; | ||
} | ||
}; | ||
return { | ||
formatTimestamp: function formatTimestamp(timestamp, period) { | ||
var d = new Date(timestamp); | ||
if (period == 'instant') { | ||
return $.plot.formatDate(d, '%b %d, %h:%M %p'); | ||
} else if (period == 'daily') { | ||
return $.plot.formatDate(d, '%b %d'); | ||
} else if (period == 'weekly') { | ||
// A bit more complicated than the above: the timestamp is in the | ||
// middle of the week, so we have to bracket the date. This is | ||
// something of a fudge here, but it works well enough. | ||
var start = new Date(d.getTime() - 3 * 24 * 60 * 60 * 1000); | ||
var end = new Date(d.getTime() + 3 * 24 * 60 * 60 * 1000); | ||
return ( | ||
$.plot.formatDate(start, '%b %d') + | ||
' - ' + | ||
$.plot.formatDate(end, '%b %d') | ||
); | ||
} | ||
}, | ||
convertSecondsToMilliseconds: function convertSecondsToMilliseconds(data) { | ||
for (var i = 0; i < data.length; i++) { | ||
data[i][0] = data[i][0] * 1000; | ||
} | ||
return data; | ||
}, | ||
}; | ||
}); |
Oops, something went wrong.