Skip to content

Commit 8f625bc

Browse files
committed
#22 - Fixed subset preview bug. This closes #22
1 parent 485fa88 commit 8f625bc

2 files changed

Lines changed: 48 additions & 35 deletions

File tree

src/common/component/vpVarSelector.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ define([
131131
// load using kernel
132132
var dataTypes = this.showOthers? []: this.dataTypes;
133133
kernelApi.searchVarList(dataTypes, function(result) {
134-
var varList = JSON.parse(result);
135-
that.state.varList = varList;
136-
// render variable list
137-
that.loadVariableList(varList);
134+
try {
135+
var varList = JSON.parse(result);
136+
that.state.varList = varList;
137+
// render variable list
138+
that.loadVariableList(varList);
139+
} catch (ex) {
140+
console.log(ex);
141+
}
138142
});
139143
}
140144

src/common/vpSubsetEditor.js

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -150,28 +150,6 @@ define([
150150
this.bindEvent();
151151
this.init();
152152

153-
// set codemirror
154-
this.codepreview = codemirror.fromTextArea($('#vp_previewCode')[0], {
155-
mode: {
156-
name: 'python',
157-
version: 3,
158-
singleLineStringErrors: false
159-
}, // text-cell(markdown cell) set to 'htmlmixed'
160-
height: '100%',
161-
width: '100%',
162-
indentUnit: 4,
163-
matchBrackets: true,
164-
readOnly:true,
165-
autoRefresh: true,
166-
// lineWrapping: false, // text-cell(markdown cell) set to true
167-
// indentWithTabs: true,
168-
theme: "ipython",
169-
extraKeys: {"Enter": "newlineAndIndentContinueMarkdownList"},
170-
scrollbarStyle: "null"
171-
});
172-
this.setPreview('# Code Preview');
173-
174-
175153
// set readonly
176154
if (useInputVariable) {
177155
$(this.wrapSelector('.' + VP_DS_PANDAS_OBJECT)).attr('disabled', true);
@@ -384,7 +362,7 @@ define([
384362
* Wrap Selector for data selector popup with its uuid
385363
* @param {string} query
386364
*/
387-
SubsetEditor.prototype.wrapSelector = function(query) {
365+
SubsetEditor.prototype.wrapSelector = function(query = '') {
388366
return vpCommon.formatString('.{0}.{1} {2}', VP_DS, this.uuid, query);
389367
}
390368

@@ -1644,17 +1622,46 @@ define([
16441622
* open popup
16451623
*/
16461624
SubsetEditor.prototype.open = function() {
1625+
if (!this.codepreview) {
1626+
// var previewTextarea = $('#vp_previewCode')[0];
1627+
var previewTextarea = $(this.wrapSelector('#vp_previewCode'))[0];
1628+
// if (wrappedTextarea) {
1629+
// previewTextarea = wrappedTextarea;
1630+
// }
1631+
// set codemirror
1632+
this.codepreview = codemirror.fromTextArea(previewTextarea, {
1633+
mode: {
1634+
name: 'python',
1635+
version: 3,
1636+
singleLineStringErrors: false
1637+
}, // text-cell(markdown cell) set to 'htmlmixed'
1638+
height: '100%',
1639+
width: '100%',
1640+
indentUnit: 4,
1641+
matchBrackets: true,
1642+
readOnly:true,
1643+
autoRefresh: true,
1644+
// lineWrapping: false, // text-cell(markdown cell) set to true
1645+
// indentWithTabs: true,
1646+
theme: "ipython",
1647+
extraKeys: {"Enter": "newlineAndIndentContinueMarkdownList"},
1648+
scrollbarStyle: "null"
1649+
});
1650+
this.setPreview('# Code Preview');
1651+
}
1652+
this.codepreview.refresh();
1653+
16471654
// reload pandasObject on open
16481655
this.loadVariables();
16491656

1650-
$(vpCommon.formatString(".{0}.{1}", VP_DS, this.uuid)).show();
1657+
$(this.wrapSelector()).show();
16511658
}
16521659

16531660
/**
16541661
* close popup
16551662
*/
16561663
SubsetEditor.prototype.close = function() {
1657-
$(vpCommon.formatString(".{0}.{1}", VP_DS, this.uuid)).hide();
1664+
$(this.wrapSelector()).hide();
16581665
}
16591666

16601667
SubsetEditor.prototype.hideButton = function() {
@@ -1908,12 +1915,14 @@ define([
19081915
}
19091916

19101917
SubsetEditor.prototype.setPreview = function(previewCodeStr) {
1911-
this.codepreview.setValue(previewCodeStr);
1912-
this.codepreview.save();
1913-
var that = this;
1914-
setTimeout(function() {
1915-
that.codepreview.refresh();
1916-
}, 1);
1918+
if (this.codepreview) {
1919+
this.codepreview.setValue(previewCodeStr);
1920+
this.codepreview.save();
1921+
var that = this;
1922+
setTimeout(function() {
1923+
that.codepreview.refresh();
1924+
}, 1);
1925+
}
19171926
}
19181927

19191928
return SubsetEditor

0 commit comments

Comments
 (0)