Skip to content

Commit 416b889

Browse files
committed
Merge branch 'master' into next
2 parents 4df4c17 + 8f8d42b commit 416b889

File tree

43 files changed

+468
-937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+468
-937
lines changed

.eslintignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ frontend/express/public/javascripts/min/**
55
frontend/express/public/javascripts/utils/**
66
frontend/express/public/javascripts/visualization/**
77
frontend/express/public/themes/**
8-
frontend/express/public/sdk/**
98
plugins/*/frontend/public/*
109
plugins/*/frontend/public/javascripts/*
1110
bin/scripts/nghttp2/*
1211
plugins/push/api/parts/apn/*
1312

1413
!plugins/*/frontend/public/javascripts
15-
!plugins/*/frontend/public/javascripts/countly.*.js
14+
!plugins/*/frontend/public/javascripts/countly.models.js
15+
!plugins/*/frontend/public/javascripts/countly.views.js

.eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@
194194
"frontend/express/libs/*.js",
195195
"plugins/pluginManager.js",
196196
"plugins/*/api/**/*.js",
197-
"plugins/*/frontend/*.js",
198-
"plugins/*/extend/*.js"
197+
"plugins/*/frontend/*.js"
199198
],
200199
"env": {
201200
"es6": true,

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
api/node_modules/
22
.idea
3+
*_en.properties
34
frontend/express/node_modules/
45
api/config.js
56
countly_marked_version.json

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: nodejs
22
dist: trusty
3-
node_js: "10"
3+
node_js: "8"
44
env:
55
global:
6-
- MONGODB=4.0.12
6+
- MONGODB=3.6.6
77
- secure: ZXdUMP+8Nk9Kd5nX31D/DIB1t2xlJd+T4W7umWjwpy+KPA9d1W1OhUG6V2Gpv3PsJf+UtMosgZsywcLFVG4l/WcjAhs3c9pegW5ZRYAEfVjkk7aHhWQGvj5DID8iAAxs91Mm8LwJ43o68x+XN6746zArPqcVzQltDunJ0G3gfh8=
88
branches:
99
except:

Gruntfile.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ module.exports = function(grunt) {
314314
locales[lang].push(path);
315315
};
316316

317-
[path.join(__dirname, 'frontend/express/public/localization/dashboard'), path.join(__dirname, 'frontend/express/public/localization/help'), path.join(__dirname, 'frontend/express/public/localization/mail')].forEach(function(dir) {
317+
function processLocaleDir(dir) {
318318
if (!fs.existsSync(dir)) {
319319
return;
320320
}
@@ -324,7 +324,9 @@ module.exports = function(grunt) {
324324
pushLocaleFile(name, dir + '/' + name);
325325
}
326326
});
327-
});
327+
}
328+
329+
[path.join(__dirname, 'frontend/express/public/localization/dashboard'), path.join(__dirname, 'frontend/express/public/localization/help'), path.join(__dirname, 'frontend/express/public/localization/mail')].forEach(processLocaleDir);
328330

329331
plugins.forEach(function(plugin) {
330332
var localization = path.join(__dirname, 'plugins', plugin, 'frontend/public/localization');
@@ -346,6 +348,8 @@ module.exports = function(grunt) {
346348
}
347349
});
348350

