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