You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/08/17 11:39:23 UTC

[GitHub] garrensmith commented on a change in pull request #958: add query history to Mango UI

garrensmith commented on a change in pull request #958: add query history to Mango UI
URL: https://github.com/apache/couchdb-fauxton/pull/958#discussion_r133677785
 
 

 ##########
 File path: app/addons/documents/mango/mango.stores.js
 ##########
 @@ -77,6 +73,59 @@ Stores.MangoStore = FauxtonAPI.Store.extend({
     return this._explainPlan;
   },
 
+  getHistoryKey: function() {
+    return this._historyKey;
+  },
+
+  setHistoryKey: function(key) {
+    this._historyKey = key + '_queryhistory';
+  },
+
+  createHistoryEntry: function(queryObject) {
+    // ensure we're working with a deserialized query object
+    const object = typeof queryObject === "string" ? JSON.parse(queryObject) : queryObject;
+
+    const singleLineValue = JSON.stringify(object);
+    const multiLineValue = this.formatCode(object);
+
+    return {
+      label: singleLineValue,
+      value: multiLineValue,
+      className: 'mango-history-entry'
+    };
+  },
+
+  addQueryHistory: function (value, label) {
+    var history = this.getHistory();
+
+    const historyEntry = this.createHistoryEntry(value);
+    historyEntry.label = label || historyEntry.label;
+
+    // remove existing entry if it exists
+    var indexOfExisting = history.findIndex(i => i.value === historyEntry.value);
+    if (indexOfExisting > -1) {
+      history.splice(indexOfExisting, 1);
+    }
+
+    // insert item at head of array
+    history.splice(0, 0, historyEntry);
+
+    // limit array length
+    if (history.length > HISTORY_LIMIT) {
 
 Review comment:
   Using splice is fine. You can also use `history.pop()`. To add something to a front of an array you can also do `array.unshift(item);`
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services