Skip to content
1 change: 1 addition & 0 deletions scout-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"jquery": "^2.1.1",
"lodash": "^3.8.0",
"moment": "^2.8.2",
"mongodb-extended-json": "^1.3.1",
"mongodb-schema": "^2.1.0",
"numeral": "^1.5.3",
"octicons": "https://github.com/github/octicons/archive/v2.2.0.tar.gz",
Expand Down
12 changes: 8 additions & 4 deletions scout-ui/src/home/collection.jade
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
.collection-view
.header
h3(data-hook='name')
div(data-hook='stats-subview')
.container-fluid
h3(data-hook='name')
.row
.col-md-12
div(data-hook='stats-subview')
.row
.col-md-12
div(data-hook='refine-bar')
.column-container
.column.main
div(data-hook='fields-subview')
.column.side
.splitter
i.fa.fa-lg.fa-rotate-90.fa-sort
div(data-hook='documents-subview')


42 changes: 30 additions & 12 deletions scout-ui/src/home/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var AmpersandView = require('ampersand-view');
var CollectionStatsView = require('../collection-stats');
var FieldListView = require('../field-list');
var DocumentListView = require('../document-view');
var RefineBarView = require('../refine-view');

var debug = require('debug')('scout-ui:home:collection');
var $ = require('jquery');

Expand Down Expand Up @@ -46,8 +48,14 @@ module.exports = AmpersandView.extend({

this.schema.ns = this.model._id;
this.listenTo(this.schema, 'error', this.onError);

this.schema.fetch();
this.model.fetch();

this.listenTo(app.queryOptions, 'change', this.onQueryChanged);
},
onQueryChanged: function() {
this.schema.refine(app.queryOptions.serialize());
},
onSplitterClick: function() {
this.toggle('open');
Expand All @@ -61,32 +69,42 @@ module.exports = AmpersandView.extend({
hook: 'stats-subview',
prepareView: function(el) {
return new CollectionStatsView({
el: el,
parent: this,
model: this.model
});
el: el,
parent: this,
model: this.model
});
}
},
fields: {
waitFor: 'schema.fields',
hook: 'fields-subview',
prepareView: function(el) {
return new FieldListView({
el: el,
parent: this,
collection: this.schema.fields
});
el: el,
parent: this,
collection: this.schema.fields
});
}
},
refinebar: {
hook: 'refine-bar',
prepareView: function(el) {
return new RefineBarView({
el: el,
parent: this,
model: app.queryOptions
});
}
},
documents: {
waitFor: 'model.documents',
hook: 'documents-subview',
prepareView: function(el) {
return new DocumentListView({
el: el,
parent: this,
collection: this.model.documents
});
el: el,
parent: this,
collection: this.model.documents
});
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion scout-ui/src/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var debug = require('debug')('scout-ui:home');
var app = require('ampersand-app');
var format = require('util').format;
var SidebarView = require('../sidebar');
var FieldListView = require('../field-list');
var CollectionView = require('./collection');

require('bootstrap/js/dropdown');
Expand Down Expand Up @@ -38,7 +39,7 @@ module.exports = AmpersandView.extend({
this.showCollection(current);
});

