Browse Source

[spark] Move function to fix editor page

Romain Rigaux 10 years ago
parent
commit
1d305fe477
1 changed files with 37 additions and 37 deletions
  1. 37 37
      apps/spark/src/spark/static/spark/js/spark.ko.js

+ 37 - 37
apps/spark/src/spark/static/spark/js/spark.ko.js

@@ -596,8 +596,44 @@ var Notebook = function (vm, notebook) {
     _snippet.init();
   };
 
+  self.createSession = function (session, callback) {
+    var snippets = $.grep(self.snippets(), function (snippet) {
+       return snippet.type() == session.type;
+    });
+
+    $.each(snippets, function(index, snippet) {
+      snippet.status('loading');
+    });
+
+    $.post("/spark/api/create_session", {
+      notebook: ko.mapping.toJSON(self.getContext()),
+      session: ko.mapping.toJSON(session), // e.g. {'type': 'hive', 'properties': [{'driverCores': '2'}]}
+    }, function (data) {
+      if (data.status == 0) {
+        self.addSession(ko.mapping.fromJS(data.session));
+        $.each(snippets, function(index, snippet) {
+          snippet.status('ready');
+        });
+        if (callback) {
+          setTimeout(callback, 500);
+        }
+      }
+      else {
+        $.each(snippets, function(index, snippet) {
+          snippet.status('failed');
+        });
+        $(document).trigger("error", data.message);
+      }
+    }).fail(function (xhr, textStatus, errorThrown) {
+      $.each(snippets, function(index, snippet) {
+        snippet.status('failed');
+      })
+      $(document).trigger("error", xhr.responseText);
+    });
+  };
+
   self.newSnippet = function () {
-  	var properties = {};
+    var properties = {};
 
     var addSparkYarnProperties = function() {
       properties['driverCores'] = '';
@@ -693,42 +729,6 @@ var Notebook = function (vm, notebook) {
     });
   };
 
-  self.createSession = function (session, callback) {
-    var snippets = $.grep(self.snippets(), function (snippet) {
-       return snippet.type() == session.type;
-    });
-
-    $.each(snippets, function(index, snippet) {
-      snippet.status('loading');
-    });
-
-    $.post("/spark/api/create_session", {
-      notebook: ko.mapping.toJSON(self.getContext()),
-      session: ko.mapping.toJSON(session), // e.g. {'type': 'hive', 'properties': [{'driverCores': '2'}]}
-    }, function (data) {
-      if (data.status == 0) {
-        self.addSession(ko.mapping.fromJS(data.session));
-        $.each(snippets, function(index, snippet) {
-          snippet.status('ready');
-        });
-        if (callback) {
-          setTimeout(callback, 500);
-        }
-      }
-      else {
-        $.each(snippets, function(index, snippet) {
-          snippet.status('failed');
-    	});
-        $(document).trigger("error", data.message);
-      }
-    }).fail(function (xhr, textStatus, errorThrown) {
-      $.each(snippets, function(index, snippet) {
-        snippet.status('failed');
-      })
-      $(document).trigger("error", xhr.responseText);
-    });
-  };
-
   self.closeSession = function (session) {
     $.post("/spark/api/close_session", {
       session: ko.mapping.toJSON(session)