Loading comments/comments.js +35 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,41 @@ module.exports = (function(){ }); }, /** * Returns number of comments for each target in the current * domain. Excludes deleted comments. * * @param {Function} callback Called with the result. * @param {Object} callback.counts Map of targets to counts: * * { * "class__Ext__": 3, * "class__Ext__method-define": 1, * "class__Ext.Panel__cfg-title": 8 * } */ countsPerTarget: function(callback) { var sql = [ 'SELECT', ' type,', ' cls,', ' member,', ' count(*) AS count', 'FROM full_visible_comments', 'WHERE domain = ?', 'GROUP BY target_id' ]; this.query(sql, [this.domain], function(rows) { var map = {}; rows.forEach(function(r) { var id = [r.type, r.cls, r.member].join("__"); map[id] = +r.count; }); callback(map); }); }, query: function(sqlLines, params, callback) { this.db.query(sqlLines.join("\n"), params, function(err, rows) { if (err) throw err; Loading comments/comments.spec.js +7 −0 Original line number Diff line number Diff line Loading @@ -54,4 +54,11 @@ describe("Comments", function() { }); }); it("#countPerTarget gets number of comments for each target", function(done) { comments.countsPerTarget(function(counts) { expect(counts["class__Ext.grid.column.Column__cfg-renderer"]).toEqual(20); done(); }); }); }); Loading
comments/comments.js +35 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,41 @@ module.exports = (function(){ }); }, /** * Returns number of comments for each target in the current * domain. Excludes deleted comments. * * @param {Function} callback Called with the result. * @param {Object} callback.counts Map of targets to counts: * * { * "class__Ext__": 3, * "class__Ext__method-define": 1, * "class__Ext.Panel__cfg-title": 8 * } */ countsPerTarget: function(callback) { var sql = [ 'SELECT', ' type,', ' cls,', ' member,', ' count(*) AS count', 'FROM full_visible_comments', 'WHERE domain = ?', 'GROUP BY target_id' ]; this.query(sql, [this.domain], function(rows) { var map = {}; rows.forEach(function(r) { var id = [r.type, r.cls, r.member].join("__"); map[id] = +r.count; }); callback(map); }); }, query: function(sqlLines, params, callback) { this.db.query(sqlLines.join("\n"), params, function(err, rows) { if (err) throw err; Loading
comments/comments.spec.js +7 −0 Original line number Diff line number Diff line Loading @@ -54,4 +54,11 @@ describe("Comments", function() { }); }); it("#countPerTarget gets number of comments for each target", function(done) { comments.countsPerTarget(function(counts) { expect(counts["class__Ext.grid.column.Column__cfg-renderer"]).toEqual(20); done(); }); }); });