From 2553e819a826263409345218bdd1cd4f9397c99d Mon Sep 17 00:00:00 2001 From: Thomas Rueckstiess Date: Wed, 8 Jul 2015 16:09:04 +0200 Subject: [PATCH] adding back filterableMixin for FieldCollections also fixing a bug that caused the type bars to not adjust their widths after filter/unfilter. This makes PR #55 obsolete. Closes #55. --- package.json | 1 + src/field-list/type-list-item.js | 20 +++++++++++--------- src/models/sampled-schema.js | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 41ef0d0b976..f488414a0f0 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "dependencies": { "ampersand-app": "^1.0.4", "ampersand-collection": "^1.4.5", + "ampersand-collection-filterable": "^0.2.1", "ampersand-collection-lodash-mixin": "^2.0.1", "ampersand-collection-rest-mixin": "^4.2.0", "ampersand-model": "^5.0.3", diff --git a/src/field-list/type-list-item.js b/src/field-list/type-list-item.js index bfe0f7f7d77..b3d1e334d3d 100644 --- a/src/field-list/type-list-item.js +++ b/src/field-list/type-list-item.js @@ -6,6 +6,7 @@ var tooltipMixin = require('../tooltip-mixin'); var $ = require('jquery'); module.exports = View.extend(tooltipMixin, { + template: require('./type-list-item.jade'), namespace: 'TypeListItem', bindings: { 'model.name': [ @@ -24,16 +25,16 @@ module.exports = View.extend(tooltipMixin, { 'click .schema-field-wrapper': 'typeClicked' }, initialize: function() { - this.listenTo(this.model, 'change:count', _.debounce(function() { - this.tooltip({ - title: format('%s (%s)', this.model.getId(), numeral(this.model.probability).format('%')) - }); - $(this.queryByHook('bar')).css({ - width: Math.floor(this.model.probability * 100) + '%' - }); - }.bind(this), 300)); + this.listenTo(this.model, 'change:probability', _.debounce(this.update.bind(this), 300)); + }, + update: function() { + $(this.el).tooltip({ + title: format('%s (%s)', this.model.getId(), numeral(this.model.probability).format('%')) + }); + $(this.queryByHook('bar')).css({ + width: Math.floor(this.model.probability * 100) + '%' + }); }, - template: require('./type-list-item.jade'), typeClicked: function() { var fieldList = this.parent.parent; if (!fieldList.minichartModel || fieldList.minichartModel.modelType !== this.model.modelType) { @@ -42,6 +43,7 @@ module.exports = View.extend(tooltipMixin, { }, render: function() { this.renderWithTemplate(this); + this.update(); return this; } }); diff --git a/src/models/sampled-schema.js b/src/models/sampled-schema.js index f6529627a25..813d2347203 100644 --- a/src/models/sampled-schema.js +++ b/src/models/sampled-schema.js @@ -2,9 +2,24 @@ var _ = require('lodash'); var Schema = require('mongodb-schema').Schema; var wrapError = require('./wrap-error'); var app = require('ampersand-app'); +var FieldCollection = require('mongodb-schema').FieldCollection; +var filterableMixin = require('ampersand-collection-filterable'); + +/** + * wrapping mongodb-schema's FieldCollection with a filterable mixin + */ +var FilterableFieldCollection = FieldCollection.extend(filterableMixin, { + modelType: 'FilterableFieldCollection' +}); module.exports = Schema.extend({ namespace: 'SampledSchema', + /** + * Our fields need to be filterable, adding a mixin + */ + collections: { + fields: FilterableFieldCollection + }, /** * Clear any data accumulated from sampling. */