Skip to content

Commit decbeb8

Browse files
committed
[locale] guidelines changes.
- unnecessary variables removed. - missing jsdoc comments added. - compare operators changed. - unnecessary escape operator removed.
1 parent 1d3194b commit decbeb8

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

plugins/locale/api/api.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var plugin = {},
1+
var exported = {},
22
langs = require('./utils/langs.js'),
33
common = require('../../../api/utils/common.js'),
44
fetch = require('../../../api/parts/data/fetch.js'),
55
plugins = require('../../pluginManager.js');
66

7-
(function(plugin) {
8-
plugins.register("/worker", function(ob) {
7+
(function() {
8+
plugins.register("/worker", function() {
99
common.dbUserMap.locale = 'lo'; // full ISO locale from device
1010
common.dbUserMap.lang = 'la'; // language extracted from locale
1111
});
@@ -22,7 +22,7 @@ var plugin = {},
2222
var locale = params.qstring.metrics._locale, lang = langs.languageFromLocale(locale);
2323
params.qstring.metrics._lang = lang;
2424

25-
if (isNewUser || user[common.dbUserMap.locale] != locale) {
25+
if (isNewUser || user[common.dbUserMap.locale] !== locale) {
2626
userProps[common.dbUserMap.locale] = locale;
2727
}
2828
}
@@ -38,7 +38,7 @@ var plugin = {},
3838
plugins.register("/o", function(ob) {
3939
var params = ob.params;
4040
var validateUserForDataReadAPI = ob.validateUserForDataReadAPI;
41-
if (params.qstring.method == "langs") {
41+
if (params.qstring.method === "langs") {
4242
validateUserForDataReadAPI(params, fetch.fetchTimeObj, 'langs');
4343
return true;
4444
}
@@ -70,6 +70,6 @@ var plugin = {},
7070
var appId = ob.appId;
7171
common.db.collection('langs').remove({'_id': {$regex: appId + ".*"}}, function() {});
7272
});
73-
}(plugin));
73+
}(exported));
7474

75-
module.exports = plugin;
75+
module.exports = exported;

plugins/locale/api/lib/countly.model.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
var countlyModel = require('../../../../api/lib/countly.model.js'),
2-
countlyCommon = require('../../../../api/lib/countly.common.js'),
3-
langs = require('../utils/langs.js'),
4-
underscore = require('underscore');
2+
langs = require('../utils/langs.js');
53

64
var langmap = langs.languages;
75

@@ -10,6 +8,11 @@ var langmap = langs.languages;
108
* @module "plugins/locale/api/lib/countly.model"
119
* @extends module:api/lib/countly.model~countlyMetric
1210
*/
11+
12+
/**
13+
* Create model
14+
* @returns {object} new model
15+
*/
1316
function create() {
1417
var countlyLocales = countlyModel.create(function(code) {
1518
if (langmap && langmap[code]) {

plugins/locale/api/utils/langs.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict';
22

3-
var langs = {},
3+
var exported = {},
44
langmap = require('langmap');
55

66
(function(langs) {
77

8-
var regexp = /[\-_]+/;
8+
var regexp = /[-_]+/;
99
langs.languageFromLocale = function(locale) {
1010
var comps = (locale + "").toLowerCase().split(regexp), lang = comps[0];
11-
if (lang == 'zh') {
12-
if (comps.length != 2) {
11+
if (lang === 'zh') {
12+
if (comps.length !== 2) {
1313
return '';
1414
}
1515
else {
@@ -36,6 +36,6 @@ var langs = {},
3636

3737
langs.languages = languages;
3838

39-
}(langs));
39+
}(exported));
4040

41-
module.exports = langs;
41+
module.exports = exported;

plugins/locale/frontend/app.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
var plugin = {},
1+
var exported = {},
22
countlyConfig = require('../../../frontend/express/config', 'dont-enclose'),
33
langs = require('../api/utils/langs.js');
44

55
(function(plugin) {
6-
plugin.init = function(app, countlyDb) {
6+
plugin.init = function(app) {
77
app.get(countlyConfig.path + '/dashboard', function(req, res, next) {
88
res.expose({
99
languages: langs.languages
1010
}, 'countlyGlobalLang');
1111
next();
1212
});
1313
};
14-
}(plugin));
14+
}(exported));
1515

16-
module.exports = plugin;
16+
module.exports = exported;

plugins/locale/frontend/public/javascripts/countly.models.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*global $, jQuery, CountlyHelpers, countlyCommon*/
12
(function() {
23
var langmap;
34
$.ajax({
@@ -10,6 +11,11 @@
1011
}
1112
});
1213

14+
/**
15+
* Get language name from language code
16+
* @param {string} code - language code
17+
* @returns {string} language name
18+
*/
1319
function getLanguageName(code) {
1420
if (langmap && langmap[code]) {
1521
return langmap[code].englishName;

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*global $, countlyTotalUsers, countlyLanguage, jQuery, app, LanguageView, countlyGlobalLang, Handlebars, countlyView, addDrill, countlyCommon, CountlyHelpers*/
12
window.LanguageView = countlyView.extend({
23
beforeRender: function() {
34
return $.when(countlyLanguage.initialize(), countlyTotalUsers.initialize("languages")).then(function() {});
@@ -68,12 +69,10 @@ window.LanguageView = countlyView.extend({
6869
refresh: function() {
6970
var self = this;
7071
$.when(this.beforeRender()).then(function() {
71-
if (app.activeView != self) {
72+
if (app.activeView !== self) {
7273
return false;
7374
}
7475
self.renderCommon(true);
75-
newPage = $("<div>" + self.template(self.templateData) + "</div>");
76-
7776
var languageData = countlyLanguage.getData();
7877
countlyCommon.drawGraph(languageData.chartDPTotal, "#dashboard-graph", "pie");
7978
countlyCommon.drawGraph(languageData.chartDPNew, "#dashboard-graph2", "pie");
@@ -92,7 +91,7 @@ app.route("/analytics/languages", "languages", function() {
9291
});
9392

9493
$(document).ready(function() {
95-
Handlebars.registerHelper('languageTitle', function(context, options) {
94+
Handlebars.registerHelper('languageTitle', function(context) {
9695
return countlyGlobalLang.languages[context];
9796
});
9897

0 commit comments

Comments
 (0)