Some cruft fixing and configuring of Galaxy.debug output instead of commented out console.logs -- should help immensely for troubleshooting

This commit is contained in:
Dannon Baker
2017-09-13 15:04:28 -04:00
parent 4f93f88f0a
commit 1502e00675
8 changed files with 17 additions and 19 deletions
@@ -30,7 +30,7 @@ var ControlledFetchCollection = Backbone.Collection.extend({
*/
fetch : function( options ){
options = this._buildFetchOptions( options );
// console.log( 'fetch options:', options );
Galaxy.debug( 'fetch options:', options );
return Backbone.Collection.prototype.fetch.call( this, options );
},
@@ -52,15 +52,15 @@ var ControlledFetchCollection = Backbone.Collection.extend({
// (i.e. this.on( 'sync', function( options ){ if( options.limit ){ ... } }))
// however, when we send to xhr/jquery we copy them to data also so that they become API query params
options.data = options.data || self._buildFetchData( options );
// console.log( 'data:', options.data );
Galaxy.debug( 'data:', options.data );
// options.data.filters --> options.data.q, options.data.qv
var filters = this._buildFetchFilters( options );
// console.log( 'filters:', filters );
Galaxy.debug( 'filters:', filters );
if( !_.isEmpty( filters ) ){
_.extend( options.data, this._fetchFiltersToAjaxData( filters ) );
}
// console.log( 'data:', options.data );
Galaxy.debug( 'data:', options.data );
return options;
},
@@ -140,7 +140,6 @@ var ControlledFetchCollection = Backbone.Collection.extend({
// if( _.isUndefined( comparator ) ){ return; }
if( comparator === collection.comparator ){ return; }
var oldOrder = collection.order;
collection.order = order;
collection.comparator = comparator;
@@ -256,7 +255,7 @@ var InfinitelyScrollingCollection = ControlledFetchCollection.extend({
/** fetch the first 'page' of data */
fetchFirst : function( options ){
// console.log( 'ControlledFetchCollection.fetchFirst:', options );
Galaxy.debug( 'ControlledFetchCollection.fetchFirst:', options );
options = options? _.clone( options ) : {};
this.allFetched = false;
this.lastFetched = 0;
@@ -268,11 +267,11 @@ var InfinitelyScrollingCollection = ControlledFetchCollection.extend({
/** fetch the next page of data */
fetchMore : function( options ){
// console.log( 'ControlledFetchCollection.fetchMore:', options );
Galaxy.debug( 'ControlledFetchCollection.fetchMore:', options );
options = _.clone( options || {} );
var collection = this;
// console.log( 'fetchMore, options.reset:', options.reset );
Galaxy.debug( 'fetchMore, options.reset:', options.reset );
if( ( !options.reset && collection.allFetched ) ){
return jQuery.when();
}
@@ -285,7 +284,7 @@ var InfinitelyScrollingCollection = ControlledFetchCollection.extend({
options.offset = collection.lastFetched;
}
var limit = options.limit = options.limit || collection.limitPerFetch || null;
// console.log( 'fetchMore, limit:', limit, 'offset:', options.offset );
Galaxy.debug( 'fetchMore, limit:', limit, 'offset:', options.offset );
collection.trigger( 'fetching-more' );
return collection.fetch( options )
@@ -296,7 +295,7 @@ var InfinitelyScrollingCollection = ControlledFetchCollection.extend({
.done( function _postFetchMore( fetchedData ){
var numFetched = _.isArray( fetchedData )? fetchedData.length : 0;
collection.lastFetched += numFetched;
// console.log( 'fetchMore, lastFetched:', collection.lastFetched );
Galaxy.debug( 'fetchMore, lastFetched:', collection.lastFetched );
// anything less than a full page means we got all there is to get
if( !limit || numFetched < limit ){
collection.allFetched = true;
@@ -314,7 +313,7 @@ var InfinitelyScrollingCollection = ControlledFetchCollection.extend({
var self = this;
options = _.pick( options, 'silent' );
options.filters = {};
return self.fetch( options ).done( function( fetchData ){
return self.fetch( options ).done( function( ){
self.allFetched = true;
self.trigger( 'all-fetched', self );
});
@@ -1,4 +1,3 @@
define([
"mvc/history/history-contents",
"mvc/history/history-preferences",
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,2 +1,2 @@
define(["libs/underscore","libs/backbone","mvc/base-mvc"],function(a,b,c){"use strict";var d=b.Collection.extend({initialize:function(a,c){b.Collection.prototype.initialize.call(this,a,c),this.setOrder(c.order||this.order,{silent:!0})},_setUpListeners:function(){return this.on({"changed-order":this.sort})},fetch:function(a){return a=this._buildFetchOptions(a),b.Collection.prototype.fetch.call(this,a)},_buildFetchOptions:function(b){b=a.clone(b)||{};var c=this;b.traditional=!0,b.data=b.data||c._buildFetchData(b);var d=this._buildFetchFilters(b);return a.isEmpty(d)||a.extend(b.data,this._fetchFiltersToAjaxData(d)),b},_buildFetchData:function(b){var c={};return this.order&&(c.order=this.order),a.defaults(a.pick(b,this._fetchParams),c)},_fetchParams:["order","limit","offset","view","keys"],_buildFetchFilters:function(b){return a.clone(b.filters||{})},_fetchFiltersToAjaxData:function(b){var c={q:[],qv:[]};return a.each(b,function(a,b){void 0!==a&&""!==a&&(a===!0&&(a="True"),a===!1&&(a="False"),null===a&&(a="None"),c.q.push(b),c.qv.push(a))}),c},reset:function(a,c){return this.allFetched=!1,b.Collection.prototype.reset.call(this,a,c)},order:null,comparators:{update_time:c.buildComparator("update_time",{ascending:!1}),"update_time-asc":c.buildComparator("update_time",{ascending:!0}),create_time:c.buildComparator("create_time",{ascending:!1}),"create_time-asc":c.buildComparator("create_time",{ascending:!0})},setOrder:function(b,c){c=c||{};var d=this,e=d.comparators[b];if(a.isUndefined(e))throw new Error("unknown order: "+b);if(e!==d.comparator){{d.order}return d.order=b,d.comparator=e,c.silent||d.trigger("changed-order",c),d}}}),e=d.extend({limitPerPage:500,initialize:function(a,b){d.prototype.initialize.call(this,a,b),this.currentPage=b.currentPage||0},getTotalItemCount:function(){return this.length},shouldPaginate:function(){return this.getTotalItemCount()>=this.limitPerPage},getLastPage:function(){return Math.floor(this.getTotalItemCount()/this.limitPerPage)},getPageCount:function(){return this.getLastPage()+1},getPageLimitOffset:function(a){return a=this.constrainPageNum(a),{limit:this.limitPerPage,offset:a*this.limitPerPage}},constrainPageNum:function(a){return Math.max(0,Math.min(a,this.getLastPage()))},fetchPage:function(b,c){var d=this;return b=d.constrainPageNum(b),d.currentPage=b,c=a.defaults(c||{},d.getPageLimitOffset(b)),d.trigger("fetching-more"),d.fetch(c).always(function(){d.trigger("fetching-more-done")})},fetchCurrentPage:function(a){return this.fetchPage(this.currentPage,a)},fetchPrevPage:function(a){return this.fetchPage(this.currentPage-1,a)},fetchNextPage:function(a){return this.fetchPage(this.currentPage+1,a)}}),f=d.extend({limitOnFirstFetch:null,limitPerFetch:100,initialize:function(a,b){d.prototype.initialize.call(this,a,b),this.limitOnFirstFetch=b.limitOnFirstFetch||this.limitOnFirstFetch,this.limitPerFetch=b.limitPerFetch||this.limitPerFetch,this.allFetched=!1,this.lastFetched=b.lastFetched||0},_buildFetchOptions:function(a){return a.remove=a.remove||!1,d.prototype._buildFetchOptions.call(this,a)},fetchFirst:function(b){return b=b?a.clone(b):{},this.allFetched=!1,this.lastFetched=0,this.fetchMore(a.defaults(b,{reset:!0,limit:this.limitOnFirstFetch}))},fetchMore:function(b){b=a.clone(b||{});var c=this;if(!b.reset&&c.allFetched)return jQuery.when();b.reset?b.offset=0:void 0===b.offset&&(b.offset=c.lastFetched);var d=b.limit=b.limit||c.limitPerFetch||null;return c.trigger("fetching-more"),c.fetch(b).always(function(){c.trigger("fetching-more-done")}).done(function(b){var e=a.isArray(b)?b.length:0;c.lastFetched+=e,(!d||d>e)&&(c.allFetched=!0,c.trigger("all-fetched",this))})},fetchAll:function(b){b=b||{};var c=this;return b=a.pick(b,"silent"),b.filters={},c.fetch(b).done(function(){c.allFetched=!0,c.trigger("all-fetched",c)})}});return{ControlledFetchCollection:d,PaginatedCollection:e,InfinitelyScrollingCollection:f}});
define(["libs/underscore","libs/backbone","mvc/base-mvc"],function(a,b,c){"use strict";var d=b.Collection.extend({initialize:function(a,c){b.Collection.prototype.initialize.call(this,a,c),this.setOrder(c.order||this.order,{silent:!0})},_setUpListeners:function(){return this.on({"changed-order":this.sort})},fetch:function(a){return a=this._buildFetchOptions(a),Galaxy.debug("fetch options:",a),b.Collection.prototype.fetch.call(this,a)},_buildFetchOptions:function(b){b=a.clone(b)||{};var c=this;b.traditional=!0,b.data=b.data||c._buildFetchData(b),Galaxy.debug("data:",b.data);var d=this._buildFetchFilters(b);return Galaxy.debug("filters:",d),a.isEmpty(d)||a.extend(b.data,this._fetchFiltersToAjaxData(d)),Galaxy.debug("data:",b.data),b},_buildFetchData:function(b){var c={};return this.order&&(c.order=this.order),a.defaults(a.pick(b,this._fetchParams),c)},_fetchParams:["order","limit","offset","view","keys"],_buildFetchFilters:function(b){return a.clone(b.filters||{})},_fetchFiltersToAjaxData:function(b){var c={q:[],qv:[]};return a.each(b,function(a,b){void 0!==a&&""!==a&&(a===!0&&(a="True"),a===!1&&(a="False"),null===a&&(a="None"),c.q.push(b),c.qv.push(a))}),c},reset:function(a,c){return this.allFetched=!1,b.Collection.prototype.reset.call(this,a,c)},order:null,comparators:{update_time:c.buildComparator("update_time",{ascending:!1}),"update_time-asc":c.buildComparator("update_time",{ascending:!0}),create_time:c.buildComparator("create_time",{ascending:!1}),"create_time-asc":c.buildComparator("create_time",{ascending:!0})},setOrder:function(b,c){c=c||{};var d=this,e=d.comparators[b];if(a.isUndefined(e))throw new Error("unknown order: "+b);return e!==d.comparator?(d.order=b,d.comparator=e,c.silent||d.trigger("changed-order",c),d):void 0}}),e=d.extend({limitPerPage:500,initialize:function(a,b){d.prototype.initialize.call(this,a,b),this.currentPage=b.currentPage||0},getTotalItemCount:function(){return this.length},shouldPaginate:function(){return this.getTotalItemCount()>=this.limitPerPage},getLastPage:function(){return Math.floor(this.getTotalItemCount()/this.limitPerPage)},getPageCount:function(){return this.getLastPage()+1},getPageLimitOffset:function(a){return a=this.constrainPageNum(a),{limit:this.limitPerPage,offset:a*this.limitPerPage}},constrainPageNum:function(a){return Math.max(0,Math.min(a,this.getLastPage()))},fetchPage:function(b,c){var d=this;return b=d.constrainPageNum(b),d.currentPage=b,c=a.defaults(c||{},d.getPageLimitOffset(b)),d.trigger("fetching-more"),d.fetch(c).always(function(){d.trigger("fetching-more-done")})},fetchCurrentPage:function(a){return this.fetchPage(this.currentPage,a)},fetchPrevPage:function(a){return this.fetchPage(this.currentPage-1,a)},fetchNextPage:function(a){return this.fetchPage(this.currentPage+1,a)}}),f=d.extend({limitOnFirstFetch:null,limitPerFetch:100,initialize:function(a,b){d.prototype.initialize.call(this,a,b),this.limitOnFirstFetch=b.limitOnFirstFetch||this.limitOnFirstFetch,this.limitPerFetch=b.limitPerFetch||this.limitPerFetch,this.allFetched=!1,this.lastFetched=b.lastFetched||0},_buildFetchOptions:function(a){return a.remove=a.remove||!1,d.prototype._buildFetchOptions.call(this,a)},fetchFirst:function(b){return Galaxy.debug("ControlledFetchCollection.fetchFirst:",b),b=b?a.clone(b):{},this.allFetched=!1,this.lastFetched=0,this.fetchMore(a.defaults(b,{reset:!0,limit:this.limitOnFirstFetch}))},fetchMore:function(b){Galaxy.debug("ControlledFetchCollection.fetchMore:",b),b=a.clone(b||{});var c=this;if(Galaxy.debug("fetchMore, options.reset:",b.reset),!b.reset&&c.allFetched)return jQuery.when();b.reset?b.offset=0:void 0===b.offset&&(b.offset=c.lastFetched);var d=b.limit=b.limit||c.limitPerFetch||null;return Galaxy.debug("fetchMore, limit:",d,"offset:",b.offset),c.trigger("fetching-more"),c.fetch(b).always(function(){c.trigger("fetching-more-done")}).done(function(b){var e=a.isArray(b)?b.length:0;c.lastFetched+=e,Galaxy.debug("fetchMore, lastFetched:",c.lastFetched),(!d||d>e)&&(c.allFetched=!0,c.trigger("all-fetched",this))})},fetchAll:function(b){b=b||{};var c=this;return b=a.pick(b,"silent"),b.filters={},c.fetch(b).done(function(){c.allFetched=!0,c.trigger("all-fetched",c)})}});return{ControlledFetchCollection:d,PaginatedCollection:e,InfinitelyScrollingCollection:f}});
//# sourceMappingURL=../../../maps/mvc/base/controlled-fetch-collection.js.map