Răsfoiți Sursa

[notebook] Add all snippets execute function

In notebooks, there's a function named 'Execute all snippets', but it's not been finished.
If an error occurred, the next will continue.
airokey 10 ani în urmă
părinte
comite
5c3049715c

+ 19 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -950,6 +950,25 @@
       });
     };
 
+    self.executeAll = function () {
+      if (self.snippets().length < 1)
+        return;
+  
+      var index = 0;
+      self.snippets()[index].execute();
+      var clock = setInterval(next, 100);
+  
+      function next() {
+        if (self.snippets()[index].status() == 'available' || self.snippets()[index].status() == 'failed') {
+          index = index + 1;
+          if (self.snippets().length > index)
+            self.snippets()[index].execute();
+          else
+            clearInterval(clock);
+        }
+      }
+    };
+
     self.closeAndRemoveSession = function (session) {
       self.closeSession(session, false, function() {
         self.sessions.remove(session);

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

@@ -171,7 +171,7 @@ ${ require.config() }
               </a>
             </li>
             <li>
-              <a class="pointer" data-bind="click: function() { $root.selectedNotebook().clearResults() }">
+              <a class="pointer" data-bind="click: function() { $root.selectedNotebook().executeAll() }">
                 <i class="fa fa-fw fa-play"></i> ${ _('Execute all snippets') }
               </a>
             </li>