Skip to content

Commit 48742c8

Browse files
committed
Merge pull request #49 from 10gen/INT-203-arrays
INT-203 - arrays as types
2 parents ab5ef70 + 2538ccf commit 48742c8

22 files changed

+418
-137
lines changed

scout-ui/gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ gulp.task('testserver', function() {
7171
});
7272

7373
gulp.task('develop', ['pages', 'assets', 'less'], function() {
74-
gulp.watch(['src/{*,**/*}.less', '../scout-style/*.less'], ['less']);
74+
gulp.watch(['src/{*,**}.less', '../scout-style/*.less'], ['less']);
7575
gulp.watch(['src/*.jade'], ['pages']);
7676
gulp.watch(['src/img/*', '../scout-style/images/*'], ['assets']);
7777

scout-ui/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"ampersand-view-switcher": "^2.0.0",
5050
"bootstrap": "https://github.com/twbs/bootstrap/archive/v3.3.2.tar.gz",
5151
"d3": "^3.5.5",
52-
"d3-tip": "^0.6.7",
5352
"debug": "^2.0.0",
5453
"domready": "^1.0.7",
5554
"event-stream": "^3.3.0",
@@ -61,7 +60,7 @@
6160
"lodash": "^3.8.0",
6261
"moment": "^2.8.2",
6362
"mongodb-extended-json": "^1.3.1",
64-
"mongodb-schema": "^2.2.1",
63+
"mongodb-schema": "git://github.com/mongodb-js/mongodb-schema.git#INT-203-arrays",
6564
"numeral": "^1.5.3",
6665
"octicons": "https://github.com/github/octicons/archive/v2.2.0.tar.gz",
6766
"phantomjs-polyfill": "0.0.1",

scout-ui/src/collection-stats/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var numeral = require('numeral');
33

44
var CollectionStatsView = AmpersandView.extend({
55
bindings: {
6-
'model._id': {
6+
'model.name': {
77
hook: 'name'
88
},
99
document_count: {

scout-ui/src/field-list/array-field.jade

Lines changed: 0 additions & 7 deletions
This file was deleted.

scout-ui/src/field-list/basic-field.jade

Lines changed: 0 additions & 8 deletions
This file was deleted.

scout-ui/src/field-list/field.jade

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.schema-field.schema-field-basic
2+
hr.field-divider
3+
.row
4+
.col-sm-4
5+
.schema-field-name
6+
span(data-hook='caret')
7+
span(data-hook='name')
8+
div(data-hook='types-subview')
9+
.col-sm-7.col-sm-offset-1
10+
div(data-hook='minichart-container')
11+
div(data-hook='fields-subview')
12+
div(data-hook='arrayfields-subview')

scout-ui/src/field-list/index.js

Lines changed: 65 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,90 @@ var TypeListView = require('./type-list');
33
var MinichartView = require('../minicharts');
44
var FieldCollection = require('mongodb-schema').FieldCollection;
55
var ViewSwitcher = require('ampersand-view-switcher');
6+
var debug = require('debug')('scout-ui:field-list:index');
7+
var $ = require('jquery');
68
var _ = require('lodash');
79

8-
var BasicFieldView = View.extend({
10+
function handleCaret(el, value, previousValue) {
11+
var $el = $(el);
12+
// only apply to own caret, not children carets
13+
if ($el.next().text() !== this.model.name) return;
14+
if (this.model.fields || this.model.arrayFields) {
15+
$el.addClass('caret');
16+
} else {
17+
$el.removeClass('caret');
18+
}
19+
}
20+
21+
var FieldView = View.extend({
922
props: {
10-
minichartModel: 'state'
23+
minichartModel: 'state',
24+
expanded: {
25+
type: 'boolean',
26+
default: false
27+
}
1128
},
1229
bindings: {
13-
'model.name': [
14-
{
15-
hook: 'name'
16-
},
17-
{
18-
hook: 'name',
19-
type: function(el) {
20-
if (this.model.getId() === '__basic__') {
21-
el.classList.add('hidden');
22-
}
23-
}
24-
}
25-
]
30+
'model.name': {
31+
hook: 'name'
32+
},
33+
'model.fields': {
34+
type: handleCaret,
35+
hook: 'caret'
36+
},
37+
'model.arrayFields': {
38+
type: handleCaret,
39+
hook: 'caret'
40+
},
41+
'expanded': {
42+
type: 'booleanClass',
43+
yes: 'expanded',
44+
no: 'collapsed'
45+
}
2646
},
27-
template: require('./basic-field.jade'),
47+
events: {
48+
'click .schema-field-name': 'click',
49+
},
50+
template: require('./field.jade'),
2851
subviews: {
2952
types: {
30-
hook: 'types-container',
53+
hook: 'types-subview',
3154
prepareView: function(el) {
3255
return new TypeListView({
3356
el: el,
3457
parent: this,
3558
collection: this.model.types
3659
});
3760
}
61+
},
62+
fields: {
63+
hook: 'fields-subview',
64+
waitFor: 'model.fields',
65+
prepareView: function(el) {
66+
return new FieldListView({
67+
el: el,
68+
parent: this,
69+
collection: this.model.fields
70+
});
71+
}
72+
},
73+
arrayFields: {
74+
hook: 'arrayfields-subview',
75+
waitFor: 'model.arrayFields',
76+
prepareView: function(el) {
77+
return new FieldListView({
78+
el: el,
79+
parent: this,
80+
collection: this.model.arrayFields
81+
});
82+
}
3883
}
3984
},
4085
initialize: function() {
4186
var that = this;
4287
// debounce prevents excessive rendering
43-
this.model.values.on('add', _.debounce(function(evt) {
44-
// for now pick first type, @todo: make the type bars clickable and toggle chart
88+
this.model.on('change:count', _.debounce(function() {
89+
// pick first type initially
4590
that.switchView(that.model.types.at(0));
4691
}, 300));
4792
},
@@ -63,28 +108,6 @@ var BasicFieldView = View.extend({
63108
model: typeModel,
64109
});
65110
this.viewSwitcher.set(miniview);
66-
}
67-
});
68-
69-
var ExpandableFieldMixin = {
70-
bindings: {
71-
'model.name': {
72-
hook: 'name'
73-
},
74-
'expanded': {
75-
type: 'booleanClass',
76-
yes: 'expanded',
77-
no: 'collapsed'
78-
}
79-
},
80-
events: {
81-
'click .schema-field-name': 'click',
82-
},
83-
props: {
84-
expanded: {
85-
type: 'boolean',
86-
default: false
87-
}
88111
},
89112
click: function(evt) {
90113
// @todo: persist state of open nodes
@@ -93,27 +116,7 @@ var ExpandableFieldMixin = {
93116
evt.preventDefault();
94117
evt.stopPropagation();
95118
return false;
96-
},
97-
subviews: {
98-
fields: {
99-
hook: 'fields-container',
100-
prepareView: function(el) {
101-
return new FieldListView({
102-
el: el,
103-
parent: this,
104-
collection: this.model.fields
105-
});
106-
}
107-
}
108119
}
109-
};
110-
111-
var EmbeddedArrayFieldView = View.extend(ExpandableFieldMixin, {
112-
template: require('./array-field.jade')
113-
});
114-
115-
var EmbeddedDocumentFieldView = View.extend(ExpandableFieldMixin, {
116-
template: require('./object-field.jade')
117120
});
118121

119122
var FieldListView = View.extend({
@@ -123,16 +126,7 @@ var FieldListView = View.extend({
123126
template: require('./index.jade'),
124127
render: function() {
125128
this.renderWithTemplate();
126-
this.renderCollection(this.collection, function(options) {
127-
var type = options.model.type;
128-
if (type === 'Array') {
129-
return new EmbeddedArrayFieldView(options);
130-
}
131-
if (type === 'Object') {
132-
return new EmbeddedDocumentFieldView(options);
133-
}
134-
return new BasicFieldView(options);
135-
}, this.queryByHook('fields'));
129+
this.renderCollection(this.collection, FieldView, this.queryByHook('fields'));
136130
}
137131
});
138132

scout-ui/src/field-list/object-field.jade

Lines changed: 0 additions & 7 deletions
This file was deleted.

scout-ui/src/field-list/type-list-item.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ module.exports = AmpersandView.extend({
4242
}
4343
},
4444
initialize: function() {
45-
this.listenTo(this.model, 'change:probability', _.debounce(function() {
45+
this.listenTo(this.model, 'change:count', _.debounce(function() {
4646
$(this.el).tooltip({
4747
title: format('%s (%s)', this.model.getId(), numeral(this.model.probability).format('%'))
4848
});
4949
}.bind(this), 300));
5050
},
5151
template: require('./type-list-item.jade'),
5252
typeClicked: function() {
53-
if (this.parent.parent.minichartModel.cid !== this.model.cid) {
54-
this.parent.parent.switchView(this.model);
53+
var fieldList = this.parent.parent;
54+
if (!fieldList.minichartModel || (fieldList.minichartModel.modelType !== this.model.modelType)) {
55+
fieldList.switchView(this.model);
5556
}
5657
}
5758

scout-ui/src/field-list/type-list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ module.exports = AmpersandView.extend({
55
template: require('./type-list.jade'),
66
render: function() {
77
this.renderWithTemplate({});
8-
this.renderCollection(this.collection, TypeListItem, this.queryByHook('types'));
8+
this.renderCollection(this.collection.sort(), TypeListItem, this.queryByHook('types'));
99
}
1010
});

0 commit comments

Comments
 (0)