Skip to content

Commit 179a30a

Browse files
committed
feature(ui): collection stats
everything wired up. collection-stats view has a hidden class so this will be executed for debugging, but its not quite pretty enough as we need to think about a better way to include stats other than just dumping them all in there.
1 parent 42c5c9a commit 179a30a

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
div.row.hidden
2+
.col-md-6
3+
dl.dl-horizontal
4+
dt # documents
5+
dd(data-hook='document_count')
6+
dt total document size
7+
dd(data-hook='document_size')
8+
dt average document size
9+
dd(data-hook='document_size_average')
10+
.col-md-6
11+
dl.dl-horizontal
12+
dt # indexes
13+
dd(data-hook='index_count')
14+
dt total index size
15+
dd(data-hook='index_size')
16+
dt average index size
17+
dd(data-hook='index_size_average')
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
var AmpersandView = require('ampersand-view');
2+
var numeral = require('numeral');
3+
4+
var CollectionStatsView = AmpersandView.extend({
5+
bindings: {
6+
'model._id': {
7+
hook: 'name'
8+
},
9+
document_count: {
10+
hook: 'document_count'
11+
},
12+
document_size: {
13+
hook: 'document_size'
14+
},
15+
document_size_average: {
16+
hook: 'document_size_average'
17+
},
18+
index_count: {
19+
hook: 'index_count'
20+
},
21+
index_size: {
22+
hook: 'index_size'
23+
},
24+
index_size_average: {
25+
hook: 'index_size_average'
26+
},
27+
},
28+
derived: {
29+
document_count: {
30+
deps: ['model.document_count'],
31+
fn: function() {
32+
return numeral(this.model.document_count).format('0.0a');
33+
}
34+
},
35+
document_size: {
36+
deps: ['model.document_size'],
37+
fn: function() {
38+
return numeral(this.model.document_size).format('0.0b');
39+
}
40+
},
41+
document_size_average: {
42+
deps: ['model.document_size_average'],
43+
fn: function() {
44+
return numeral(this.model.document_size_average).format('0.0b');
45+
}
46+
},
47+
index_count: {
48+
deps: ['model.index_count'],
49+
fn: function() {
50+
return numeral(this.model.index_count).format('0.0a');
51+
}
52+
},
53+
index_size: {
54+
deps: ['model.index_size'],
55+
fn: function() {
56+
return numeral(this.model.index_size).format('0.0b');
57+
}
58+
},
59+
index_size_average: {
60+
deps: ['model.index_size_average'],
61+
fn: function() {
62+
return numeral(this.model.index_size_average).format('0.0b');
63+
}
64+
}
65+
},
66+
template: require('./index.jade')
67+
});
68+
69+
module.exports = CollectionStatsView;

scout-ui/src/home/collection.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
.panel
33
.panel-heading
44
h3(data-hook='name')
5+
div(data-hook='stats-container')
56
.panel-body
67
div(data-hook='fields-container')

scout-ui/src/home/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var debug = require('debug')('scout-ui:home');
55
var app = require('ampersand-app');
66
var format = require('util').format;
77
var SidebarView = require('../sidebar');
8-
8+
var CollectionStatsView = require('../collection-stats');
99
var FieldListView = require('../field-list');
1010

1111
require('bootstrap/js/dropdown');
@@ -27,13 +27,24 @@ var CollectionView = AmpersandView.extend({
2727
this.schema.ns = this.model._id;
2828
this.listenTo(this.schema, 'error', this.onError);
2929
this.schema.fetch();
30+
this.model.fetch();
3031
},
3132
template: require('./collection.jade'),
3233
onError: function(schema, err) {
3334
// @todo: Figure out a good way to handle this (server is probably crashed).
3435
console.error('Error getting schema: ', err);
3536
},
3637
subviews: {
38+
stats: {
39+
hook: 'stats-container',
40+
prepareView: function(el) {
41+
return new CollectionStatsView({
42+
el: el,
43+
parent: this,
44+
model: this.model
45+
});
46+
}
47+
},
3748
fields: {
3849
waitFor: 'schema.fields',
3950
hook: 'fields-container',

scout-ui/src/models/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ var SampledSchema = Schema.extend({
4444
wrapError(this, options);
4545

4646
var model = this;
47+
var collection;
48+
if (this.parent && this.parent.model && this.parent.model.documents) {
49+
collection = this.parent.model.documents;
50+
collection.reset();
51+
}
52+
53+
4754
window.schema = this;
4855
window.data = [];
4956
var parser = this.stream()
@@ -52,6 +59,9 @@ var SampledSchema = Schema.extend({
5259
})
5360
.on('data', function(doc) {
5461
window.data.push(doc);
62+
if (collection) {
63+
collection.add(doc);
64+
}
5565
})
5666
.on('end', function() {
5767
process.nextTick(function() {
@@ -127,8 +137,11 @@ var Collection = core.Collection.extend({
127137
}
128138
}
129139
}
140+
},
141+
scout: function() {
142+
return client.collection.bind(client, this.getId());
130143
}
131-
});
144+
}, WithScout);
132145

133146
module.exports = {
134147
types: brain.types,
@@ -138,6 +151,7 @@ module.exports = {
138151
collections: core.CollectionCollection.extend(WithSelectable, {
139152
model: Collection,
140153
parse: function(res) {
154+
// Hide specialish namespaces (eg `local.*`, `*oplog*`) from sidebar.
141155
return res.filter(function(d) {
142156
return !types.ns(d._id).specialish;
143157
});

0 commit comments

Comments
 (0)