Skip to content

Commit 65dfafc

Browse files
authored
Merge pull request #668 from prikshittekta/guidelines
guidelines fixes - views, web, systemlogs, enterpriseinfo
2 parents c438f0c + 535fe47 commit 65dfafc

File tree

18 files changed

+480
-332
lines changed

18 files changed

+480
-332
lines changed

api/utils/render.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ var chromePath = "";
2929
*/
3030
exports.renderView = function(options, cb) {
3131
Promise.coroutine(function * () {
32+
/**
33+
* Function to set a timeout
34+
* @param {number} ms - Total milliseconds
35+
* @returns {Promise} Promise
36+
*/
3237
function timeout(ms) {
3338
return new Promise(function(resolve) {
3439
setTimeout(resolve, ms);
@@ -110,7 +115,7 @@ exports.renderView = function(options, cb) {
110115
if (id) {
111116
var rect = yield page.evaluate(function(selector) {
112117
var element = document.querySelector(selector);
113-
var dimensions = element.getBoundingClientRect();
118+
dimensions = element.getBoundingClientRect();
114119
return {
115120
left: dimensions.x,
116121
top: dimensions.y,
@@ -160,23 +165,26 @@ exports.renderView = function(options, cb) {
160165
}
161166
});
162167
};
163-
168+
/**
169+
* Function to fetch Chrome executable
170+
* @returns {Promise} Promise
171+
*/
164172
function fetchChromeExecutablePath() {
165-
return new Promise(function(resolve, reject) {
166-
exec('ls /etc/ | grep -i "redhat-release" | wc -l', function(error, stdout, stderr) {
167-
if (error || stdout != 1) {
168-
if (stderr) {
169-
console.log(stderr);
173+
return new Promise(function(resolve) {
174+
exec('ls /etc/ | grep -i "redhat-release" | wc -l', function(error1, stdout1, stderr1) {
175+
if (error1 || parseInt(stdout1) !== 1) {
176+
if (stderr1) {
177+
console.log(stderr1);
170178
}
171179

172180
alternateChrome = false;
173181
return resolve();
174182
}
175183

176-
exec('cat /etc/redhat-release | grep -i "release 6" | wc -l', function(error, stdout, stderr) {
177-
if (error || stdout != 1) {
178-
if (stderr) {
179-
console.log(stderr);
184+
exec('cat /etc/redhat-release | grep -i "release 6" | wc -l', function(error2, stdout2, stderr2) {
185+
if (error2 || parseInt(stdout2) !== 1) {
186+
if (stderr2) {
187+
console.log(stderr2);
180188
}
181189

182190
alternateChrome = false;

plugins/enterpriseinfo/api/api.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
var plugin = {},
2-
common = require('../../../api/utils/common.js'),
3-
plugins = require('../../pluginManager.js');
1+
var pluginOb = {};
42

5-
(function(plugin) {
3+
(function() {
64
//write api call
75
/*
86
plugins.register("/i", function(ob){
97
108
});
119
*/
12-
}(plugin));
10+
}(pluginOb));
1311

14-
module.exports = plugin;
12+
module.exports = pluginOb;

plugins/enterpriseinfo/frontend/app.js

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var plugin = {},
1+
var exported = {},
22
countlyConfig = require('../../../frontend/express/config', 'dont-enclose'),
33
versionInfo = require('../../../frontend/express/version.info'),
44
path = require('path'),
@@ -7,14 +7,18 @@ var plugin = {},
77

88
(function(plugin) {
99
plugin.init = function(app, countlyDb) {
10+
/**
11+
* Function to get total users
12+
* @param {Function} callback - Callback function
13+
*/
1014
function getTotalUsers(callback) {
11-
countlyDb.collection("apps").find({}, {_id: 1}).toArray(function(err, allApps) {
12-
if (err || !allApps) {
15+
countlyDb.collection("apps").find({}, {_id: 1}).toArray(function(err1, allApps) {
16+
if (err1 || !allApps) {
1317
callback(0, 0);
1418
}
1519
else {
16-
async.map(allApps, getUserCountForApp, function(err, results) {
17-
if (err) {
20+
async.map(allApps, getUserCountForApp, function(err2, results) {
21+
if (err2) {
1822
callback(0, 0);
1923
}
2024

@@ -29,9 +33,13 @@ var plugin = {},
2933
}
3034
});
3135
}
32-
33-
function getUserCountForApp(app, callback) {
34-
countlyDb.collection("app_users" + app._id).find({}).count(function(err, count) {
36+
/**
37+
* Function to get user count for app
38+
* @param {Object} appData - App data object
39+
* @param {Function} callback - Callback function
40+
*/
41+
function getUserCountForApp(appData, callback) {
42+
countlyDb.collection("app_users" + appData._id).find({}).count(function(err, count) {
3543
if (err || !count) {
3644
callback(0);
3745
}
@@ -52,11 +60,11 @@ var plugin = {},
5260
});
5361
});
5462
app.get(countlyConfig.path + '/dashboard', function(req, res, next) {
55-
if (req.session.uid && versionInfo.type == "777a2bf527a18e0fffe22fb5b3e322e68d9c07a6" && !versionInfo.footer) {
63+
if (req.session.uid && versionInfo.type === "777a2bf527a18e0fffe22fb5b3e322e68d9c07a6" && !versionInfo.footer) {
5664
countlyDb.collection('members').findOne({"_id": countlyDb.ObjectID(req.session.uid)}, function(err, member) {
5765
if (member && (typeof member.offer === "undefined" || member.offer < 2)) {
58-
countlyDb.collection('members').findAndModify({_id: countlyDb.ObjectID(req.session.uid)}, {}, {$inc: {offer: 1}}, function(err, member) {});
59-
getTotalUsers(function(totalUsers, totalApps) {
66+
countlyDb.collection('members').findAndModify({_id: countlyDb.ObjectID(req.session.uid)}, {}, {$inc: {offer: 1}}, function() {});
67+
getTotalUsers(function(totalUsers) {
6068
if (totalUsers > 5000) {
6169
res.expose({
6270
discount: "AWESOMECUSTOMER20"
@@ -69,6 +77,6 @@ var plugin = {},
6977
next();
7078
});
7179
};
72-
}(plugin));
80+
}(exported));
7381

74-
module.exports = plugin;
82+
module.exports = exported;

plugins/enterpriseinfo/frontend/public/javascripts/countly.views.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*global CountlyHelpers, EnterpriseView, countlyGlobalEE, countlyView, countlyGlobal, Handlebars, app, $, jQuery*/
2+
13
window.EnterpriseView = countlyView.extend({
24
initialize: function() {},
35
beforeRender: function() {
@@ -52,9 +54,9 @@ app.route("/enterprise", "enterprise", function() {
5254

5355
$(document).ready(function() {
5456
if (countlyGlobal.plugins.indexOf("drill") < 0) {
55-
if (typeof countlyGlobalEE !== "undefined" && countlyGlobalEE.discount) {
56-
var msg = {title: "5000+ users reached", message: "<a href='https://count.ly/enterprise-edition/' target='_blank'>To get 20% off Enterprise edition contact us with code:<br/><strong>" + countlyGlobalEE.discount + "</strong></a>", info: "Thank you for being with us", sticky: true, closeOnClick: false};
57-
CountlyHelpers.notify(msg);
57+
if (typeof countlyGlobalEE !== "undefined" && countlyGlobalEE.discount) {
58+
var msg = {title: "5000+ users reached", message: "<a href='https://count.ly/enterprise-edition/' target='_blank'>To get 20% off Enterprise edition contact us with code:<br/><strong>" + countlyGlobalEE.discount + "</strong></a>", info: "Thank you for being with us", sticky: true, closeOnClick: false};
59+
CountlyHelpers.notify(msg);
5860
}
5961

6062
var badge = '<a id="enterprise-badge" href="#/enterprise"><div data-localize="enterpriseinfo.badge">Get Enterprise</div></a>';

plugins/systemlogs/api/api.js

+55-39
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
var plugin = {},
1+
var pluginOb = {},
22
common = require('../../../api/utils/common.js'),
33
countlyCommon = require('../../../api/lib/countly.common.js'),
44
plugins = require('../../pluginManager.js');
55

6-
(function(plugin) {
6+
(function() {
77

88
//read api call
99
plugins.register("/o", function(ob) {
1010
var params = ob.params;
1111
var validate = ob.validateUserForGlobalAdmin;
12-
if (params.qstring.method == 'systemlogs') {
12+
if (params.qstring.method === 'systemlogs') {
1313
var query = {};
1414
if (typeof params.qstring.query === "string") {
1515
try {
@@ -20,7 +20,7 @@ var plugin = {},
2020
query = {};
2121
}
2222
}
23-
if (params.qstring.sSearch && params.qstring.sSearch != "") {
23+
if (params.qstring.sSearch && params.qstring.sSearch !== "") {
2424
query.i = {"$regex": new RegExp(".*" + params.qstring.sSearch + ".*", 'i')};
2525
//filter["$text"] = { "$search": "\""+params.qstring.sSearch+"\"" };
2626
}
@@ -29,51 +29,51 @@ var plugin = {},
2929
query.ts = countlyCommon.getTimestampRangeQuery(params, true);
3030
}
3131
query._id = {$ne: "meta_v2"};
32-
validate(params, function(params) {
32+
validate(params, function(paramsNew) {
3333
var columns = ["ts", "u", "a", "ip", "i"];
34-
common.db.collection('systemlogs').count({}, function(err, total) {
34+
common.db.collection('systemlogs').count({}, function(err1, total) {
3535
total--;
3636
var cursor = common.db.collection('systemlogs').find(query);
37-
cursor.count(function(err, count) {
38-
if (params.qstring.iDisplayStart && params.qstring.iDisplayStart != 0) {
39-
cursor.skip(parseInt(params.qstring.iDisplayStart));
37+
cursor.count(function(err2, count) {
38+
if (paramsNew.qstring.iDisplayStart && parseInt(paramsNew.qstring.iDisplayStart) !== 0) {
39+
cursor.skip(parseInt(paramsNew.qstring.iDisplayStart));
4040
}
41-
if (params.qstring.iDisplayLength && params.qstring.iDisplayLength != -1) {
42-
cursor.limit(parseInt(params.qstring.iDisplayLength));
41+
if (paramsNew.qstring.iDisplayLength && parseInt(paramsNew.qstring.iDisplayLength) !== -1) {
42+
cursor.limit(parseInt(paramsNew.qstring.iDisplayLength));
4343
}
44-
if (params.qstring.iSortCol_0 && params.qstring.sSortDir_0) {
45-
var ob = {};
46-
ob[columns[params.qstring.iSortCol_0]] = (params.qstring.sSortDir_0 == "asc") ? 1 : -1;
47-
cursor.sort(ob);
44+
if (paramsNew.qstring.iSortCol_0 && paramsNew.qstring.sSortDir_0) {
45+
var obj = {};
46+
obj[columns[paramsNew.qstring.iSortCol_0]] = (paramsNew.qstring.sSortDir_0 === "asc") ? 1 : -1;
47+
cursor.sort(obj);
4848
}
4949

50-
cursor.toArray(function(err, res) {
51-
if (err) {
52-
console.log(err);
50+
cursor.toArray(function(err3, res) {
51+
if (err3) {
52+
console.log(err3);
5353
}
5454
res = res || [];
55-
common.returnOutput(params, {sEcho: params.qstring.sEcho, iTotalRecords: total, iTotalDisplayRecords: count, aaData: res});
55+
common.returnOutput(paramsNew, {sEcho: paramsNew.qstring.sEcho, iTotalRecords: total, iTotalDisplayRecords: count, aaData: res});
5656
});
5757
});
5858
});
5959
});
6060
return true;
6161
}
62-
else if (params.qstring.method == 'systemlogs_meta') {
63-
validate(params, function(params) {
62+
else if (params.qstring.method === 'systemlogs_meta') {
63+
validate(params, function(paramsNew) {
6464
//get all users
65-
common.db.collection('members').find({}, {username: 1, email: 1, full_name: 1}).toArray(function(err, users) {
66-
common.db.collection('systemlogs').findOne({_id: "meta_v2"}, {_id: 0}, function(err, res) {
65+
common.db.collection('members').find({}, {username: 1, email: 1, full_name: 1}).toArray(function(err1, users) {
66+
common.db.collection('systemlogs').findOne({_id: "meta_v2"}, {_id: 0}, function(err2, res) {
6767
var result = {};
68-
if (!err && res) {
68+
if (!err2 && res) {
6969
for (var i in res) {
7070
result[i] = Object.keys(res[i]).map(function(arg) {
7171
return common.db.decode(arg);
7272
});
7373
}
7474
}
7575
result.users = users || [];
76-
common.returnOutput(params, result);
76+
common.returnOutput(paramsNew, result);
7777
});
7878
});
7979
});
@@ -112,7 +112,6 @@ var plugin = {},
112112
});
113113

114114
plugins.register("/i/apps/update", function(ob) {
115-
var appId = ob.appId;
116115
var data = {};
117116
data.before = {};
118117
data.after = {};
@@ -200,7 +199,7 @@ var plugin = {},
200199
if (typeof ob.data.before !== "undefined" && typeof ob.data.update !== "undefined") {
201200
var data = {};
202201
for (var i in ob.data) {
203-
if (i != "before" && i != "after") {
202+
if (i !== "before" && i !== "after") {
204203
data[i] = ob.data[i];
205204
}
206205
}
@@ -214,20 +213,26 @@ var plugin = {},
214213
}
215214
});
216215

217-
//recursive function to compare changes
216+
/**
217+
* recursive function to compare changes
218+
* @param {Object} dataafter - after data values
219+
* @param {Object} databefore - before data values
220+
* @param {Object} before - before
221+
* @param {Object} after - after
222+
*/
218223
function compareChangesInside(dataafter, databefore, before, after) {
219224
var keys = Object.keys(after);
220225
var keys2 = Object.keys(before);
221-
for (var i = 0; i < keys2.length; i++) {
226+
for (let i = 0; i < keys2.length; i++) {
222227
if (!after[keys2[i]]) {
223228
keys.push(keys2[i]);
224229
}
225230
}
226231

227-
for (var i = 0; i < keys.length; i++) {
232+
for (let i = 0; i < keys.length; i++) {
228233
if (typeof after[keys[i]] !== "undefined" && typeof before[keys[i]] !== "undefined") {
229234
if (typeof after[keys[i]] === "object") {
230-
if (Array.isArray(after[keys[i]]) && JSON.stringify(after[keys[i]]) != JSON.stringify(before[keys[i]])) {
235+
if (Array.isArray(after[keys[i]]) && JSON.stringify(after[keys[i]]) !== JSON.stringify(before[keys[i]])) {
231236
databefore[keys[i]] = before[keys[i]];
232237
dataafter[keys[i]] = after[keys[i]];
233238
}
@@ -240,14 +245,14 @@ var plugin = {},
240245
}
241246

242247
compareChangesInside(dataafter[keys[i]], databefore[keys[i]], before[keys[i]], after[keys[i]]);
243-
if (typeof dataafter[keys[i]] === "object" && typeof databefore[keys[i]] === "object" && Object.keys(dataafter[keys[i]]) == 0 && Object.keys(databefore[keys[i]]) == 0) {
248+
if (typeof dataafter[keys[i]] === "object" && typeof databefore[keys[i]] === "object" && (Object.keys(dataafter[keys[i]])).length === 0 && (Object.keys(databefore[keys[i]])).length === 0) {
244249
delete databefore[keys[i]];
245250
delete dataafter[keys[i]];
246251
}
247252
}
248253
}
249254
else {
250-
if (after[keys[i]] != before[keys[i]]) {
255+
if (after[keys[i]] !== before[keys[i]]) {
251256
databefore[keys[i]] = before[keys[i]];
252257
dataafter[keys[i]] = after[keys[i]];
253258
}
@@ -265,7 +270,12 @@ var plugin = {},
265270
}
266271
}
267272
}
268-
273+
/**
274+
* Function to compare changes
275+
* @param {Object} data - data object
276+
* @param {Object} before - before values
277+
* @param {Object} after - after values
278+
*/
269279
function compareChanges(data, before, after) {
270280
if (before && after) {
271281
if (typeof before._id !== "undefined") {
@@ -277,7 +287,13 @@ var plugin = {},
277287
compareChangesInside(data.after, data.before, before, after);
278288
}
279289
}
280-
290+
/**
291+
* Function to record action
292+
* @param {Object} params - Default parameters object
293+
* @param {Object} user - user object
294+
* @param {String} action - action
295+
* @param {Object} data - data object
296+
*/
281297
function recordAction(params, user, action, data) {
282298
var log = {};
283299
log.a = action;
@@ -291,7 +307,7 @@ var plugin = {},
291307
}
292308
if (user._id) {
293309
log.user_id = user._id + "";
294-
if (log.u == "") {
310+
if (log.u === "") {
295311
common.db.collection('members').findOne({_id: common.db.ObjectID.createFromHexString(user._id)}, function(err, res) {
296312
if (!err && res) {
297313
log.u = res.email || res.username;
@@ -318,7 +334,7 @@ var plugin = {},
318334
common.db.collection('members').findOne(query, function(err, res) {
319335
if (!err && res) {
320336
log.user_id = res._id + "";
321-
if (log.u == "") {
337+
if (log.u === "") {
322338
log.u = res.email || res.username;
323339
}
324340
}
@@ -333,6 +349,6 @@ var plugin = {},
333349
update["a." + common.db.encode(action)] = true;
334350
common.db.collection("systemlogs").update({_id: "meta_v2"}, {$set: update}, {upsert: true}, function() {});
335351
}
336-
}(plugin));
352+
}(pluginOb));
337353

338-
module.exports = plugin;
354+
module.exports = pluginOb;

0 commit comments

Comments
 (0)