@@ -27,6 +27,13 @@ MPG.databaseName = '';
2727 */
2828MPG . collectionName = '' ;
2929
30+ /**
31+ * History of queries.
32+ *
33+ * @type {Array }
34+ */
35+ MPG . queryHistory = [ ] ;
36+
3037/**
3138 * List of MongoDB and SQL keywords.
3239 * XXX Used for autocompletion.
@@ -83,6 +90,13 @@ MPG.initializeCodeMirror = function() {
8390 document . querySelector ( '#mpg-filter-or-doc-textarea' )
8491 ) ;
8592
93+ var historyPopButton = document . createElement ( 'button' ) ;
94+
95+ historyPopButton . className = 'mpg-history-pop-button' ;
96+ historyPopButton . innerHTML = '<i class="fa fa-history" aria-hidden="true"></i>' ;
97+
98+ document . querySelector ( '.CodeMirror' ) . appendChild ( historyPopButton ) ;
99+
86100} ;
87101
88102/**
@@ -653,6 +667,34 @@ MPG.eventListeners.addCodeMirror = function() {
653667
654668} ;
655669
670+ /**
671+ * Adds an event listener on "History pop" button.
672+ *
673+ * @returns {void }
674+ */
675+ MPG . eventListeners . addHistoryPop = function ( ) {
676+
677+ document . querySelector ( '.CodeMirror .mpg-history-pop-button' )
678+ . addEventListener ( 'click' , function ( _event ) {
679+
680+ var lastQuery = MPG . queryHistory . pop ( ) ;
681+
682+ if ( lastQuery === MPG . codeMirror . getValue ( ) ) {
683+ lastQuery = MPG . queryHistory . pop ( ) ;
684+ }
685+
686+ if ( typeof lastQuery === 'string' ) {
687+ MPG . codeMirror . setValue ( lastQuery ) ;
688+ MPG . codeMirror . save ( ) ;
689+ } else {
690+ MPG . codeMirror . setValue ( '' ) ;
691+ MPG . codeMirror . save ( ) ;
692+ }
693+
694+ } ) ;
695+
696+ } ;
697+
656698/**
657699 * Adds an event listener on "Find" button.
658700 *
@@ -698,6 +740,7 @@ MPG.eventListeners.addFind = function() {
698740 if ( filterOrDocTextAreaValue === '' ) {
699741 requestBody . filter = { } ;
700742 } else {
743+ MPG . queryHistory . push ( filterOrDocTextAreaValue ) ;
701744 requestBody . filter = JSON . parse ( filterOrDocTextAreaValue ) ;
702745 }
703746
@@ -789,6 +832,7 @@ window.addEventListener('DOMContentLoaded', function(_event) {
789832 MPG . eventListeners . addCount ( ) ;
790833 MPG . eventListeners . addDeleteOne ( ) ;
791834 MPG . eventListeners . addCodeMirror ( ) ;
835+ MPG . eventListeners . addHistoryPop ( ) ;
792836 MPG . eventListeners . addFind ( ) ;
793837 MPG . eventListeners . addCtrlSpace ( ) ;
794838 MPG . eventListeners . addExport ( ) ;
0 commit comments