incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject [12/13] git commit: Fixed BLUR-366: Added search history to the search page
Date Mon, 27 Oct 2014 02:43:15 GMT
Fixed BLUR-366: Added search history to the search page


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/3055e514
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/3055e514
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/3055e514

Branch: refs/heads/master
Commit: 3055e514410bfe79309cc032150a47c920b5c7b3
Parents: 277cb98
Author: Chris Rohr <rohr.chris@gmail.com>
Authored: Sun Oct 26 22:41:14 2014 -0400
Committer: Chris Rohr <rohr.chris@gmail.com>
Committed: Sun Oct 26 22:41:14 2014 -0400

----------------------------------------------------------------------
 LICENSE                                         |    4 +
 blur-console/src/main/webapp/Gruntfile.js       |    1 +
 .../src/main/webapp/js/blurconsole.search.js    |   68 +-
 .../src/main/webapp/libs/moment/moment.js       | 2861 ++++++++++++++++++
 .../src/main/webapp/views/search.tpl.html       |    5 +-
 5 files changed, 2936 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3055e514/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
index b94b796..897bd31 100644
--- a/LICENSE
+++ b/LICENSE
@@ -366,6 +366,10 @@ respond
 ./docs/resources/js/respond.min.js
 Copyright (c) 2012 Scott Jehl
 
+moment.js
+./blur-console/src/main/webapp/libs/moment/moment.js
+Copyright (c) 2011-2014 Tim Wood, Iskren Chernev, Moment.js contributors
+
 ==========================================================================
 The following license applies to the following libraries: d3
 ./blur-gui/src/main/webapp/js/d3.v2.js

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3055e514/blur-console/src/main/webapp/Gruntfile.js
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/Gruntfile.js b/blur-console/src/main/webapp/Gruntfile.js
index f3c794d..d32dd80 100644
--- a/blur-console/src/main/webapp/Gruntfile.js
+++ b/blur-console/src/main/webapp/Gruntfile.js
@@ -43,6 +43,7 @@ module.exports = function (grunt) {
         'libs/flot/jquery.flot.categories.js',
         'libs/flot/jquery.flot.stack.js',
         'libs/typeahead/typeahead.jquery.js',
+        'libs/moment/moment.js',
         'js/blurconsole.js',
         'js/*\.js'
     ];

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3055e514/blur-console/src/main/webapp/js/blurconsole.search.js
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/js/blurconsole.search.js b/blur-console/src/main/webapp/js/blurconsole.search.js
index c51123f..db30b84 100644
--- a/blur-console/src/main/webapp/js/blurconsole.search.js
+++ b/blur-console/src/main/webapp/js/blurconsole.search.js
@@ -16,7 +16,7 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */
-/*global blurconsole:false, confirm:false */
+/*global blurconsole:false, confirm:false, moment:false */
 blurconsole.search = (function () {
   'use strict';
 
@@ -65,7 +65,8 @@ blurconsole.search = (function () {
       $countHolder : $('#resultCount'),
       $facetTrigger : $('#facetTrigger'),
       $optionsTrigger: $('#searchOptionsTrigger'),
-      $searchTrigger : $('#searchTrigger')
+      $searchTrigger : $('#searchTrigger'),
+      $historyTrigger : $('#searchHistory')
     };
   }
 
@@ -197,6 +198,8 @@ blurconsole.search = (function () {
       stateMap.$currentTable = $(evt.currentTarget).val();
     });
     jqueryMap.$resultsHolder.on('click', 'a.fetchRow', _fetchRow);
+    jqueryMap.$historyTrigger.on('click', _showHistory);
+    $(document).on('click.history', '.rerunhistory', _setupSearchFromHistory);
   }
 
   function _unregisterPageEvents() {
@@ -210,7 +213,9 @@ blurconsole.search = (function () {
       jqueryMap.$optionsTrigger.popover('destroy');
       jqueryMap.$optionsTrigger.off('shown.bs.popover');
       $(document).off('change');
+      $(document).off('click.history');
       jqueryMap.$tableField.off('change');
+      jqueryMap.$historyTrigger.off('click');
       //jqueryMap.$facetTrigger.off('click');
     }
   }
@@ -230,6 +235,41 @@ blurconsole.search = (function () {
     return cols;
   }
 
+  function _getHistoryList() {
+    if (_supportsLocalStorage()) {
+      return JSON.parse(localStorage.getItem('search-history')) || [];
+    } else {
+      return stateMap.searchHistory || [];
+    }
+  }
+
+  function _saveToHistory(runDate, query) {
+    var currentHistory = _getHistoryList();
+    if (currentHistory.length === 20) {
+      currentHistory.shift();
+    }
+
+    if (currentHistory.length === 0 || currentHistory[currentHistory.length-1].query !==
query) {
+      currentHistory.push({runTime: runDate, query: query});
+      if (_supportsLocalStorage()) {
+        localStorage.setItem('search-history', JSON.stringify(currentHistory));
+      } else {
+        stateMap.searchHistory = currentHistory;
+      }
+    }
+  }
+
+  function _supportsLocalStorage() {
+    var b = 'blur';
+    try {
+      localStorage.setItem(b, b);
+      localStorage.removeItem(b);
+      return true;
+    } catch(e) {
+      return false;
+    }
+  }
+
   //------------------------------ Event Handlers and DOM Methods ---------------------
   function _updateOptionDisplay() {
     var displayText = '';
@@ -350,6 +390,7 @@ blurconsole.search = (function () {
     if (stateMap.$currentDisplay === 'fetch') {
       _drawFetchHolder();
     } else {
+      _saveToHistory(new Date(), stateMap.$currentQuery);
       _drawSearchHolder();
     }
   }
@@ -528,6 +569,29 @@ blurconsole.search = (function () {
     jqueryMap.facetModal.modal();
   }
 
+  function _showHistory() {
+    var history = _getHistoryList();
+    history.sort(function(a, b){
+      return new Date(b.runTime) - new Date(a.runTime);
+    });
+
+    var markup = '<table class="table table-bordered table-condensed table-hover"><thead><tr><th>Query</th><th>Ran</th><th></th></tr></thead><tbody>';
+    $.each(history, function(i, his){
+      markup += '<tr><td>' + his.query + '</td><td>' + moment(his.runTime).fromNow()
+ '</td><td><button class="btn btn-default rerunhistory" type="button" title="Re-run
search" data-query="' + his.query + '"><i class="glyphicon glyphicon-search"></i></button></td></tr>';
+    });
+    markup += '</tbody></table>';
+    jqueryMap.historyModal = $(blurconsole.browserUtils.modal('historyDialog', 'Search History',
markup, null, 'large'));
+    jqueryMap.historyModal.modal();
+  }
+
+  function _setupSearchFromHistory(evt) {
+    jqueryMap.historyModal.modal('hide');
+    var query = $(evt.currentTarget).data('query');
+    jqueryMap.$queryField.val(query);
+    jqueryMap.$resultsHolder.html('');
+    jqueryMap.$countHolder.html('');
+  }
+
   //--------------------------------- Public API ------------------------------------------
   function initModule($container) {
     $container.load(configMap.view, function() {


Mime
View raw message