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

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: Fix minor bug Created 7 years, 11 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
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 10
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 }; 350 };
351 351
352 /** 352 /**
353 * Reload our model with the current parameters. 353 * Reload our model with the current parameters.
354 */ 354 */
355 HistoryModel.prototype.reload = function() { 355 HistoryModel.prototype.reload = function() {
356 // Save user-visible state, clear the model, and restore the state. 356 // Save user-visible state, clear the model, and restore the state.
357 var search = this.searchText_; 357 var search = this.searchText_;
358 var page = this.requestedPage_; 358 var page = this.requestedPage_;
359 var range = this.rangeInDays_; 359 var range = this.rangeInDays_;
360 var offset = this.offset_;
360 var groupByDomain = this.groupByDomain_; 361 var groupByDomain = this.groupByDomain_;
361 362
362 this.clearModel_(); 363 this.clearModel_();
363 this.searchText_ = search; 364 this.searchText_ = search;
364 this.requestedPage_ = page; 365 this.requestedPage_ = page;
365 this.rangeInDays_ = range; 366 this.rangeInDays_ = range;
367 this.offset_ = offset;
366 this.groupByDomain_ = groupByDomain; 368 this.groupByDomain_ = groupByDomain;
367 this.queryHistory_(); 369 this.queryHistory_();
368 }; 370 };
369 371
370 /** 372 /**
371 * @return {string} The current search text. 373 * @return {string} The current search text.
372 */ 374 */
373 HistoryModel.prototype.getSearchText = function() { 375 HistoryModel.prototype.getSearchText = function() {
374 return this.searchText_; 376 return this.searchText_;
375 }; 377 };
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 // Getter and setter for HistoryModel.rangeInDays_. 461 // Getter and setter for HistoryModel.rangeInDays_.
460 Object.defineProperty(HistoryModel.prototype, 'rangeInDays', { 462 Object.defineProperty(HistoryModel.prototype, 'rangeInDays', {
461 get: function() { 463 get: function() {
462 return this.rangeInDays_; 464 return this.rangeInDays_;
463 }, 465 },
464 set: function(range) { 466 set: function(range) {
465 this.rangeInDays_ = range; 467 this.rangeInDays_ = range;
466 } 468 }
467 }); 469 });
468 470
471 /**
472 * Getter and setter for HistoryModel.offset_. The offset moves the current
473 * query 'window' |range| days behind. As such for range set to WEEK an offset
474 * of 0 refers to the last 7 days, an offset of 1 refers to the 7 day period
475 * that ended 7 days ago, etc. For MONTH an offset of 0 refers to the current
476 * calendar month, 1 to the previous one, etc.
477 */
478 Object.defineProperty(HistoryModel.prototype, 'offset', {
479 get: function() {
480 return this.offset_;
481 },
482 set: function(offset) {
483 this.offset_ = offset;
484 }
485 });
486
469 // HistoryModel, Private: ----------------------------------------------------- 487 // HistoryModel, Private: -----------------------------------------------------
470 488
471 /** 489 /**
472 * Clear the history model. 490 * Clear the history model.
473 * @private 491 * @private
474 */ 492 */
475 HistoryModel.prototype.clearModel_ = function() { 493 HistoryModel.prototype.clearModel_ = function() {
476 this.inFlight_ = false; // Whether a query is inflight. 494 this.inFlight_ = false; // Whether a query is inflight.
477 this.searchText_ = ''; 495 this.searchText_ = '';
478 // Flag to show that the results are grouped by domain or not. 496 // Flag to show that the results are grouped by domain or not.
479 this.groupByDomain_ = false; 497 this.groupByDomain_ = false;
480 498
481 this.visits_ = []; // Date-sorted list of visits (most recent first). 499 this.visits_ = []; // Date-sorted list of visits (most recent first).
482 this.last_id_ = 0; 500 this.last_id_ = 0;
483 selectionAnchor = -1; 501 selectionAnchor = -1;
484 502
485 // The page that the view wants to see - we only fetch slightly past this 503 // The page that the view wants to see - we only fetch slightly past this
486 // point. If the view requests a page that we don't have data for, we try 504 // point. If the view requests a page that we don't have data for, we try
487 // to fetch it and call back when we're done. 505 // to fetch it and call back when we're done.
488 this.requestedPage_ = 0; 506 this.requestedPage_ = 0;
489 507
508 // Skip |offset_| * weeks/months from the begining.
509 this.offset_ = 0;
510
490 // The range of history to view or search over, WEEK by default. 511 // The range of history to view or search over, WEEK by default.
491 this.rangeInDays_ = HistoryModel.Range.WEEK; 512 this.rangeInDays_ = HistoryModel.Range.WEEK;
492 513
493 // Keeps track of whether or not there are more results available than are 514 // Keeps track of whether or not there are more results available than are
494 // currently held in |this.visits_|. 515 // currently held in |this.visits_|.
495 this.isQueryFinished_ = false; 516 this.isQueryFinished_ = false;
496 517
497 // An opaque value that is returned with the query results. This is used to 518 // An opaque value that is returned with the query results. This is used to
498 // fetch the next page of results for a query. 519 // fetch the next page of results for a query.
499 this.queryCursor_ = null; 520 this.queryCursor_ = null;
(...skipping 26 matching lines...) Expand all
526 // Show the result or a message if no results were returned. 547 // Show the result or a message if no results were returned.
527 this.view_.onModelReady(); 548 this.view_.onModelReady();
528 }; 549 };
529 550
530 /** 551 /**
531 * Query for history, either for a search or time-based browsing. 552 * Query for history, either for a search or time-based browsing.
532 * @private 553 * @private
533 */ 554 */
534 HistoryModel.prototype.queryHistory_ = function() { 555 HistoryModel.prototype.queryHistory_ = function() {
535 var endTime = 0; 556 var endTime = 0;
536 // Set the range to the values from the interface. 557 // Set the range and offset to the values from the interface.
558 var offset = this.offset_;
537 var range = this.rangeInDays_; 559 var range = this.rangeInDays_;
538 if (!this.getGroupByDomain()) { 560 if (!this.getGroupByDomain()) {
539 // Do the time-based search. 561 // Do the time-based search.
540 // If there are already some visits, pick up the previous query where it 562 // If there are already some visits, pick up the previous query where it
541 // left off. 563 // left off.
542 if (this.visits_.length > 0) { 564 if (this.visits_.length > 0) {
543 var lastVisit = this.visits_.slice(-1)[0]; 565 var lastVisit = this.visits_.slice(-1)[0];
544 endTime = lastVisit.date.getTime(); 566 endTime = lastVisit.date.getTime();
545 cursor = this.queryCursor_; 567 cursor = this.queryCursor_;
546 } 568 }
547 range = HistoryModel.Range.NOT_GROUPED; 569 range = HistoryModel.Range.NOT_GROUPED;
548 } 570 }
549 $('loading-spinner').hidden = false; 571 $('loading-spinner').hidden = false;
550 this.inFlight_ = true; 572 this.inFlight_ = true;
551 chrome.send('queryHistory', 573 chrome.send('queryHistory',
552 [this.searchText_, range, endTime, this.queryCursor_, 574 [this.searchText_, offset, range, endTime, this.queryCursor_,
553 RESULTS_PER_PAGE]); 575 RESULTS_PER_PAGE]);
554 }; 576 };
555 577
556 /** 578 /**
557 * Check to see if we have data for the given page. 579 * Check to see if we have data for the given page.
558 * @param {number} page The page number. 580 * @param {number} page The page number.
559 * @return {boolean} Whether we have any data for the given page. 581 * @return {boolean} Whether we have any data for the given page.
560 * @private 582 * @private
561 */ 583 */
562 HistoryModel.prototype.haveDataForPage_ = function(page) { 584 HistoryModel.prototype.haveDataForPage_ = function(page) {
563 return (page * RESULTS_PER_PAGE < this.getSize()); 585 return (page * RESULTS_PER_PAGE < this.getSize());
564 }; 586 };
565 587
566 /** 588 /**
567 * Check to see if we have data to fill the given page. 589 * Check to see if we have data to fill the given page.
568 * @param {number} page The page number. 590 * @param {number} page The page number.
569 * @return {boolean} Whether we have data to fill the page. 591 * @return {boolean} Whether we have data to fill the page.
570 * @private 592 * @private
571 */ 593 */
572 HistoryModel.prototype.canFillPage_ = function(page) { 594 HistoryModel.prototype.canFillPage_ = function(page) {
573 return ((page + 1) * RESULTS_PER_PAGE <= this.getSize()); 595 return ((page + 1) * RESULTS_PER_PAGE <= this.getSize());
574 }; 596 };
575 597
576 /** 598 /**
577 * Enables or disables grouping by domain. 599 * Enables or disables grouping by domain.
578 * @param {boolean} groupByDomain New groupByDomain_ value. 600 * @param {boolean} groupByDomain New groupByDomain_ value.
579 */ 601 */
580 HistoryModel.prototype.setGroupByDomain = function(groupByDomain) { 602 HistoryModel.prototype.setGroupByDomain = function(groupByDomain) {
581 this.groupByDomain_ = groupByDomain; 603 this.groupByDomain_ = groupByDomain;
604 this.offset_ = 0;
582 }; 605 };
583 606
584 /** 607 /**
585 * Gets whether we are grouped by domain. 608 * Gets whether we are grouped by domain.
586 * @return {boolean} Whether the results are grouped by domain. 609 * @return {boolean} Whether the results are grouped by domain.
587 */ 610 */
588 HistoryModel.prototype.getGroupByDomain = function() { 611 HistoryModel.prototype.getGroupByDomain = function() {
589 return this.groupByDomain_; 612 return this.groupByDomain_;
590 }; 613 };
591 614
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 }); 652 });
630 653
631 // Add handlers for the range options. 654 // Add handlers for the range options.
632 $('timeframe-filter').addEventListener('change', function(e) { 655 $('timeframe-filter').addEventListener('change', function(e) {
633 self.setRangeInDays(parseInt(e.target.value, 10)); 656 self.setRangeInDays(parseInt(e.target.value, 10));
634 }); 657 });
635 658
636 $('display-filter-sites').addEventListener('click', function(e) { 659 $('display-filter-sites').addEventListener('click', function(e) {
637 self.setGroupByDomain($('display-filter-sites').checked); 660 self.setGroupByDomain($('display-filter-sites').checked);
638 }); 661 });
662
663 $('range-previous').addEventListener('click', function(e) {
664 self.setOffset(self.getOffset() + 1);
665 });
666 $('range-next').addEventListener('click', function(e) {
667 self.setOffset(self.getOffset() - 1);
668 });
669 $('range-today').addEventListener('click', function(e) {
670 self.setOffset(0);
671 });
639 } 672 }
640 673
641 // HistoryView, public: ------------------------------------------------------- 674 // HistoryView, public: -------------------------------------------------------
642 /** 675 /**
643 * Do a search and optionally view a certain page. 676 * Do a search and optionally view a certain page.
644 * @param {string} term The string to search for. 677 * @param {string} term The string to search for.
645 * @param {number} opt_page The page we wish to view, only use this for 678 * @param {number} opt_page The page we wish to view, only use this for
646 * setting up initial views, as this triggers a search. 679 * setting up initial views, as this triggers a search.
647 */ 680 */
648 HistoryView.prototype.setSearch = function(term, opt_page) { 681 HistoryView.prototype.setSearch = function(term, opt_page) {
649 this.pageIndex_ = parseInt(opt_page || 0, 10); 682 this.pageIndex_ = parseInt(opt_page || 0, 10);
650 window.scrollTo(0, 0); 683 window.scrollTo(0, 0);
651 this.model_.setSearchText(term, this.pageIndex_); 684 this.model_.setSearchText(term, this.pageIndex_);
652 pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(), 685 pageState.setUIState(term, this.pageIndex_, this.model_.getGroupByDomain(),
653 this.getRangeInDays()); 686 this.getRangeInDays(), this.getOffset());
654 }; 687 };
655 688
656 /** 689 /**
657 * Enable or disable results as being grouped by domain. 690 * Enable or disable results as being grouped by domain.
658 * @param {boolean} groupedByDomain Whether to group by domain or not. 691 * @param {boolean} groupedByDomain Whether to group by domain or not.
659 */ 692 */
660 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) { 693 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) {
661 // Group by domain is not currently supported for search results, so reset 694 // Group by domain is not currently supported for search results, so reset
662 // the search term if there was one. 695 // the search term if there was one.
663 this.model_.clearSearchText(); 696 this.model_.clearSearchText();
664 this.model_.setGroupByDomain(groupedByDomain); 697 this.model_.setGroupByDomain(groupedByDomain);
665 $('timeframe-filter').disabled = !groupedByDomain; 698 setRangeButtonsState(groupedByDomain, this);
666 this.model_.reload(); 699 this.model_.reload();
667 pageState.setUIState(this.model_.getSearchText(), 700 pageState.setUIState(this.model_.getSearchText(),
668 this.pageIndex_, 701 this.pageIndex_,
669 this.model_.getGroupByDomain(), 702 this.model_.getGroupByDomain(),
670 this.getRangeInDays()); 703 this.getRangeInDays(),
704 this.getOffset());
671 }; 705 };
672 706
673 /** 707 /**
674 * Reload the current view. 708 * Reload the current view.
675 */ 709 */
676 HistoryView.prototype.reload = function() { 710 HistoryView.prototype.reload = function() {
677 this.model_.reload(); 711 this.model_.reload();
678 this.updateRemoveButton(); 712 this.updateRemoveButton();
679 }; 713 };
680 714
681 /** 715 /**
682 * Switch to a specified page. 716 * Switch to a specified page.
683 * @param {number} page The page we wish to view. 717 * @param {number} page The page we wish to view.
684 */ 718 */
685 HistoryView.prototype.setPage = function(page) { 719 HistoryView.prototype.setPage = function(page) {
686 this.clear_(); 720 this.clear_();
687 this.pageIndex_ = parseInt(page, 10); 721 this.pageIndex_ = parseInt(page, 10);
688 window.scrollTo(0, 0); 722 window.scrollTo(0, 0);
689 this.model_.requestPage(page); 723 this.model_.requestPage(page);
690 pageState.setUIState(this.model_.getSearchText(), 724 pageState.setUIState(this.model_.getSearchText(),
691 this.pageIndex_, 725 this.pageIndex_,
692 this.model_.getGroupByDomain(), 726 this.model_.getGroupByDomain(),
693 this.getRangeInDays()); 727 this.getRangeInDays(),
728 this.getOffset());
694 }; 729 };
695 730
696 /** 731 /**
697 * @return {number} The page number being viewed. 732 * @return {number} The page number being viewed.
698 */ 733 */
699 HistoryView.prototype.getPage = function() { 734 HistoryView.prototype.getPage = function() {
700 return this.pageIndex_; 735 return this.pageIndex_;
701 }; 736 };
702 737
703 /** 738 /**
704 * Set the current range for grouped results. 739 * Set the current range for grouped results.
705 * @param {string} range The number of days to which the range should be set. 740 * @param {string} range The number of days to which the range should be set.
706 */ 741 */
707 HistoryView.prototype.setRangeInDays = function(range) { 742 HistoryView.prototype.setRangeInDays = function(range) {
708 window.scrollTo(0, 0); 743 window.scrollTo(0, 0);
709 // Set the range and reset the offset. 744 // Set the range and reset the offset.
745 this.model_.offset = 0;
710 this.model_.rangeInDays = range; 746 this.model_.rangeInDays = range;
747 setRangeButtonsState(true, this);
711 this.model_.reload(); 748 this.model_.reload();
712 pageState.setUIState(this.model_.getSearchText(), this.pageIndex_, 749 pageState.setUIState(this.model_.getSearchText(), this.pageIndex_,
713 this.model_.getGroupByDomain(), range); 750 this.model_.getGroupByDomain(), range, this.getOffset());
714 }; 751 };
715 752
716 /** 753 /**
717 * Get the current range in days. 754 * Get the current range in days.
718 * @return {number} Current range in days from the model. 755 * @return {number} Current range in days from the model.
719 */ 756 */
720 HistoryView.prototype.getRangeInDays = function() { 757 HistoryView.prototype.getRangeInDays = function() {
721 return this.model_.rangeInDays; 758 return this.model_.rangeInDays;
722 }; 759 };
723 760
724 /** 761 /**
762 * Set the current offset for grouped results.
763 * @param {number} offset Offset to set.
764 */
765 HistoryView.prototype.setOffset = function(offset) {
766 window.scrollTo(0, 0);
767 this.model_.offset = offset;
768 this.model_.reload();
769 setRangeButtonsState(true, this);
770 pageState.setUIState(this.model_.getSearchText(),
771 this.pageIndex_,
772 this.model_.getGroupByDomain(),
773 this.getRangeInDays(),
774 this.getOffset());
775 };
776
777 /**
778 * Get the current offset.
779 * @return {number} Current offset from the model.
780 */
781 HistoryView.prototype.getOffset = function() {
782 return this.model_.offset;
783 };
784
785 /**
725 * Callback for the history model to let it know that it has data ready for us 786 * Callback for the history model to let it know that it has data ready for us
726 * to view. 787 * to view.
727 */ 788 */
728 HistoryView.prototype.onModelReady = function() { 789 HistoryView.prototype.onModelReady = function() {
729 this.displayResults_(); 790 this.displayResults_();
730 this.updateNavBar_(); 791 this.updateNavBar_();
731 }; 792 };
732 793
733 /** 794 /**
734 * Enables or disables the 'Remove selected items' button as appropriate. 795 * Enables or disables the 'Remove selected items' button as appropriate.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 createElementWithClassName('h2', 'timeframe')); 1007 createElementWithClassName('h2', 'timeframe'));
947 timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF( 1008 timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF(
948 'historyinterval', 1009 'historyinterval',
949 this.model_.queryStartTime, 1010 this.model_.queryStartTime,
950 this.model_.queryEndTime))); 1011 this.model_.queryEndTime)));
951 } 1012 }
952 1013
953 if (results.length == 0) { 1014 if (results.length == 0) {
954 var noResults = document.createElement('div'); 1015 var noResults = document.createElement('div');
955 noResults.textContent = loadTimeData.getString('noresults'); 1016 noResults.textContent = loadTimeData.getString('noresults');
956 this.resultDiv_.appendChild(noResults); 1017 resultsFragment.appendChild(noResults);
1018 this.resultDiv_.appendChild(resultsFragment);
957 this.updateNavBar_(); 1019 this.updateNavBar_();
958 return; 1020 return;
959 } 1021 }
960 1022
961 if (this.model_.getGroupByDomain() && 1023 if (this.model_.getGroupByDomain() &&
962 this.getRangeInDays() == HistoryModel.Range.MONTH) { 1024 this.getRangeInDays() == HistoryModel.Range.MONTH) {
963 // Group everything together in the month view. 1025 // Group everything together in the month view.
964 this.addMonthResults_(results, resultsFragment); 1026 this.addMonthResults_(results, resultsFragment);
965 } else { 1027 } else {
966 var dayStart = 0; 1028 var dayStart = 0;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 var hashData = state_obj.getHashData(); 1085 var hashData = state_obj.getHashData();
1024 if (hashData.q != state_obj.model.getSearchText()) { 1086 if (hashData.q != state_obj.model.getSearchText()) {
1025 state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10)); 1087 state_obj.view.setSearch(hashData.q, parseInt(hashData.p, 10));
1026 } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) { 1088 } else if (parseInt(hashData.p, 10) != state_obj.view.getPage()) {
1027 state_obj.view.setPage(hashData.p); 1089 state_obj.view.setPage(hashData.p);
1028 } else if ((hashData.g == 'true') != 1090 } else if ((hashData.g == 'true') !=
1029 state_obj.view.model_.getGroupByDomain()) { 1091 state_obj.view.model_.getGroupByDomain()) {
1030 state_obj.view.setGroupByDomain(hashData.g); 1092 state_obj.view.setGroupByDomain(hashData.g);
1031 } else if (parseInt(hashData.r, 10) != state_obj.model.rangeInDays) { 1093 } else if (parseInt(hashData.r, 10) != state_obj.model.rangeInDays) {
1032 state_obj.view.setRangeInDays(parseInt(hashData.r, 10)); 1094 state_obj.view.setRangeInDays(parseInt(hashData.r, 10));
1095 } else if (parseInt(hashData.o, 10) != state_obj.model.offset) {
1096 state_obj.view.setOffset(parseInt(hashData.o, 10));
1033 } 1097 }
1034 }), 50, this); 1098 }), 50, this);
1035 } 1099 }
1036 1100
1037 /** 1101 /**
1038 * Holds the singleton instance. 1102 * Holds the singleton instance.
1039 */ 1103 */
1040 PageState.instance = null; 1104 PageState.instance = null;
1041 1105
1042 /** 1106 /**
1043 * @return {Object} An object containing parameters from our window hash. 1107 * @return {Object} An object containing parameters from our window hash.
1044 */ 1108 */
1045 PageState.prototype.getHashData = function() { 1109 PageState.prototype.getHashData = function() {
1046 var result = { 1110 var result = {
1047 e: 0, 1111 e: 0,
1048 q: '', 1112 q: '',
1049 p: 0, 1113 p: 0,
1050 g: false, 1114 g: false,
1051 r: 0 1115 r: 0,
1116 o: 0
1052 }; 1117 };
1053 1118
1054 if (!window.location.hash) 1119 if (!window.location.hash)
1055 return result; 1120 return result;
1056 1121
1057 var hashSplit = window.location.hash.substr(1).split('&'); 1122 var hashSplit = window.location.hash.substr(1).split('&');
1058 for (var i = 0; i < hashSplit.length; i++) { 1123 for (var i = 0; i < hashSplit.length; i++) {
1059 var pair = hashSplit[i].split('='); 1124 var pair = hashSplit[i].split('=');
1060 if (pair.length > 1) { 1125 if (pair.length > 1) {
1061 result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' ')); 1126 result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
1062 } 1127 }
1063 } 1128 }
1064 1129
1065 return result; 1130 return result;
1066 }; 1131 };
1067 1132
1068 /** 1133 /**
1069 * Set the hash to a specified state, this will create an entry in the 1134 * Set the hash to a specified state, this will create an entry in the
1070 * session history so the back button cycles through hash states, which 1135 * session history so the back button cycles through hash states, which
1071 * are then picked up by our listener. 1136 * are then picked up by our listener.
1072 * @param {string} term The current search string. 1137 * @param {string} term The current search string.
1073 * @param {number} page The page currently being viewed. 1138 * @param {number} page The page currently being viewed.
1074 * @param {boolean} grouped Whether the results are grouped or not. 1139 * @param {boolean} grouped Whether the results are grouped or not.
1075 * @param {number} range The range in days to view or search over. If 0, use 1140 * @param {number} range The range in days to view or search over. If 0, use
1076 * the entire history. 1141 * the entire history.
1142 * @param {number} offset Set the begining of the query to range * offset days.
1077 */ 1143 */
1078 PageState.prototype.setUIState = function(term, page, grouped, range) { 1144 PageState.prototype.setUIState = function(term, page, grouped, range, offset) {
1079 // Make sure the form looks pretty. 1145 // Make sure the form looks pretty.
1080 $('search-field').value = term; 1146 $('search-field').value = term;
1081 if (grouped) { 1147 if (grouped) {
1082 $('timeframe-filter').value = range; 1148 $('timeframe-filter').value = range;
1083 $('display-filter-sites').checked = true; 1149 $('display-filter-sites').checked = true;
1084 } else { 1150 } else {
1085 $('timeframe-filter').disabled = true; 1151 $('timeframe-filter').disabled = true;
1086 $('display-filter-sites').checked = false; 1152 $('display-filter-sites').checked = false;
1087 } 1153 }
1088 var hash = this.getHashData(); 1154 var hash = this.getHashData();
1089 if (hash.q != term || hash.p != page || hash.g != grouped || 1155 if (hash.q != term || hash.p != page || hash.g != grouped ||
1090 hash.r != range) { 1156 hash.r != range || hash.o != offset) {
1091 window.location.hash = PageState.getHashString( 1157 window.location.hash = PageState.getHashString(
1092 term, page, grouped, range); 1158 term, page, grouped, range, offset);
1093 } 1159 }
1094 }; 1160 };
1095 1161
1096 /** 1162 /**
1097 * Static method to get the hash string for a specified state 1163 * Static method to get the hash string for a specified state
1098 * @param {string} term The current search string. 1164 * @param {string} term The current search string.
1099 * @param {number} page The page currently being viewed. 1165 * @param {number} page The page currently being viewed.
1100 * @param {boolean} grouped Whether the results are grouped or not. 1166 * @param {boolean} grouped Whether the results are grouped or not.
1101 * @param {number} range The range in days to view or search over. 1167 * @param {number} range The range in days to view or search over.
1168 * @param {number} offset Set the begining of the query to range * offset days.
1102 * @return {string} The string to be used in a hash. 1169 * @return {string} The string to be used in a hash.
1103 */ 1170 */
1104 PageState.getHashString = function(term, page, grouped, range) { 1171 PageState.getHashString = function(term, page, grouped, range, offset) {
1105 // Omit elements that are empty. 1172 // Omit elements that are empty.
1106 var newHash = []; 1173 var newHash = [];
1107 1174
1108 if (term) 1175 if (term)
1109 newHash.push('q=' + encodeURIComponent(term)); 1176 newHash.push('q=' + encodeURIComponent(term));
1110 1177
1111 if (page) 1178 if (page)
1112 newHash.push('p=' + page); 1179 newHash.push('p=' + page);
1113 1180
1114 if (grouped) 1181 if (grouped)
1115 newHash.push('g=' + grouped); 1182 newHash.push('g=' + grouped);
1116 1183
1117 if (range) 1184 if (range)
1118 newHash.push('r=' + range); 1185 newHash.push('r=' + range);
1119 1186
1187 if (offset)
1188 newHash.push('o=' + offset);
1189
1120 return newHash.join('&'); 1190 return newHash.join('&');
1121 }; 1191 };
1122 1192
1123 /////////////////////////////////////////////////////////////////////////////// 1193 ///////////////////////////////////////////////////////////////////////////////
1124 // Document Functions: 1194 // Document Functions:
1125 /** 1195 /**
1126 * Window onload handler, sets up the page. 1196 * Window onload handler, sets up the page.
1127 */ 1197 */
1128 function load() { 1198 function load() {
1129 uber.onContentFrameLoaded(); 1199 uber.onContentFrameLoaded();
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 innerResultList.style.height = height + 'px'; 1435 innerResultList.style.height = height + 'px';
1366 innerArrow.classList.remove('collapse'); 1436 innerArrow.classList.remove('collapse');
1367 innerArrow.classList.add('expand'); 1437 innerArrow.classList.add('expand');
1368 } else { 1438 } else {
1369 innerResultList.style.height = 0; 1439 innerResultList.style.height = 0;
1370 innerArrow.classList.remove('expand'); 1440 innerArrow.classList.remove('expand');
1371 innerArrow.classList.add('collapse'); 1441 innerArrow.classList.add('collapse');
1372 } 1442 }
1373 } 1443 }
1374 1444
1445 /**
1446 * Enables or disables the time range buttons.
1447 * @param {boolean} groupByDomain Whether grouping by domain is active
1448 * @param {HistoryView} view The current history view.
1449 */
1450 function setRangeButtonsState(groupByDomain, view) {
1451 // The enabled state for the previous, today and next buttons.
1452 var buttonsState = [false, false, false];
1453 var start = 0;
1454 var isQueryFinished = view.model_.isQueryFinished_;
1455 var offset = view.getOffset();
1456
1457 // Set today button.
1458 if (offset != start) {
1459 buttonsState[2] = true;
James Hawkins 2013/01/28 17:48:15 Consider creating local const vars, e.g.: PREVIOU
Sergiu 2013/01/30 16:09:39 Changed them to local variables, initially I thoug
1460 buttonsState[1] = true;
1461 }
1462
1463 // TODO(sergiu): isQueryFinished does not return the correct value now but
1464 // ideally it would return false when there are no older results available.
1465 // Until then allow to go back in time as much as the user wants.
1466 // See http://crbug.com/167363.
1467 buttonsState[0] = true;
1468
1469 $('range-previous').disabled = !(groupByDomain && buttonsState[0]);
1470 $('range-today').disabled = !(groupByDomain && buttonsState[1]);
1471 $('range-next').disabled = !(groupByDomain && buttonsState[2]);
1472 $('timeframe-filter').disabled = !groupByDomain;
1473 }
1474
1375 /////////////////////////////////////////////////////////////////////////////// 1475 ///////////////////////////////////////////////////////////////////////////////
1376 // Chrome callbacks: 1476 // Chrome callbacks:
1377 1477
1378 /** 1478 /**
1379 * Our history system calls this function with results from searches. 1479 * Our history system calls this function with results from searches.
1380 * @param {Object} info An object containing information about the query. 1480 * @param {Object} info An object containing information about the query.
1381 * @param {Array} results A list of results. 1481 * @param {Array} results A list of results.
1382 */ 1482 */
1383 function historyResult(info, results) { 1483 function historyResult(info, results) {
1384 historyModel.addResults(info, results); 1484 historyModel.addResults(info, results);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 historyView.reload(); 1522 historyView.reload();
1423 } 1523 }
1424 1524
1425 // Add handlers to HTML elements. 1525 // Add handlers to HTML elements.
1426 document.addEventListener('DOMContentLoaded', load); 1526 document.addEventListener('DOMContentLoaded', load);
1427 1527
1428 // This event lets us enable and disable menu items before the menu is shown. 1528 // This event lets us enable and disable menu items before the menu is shown.
1429 document.addEventListener('canExecute', function(e) { 1529 document.addEventListener('canExecute', function(e) {
1430 e.canExecute = true; 1530 e.canExecute = true;
1431 }); 1531 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698