351+
processLocaleDir(path.join(__dirname, 'frontend/express/public/localization/custom'));
352+
349353
for (var lang in locales) {
350354
grunt.config('concat.locales_' + lang + '.options.separator', '\n\n');
351355
grunt.config('concat.locales_' + lang + '.src', locales[lang]);

api/parts/data/exports.js

+2-21
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@ var contents = {
2020
};
2121
var delimiter = "_";
2222

23-
/**
24-
* Check type of value, if similar to timestamp, conver to Moment object
25-
* @param {any} value - value to checked
26-
* @returns {varies} Moment object or passed value
27-
**/
28-
function typeCheck(value) {
29-
if (common.isNumber(value)) {
30-
//this is a seconds timestamp
31-
if ((Math.round(parseFloat(value, 10)) + "").length === 10) {
32-
value = moment(new Date(parseInt(value, 10) * 1000)).format("ddd, D MMM YYYY HH:mm:ss");
33-
}
34-
//this is a miliseconds timestamp
35-
else if ((Math.round(parseFloat(value, 10)) + "").length === 13) {
36-
value = moment(new Date(parseInt(value, 10))).format("ddd, D MMM YYYY HH:mm:ss");
37-
}
38-
}
39-
return value;
40-
}
41-
4223
/**
4324
* Flattens array of objects
4425
* @param {array} arr - array with objects to flatten
@@ -95,7 +76,7 @@ function flattenObject(ob, fields) {
9576
if (fields) {
9677
fields[i] = true;
9778
}
98-
toReturn[i] = typeCheck(ob[i]);
79+
toReturn[i] = ob[i];
9980
}
10081
}
10182
return toReturn;
@@ -156,7 +137,7 @@ exports.stream = function(params, stream, filename, type) {
156137
if (type && contents[type]) {
157138
headers["Content-Type"] = contents[type];
158139
}
159-
headers["Content-Disposition"] = "attachment;filename=" + filename + "." + type;
140+
headers["Content-Disposition"] = "attachment;filename=" + encodeURIComponent(filename) + "." + type;
160141
if (params.res.writeHead) {
161142
params.res.writeHead(200, headers);
162143
params.res.write("[");

api/parts/data/stats.js

+4-30
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,8 @@ function getTotalEvents(callback, apps) {
149149
}
150150
query._id = {$in: inarray};
151151
}
152-
countlyDb.collection("events").find(query, {'list': 1}).toArray(function(err, events) {
153-
if (err || !events) {
154-
callback(0);
155-
}
156-
else {
157-
var eventCount = 0;
158-
159-
for (let i = 0; i < events.length; i++) {
160-
if (events[i] && events[i].list) {
161-
eventCount += events[i].list.length;
162-
}
163-
}
164-
165-
callback(eventCount);
166-
}
152+
countlyDb.collection("events").aggregate([{$match: query}, {$project: {len: {$size: '$list'}}}, {$group: {_id: 'count', len: {$sum: '$len'}}}], function(err, count) {
153+
callback(count && count[0] && count[0].len || 0);
167154
});
168155
}
169156

@@ -221,21 +208,8 @@ function getTotalMsgSent(callback, apps) {
221208
}
222209
query.apps = {$in: inarray};
223210
}
224-
countlyDb.collection("messages").find(query, {"result": 1}).toArray(function(err, messages) {
225-
if (err || !messages) {
226-
callback(0);
227-
}
228-
else {
229-
var sentMsgCount = 0;
230-
231-
for (let i = 0; i < messages.length; i++) {
232-
if (messages[i] && messages[i].result && messages[i].result.sent) {
233-
sentMsgCount += messages[i].result.sent;
234-
}
235-
}
236-
237-
callback(sentMsgCount);
238-
}
211+
countlyDb.collection("messages").aggregate([{$match: query}, {$group: {_id: 'count', sent: {$sum: '$result.sent'}}}], function(err, count) {
212+
callback(count && count[0] && count[0].sent || 0);
239213
});
240214
}
241215

api/parts/jobs/executor.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ process.on('unhandledRejection', (reason, p) => {
1212
});
1313

1414
process.on('exit', () => {
15-
console.log('Exiting due to master exited');
16-
process.exit(1);
15+
console.log('Executor exited');
1716
});
1817

1918
/**

api/parts/jobs/manager.js

+7
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ class Manager {
259259
continue;
260260
}
261261

262+
if (job instanceof JOB.IPCJob) {
263+
if (!this.hasResources(job)) {
264+
log.i('All resources are busy for %j, skipping for now', json);
265+
continue;
266+
}
267+
}
268+
262269
log.i('Trying to start job %j', json);
263270
let update = {
264271
$set: {

api/parts/jobs/resource.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,19 @@ class ResourceFaçade extends ResourceInterface {
383383
else {
384384
log.w('Opening underlying resource %s from façade', this.id);
385385
return new Promise((resolve, reject) => {
386-
setTimeout(() => {
386+
let to = setTimeout(() => {
387387
reject(JOB.ERROR.TIMEOUT);
388388
this.close().catch(e => log.w('[%d]: Error in .open() of resource %s', process.pid, this.id, e.stack || e));
389389
}, RESOURCE_CMD_TIMEOUT);
390390
this.channel.send(CMD.OPENED);
391-
this.channel.once(CMD.OPENED, resolve);
392-
this.channel.once(CMD.CLOSED, reject);
391+
this.channel.once(CMD.OPENED, arg => {
392+
clearTimeout(to);
393+
resolve(arg);
394+
});
395+
this.channel.once(CMD.CLOSED, arg => {
396+
clearTimeout(to);
397+
reject(arg);
398+
});
393399
});
394400
}
395401
}

api/utils/render.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@
55
* @module api/utils/render
66
*/
77

8-
var puppeteer = require('puppeteer');
8+
var puppeteer;
9+
try {
10+
puppeteer = require('puppeteer');
11+
}
12+
catch (err) {
13+
console.warn(
14+
`Puppeteer not installed. Please install puppeteer (1.19.0) if
15+
you would like to use api/utils/render.js. \nGracefully skipping
16+
any functionality associated with Puppeteer...`, err.stack
17+
);
18+
}
919
var Promise = require('bluebird');
1020
var pathModule = require('path');
1121
var exec = require('child_process').exec;
@@ -32,8 +42,15 @@ var countlyConfig = require('./../config', 'dont-enclose');
3242
* @param {number} options.dimensions.padding - the padding value to subtract from the height of the screenshot
3343
* @param {number} options.dimensions.scale - the scale(ppi) value of the screenshot
3444
* @param {function} cb - callback function called with the error value or the image data
45+
* @return {void} void
3546
*/
3647
exports.renderView = function(options, cb) {
48+
if (puppeteer === undefined) {
49+
cb = typeof cb === 'function' ? cb : () => undefined;
50+
return cb(new Error(
51+
'Puppeteer not installed. Please install Puppeteer (1.19.0) to use this plugin.'
52+
));
53+
}
3754
Promise.coroutine(function * () {
3855
/**
3956
* Function to set a timeout

bin/config/nginx.server.block.conf

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ server {
2626
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2727
proxy_set_header X-Real-IP $remote_addr;
2828
}
29-
location ~ (/pixel.png|/images/dashboard/countly_logo.svg|/views/heatmap.js|/views/javascripts/simpleheat.js|/views/stylesheets/heatmap.css|/stylesheets/font-awesome/css/*|/stylesheets/font-awesome/fonts/*|/fonts/*|/stylesheets/ionicons/*|/feedback|/star-rating/stylesheets/countly-feedback-web.css|/star-rating/stylesheets/countly-feedback.css|/star-rating/javascripts/tippy.all.min.js|/star-rating/images/star-rating/*|/javascripts/dom/jquery/*|/stylesheets/font-awesome/css/*|/stylesheets/font-awesome/fonts/*|/fonts/*|/stylesheets/ionicons/*|/at/*|/images/dashboard/logo.png|/appimages/*.png|/dashboards/images/screenshots/screenshot_*.png) {
29+
location ~ (/pixel.png|/images/dashboard/countly_logo.svg|/sdk/web/countly.min.js|/views/heatmap.js|/views/javascripts/simpleheat.js|/views/stylesheets/heatmap.css|/stylesheets/font-awesome/css/*|/stylesheets/font-awesome/fonts/*|/fonts/*|/stylesheets/ionicons/*|/feedback|/star-rating/stylesheets/countly-feedback-web.css|/star-rating/stylesheets/countly-feedback.css|/star-rating/javascripts/tippy.all.min.js|/star-rating/images/star-rating/*|/javascripts/dom/jquery/*|/stylesheets/font-awesome/css/*|/stylesheets/font-awesome/fonts/*|/fonts/*|/stylesheets/ionicons/*|/at/*|/images/dashboard/logo.png|/appimages/*.png|/dashboards/images/screenshots/screenshot_*.png) {
3030
if ($http_content_type = "text/ping") {
3131
return 404;
3232
}
@@ -36,4 +36,4 @@ server {
3636
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3737
proxy_set_header X-Real-IP $remote_addr;
3838
}
39-
}
39+
}

frontend/express/public/javascripts/countly/countly.common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
var _period = (store.get("countly_date")) ? store.get("countly_date") : "30days";
1414
var _persistentSettings;
1515
var htmlEncodeOptions = {
16-
"whiteList": {"a": ["href", "class", "target"], "b": [], "br": [], "strong": [], "p": [], "span": ["class"], "div": ["class"]},
16+
"whiteList": {"a": ["href", "class", "target"], "ul": [], "li": [], "b": [], "br": [], "strong": [], "p": [], "span": ["class"], "div": ["class"]},
1717
onTagAttr: function(tag, name, value/* isWhiteAttr*/) {
1818
if (tag === "a") {
1919
var re = new RegExp(/{[0-9]*}/);

0 commit comments

Comments
 (0)