Chromium Code Reviews| Index: chrome/browser/resources/history/history.js |
| diff --git a/chrome/browser/resources/history/history.js b/chrome/browser/resources/history/history.js |
| index 57532a0f1bbcf197de2ebf1130dec15ef7c9a1ad..3931919d291495c173639348de67ff1daf805b5e 100644 |
| --- a/chrome/browser/resources/history/history.js |
| +++ b/chrome/browser/resources/history/history.js |
| @@ -358,12 +358,14 @@ HistoryModel.prototype.reload = function() { |
| var search = this.searchText_; |
| var page = this.requestedPage_; |
| var range = this.rangeInDays_; |
| + var offset = this.offset_; |
| var groupByDomain = this.groupByDomain_; |
| this.clearModel_(); |
| this.searchText_ = search; |
| this.requestedPage_ = page; |
| this.rangeInDays_ = range; |
| + this.offset_ = offset; |
| this.groupByDomain_ = groupByDomain; |
| this.queryHistory_(); |
| }; |
| @@ -479,6 +481,22 @@ Object.defineProperty(HistoryModel.prototype, 'rangeInDays', { |
| } |
| }); |
| +/** |
| + * Getter and setter for HistoryModel.offset_. The offset moves the current |
| + * query 'window' |range| days behind. As such for range set to WEEK an offset |
| + * of 0 refers to the last 7 days, an offset of 1 refers to the 7 day period |
| + * that ended 7 days ago, etc. For MONTH an offset of 0 refers to the current |
| + * calendar month, 1 to the previous one, etc. |
| + */ |
| +Object.defineProperty(HistoryModel.prototype, 'offset', { |
| + get: function() { |
| + return this.offset_; |
| + }, |
| + set: function(offset) { |
| + this.offset_ = offset; |
| + } |
| +}); |
| + |
| // HistoryModel, Private: ----------------------------------------------------- |
| /** |
| @@ -500,6 +518,9 @@ HistoryModel.prototype.clearModel_ = function() { |
| // to fetch it and call back when we're done. |
| this.requestedPage_ = 0; |
| + // Skip |offset_| * weeks/months from the begining. |
| + this.offset_ = 0; |
| + |
| // The range of history to view or search over, WEEK by default. |
| this.rangeInDays_ = HistoryModel.Range.RECENT; |
| @@ -547,13 +568,15 @@ HistoryModel.prototype.updateSearch_ = function() { |
| * @private |
| */ |
| HistoryModel.prototype.queryHistory_ = function() { |
| - // Set the range to the values from the interface. |
| + // Set the range and offset to the values from the interface. |
| + var offset = this.offset_; |
| var range = this.rangeInDays_; |
| $('loading-spinner').hidden = false; |
| this.inFlight_ = true; |
| chrome.send('queryHistory', |
| - [this.searchText_, range, this.queryCursor_, this.getMaxResults()]); |
| + [this.searchText_, offset, range, this.queryCursor_, |
| + this.getMaxResults()]); |
| }; |
| /** |
| @@ -582,6 +605,7 @@ HistoryModel.prototype.canFillPage_ = function(page) { |
| */ |
| HistoryModel.prototype.setGroupByDomain = function(groupByDomain) { |
| this.groupByDomain_ = groupByDomain; |
| + this.offset_ = 0; |
| }; |
| /** |
| @@ -639,6 +663,16 @@ function HistoryView(model) { |
| $('display-filter-sites').addEventListener('click', function(e) { |
| self.setGroupByDomain($('display-filter-sites').checked); |
| }); |
| + |
| + $('range-previous').addEventListener('click', function(e) { |
| + self.setOffset(self.getOffset() + 1); |
| + }); |
| + $('range-next').addEventListener('click', function(e) { |
| + self.setOffset(self.getOffset() - 1); |
| + }); |
| + $('range-today').addEventListener('click', function(e) { |
| + self.setOffset(0); |
| + }); |
| } |
| // HistoryView, public: ------------------------------------------------------- |
| @@ -653,7 +687,7 @@ HistoryView.prototype.setSearch = function(term, opt_page) { |
| window.scrollTo(0, 0); |
| this.model_.setSearchText(term, this.pageIndex_); |
| pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(), |
| - this.getRangeInDays()); |
| + this.getRangeInDays(), this.getOffset()); |
| }; |
| /** |
| @@ -669,7 +703,8 @@ HistoryView.prototype.setGroupByDomain = function(groupedByDomain) { |
| pageState.setUIState(this.model_.getSearchText(), |
| this.pageIndex_, |
| this.model_.getGroupByDomain(), |
| - this.getRangeInDays()); |
| + this.getRangeInDays(), |
| + this.getOffset()); |
| }; |
| /** |
| @@ -692,7 +727,8 @@ HistoryView.prototype.setPage = function(page) { |
| pageState.setUIState(this.model_.getSearchText(), |
| this.pageIndex_, |
| this.model_.getGroupByDomain(), |
| - this.getRangeInDays()); |
| + this.getRangeInDays(), |
| + this.getOffset()); |
| }; |
| /** |
| @@ -707,12 +743,13 @@ HistoryView.prototype.getPage = function() { |
| * @param {string} range The number of days to which the range should be set. |
| */ |
| HistoryView.prototype.setRangeInDays = function(range) { |
| - // Set the range and reset the page |
| + // Set the range offset and reset the page |
| this.model_.rangeInDays = range; |
| + this.model_.offset = 0; |
| this.pageIndex_ = 0; |
| this.model_.reload(); |
| pageState.setUIState(this.model_.getSearchText(), this.pageIndex_, |
| - this.model_.getGroupByDomain(), range); |
| + this.model_.getGroupByDomain(), range, this.getOffset()); |
| }; |
| /** |
| @@ -724,6 +761,29 @@ HistoryView.prototype.getRangeInDays = function() { |
| }; |
| /** |
| + * Set the current offset for grouped results. |
| + * @param {number} offset Offset to set. |
| + */ |
| +HistoryView.prototype.setOffset = function(offset) { |
| + window.scrollTo(0, 0); |
|
Patrick Dubroy
2013/01/30 23:25:33
I'm having deja vu...I swear I wrote this comment
|
| + this.model_.offset = offset; |
| + this.model_.reload(); |
| + pageState.setUIState(this.model_.getSearchText(), |
| + this.pageIndex_, |
| + this.model_.getGroupByDomain(), |
| + this.getRangeInDays(), |
| + this.getOffset()); |
| +}; |
| + |
| +/** |
| + * Get the current offset. |
| + * @return {number} Current offset from the model. |
| + */ |
| +HistoryView.prototype.getOffset = function() { |
| + return this.model_.offset; |
| +}; |
| + |
| +/** |
| * Callback for the history model to let it know that it has data ready for us |
| * to view. |
| */ |
| @@ -814,6 +874,30 @@ HistoryView.prototype.getGroupedVisitsDOM_ = function( |
| }; |
| /** |
| + * Enables or disables the time range buttons. |
| + * @private |
| + */ |
| +HistoryView.prototype.setRangeButtonsState_ = function() { |
|
Patrick Dubroy
2013/01/30 23:25:33
I think "updateRangeButtons_" would be a slightly
|
| + // The enabled state for the previous, today and next buttons. |
| + var buttonsState = [false, false, false]; |
|
Patrick Dubroy
2013/01/30 23:25:33
What do you need this array for? Why can't you jus
|
| + var start = 0; |
| + var enableButtons = (this.getRangeInDays() != HistoryModel.Range.RECENT); |
| + var offset = this.getOffset(); |
| + |
| + // Set today button. |
| + if (offset != start) { |
| + buttonsState[2] = true; |
| + buttonsState[1] = true; |
| + } |
| + |
| + buttonsState[0] = !this.model_.isQueryFinished_; |
| + |
| + $('range-previous').disabled = !(enableButtons && buttonsState[0]); |
| + $('range-today').disabled = !(enableButtons && buttonsState[1]); |
| + $('range-next').disabled = !(enableButtons && buttonsState[2]); |
| +}; |
| + |
| +/** |
| * Groups visits by domain, sorting them by the number of visits. |
| * @param {Array} visits Visits received from the query results. |
| * @param {Element} results Object where the results are added to. |
| @@ -954,7 +1038,8 @@ HistoryView.prototype.displayResults_ = function() { |
| if (results.length == 0) { |
| var noResults = document.createElement('div'); |
| noResults.textContent = loadTimeData.getString('noresults'); |
| - this.resultDiv_.appendChild(noResults); |
| + resultsFragment.appendChild(noResults); |
| + this.resultDiv_.appendChild(resultsFragment); |
| this.updateNavBar_(); |
| return; |
| } |
| @@ -991,6 +1076,7 @@ HistoryView.prototype.displayResults_ = function() { |
| * @private |
| */ |
| HistoryView.prototype.updateNavBar_ = function() { |
| + this.setRangeButtonsState_(); |
| $('newest-button').hidden = this.pageIndex_ == 0; |
| $('newer-button').hidden = this.pageIndex_ == 0; |
| $('older-button').hidden = |
| @@ -1032,6 +1118,8 @@ function PageState(model, view) { |
| state_obj.view.setGroupByDomain(isGroupedByDomain); |
| } else if (parseInt(hashData.r, 10) != state_obj.model.rangeInDays) { |
| state_obj.view.setRangeInDays(parseInt(hashData.r, 10)); |
| + } else if (parseInt(hashData.o, 10) != state_obj.model.offset) { |
| + state_obj.view.setOffset(parseInt(hashData.o, 10)); |
| } |
| }), 50, this); |
| } |
| @@ -1050,7 +1138,8 @@ PageState.prototype.getHashData = function() { |
| q: '', |
| p: 0, |
| g: false, |
| - r: 0 |
| + r: 0, |
| + o: 0 |
| }; |
| if (!window.location.hash) |
| @@ -1076,8 +1165,9 @@ PageState.prototype.getHashData = function() { |
| * @param {boolean} grouped Whether the results are grouped or not. |
| * @param {number} range The range in days to view or search over. If 0, use |
| * the entire history. |
| + * @param {number} offset Set the begining of the query to range * offset days. |
| */ |
| -PageState.prototype.setUIState = function(term, page, grouped, range) { |
| +PageState.prototype.setUIState = function(term, page, grouped, range, offset) { |
| // Make sure the form looks pretty. |
| $('search-field').value = term; |
| if (grouped) |
| @@ -1086,9 +1176,9 @@ PageState.prototype.setUIState = function(term, page, grouped, range) { |
| $('display-filter-sites').checked = false; |
| var hash = this.getHashData(); |
| if (hash.q != term || hash.p != page || hash.g != grouped || |
| - hash.r != range) { |
| + hash.r != range || hash.o != offset) { |
| window.location.hash = PageState.getHashString( |
| - term, page, grouped, range); |
| + term, page, grouped, range, offset); |
| } |
| }; |
| @@ -1098,9 +1188,10 @@ PageState.prototype.setUIState = function(term, page, grouped, range) { |
| * @param {number} page The page currently being viewed. |
| * @param {boolean} grouped Whether the results are grouped or not. |
| * @param {number} range The range in days to view or search over. |
| + * @param {number} offset Set the begining of the query to range * offset days. |
| * @return {string} The string to be used in a hash. |
| */ |
| -PageState.getHashString = function(term, page, grouped, range) { |
| +PageState.getHashString = function(term, page, grouped, range, offset) { |
| // Omit elements that are empty. |
| var newHash = []; |
| @@ -1116,6 +1207,9 @@ PageState.getHashString = function(term, page, grouped, range) { |
| if (range) |
| newHash.push('r=' + range); |
| + if (offset) |
| + newHash.push('o=' + offset); |
| + |
| return newHash.join('&'); |
| }; |