1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

frontend: use gulp, eslint, code refactor

Apologies in advance for the insanely huge commit. This commit is
primarily based on Anton Linevych's amazing work found here [1]. While
he had gone through the pains of making small, atomic changes to each
file, I had put off reviewing the PR for a long time. By the time I
finally got around to it, the project had changed so much that it didn't
make sense to keep the commits the same way. So I've cherry-picked most
of his commits, with some changes here and there, and I've squashed them
into one commit.

[1] https://gitlab.com/linevych/commento-ce/tree/feature/frontend_building_improvements
This commit is contained in:
Anton Linevych
2018-06-24 04:01:21 +02:00
committed by Adhityaa Chandrasekar
parent e4f71fe402
commit 9e3935b3b2
30 changed files with 5059 additions and 395 deletions

View File

@ -1,35 +1,41 @@
(function (global, document) {
"use strict";
(document);
global.numberify = function(x) {
if (x == 0)
if (x === 0) {
return {"zeros": "000", "num": "", "units": ""}
}
if (x < 10)
if (x < 10) {
return {"zeros": "00", "num": x, "units": ""}
}
if (x < 100)
if (x < 100) {
return {"zeros": "0", "num": x, "units": ""}
}
if (x < 1000)
if (x < 1000) {
return {"zeros": "", "num": x, "units": ""}
}
var res;
if (x < 1000000) {
res = global.numberify((x/1000).toFixed(0))
res.units = "K"
}
else if (x < 1000000000) {
} else if (x < 1000000000) {
res = global.numberify((x/1000000).toFixed(0))
res.units = "M"
}
else if (x < 1000000000000) {
} else if (x < 1000000000000) {
res = global.numberify((x/1000000000).toFixed(0))
res.units = "B"
}
if (res.num*10 % 10 == 0)
if (res.num*10 % 10 === 0) {
res.num = Math.ceil(res.num);
}
return res;
}
@ -74,12 +80,12 @@
var labels = new Array();
for (var i = 0; i < views.length; i++) {
if ((views.length-i) % 7 == 0) {
if ((views.length-i) % 7 === 0) {
var x = (views.length-i)/7;
labels.push(x + " week" + (x > 1 ? "s" : "") + " ago");
}
else
} else {
labels.push("");
}
}
new Chartist.Line("#views-graph", {
@ -92,8 +98,12 @@
series: [comments],
}, options);
data.domains[data.cd].viewsLast30Days = numberify(views.reduce(function(a, b) { return a + b; }, 0));
data.domains[data.cd].commentsLast30Days = numberify(comments.reduce(function(a, b) { return a + b; }, 0));
data.domains[data.cd].viewsLast30Days = numberify(views.reduce(function(a, b) {
return a + b;
}, 0));
data.domains[data.cd].commentsLast30Days = numberify(comments.reduce(function(a, b) {
return a + b;
}, 0));
});
}