##// END OF EJS Templates
Fix bugs introduced into session.js
Jessica B. Hamrick -
Show More
@@ -11,11 +11,12 define([
11 11
12 12 var Session = function (options) {
13 13 this.id = null;
14 this.notebook = {
14 this.notebook_model = {
15 15 name: options.notebook_name,
16 16 path: options.notebook_path
17 17 };
18 this.kernel = {
18 this.kernel_model = {
19 id: null,
19 20 name: options.kernel_name
20 21 };
21 22
@@ -23,7 +24,8 define([
23 24 this.ws_url = options.ws_url;
24 25 this.sessions_url = utils.url_join_encode(this.base_url, 'api/sessions');
25 26
26 this.notebook_obj = options.notebook;
27 this.notebook = options.notebook;
28 this.kernel = null;
27 29 this.events = options.events;
28 30 };
29 31
@@ -48,7 +50,9 define([
48 50 var that = this;
49 51 var on_success = function (data, status, xhr) {
50 52 var kernel_service_url = utils.url_path_join(that.base_url, "api/kernels");
51 that.kernel = new kernel.Kernel(kernel_service_url, that.ws_url, that.notebook_obj, that.kernel_name);
53 that.kernel = new kernel.Kernel(
54 kernel_service_url, that.ws_url, that.notebook,
55 that.kernel_model.id, that.kernel_model.name);
52 56 that.kernel._kernel_started(data.kernel);
53 57 if (success) {
54 58 success(data, status, xhr);
@@ -91,9 +95,9 define([
91 95 * PATCH /api/sessions/[:session_id]
92 96 */
93 97 Session.prototype.change = function (notebook_name, notebook_path, kernel_name, success, error) {
94 this.notebook.name = notebook_name;
95 this.notebook.path = notebook_path;
96 this.kernel.name = kernel_name;
98 this.notebook_model.name = notebook_name;
99 this.notebook_model.path = notebook_path;
100 this.kernel_model.name = kernel_name;
97 101
98 102 var url = utils.url_join_encode(this.sessions_url, this.id);
99 103 $.ajax(url, {
@@ -108,17 +112,19 define([
108 112 };
109 113
110 114 Session.prototype.rename_notebook = function (name, path, success, error) {
111 this.change(name, path, this.kernel.name, success, error);
115 this.change(name, path, this.kernel_model.name, success, error);
112 116 };
113 117
114 118 /**
115 119 * DELETE /api/sessions/[:session_id]
116 120 */
117 Session.prototype.kill = function (success, error) {
118 if (this.kernel) {
119 this.kernel.running = false;
120 this.kernel.stop_channels();
121 Session.prototype.delete = function (success, error) {
122 var that = this;
123 var on_success = function (data, status, xhr) {
124 if (that.kernel) {
125 that.kernel._kernel_dead();
121 126 }
127 };
122 128
123 129 var url = utils.url_join_encode(this.sessions_url, this.id);
124 130 $.ajax(url, {
@@ -126,26 +132,29 define([
126 132 cache: false,
127 133 type: "DELETE",
128 134 dataType: "json",
129 success: this._on_success(success),
135 success: this._on_success(on_success),
130 136 error: this._on_error(error)
131 137 });
132 138 };
133 139
134 140 Session.prototype._get_model = function () {
135 141 return {
136 notebook: this.notebook,
137 kernel: this.kernel
142 notebook: this.notebook_model,
143 kernel: this.kernel_model
138 144 };
139 145 };
140 146
141 147 Session.prototype._update_model = function (data) {
148 if (data && data.id) {
142 149 this.id = data.id;
143 if (data.notebook) {
144 this.notebook.name = data.notebook.name;
145 this.notebook.path = data.notebook.path;
146 150 }
147 if (data.kernel) {
148 this.kernel.name = data.kernel.name;
151 if (data && data.notebook) {
152 this.notebook_model.name = data.notebook.name;
153 this.notebook_model.path = data.notebook.path;
154 }
155 if (data && data.kernel) {
156 this.kernel_model.name = data.kernel.name;
157 this.kernel_model.id = data.kernel.id;
149 158 }
150 159 };
151 160
General Comments 0
You need to be logged in to leave comments. Login now