Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/resources/history/history.js

Issue 11886104: History: Add range navigation control for grouped visits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replies to comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/history/history.html ('k') | chrome/browser/ui/webui/history_ui.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 <include src="../uber/uber_utils.js"> 5 <include src="../uber/uber_utils.js">
6 6
7 /////////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////////
8 // Globals: 8 // Globals:
9 /** @const */ var RESULTS_PER_PAGE = 150; 9 /** @const */ var RESULTS_PER_PAGE = 150;
10 /** @const */ var RESULTS_MAX_LIMIT = 2000; 10 /** @const */ var RESULTS_MAX_LIMIT = 2000;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 }; 351 };
352 352
353 /** 353 /**
354 * Reload our model with the current parameters. 354 * Reload our model with the current parameters.
355 */ 355 */
356 HistoryModel.prototype.reload = function() { 356 HistoryModel.prototype.reload = function() {
357 // Save user-visible state, clear the model, and restore the state. 357 // Save user-visible state, clear the model, and restore the state.
358 var search = this.searchText_; 358 var search = this.searchText_;
359 var page = this.requestedPage_; 359 var page = this.requestedPage_;
360 var range = this.rangeInDays_; 360 var range = this.rangeInDays_;
361 var offset = this.offset_;
361 var groupByDomain = this.groupByDomain_; 362 var groupByDomain = this.groupByDomain_;
362 363
363 this.clearModel_(); 364 this.clearModel_();
364 this.searchText_ = search; 365 this.searchText_ = search;
365 this.requestedPage_ = page; 366 this.requestedPage_ = page;
366 this.rangeInDays_ = range; 367 this.rangeInDays_ = range;
368 this.offset_ = offset;
367 this.groupByDomain_ = groupByDomain; 369 this.groupByDomain_ = groupByDomain;
368 this.queryHistory_(); 370 this.queryHistory_();
369 }; 371 };
370 372
371 /** 373 /**
372 * @return {string} The current search text. 374 * @return {string} The current search text.
373 */ 375 */
374 HistoryModel.prototype.getSearchText = function() { 376 HistoryModel.prototype.getSearchText = function() {
375 return this.searchText_; 377 return this.searchText_;
376 }; 378 };
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // Getter and setter for HistoryModel.rangeInDays_. 474 // Getter and setter for HistoryModel.rangeInDays_.
473 Object.defineProperty(HistoryModel.prototype, 'rangeInDays', { 475 Object.defineProperty(HistoryModel.prototype, 'rangeInDays', {
474 get: function() { 476 get: function() {
475 return this.rangeInDays_; 477 return this.rangeInDays_;
476 }, 478 },
477 set: function(range) { 479 set: function(range) {
478 this.rangeInDays_ = range; 480 this.rangeInDays_ = range;
479 } 481 }
480 }); 482 });
481 483
484 /**
485 * Getter and setter for HistoryModel.offset_. The offset moves the current
486 * query 'window' |range| days behind. As such for range set to WEEK an offset
487 * of 0 refers to the last 7 days, an offset of 1 refers to the 7 day period
488 * that ended 7 days ago, etc. For MONTH an offset of 0 refers to the current
489 * calendar month, 1 to the previous one, etc.
490 */
491 Object.defineProperty(HistoryModel.prototype, 'offset', {
James Hawkins 2013/01/30 16:30:09 What is the purpose of using defineProperty?
Sergiu 2013/01/30 17:07:13 Well, I didn't want to access private members from
492 get: function() {
493 return this.offset_;
494 },
495 set: function(offset) {
496 this.offset_ = offset;
497 }
498 });
499
482 // HistoryModel, Private: ----------------------------------------------------- 500 // HistoryModel, Private: -----------------------------------------------------
483 501
484 /** 502 /**
485 * Clear the history model. 503 * Clear the history model.
486 * @private 504 * @private
487 */ 505 */
488 HistoryModel.prototype.clearModel_ = function() { 506 HistoryModel.prototype.clearModel_ = function() {
489 this.inFlight_ = false; // Whether a query is inflight. 507 this.inFlight_ = false; // Whether a query is inflight.
490 this.searchText_ = ''; 508 this.searchText_ = '';
491 // Flag to show that the results are grouped by domain or not. 509 // Flag to show that the results are grouped by domain or not.
492 this.groupByDomain_ = false; 510 this.groupByDomain_ = false;
493 511
494 this.visits_ = []; // Date-sorted list of visits (most recent first). 512 this.visits_ = []; // Date-sorted list of visits (most recent first).
495 this.last_id_ = 0; 513 this.last_id_ = 0;
496 selectionAnchor = -1; 514 selectionAnchor = -1;
497 515
498 // The page that the view wants to see - we only fetch slightly past this 516 // The page that the view wants to see - we only fetch slightly past this
499 // point. If the view requests a page that we don't have data for, we try 517 // point. If the view requests a page that we don't have data for, we try
500 // to fetch it and call back when we're done. 518 // to fetch it and call back when we're done.
501 this.requestedPage_ = 0; 519 this.requestedPage_ = 0;
502 520
521 // Skip |offset_| * weeks/months from the begining.
522 this.offset_ = 0;
523
503 // The range of history to view or search over, WEEK by default. 524 // The range of history to view or search over, WEEK by default.
504 this.rangeInDays_ = HistoryModel.Range.RECENT; 525 this.rangeInDays_ = HistoryModel.Range.RECENT;
505 526
506 // Keeps track of whether or not there are more results available than are 527 // Keeps track of whether or not there are more results available than are
507 // currently held in |this.visits_|. 528 // currently held in |this.visits_|.
508 this.isQueryFinished_ = false; 529 this.isQueryFinished_ = false;
509 530
510 // An opaque value that is returned with the query results. This is used to 531 // An opaque value that is returned with the query results. This is used to
511 // fetch the next page of results for a query. 532 // fetch the next page of results for a query.
512 this.queryCursor_ = null; 533 this.queryCursor_ = null;
(...skipping 27 matching lines...) Expand all
540 561
541 // Show the result or a message if no results were returned. 562 // Show the result or a message if no results were returned.
542 this.view_.onModelReady(); 563 this.view_.onModelReady();
543 }; 564 };
544 565
545 /** 566 /**
546 * Query for history, either for a search or time-based browsing. 567 * Query for history, either for a search or time-based browsing.
547 * @private 568 * @private
548 */ 569 */
549 HistoryModel.prototype.queryHistory_ = function() { 570 HistoryModel.prototype.queryHistory_ = function() {
550 // Set the range to the values from the interface. 571 // Set the range and offset to the values from the interface.
572 var offset = this.offset_;
551 var range = this.rangeInDays_; 573 var range = this.rangeInDays_;
552 574
553 $('loading-spinner').hidden = false; 575 $('loading-spinner').hidden = false;
554 this.inFlight_ = true; 576 this.inFlight_ = true;
555 chrome.send('queryHistory', 577 chrome.send('queryHistory',
556 [this.searchText_, range, this.queryCursor_, this.getMaxResults()]); 578 [this.searchText_, offset, range, this.queryCursor_,
579 this.getMaxResults()]);
557 }; 580 };
558 581
559 /** 582 /**
560 * Check to see if we have data for the given page. 583 * Check to see if we have data for the given page.
561 * @param {number} page The page number. 584 * @param {number} page The page number.
562 * @return {boolean} Whether we have any data for the given page. 585 * @return {boolean} Whether we have any data for the given page.
563 * @private 586 * @private
564 */ 587 */
565 HistoryModel.prototype.haveDataForPage_ = function(page) { 588 HistoryModel.prototype.haveDataForPage_ = function(page) {
566 return (page * this.getMaxResults() < this.getSize()); 589 return (page * this.getMaxResults() < this.getSize());
567 }; 590 };
568 591
569 /** 592 /**
570 * Check to see if we have data to fill the given page. 593 * Check to see if we have data to fill the given page.
571 * @param {number} page The page number. 594 * @param {number} page The page number.
572 * @return {boolean} Whether we have data to fill the page. 595 * @return {boolean} Whether we have data to fill the page.
573 * @private 596 * @private
574 */ 597 */
575 HistoryModel.prototype.canFillPage_ = function(page) { 598 HistoryModel.prototype.canFillPage_ = function(page) {
576 return ((page + 1) * this.getMaxResults() <= this.getSize()); 599 return ((page + 1) * this.getMaxResults() <= this.getSize());
577 }; 600 };
578 601
579 /** 602 /**
580 * Enables or disables grouping by domain. 603 * Enables or disables grouping by domain.
581 * @param {boolean} groupByDomain New groupByDomain_ value. 604 * @param {boolean} groupByDomain New groupByDomain_ value.
582 */ 605 */
583 HistoryModel.prototype.setGroupByDomain = function(groupByDomain) { 606 HistoryModel.prototype.setGroupByDomain = function(groupByDomain) {
584 this.groupByDomain_ = groupByDomain; 607 this.groupByDomain_ = groupByDomain;
608 this.offset_ = 0;
585 }; 609 };
586 610
587 /** 611 /**
588 * Gets whether we are grouped by domain. 612 * Gets whether we are grouped by domain.
589 * @return {boolean} Whether the results are grouped by domain. 613 * @return {boolean} Whether the results are grouped by domain.
590 */ 614 */
591 HistoryModel.prototype.getGroupByDomain = function() { 615 HistoryModel.prototype.getGroupByDomain = function() {
592 return this.groupByDomain_; 616 return this.groupByDomain_;
593 }; 617 };
594 618
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 }); 656 });
633 657
634 // Add handlers for the range options. 658 // Add handlers for the range options.
635 $('timeframe-filter').addEventListener('change', function(e) { 659 $('timeframe-filter').addEventListener('change', function(e) {
636 self.setRangeInDays(parseInt(e.target.value, 10)); 660 self.setRangeInDays(parseInt(e.target.value, 10));
637 }); 661 });
638 662
639 $('display-filter-sites').addEventListener('click', function(e) { 663 $('display-filter-sites').addEventListener('click', function(e) {
640 self.setGroupByDomain($('display-filter-sites').checked); 664 self.setGroupByDomain($('display-filter-sites').checked);
641 }); 665 });
666
667 $('range-previous').addEventListener('click', function(e) {
668 if (self.getRangeInDays() == HistoryModel.Range.RECENT)
669 self.setPage(self.pageIndex_ + 1);
670 else
671 self.setOffset(self.getOffset() + 1);
672 });
673 $('range-next').addEventListener('click', function(e) {
674 if (self.getRangeInDays() == HistoryModel.Range.RECENT)
675 self.setPage(self.pageIndex_ - 1);
676 else
677 self.setOffset(self.getOffset() - 1);
678 });
679 $('range-today').addEventListener('click', function(e) {
680 if (self.getRangeInDays() == HistoryModel.Range.RECENT)
681 self.setPage(0);
682 else
683 self.setOffset(0);
684 });
642 } 685 }
643 686
644 // HistoryView, public: ------------------------------------------------------- 687 // HistoryView, public: -------------------------------------------------------
645 /** 688 /**
646 * Do a search and optionally view a certain page. 689 * Do a search and optionally view a certain page.
647 * @param {string} term The string to search for. 690 * @param {string} term The string to search for.
648 * @param {number} opt_page The page we wish to view, only use this for 691 * @param {number} opt_page The page we wish to view, only use this for
649 * setting up initial views, as this triggers a search. 692 * setting up initial views, as this triggers a search.
650 */ 693 */
651 HistoryView.prototype.setSearch = function(term, opt_page) { 694 HistoryView.prototype.setSearch = function(term, opt_page) {
652 this.pageIndex_ = parseInt(opt_page || 0, 10); 695 this.pageIndex_ = parseInt(opt_page || 0, 10);
653 window.scrollTo(0, 0); 696 window.scrollTo(0, 0);
654 this.model_.setSearchText(term, this.pageIndex_); 697 this.model_.setSearchText(term, this.pageIndex_);
655 pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(), 698 pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(),
656 this.getRangeInDays()); 699 this.getRangeInDays(), this.getOffset());
657 }; 700 };
658 701
659 /** 702 /**
660 * Enable or disable results as being grouped by domain. 703 * Enable or disable results as being grouped by domain.
661 * @param {boolean} groupedByDomain Whether to group by domain or not. 704 * @param {boolean} groupedByDomain Whether to group by domain or not.
662 */ 705 */
663 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) { 706 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) {
664 // Group by domain is not currently supported for search results, so reset 707 // Group by domain is not currently supported for search results, so reset
665 // the search term if there was one. 708 // the search term if there was one.
666 this.model_.clearSearchText(); 709 this.model_.clearSearchText();
667 this.model_.setGroupByDomain(groupedByDomain); 710 this.model_.setGroupByDomain(groupedByDomain);
668 this.model_.reload(); 711 this.model_.reload();
669 pageState.setUIState(this.model_.getSearchText(), 712 pageState.setUIState(this.model_.getSearchText(),
670 this.pageIndex_, 713 this.pageIndex_,
671 this.model_.getGroupByDomain(), 714 this.model_.getGroupByDomain(),
672 this.getRangeInDays()); 715 this.getRangeInDays(),
716 this.getOffset());
673 }; 717 };
674 718
675 /** 719 /**
676 * Reload the current view. 720 * Reload the current view.
677 */ 721 */
678 HistoryView.prototype.reload = function() { 722 HistoryView.prototype.reload = function() {
679 this.model_.reload(); 723 this.model_.reload();
680 this.updateRemoveButton(); 724 this.updateRemoveButton();
681 }; 725 };
682 726
683 /** 727 /**
684 * Switch to a specified page. 728 * Switch to a specified page.
685 * @param {number} page The page we wish to view. 729 * @param {number} page The page we wish to view.
686 */ 730 */
687 HistoryView.prototype.setPage = function(page) { 731 HistoryView.prototype.setPage = function(page) {
688 this.clear_(); 732 this.clear_();
689 this.pageIndex_ = parseInt(page, 10); 733 this.pageIndex_ = parseInt(page, 10);
690 window.scrollTo(0, 0); 734 window.scrollTo(0, 0);
691 this.model_.requestPage(page); 735 this.model_.requestPage(page);
692 pageState.setUIState(this.model_.getSearchText(), 736 pageState.setUIState(this.model_.getSearchText(),
693 this.pageIndex_, 737 this.pageIndex_,
694 this.model_.getGroupByDomain(), 738 this.model_.getGroupByDomain(),
695 this.getRangeInDays()); 739 this.getRangeInDays(),
740 this.getOffset());
696 }; 741 };
697 742
698 /** 743 /**
699 * @return {number} The page number being viewed. 744 * @return {number} The page number being viewed.
700 */ 745 */
701 HistoryView.prototype.getPage = function() { 746 HistoryView.prototype.getPage = function() {
702 return this.pageIndex_; 747 return this.pageIndex_;
703 }; 748 };
704 749
705 /** 750 /**
706 * Set the current range for grouped results. 751 * Set the current range for grouped results.
707 * @param {string} range The number of days to which the range should be set. 752 * @param {string} range The number of days to which the range should be set.
708 */ 753 */
709 HistoryView.prototype.setRangeInDays = function(range) { 754 HistoryView.prototype.setRangeInDays = function(range) {
710 // Set the range and reset the page 755 // Set the range offset and reset the page
711 this.model_.rangeInDays = range; 756 this.model_.rangeInDays = range;
757 this.model_.offset = 0;
712 this.pageIndex_ = 0; 758 this.pageIndex_ = 0;
713 this.model_.reload(); 759 this.model_.reload();
714 pageState.setUIState(this.model_.getSearchText(), this.pageIndex_, 760 pageState.setUIState(this.model_.getSearchText(), this.pageIndex_,
715 this.model_.getGroupByDomain(), range); 761 this.model_.getGroupByDomain(), range, this.getOffset());
716 }; 762 };
717 763
718 /** 764 /**
719 * Get the current range in days. 765 * Get the current range in days.
720 * @return {number} Current range in days from the model. 766 * @return {number} Current range in days from the model.
721 */ 767 */
722 HistoryView.prototype.getRangeInDays = function() { 768 HistoryView.prototype.getRangeInDays = function() {
723 return this.model_.rangeInDays; 769 return this.model_.rangeInDays;
724 }; 770 };
725 771
726 /** 772 /**
773 * Set the current offset for grouped results.
774 * @param {number} offset Offset to set.
775 */
776 HistoryView.prototype.setOffset = function(offset) {
777 window.scrollTo(0, 0);
778 this.model_.offset = offset;
779 this.model_.reload();
780 pageState.setUIState(this.model_.getSearchText(),
781 this.pageIndex_,
782 this.model_.getGroupByDomain(),
783 this.getRangeInDays(),
784 this.getOffset());
785 };
786
787 /**
788 * Get the current offset.
789 * @return {number} Current offset from the model.
790 */
791 HistoryView.prototype.getOffset = function() {
792 return this.model_.offset;
793 };
794
795 /**
727 * Callback for the history model to let it know that it has data ready for us 796 * Callback for the history model to let it know that it has data ready for us
728 * to view. 797 * to view.
729 */ 798 */
730 HistoryView.prototype.onModelReady = function() { 799 HistoryView.prototype.onModelReady = function() {
731 this.displayResults_(); 800 this.displayResults_();
732 this.updateNavBar_(); 801 this.updateNavBar_();
733 }; 802 };
734 803
735 /** 804 /**
736 * Enables or disables the 'Remove selected items' button as appropriate. 805 * Enables or disables the 'Remove selected items' button as appropriate.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 var isMonthGroupedResult = this.getRangeInDays() == HistoryModel.Range.MONTH; 876 var isMonthGroupedResult = this.getRangeInDays() == HistoryModel.Range.MONTH;
808 for (var j = 0, visit; visit = domainVisits[j]; j++) { 877 for (var j = 0, visit; visit = domainVisits[j]; j++) {
809 resultsList.appendChild(visit.getResultDOM({ 878 resultsList.appendChild(visit.getResultDOM({
810 useMonthDate: isMonthGroupedResult 879 useMonthDate: isMonthGroupedResult
811 })); 880 }));
812 this.setVisitRendered_(visit); 881 this.setVisitRendered_(visit);
813 } 882 }
814 }; 883 };
815 884
816 /** 885 /**
886 * Enables or disables the time range buttons.
887 * @private
888 */
889 HistoryView.prototype.setRangeButtonsState_ = function() {
890 // The enabled state for the previous, today and next buttons.
891 var previousState = false;
892 var todayState = false;
893 var nextState = false;
894 var usePage = (this.getRangeInDays() == HistoryModel.Range.RECENT);
895 var offset = this.getOffset();
896 var page = this.getPage();
897
898 // Use pagination for most recent visits, offset otherwise.
899 // TODO(sergiu): Maybe send just one variable in the future.
900 if (usePage) {
901 if (page != 0) {
902 nextState = true;
903 todayState = true;
904 }
905 previousState = this.model_.hasMoreResults();
906 } else {
907 if (offset != 0) {
908 nextState = true;
909 todayState = true;
910 }
911 previousState = !this.model_.isQueryFinished_;
912 }
913
914 $('range-previous').disabled = !previousState;
915 $('range-today').disabled = !todayState;
916 $('range-next').disabled = !nextState;
917 };
918
919 /**
817 * Groups visits by domain, sorting them by the number of visits. 920 * Groups visits by domain, sorting them by the number of visits.
818 * @param {Array} visits Visits received from the query results. 921 * @param {Array} visits Visits received from the query results.
819 * @param {Element} results Object where the results are added to. 922 * @param {Element} results Object where the results are added to.
820 * @private 923 * @private
821 */ 924 */
822 HistoryView.prototype.groupVisitsByDomain_ = function(visits, results) { 925 HistoryView.prototype.groupVisitsByDomain_ = function(visits, results) {
823 var visitsByDomain = {}; 926 var visitsByDomain = {};
824 var domains = []; 927 var domains = [];
825 928
826 // Group the visits into a dictionary and generate a list of domains. 929 // Group the visits into a dictionary and generate a list of domains.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 createElementWithClassName('h2', 'timeframe')); 1050 createElementWithClassName('h2', 'timeframe'));
948 timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF( 1051 timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF(
949 'historyinterval', 1052 'historyinterval',
950 this.model_.queryStartTime, 1053 this.model_.queryStartTime,
951 this.model_.queryEndTime))); 1054 this.model_.queryEndTime)));
952 } 1055 }
953 1056
954 if (results.length == 0) { 1057 if (results.length == 0) {
955 var noResults = document.createElement('div'); 1058 var noResults = document.createElement('div');
956 noResults.textContent = loadTimeData.getString('noresults'); 1059 noResults.textContent = loadTimeData.getString('noresults');
957 this.resultDiv_.appendChild(noResults); 1060 resultsFragment.appendChild(noResults);
1061 this.resultDiv_.appendChild(resultsFragment);
958 this.updateNavBar_(); 1062 this.updateNavBar_();
959 return; 1063 return;
960 } 1064 }
961 1065
962 if (this.getRangeInDays() == HistoryModel.Range.MONTH && 1066 if (this.getRangeInDays() == HistoryModel.Range.MONTH &&
963 groupByDomain) { 1067 groupByDomain) {
964 // Group everything together in the month view. 1068 // Group everything together in the month view.
965 this.addMonthResults_(results, resultsFragment); 1069 this.addMonthResults_(results, resultsFragment);
966 } else { 1070 } else {
967 var dayStart = 0; 1071 var dayStart = 0;
(...skipping 16 matching lines...) Expand all
984 this.resultDiv_.appendChild(resultsFragment); 1088 this.resultDiv_.appendChild(resultsFragment);
985 } 1089 }
986 this.updateNavBar_(); 1090 this.updateNavBar_();
987 }; 1091 };
988 1092
989 /** 1093 /**
990 * Update the visibility of the page navigation buttons. 1094 * Update the visibility of the page navigation buttons.
991 * @private 1095 * @private
992 */ 1096 */
993 HistoryView.prototype.updateNavBar_ = function() { 1097 HistoryView.prototype.updateNavBar_ = function() {
1098 this.setRangeButtonsState_();
994 $('newest-button').hidden = this.pageIndex_ == 0; 1099 $('newest-button').hidden = this.pageIndex_ == 0;
995 $('newer-button').hidden = this.pageIndex_ == 0; 1100 $('newer-button').hidden = this.pageIndex_ == 0;
996 $('older-button').hidden = 1101 $('older-button').hidden =
997 this.model_.rangeInDays_ != HistoryModel.Range.RECENT || 1102 this.model_.rangeInDays_ != HistoryModel.Range.RECENT ||
998 !this.model_.hasMoreResults(); 1103 !this.model_.hasMoreResults();
999 }; 1104 };
1000 1105
1001 /////////////////////////////////////////////////////////////////////////////// 1106 ///////////////////////////////////////////////////////////////////////////////
1002 // State object: 1107 // State object:
1003 /** 1108 /**
(...skipping 21 matching lines...) Expand all
1025 var hashData = state_obj.getHashData(); 1130 var hashData = state_obj.getHashData();
1026 var isGroupedByDomain = (hashData.g == 'true'); 1131 var isGroupedByDomain = (hashData.g == 'true');
1027 if (hashData.q != state_obj.model.getSearchText()) { 1132 if (hashData.q != state_obj.model.getSearchText()) {
1028 state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10)); 1133 state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10));
1029 } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) { 1134 } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) {
1030 state_obj.view.setPage(hashData.p); 1135 state_obj.view.setPage(hashData.p);
1031 } else if (isGroupedByDomain != state_obj.view.model_.getGroupByDomain()) { 1136 } else if (isGroupedByDomain != state_obj.view.model_.getGroupByDomain()) {
1032 state_obj.view.setGroupByDomain(isGroupedByDomain); 1137 state_obj.view.setGroupByDomain(isGroupedByDomain);
1033 } else if (parseInt(hashData.r, 10) != state_obj.model.rangeInDays) { 1138 } else if (parseInt(hashData.r, 10) != state_obj.model.rangeInDays) {
1034 state_obj.view.setRangeInDays(parseInt(hashData.r, 10)); 1139 state_obj.view.setRangeInDays(parseInt(hashData.r, 10));
1140 } else if (parseInt(hashData.o, 10) != state_obj.model.offset) {
1141 state_obj.view.setOffset(parseInt(hashData.o, 10));
1035 } 1142 }
1036 }), 50, this); 1143 }), 50, this);
1037 } 1144 }
1038 1145
1039 /** 1146 /**
1040 * Holds the singleton instance. 1147 * Holds the singleton instance.
1041 */ 1148 */
1042 PageState.instance = null; 1149 PageState.instance = null;
1043 1150
1044 /** 1151 /**
1045 * @return {Object} An object containing parameters from our window hash. 1152 * @return {Object} An object containing parameters from our window hash.
1046 */ 1153 */
1047 PageState.prototype.getHashData = function() { 1154 PageState.prototype.getHashData = function() {
1048 var result = { 1155 var result = {
1049 e: 0, 1156 e: 0,
1050 q: '', 1157 q: '',
1051 p: 0, 1158 p: 0,
1052 g: false, 1159 g: false,
1053 r: 0 1160 r: 0,
1161 o: 0
1054 }; 1162 };
1055 1163
1056 if (!window.location.hash) 1164 if (!window.location.hash)
1057 return result; 1165 return result;
1058 1166
1059 var hashSplit = window.location.hash.substr(1).split('&'); 1167 var hashSplit = window.location.hash.substr(1).split('&');
1060 for (var i = 0; i < hashSplit.length; i++) { 1168 for (var i = 0; i < hashSplit.length; i++) {
1061 var pair = hashSplit[i].split('='); 1169 var pair = hashSplit[i].split('=');
1062 if (pair.length > 1) { 1170 if (pair.length > 1) {
1063 result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' ')); 1171 result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
1064 } 1172 }
1065 } 1173 }
1066 1174
1067 return result; 1175 return result;
1068 }; 1176 };
1069 1177
1070 /** 1178 /**
1071 * Set the hash to a specified state, this will create an entry in the 1179 * Set the hash to a specified state, this will create an entry in the
1072 * session history so the back button cycles through hash states, which 1180 * session history so the back button cycles through hash states, which
1073 * are then picked up by our listener. 1181 * are then picked up by our listener.
1074 * @param {string} term The current search string. 1182 * @param {string} term The current search string.
1075 * @param {number} page The page currently being viewed. 1183 * @param {number} page The page currently being viewed.
1076 * @param {boolean} grouped Whether the results are grouped or not. 1184 * @param {boolean} grouped Whether the results are grouped or not.
1077 * @param {number} range The range in days to view or search over. If 0, use 1185 * @param {number} range The range in days to view or search over. If 0, use
1078 * the entire history. 1186 * the entire history.
1187 * @param {number} offset Set the begining of the query to range * offset days.
1079 */ 1188 */
1080 PageState.prototype.setUIState = function(term, page, grouped, range) { 1189 PageState.prototype.setUIState = function(term, page, grouped, range, offset) {
1081 // Make sure the form looks pretty. 1190 // Make sure the form looks pretty.
1082 $('search-field').value = term; 1191 $('search-field').value = term;
1083 if (grouped) 1192 if (grouped)
1084 $('display-filter-sites').checked = true; 1193 $('display-filter-sites').checked = true;
1085 else 1194 else
1086 $('display-filter-sites').checked = false; 1195 $('display-filter-sites').checked = false;
1087 var hash = this.getHashData(); 1196 var hash = this.getHashData();
1088 if (hash.q != term || hash.p != page || hash.g != grouped || 1197 if (hash.q != term || hash.p != page || hash.g != grouped ||
1089 hash.r != range) { 1198 hash.r != range || hash.o != offset) {
1090 window.location.hash = PageState.getHashString( 1199 window.location.hash = PageState.getHashString(
1091 term, page, grouped, range); 1200 term, page, grouped, range, offset);
1092 } 1201 }
1093 }; 1202 };
1094 1203
1095 /** 1204 /**
1096 * Static method to get the hash string for a specified state 1205 * Static method to get the hash string for a specified state
1097 * @param {string} term The current search string. 1206 * @param {string} term The current search string.
1098 * @param {number} page The page currently being viewed. 1207 * @param {number} page The page currently being viewed.
1099 * @param {boolean} grouped Whether the results are grouped or not. 1208 * @param {boolean} grouped Whether the results are grouped or not.
1100 * @param {number} range The range in days to view or search over. 1209 * @param {number} range The range in days to view or search over.
1210 * @param {number} offset Set the begining of the query to range * offset days.
1101 * @return {string} The string to be used in a hash. 1211 * @return {string} The string to be used in a hash.
1102 */ 1212 */
1103 PageState.getHashString = function(term, page, grouped, range) { 1213 PageState.getHashString = function(term, page, grouped, range, offset) {
1104 // Omit elements that are empty. 1214 // Omit elements that are empty.
1105 var newHash = []; 1215 var newHash = [];
1106 1216
1107 if (term) 1217 if (term)
1108 newHash.push('q=' + encodeURIComponent(term)); 1218 newHash.push('q=' + encodeURIComponent(term));
1109 1219
1110 if (page) 1220 if (page)
1111 newHash.push('p=' + page); 1221 newHash.push('p=' + page);
1112 1222
1113 if (grouped) 1223 if (grouped)
1114 newHash.push('g=' + grouped); 1224 newHash.push('g=' + grouped);
1115 1225
1116 if (range) 1226 if (range)
1117 newHash.push('r=' + range); 1227 newHash.push('r=' + range);
1118 1228
1229 if (offset)
1230 newHash.push('o=' + offset);
1231
1119 return newHash.join('&'); 1232 return newHash.join('&');
1120 }; 1233 };
1121 1234
1122 /////////////////////////////////////////////////////////////////////////////// 1235 ///////////////////////////////////////////////////////////////////////////////
1123 // Document Functions: 1236 // Document Functions:
1124 /** 1237 /**
1125 * Window onload handler, sets up the page. 1238 * Window onload handler, sets up the page.
1126 */ 1239 */
1127 function load() { 1240 function load() {
1128 uber.onContentFrameLoaded(); 1241 uber.onContentFrameLoaded();
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 historyView.reload(); 1534 historyView.reload();
1422 } 1535 }
1423 1536
1424 // Add handlers to HTML elements. 1537 // Add handlers to HTML elements.
1425 document.addEventListener('DOMContentLoaded', load); 1538 document.addEventListener('DOMContentLoaded', load);
1426 1539
1427 // This event lets us enable and disable menu items before the menu is shown. 1540 // This event lets us enable and disable menu items before the menu is shown.
1428 document.addEventListener('canExecute', function(e) { 1541 document.addEventListener('canExecute', function(e) {
1429 e.canExecute = true; 1542 e.canExecute = true;
1430 }); 1543 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/history/history.html ('k') | chrome/browser/ui/webui/history_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698