this.listenTo(this, 'change:rendered', this.onRendered);
this.once('change:rendered', this.onRendered);
this.model.fetch();
},
onRendered: function() {
Expand Down
8 changes: 5 additions & 3 deletions scout-ui/src/home/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,23 @@

.collection-view {

@header-height: 120px;

.header {
padding-left: 20px;
display: flex;
position: relative;
z-index: 10;
height: 100px;
height: @header-height;
}

.column-container {
padding-right: 20px;
display: flex;
overflow: hidden;
height: 100vh;
margin-top: -100px;
padding-top: 100px;
margin-top: -@header-height;
padding-top: @header-height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

position: relative;
width: 100%;
}
Expand Down
6 changes: 6 additions & 0 deletions scout-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var domReady = require('domready');
var ViewSwitcher = require('ampersand-view-switcher');
var qs = require('qs');
var Router = require('./router');
var QueryOptions = require('./models/query-options');

var PageContainer = AmpersandView.extend({
template: '<div id="application"><div class="page-container" data-hook="page-container"></div></div>',
Expand Down Expand Up @@ -48,12 +49,14 @@ var PageContainer = AmpersandView.extend({
});

var StatusbarView = require('./statusbar');

app.extend({
/**
* init URL handlers and the history tracker.
*/
router: new Router(),
statusbar: new StatusbarView(),
queryOptions: new QueryOptions(),
currentPage: null,
init: function() {
domReady(function() {
Expand Down Expand Up @@ -99,4 +102,7 @@ app.extend({
}
});

// for debugging purposes
window.app = app;

module.exports = app.init();
1 change: 1 addition & 0 deletions scout-ui/src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
// Components
@import "./src/home/index.less";
@import "./src/minicharts/index.less";
@import "./src/refine-view/index.less";
@import "./src/field-list/index.less";
@import "./src/object-tree/index.less";
87 changes: 65 additions & 22 deletions scout-ui/src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ var types = brain.types;
var _ = require('underscore');
var es = require('event-stream');
var Schema = require('mongodb-schema').Schema;
var QueryOptions = require('./query-options');

// Yay! Use the API from the devtools console.
window.scout = client;

// Handy debugging! Just type `data` in the devtools console to see the array
// of documents currently in the schema.
window.data = [];

// The currently active schema.
window.schema = null;

Expand All @@ -34,6 +31,52 @@ client.on('error', function(err) {
});

var SampledSchema = Schema.extend({
/**
* Clear any data accumulated from sampling.
*/
reset: function(options) {
this.fields.reset();
if (this.parent && this.parent.model && this.parent.model.documents) {
this.parent.model.documents.reset();
}
},
/**
* After you fetch an initial sample, next you'll want to drill-down to a
* smaller slice or drill back up to look at a larger slice.
*
* @example
* schema.fetch({});
* schema.refine({a: 1});
* schema.refine({a: 1, b: 1});
* schema.refine({a: 2});
*/
refine: function(options) {
this.reset();
this.fetch(options);
},
/**
* Take another sample on top of what you currently have.
*
* @example
* schema.fetch({limit: 100});
* // schema.documents.length is now 100
* schema.more({limit: 100});
* // schema.documents.length is now 200
* schema.more({limit: 10});
* // schema.documents.length is now 210
*/
more: function(options) {
this.fetch(options);
},
/**
* Get a sample of documents for a collection from the server.
* Really this should only be called directly from the `initialize` function
*
* @param {Object} [options]
* @option {Number} [size=100] Number of documents the sample should contain.
* @option {Object} [query={}]
* @option {Object} [fields=null]
*/
fetch: function(options) {
options = _.defaults((options || {}), {
size: 100,
Expand All @@ -44,37 +87,36 @@ var SampledSchema = Schema.extend({
wrapError(this, options);

var model = this;
var collection;
window.schema = this;

/**
* Collection of sampled documents someone else wants to keep track of.
*
* {@see scout-ui/src/home/collection.js#model}
* @todo (imlucas): Yes this is a crappy hack.
*/
var documents;
if (this.parent && this.parent.model && this.parent.model.documents) {
collection = this.parent.model.documents;
collection.reset();
documents = this.parent.model.documents;
}


window.schema = this;
window.data = [];
var parser = this.stream()
.on('error', function(err) {
options.error(err, 'error', err.message);
})
.on('data', function(doc) {
window.data.push(doc);
if (collection) {
collection.add(doc);
if (documents) {
documents.add(doc);
}
})
.on('end', function() {
process.nextTick(function() {
model.trigger('sync', model, model.serialize(), options);
});
model.trigger('sync', model, model.serialize(), options);
});

model.trigger('request', model, {}, options);
process.nextTick(function() {
client.sample(model.ns, options)
.on('error', parser.emit.bind(parser, 'error'))
.pipe(parser);
});
client.sample(model.ns, options)
.on('error', parser.emit.bind(parser, 'error'))
.pipe(parser);
}
});

Expand Down Expand Up @@ -163,5 +205,6 @@ module.exports = {
}
}, WithScout),
SampledDocumentCollection: SampledDocumentCollection,
SampledSchema: SampledSchema
SampledSchema: SampledSchema,
QueryOptions: QueryOptions
};
38 changes: 38 additions & 0 deletions scout-ui/src/models/query-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var AmpersandState = require('ampersand-state');
var app = require('ampersand-app');

module.exports = AmpersandState.extend({
props: {
query: {
type: 'object',
default: function() {
return {};
}
},
sort: {
type: 'object',
default: function() {
return {
'_id': -1
};
}
},
limit: {
type: 'number',
default: 10000,
},
skip: {
type: 'number',
default: 0
}
},
derived: {
queryString: {
deps: ['query'],
fn: function() {
return JSON.stringify(this.query);
}
}
}
});

6 changes: 6 additions & 0 deletions scout-ui/src/refine-view/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.refine-view-container
form
.input-group(data-hook='refine-input-group')
input#refineInput.form-control(type='text', data-hook='refine-input')
span.input-group-btn
button.btn.btn-default(type='button', data-hook='refine-button') Refine
Loading