Skip to content

Commit c06aac1

Browse files
imlucaskangas
authored andcommitted
INT-371 Update sampling msg dynamically
1 parent 59de1e6 commit c06aac1

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"numeral": "^1.5.3",
8484
"octicons": "https://github.com/github/octicons/archive/v2.2.0.tar.gz",
8585
"phantomjs-polyfill": "0.0.1",
86+
"pluralize": "^1.1.2",
8687
"qs": "^3.1.0",
8788
"scout-brain": "http://bin.mongodb.org/js/scout-brain/v0.0.2/scout-brain-0.0.2.tar.gz",
8889
"scout-client": "http://bin.mongodb.org/js/scout-client/v0.0.3/scout-client-0.0.3.tar.gz",

src/home/collection.jade

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.collection-view
2-
.sampling-status
3-
span This report is based on a sample of 100 documents.
2+
.sampling-status(data-hook='sampling-message')
3+
span This report is based on a sample of <span data-hook="sample_size">100 documents</span>.
44
header
55
.row
66
.col-md-6

src/home/collection.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var DocumentListView = require('../document-view');
66
var RefineBarView = require('../refine-view');
77
var MongoDBCollection = require('../models/mongodb-collection');
88
var SampledSchema = require('../models/sampled-schema');
9+
var pluralize = require('pluralize');
10+
var format = require('util').format;
911

1012
module.exports = AmpersandView.extend({
1113
namespace: 'Collection',
@@ -30,6 +32,23 @@ module.exports = AmpersandView.extend({
3032
type: 'booleanClass',
3133
yes: 'sidebar-open',
3234
hook: 'json-sidebar-toggle-class'
35+
},
36+
sample_size: {
37+
hook: 'sample_size'
38+
},
39+
'schema.sample_size': {
40+
hook: 'sampling-message',
41+
type: 'booleanClass',
42+
no: 'hidden'
43+
}
44+
},
45+
derived: {
46+
sample_size: {
47+
deps: ['schema.sample_size'],
48+
fn: function() {
49+
return format('%d %s', this.schema.sample_size,
50+
pluralize('document', this.schema.sample_size));
51+
}
3352
}
3453
},
3554
children: {
@@ -41,6 +60,7 @@ module.exports = AmpersandView.extend({
4160

4261
this.schema.ns = this.model.getId();
4362
this.schema.fetch();
63+
4464
this.model.fetch();
4565

4666
this.listenTo(app.queryOptions, 'change', this.onQueryChanged);

src/models/sampled-schema.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ var FilterableFieldCollection = FieldCollection.extend(filterableMixin, {
1313
});
1414

1515
module.exports = Schema.extend({
16+
props: {
17+
sample_size: {
18+
type: 'number',
19+
default: 0
20+
}
21+
},
1622
namespace: 'SampledSchema',
1723
/**
1824
* Our fields need to be filterable, adding a mixin
@@ -24,6 +30,7 @@ module.exports = Schema.extend({
2430
* Clear any data accumulated from sampling.
2531
*/
2632
reset: function() {
33+
this.sample_size = 0;
2734
this.fields.reset();
2835
this.count = 0;
2936
if (this.parent && this.parent.model && this.parent.model.documents) {
@@ -97,6 +104,7 @@ module.exports = Schema.extend({
97104
options.error(err, 'error', err.message);
98105
})
99106
.on('data', function(doc) {
107+
model.sample_size += 1;
100108
if (documents) {
101109
documents.add(doc);
102110
}

0 commit comments

Comments
 (0)