Browse Source

[editor] Added back temporary saving of query

Enrico Berti 9 năm trước cách đây
mục cha
commit
e45ac9b547

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -2357,6 +2357,9 @@
       editor.on("blur", function () {
         snippet.inFocus(false);
         snippet.statement_raw(editor.getValue());
+        if (options.onBlur) {
+          options.onBlur($el, editor.getValue());
+        }
       });
 
       var currentAssistTables = {};

+ 13 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -199,7 +199,7 @@ ${ require.config() }
            
 
         % if mode == 'editor':
-        <a class="btn" href="${ url('notebook:editor') }?type=${ editor_type }" title="${ _('New %s Query') % editor_type.title() }" rel="tooltip" data-placement="bottom">
+        <a class="btn" href="${ url('notebook:editor') }?type=${ editor_type }&new=true" title="${ _('New %s Query') % editor_type.title() }" rel="tooltip" data-placement="bottom">
           <i class="fa fa-file-o"></i>
         </a>
         % else:
@@ -599,6 +599,7 @@ ${ require.config() }
           snippet: $data,
           openIt: '${ _ko("Alt or Ctrl + Click to open it") }',
           expandStar: '${ _ko("Alt or Ctrl + Click to replace with all columns") }',
+          onBlur: saveTemporarySnippet,
           aceOptions: {
             showLineNumbers: $root.editorMode,
             showGutter: $root.editorMode,
@@ -1657,6 +1658,12 @@ ${ require.config() }
     return _datum;
   }
 
+  function saveTemporarySnippet($element, value) {
+    if ($element.data('last-active-editor')) {
+      $.totalStorage('hue.notebook.lastWrittenSnippet', value);
+    }
+  }
+
   require([
     "knockout",
     "ko.charts",
@@ -1998,6 +2005,11 @@ ${ require.config() }
       ko.applyBindings(viewModel);
       viewModel.init();
 
+      if (viewModel.editorMode && window.location.getParameter('editor') == '' && window.location.getParameter('new') == '') {
+        viewModel.selectedNotebook().snippets()[0].statement_raw($.totalStorage('hue.notebook.lastWrittenSnippet'));
+        $.totalStorage('hue.notebook.lastWrittenSnippet', '');
+      }
+
       if (location.getParameter("github_status") != "") {
         if (location.getParameter("github_status") == "0") {
           $.jHueNotify.info("${ _('User successfully authenticated to GitHub.') }");