##// END OF EJS Templates
Handle unrecognized outputs and cells from the future
Min RK -
Show More
@@ -53,7 +53,9 b' define(['
53 get: function() { return that._metadata; },
53 get: function() { return that._metadata; },
54 set: function(value) {
54 set: function(value) {
55 that._metadata = value;
55 that._metadata = value;
56 that.celltoolbar.rebuild();
56 if (that.celltoolbar) {
57 that.celltoolbar.rebuild();
58 }
57 }
59 }
58 });
60 });
59
61
@@ -194,11 +196,11 b' define(['
194 if((cur.line !== 0 || cur.ch !==0) && event.keyCode === 38){
196 if((cur.line !== 0 || cur.ch !==0) && event.keyCode === 38){
195 event._ipkmIgnore = true;
197 event._ipkmIgnore = true;
196 }
198 }
197 var nLastLine = editor.lastLine()
199 var nLastLine = editor.lastLine();
198 if( ( event.keyCode === 40)
200 if ((event.keyCode === 40) &&
199 && (( cur.line !== nLastLine)
201 ((cur.line !== nLastLine) ||
200 || ( cur.ch !== editor.getLineHandle(nLastLine).text.length))
202 (cur.ch !== editor.getLineHandle(nLastLine).text.length))
201 ){
203 ) {
202 event._ipkmIgnore = true;
204 event._ipkmIgnore = true;
203 }
205 }
204 // if this is an edit_shortcuts shortcut, the global keyboard/shortcut
206 // if this is an edit_shortcuts shortcut, the global keyboard/shortcut
@@ -255,6 +257,14 b' define(['
255 };
257 };
256
258
257 /**
259 /**
260 * should be overritten by subclass
261 * @method execute
262 */
263 Cell.prototype.execute = function () {
264 return;
265 };
266
267 /**
258 * handle cell level logic when a cell is rendered
268 * handle cell level logic when a cell is rendered
259 * @method render
269 * @method render
260 * @return is the action being taken
270 * @return is the action being taken
@@ -386,7 +396,9 b' define(['
386 * @method refresh
396 * @method refresh
387 */
397 */
388 Cell.prototype.refresh = function () {
398 Cell.prototype.refresh = function () {
389 this.code_mirror.refresh();
399 if (this.code_mirror) {
400 this.code_mirror.refresh();
401 }
390 };
402 };
391
403
392 /**
404 /**
@@ -590,8 +602,61 b' define(['
590 this.code_mirror.setOption('mode', default_mode);
602 this.code_mirror.setOption('mode', default_mode);
591 };
603 };
592
604
605 var UnrecognizedCell = function (options) {
606 /** Constructor for unrecognized cells */
607 Cell.apply(this, arguments);
608 this.cell_type = 'unrecognized';
609 this.celltoolbar = null;
610 this.data = {};
611
612 Object.seal(this);
613 };
614
615 UnrecognizedCell.prototype = Object.create(Cell.prototype);
616
617
618 // cannot merge or split unrecognized cells
619 UnrecognizedCell.prototype.is_mergeable = function () {
620 return false;
621 };
622
623 UnrecognizedCell.prototype.is_splittable = function () {
624 return false;
625 };
626
627 UnrecognizedCell.prototype.toJSON = function () {
628 // deepcopy the metadata so copied cells don't share the same object
629 return JSON.parse(JSON.stringify(this.data));
630 };
631
632 UnrecognizedCell.prototype.fromJSON = function (data) {
633 this.data = data;
634 if (data.metadata !== undefined) {
635 this.metadata = data.metadata;
636 } else {
637 data.metadata = this.metadata;
638 }
639 this.element.find('.inner_cell').text("Unrecognized cell type: " + data.cell_type);
640 };
641
642 UnrecognizedCell.prototype.create_element = function () {
643 Cell.prototype.create_element.apply(this, arguments);
644 var cell = this.element = $("<div>").addClass('cell unrecognized_cell');
645 cell.attr('tabindex','2');
646
647 var prompt = $('<div/>').addClass('prompt input_prompt');
648 cell.append(prompt);
649 var inner_cell = $('<div/>').addClass('inner_cell');
650 inner_cell.text("Unrecognized cell type");
651 cell.append(inner_cell);
652 this.element = cell;
653 };
654
593 // Backwards compatibility.
655 // Backwards compatibility.
594 IPython.Cell = Cell;
656 IPython.Cell = Cell;
595
657
596 return {'Cell': Cell};
658 return {
659 Cell: Cell,
660 UnrecognizedCell: UnrecognizedCell
661 };
597 });
662 });
@@ -6,6 +6,7 b' define(['
6 'jquery',
6 'jquery',
7 'base/js/utils',
7 'base/js/utils',
8 'base/js/dialog',
8 'base/js/dialog',
9 'notebook/js/cell',
9 'notebook/js/textcell',
10 'notebook/js/textcell',
10 'notebook/js/codecell',
11 'notebook/js/codecell',
11 'services/sessions/session',
12 'services/sessions/session',
@@ -22,13 +23,14 b' define(['
22 'notebook/js/scrollmanager'
23 'notebook/js/scrollmanager'
23 ], function (
24 ], function (
24 IPython,
25 IPython,
25 $,
26 $,
26 utils,
27 utils,
27 dialog,
28 dialog,
28 textcell,
29 cellmod,
29 codecell,
30 textcell,
31 codecell,
30 session,
32 session,
31 celltoolbar,
33 celltoolbar,
32 marked,
34 marked,
33 CodeMirror,
35 CodeMirror,
34 runMode,
36 runMode,
@@ -894,7 +896,8 b' define(['
894 cell = new textcell.RawCell(cell_options);
896 cell = new textcell.RawCell(cell_options);
895 break;
897 break;
896 default:
898 default:
897 console.log("invalid cell type: ", type);
899 console.log("Unrecognized cell type: ", type, cellmod);
900 cell = new cellmod.UnrecognizedCell(cell_options);
898 }
901 }
899
902
900 if(this._insert_element_at_index(cell.element,index)) {
903 if(this._insert_element_at_index(cell.element,index)) {
@@ -245,7 +245,7 b' define(['
245 'text/plain'
245 'text/plain'
246 ];
246 ];
247
247
248 OutputArea.prototype.validate_output = function (json) {
248 OutputArea.prototype.validate_mimebundle = function (json) {
249 // scrub invalid outputs
249 // scrub invalid outputs
250 var data = json.data;
250 var data = json.data;
251 $.map(OutputArea.output_types, function(key){
251 $.map(OutputArea.output_types, function(key){
@@ -263,11 +263,6 b' define(['
263 OutputArea.prototype.append_output = function (json) {
263 OutputArea.prototype.append_output = function (json) {
264 this.expand();
264 this.expand();
265
265
266 // validate output data types
267 if (json.data) {
268 json = this.validate_output(json);
269 }
270
271 // Clear the output if clear is queued.
266 // Clear the output if clear is queued.
272 var needs_height_reset = false;
267 var needs_height_reset = false;
273 if (this.clear_queued) {
268 if (this.clear_queued) {
@@ -276,14 +271,26 b' define(['
276 }
271 }
277
272
278 var record_output = true;
273 var record_output = true;
279
274 console.log("appending", json);
280 if (json.output_type === 'execute_result') {
275 switch(json.output_type) {
281 this.append_execute_result(json);
276 case 'execute_result':
282 } else if (json.output_type === 'error') {
277 json = this.validate_mimebundle(json);
283 this.append_error(json);
278 this.append_execute_result(json);
284 } else if (json.output_type === 'stream') {
279 break;
285 // append_stream might have merged the output with earlier stream output
280 case 'stream':
286 record_output = this.append_stream(json);
281 // append_stream might have merged the output with earlier stream output
282 record_output = this.append_stream(json);
283 break;
284 case 'error':
285 this.append_error(json);
286 break;
287 case 'display_data':
288 // append handled below
289 json = this.validate_mimebundle(json);
290 break;
291 default:
292 console.log("unrecognized output type: " + json.output_type);
293 this.append_unrecognized(json);
287 }
294 }
288
295
289 // We must release the animation fixed height in a callback since Gecko
296 // We must release the animation fixed height in a callback since Gecko
@@ -482,6 +489,15 b' define(['
482 };
489 };
483
490
484
491
492 OutputArea.prototype.append_unrecognized = function (json) {
493 var toinsert = this.create_output_area();
494 var subarea = $('<div/>').addClass('output_subarea output_unrecognized');
495 toinsert.append(subarea);
496 subarea.text("Unrecognized output: " + json.output_type);
497 this._safe_append(toinsert);
498 };
499
500
485 OutputArea.prototype.append_display_data = function (json, handle_inserted) {
501 OutputArea.prototype.append_display_data = function (json, handle_inserted) {
486 var toinsert = this.create_output_area();
502 var toinsert = this.create_output_area();
487 if (this.append_mime_type(json, toinsert, handle_inserted)) {
503 if (this.append_mime_type(json, toinsert, handle_inserted)) {
@@ -340,7 +340,7 b' define(['
340 var textcell = {
340 var textcell = {
341 TextCell: TextCell,
341 TextCell: TextCell,
342 MarkdownCell: MarkdownCell,
342 MarkdownCell: MarkdownCell,
343 RawCell: RawCell,
343 RawCell: RawCell
344 };
344 };
345 return textcell;
345 return textcell;
346 });
346 });
@@ -61,3 +61,24 b' div.prompt:empty {'
61 padding-top: 0;
61 padding-top: 0;
62 padding-bottom: 0;
62 padding-bottom: 0;
63 }
63 }
64
65 div.unrecognized_cell {
66 // from text_cell
67 padding: 5px 5px 5px 0px;
68 .hbox();
69
70 .inner_cell {
71 .border-radius(@border-radius-base);
72 padding: 5px;
73 font-weight: bold;
74 color: red;
75 border: 1px solid @light_border_color;
76 background: darken(@cell_background, 5%);
77 }
78 }
79 @media (max-width: 480px) {
80 // remove prompt indentation on small screens
81 div.unrecognized_cell > div.prompt {
82 display: none;
83 }
84 }
@@ -172,3 +172,9 b' input.raw_input:focus {'
172 p.p-space {
172 p.p-space {
173 margin-bottom: 10px;
173 margin-bottom: 10px;
174 }
174 }
175
176 div.output_unrecognized {
177 padding: 5px;
178 font-weight: bold;
179 color: red;
180 } No newline at end of file
@@ -419,6 +419,36 b' div.prompt:empty {'
419 padding-top: 0;
419 padding-top: 0;
420 padding-bottom: 0;
420 padding-bottom: 0;
421 }
421 }
422 div.unrecognized_cell {
423 padding: 5px 5px 5px 0px;
424 /* Old browsers */
425 display: -webkit-box;
426 -webkit-box-orient: horizontal;
427 -webkit-box-align: stretch;
428 display: -moz-box;
429 -moz-box-orient: horizontal;
430 -moz-box-align: stretch;
431 display: box;
432 box-orient: horizontal;
433 box-align: stretch;
434 /* Modern browsers */
435 display: flex;
436 flex-direction: row;
437 align-items: stretch;
438 }
439 div.unrecognized_cell .inner_cell {
440 border-radius: 4px;
441 padding: 5px;
442 font-weight: bold;
443 color: red;
444 border: 1px solid #cfcfcf;
445 background: #eaeaea;
446 }
447 @media (max-width: 480px) {
448 div.unrecognized_cell > div.prompt {
449 display: none;
450 }
451 }
422 /* any special styling for code cells that are currently running goes here */
452 /* any special styling for code cells that are currently running goes here */
423 div.input {
453 div.input {
424 page-break-inside: avoid;
454 page-break-inside: avoid;
@@ -888,6 +918,12 b' input.raw_input:focus {'
888 p.p-space {
918 p.p-space {
889 margin-bottom: 10px;
919 margin-bottom: 10px;
890 }
920 }
921 div.output_unrecognized {
922 border-radius: 4px;
923 padding: 5px;
924 font-weight: bold;
925 color: red;
926 }
891 .rendered_html {
927 .rendered_html {
892 color: #000000;
928 color: #000000;
893 /* any extras will just be numbers: */
929 /* any extras will just be numbers: */
@@ -8288,6 +8288,36 b' div.prompt:empty {'
8288 padding-top: 0;
8288 padding-top: 0;
8289 padding-bottom: 0;
8289 padding-bottom: 0;
8290 }
8290 }
8291 div.unrecognized_cell {
8292 padding: 5px 5px 5px 0px;
8293 /* Old browsers */
8294 display: -webkit-box;
8295 -webkit-box-orient: horizontal;
8296 -webkit-box-align: stretch;
8297 display: -moz-box;
8298 -moz-box-orient: horizontal;
8299 -moz-box-align: stretch;
8300 display: box;
8301 box-orient: horizontal;
8302 box-align: stretch;
8303 /* Modern browsers */
8304 display: flex;
8305 flex-direction: row;
8306 align-items: stretch;
8307 }
8308 div.unrecognized_cell .inner_cell {
8309 border-radius: 4px;
8310 padding: 5px;
8311 font-weight: bold;
8312 color: red;
8313 border: 1px solid #cfcfcf;
8314 background: #eaeaea;
8315 }
8316 @media (max-width: 480px) {
8317 div.unrecognized_cell > div.prompt {
8318 display: none;
8319 }
8320 }
8291 /* any special styling for code cells that are currently running goes here */
8321 /* any special styling for code cells that are currently running goes here */
8292 div.input {
8322 div.input {
8293 page-break-inside: avoid;
8323 page-break-inside: avoid;
@@ -8757,6 +8787,12 b' input.raw_input:focus {'
8757 p.p-space {
8787 p.p-space {
8758 margin-bottom: 10px;
8788 margin-bottom: 10px;
8759 }
8789 }
8790 div.output_unrecognized {
8791 border-radius: 4px;
8792 padding: 5px;
8793 font-weight: bold;
8794 color: red;
8795 }
8760 .rendered_html {
8796 .rendered_html {
8761 color: #000000;
8797 color: #000000;
8762 /* any extras will just be numbers: */
8798 /* any extras will just be numbers: */
General Comments 0
You need to be logged in to leave comments. Login now