Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Add manual distinct count button
Browse files Browse the repository at this point in the history
Address #759

Signed-off-by: Jeffrey Miller <jeffmax@gmail.com>
  • Loading branch information
jeffmax committed Jan 22, 2015
1 parent e25b4fb commit e8efaad
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/js/cilantro/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ define([
* concept names, operators and values to make filters more readable.
*/
styleFilters: false,

/*
* Automatically refresh count statistics for context when filters
* change.
*/
distinctCountAutoRefresh: true,

/*
* Timeouts
Expand Down
27 changes: 20 additions & 7 deletions src/js/cilantro/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,24 @@ define([

this.listenTo(this.parent, 'request', this.onParentRequest);
this.listenTo(this.parent, 'sync', this.onParentSync);
},

if (this.parent.collection) {
this.listenTo(this.parent.collection, 'reset', this.onParentReset);
onParentRequest: function() {
// if the parent make a request and we are
// waiting for a stat response, it will be
// stale when it arrives
if (this.xhr) {
this.xhr.abort();
this.xhr = null;
}
},

onParentRequest: function() {},

onParentReset: function() {
this.fetch();
this.xhr = this.fetch();
},

onParentSync: function() {
this.fetch();
this.xhr = this.fetch();
},

url: function() {
Expand All @@ -116,6 +120,11 @@ define([
else {
throw new Error('Stat supported model has no stats URL defined.');
}
},

manualFetch: function() {
this.xhr = this.fetch();
return this.xhr;
}
});

Expand All @@ -127,9 +136,13 @@ define([
throw new Error('statModel must be defined');
}

this.stats = new this.statModel({parent: this});

Model.prototype.constructor.call(this, attrs, options);

this.stats = new this.statModel({parent: this});
if (this.collection) {
this.stats.listenTo(this.collection, 'reset', this.stats.onParentReset);
}
}
});

Expand Down
4 changes: 4 additions & 0 deletions src/js/cilantro/models/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ define([
});

this.on('sync', this.onSync);

if (!c.config.get('distinctCountAutoRefresh')) {
this.stats.stopListening(this, 'sync');
}

// Define a debounced save method for handling rapid successions
// of [un]apply events.
Expand Down
31 changes: 27 additions & 4 deletions src/js/cilantro/ui/context/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ define([
removeAll: '[data-action=remove]',
count: '[data-target=count]',
units: '[data-target=units]',
loading: '[data-target=loading-message]'
loading: '[data-target=loading-message]',
refresh: '[data-action=refresh]'
},

events: {
'click @ui.removeAll': 'clickRemoveAll'
'click @ui.removeAll': 'clickRemoveAll',
'click @ui.refresh': 'refreshCount'
},

modelEvents: {
'request': 'showLoad'
'request': 'showLoad',
'sync': 'enableRefreshButton',
'change': 'disableRefreshButton'
},

collectionEvents: {
Expand All @@ -41,6 +45,8 @@ define([
attrs.prettyCount = c.utils.prettyNumber(
attrs.count, c.config.get('threshold'));

attrs.showDistinctButton = !c.config.get('distinctCountAutoRefresh');

return attrs;
},

Expand All @@ -55,7 +61,9 @@ define([
showLoad: function() {
this.ui.count.hide();
this.ui.units.hide();
this.ui.loading.show();
if (c.config.get('distinctCountAutoRefresh')) {
this.ui.loading.show();
}
},

showCount: function() {
Expand All @@ -64,6 +72,15 @@ define([
this.ui.loading.hide();
this.render();
},

enableRefreshButton: function() {
this.ui.refresh.removeProp('disabled');
},

disableRefreshButton: function() {
this.ui.refresh.prop('disabled', true);
this.ui.loading.hide();
},

renderRemoveAll: function() {
// Required filters cannot be removed, so filter them out
Expand All @@ -72,6 +89,12 @@ define([
});

this.ui.removeAll.prop('disabled', !models.length);
},

refreshCount:function(){
this.model.stats.manualFetch();
this.ui.refresh.prop('disabled', true);
this.ui.loading.show();
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/templates/context/actions.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class=pull-right>
<% if (data.showDistinctButton) { %>
<button data-action=refresh class='btn btn-info btn-mini' title='Retrieve Distinct Count' disabled><i class='icon-refresh icon-white'></i></button>
<% } %>
<button data-action=remove class='btn btn-danger btn-mini' title='Remove All Filters' disabled><i class='icon-remove icon-white'></i></button>
</div>

Expand Down

0 comments on commit e8efaad

Please sign in to comment.