', VP_INS_SELECT_BOX, 'method');
tag.appendFormatLine('
', VP_INS_SELECT_LIST, 'method');
tag.appendLine(' ');
@@ -112,12 +190,64 @@ define([
InstanceEditor.prototype.bindEvent = function() {
var that = this;
+
+ // select datatype
+ $(document).on('click', this.wrapSelector('.' + VP_INS_SELECT_LIST + '.datatype .' + VP_INS_SELECT_ITEM), function(event) {
+ var varType = $(this).attr('data-var-type');
+ $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.datatype .' + VP_INS_SELECT_ITEM)).removeClass('selected');
+ $(this).addClass('selected');
+
+ // if others selected, cannot create variable
+ if (varType == '') {
+ $(that.wrapSelector('.' + VP_CREATE_VAR_BOX)).hide();
+ } else {
+ $(that.wrapSelector('.' + VP_CREATE_VAR_BOX)).show();
+ }
+
+ that.reload();
+ });
+
+ // select variable
+ $(document).on('click', this.wrapSelector('.' + VP_INS_SELECT_LIST + '.variable .' + VP_INS_SELECT_ITEM), function(event) {
+ var varName = $(this).attr('data-var-name');
+ var varType = $(this).attr('data-var-type');
+
+ // console.log('clicked', varName, varType, that.state);
+ $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
+ type:"instance_editor_selected",
+ varName: varName,
+ varType: varType,
+ isMethod: false
+ });
+ });
+
+ // create variable
+ $(document).on('click', this.wrapSelector('.' + VP_CREATE_VAR_BTN), function(event) {
+ var varName = $(that.wrapSelector('.' + VP_CREATE_VAR)).val();
+ var selectedType = $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.datatype .' + VP_INS_SELECT_ITEM + '.selected'));
+ var varType = selectedType.attr('data-var-type');
+ var assignCode = selectedType.attr('data-var-assign');
+
+ if (varName == '') {
+ ; // no variable name entered
+ } else {
+ var code = vpCommon.formatString('{0}{1}\n{2}', varName, assignCode, 'type(' + varName + ').__name__');
+ kernelApi.executePython(code, function(result) {
+ if (result.includes(varType)) {
+ vpCommon.renderSuccessMessage('Variable Created!');
+ that.reload();
+ }
+ $(that.wrapSelector('.' + VP_CREATE_VAR)).val('');
+ });
+ }
+ });
+
// select attribute
$(document).on('click', this.wrapSelector('.' + VP_INS_SELECT_LIST + '.attr .' + VP_INS_SELECT_ITEM), function(event) {
var varName = $(this).attr('data-var-name');
var varType = $(this).attr('data-var-type');
- console.log('clicked', varName, varType);
+ // console.log('clicked', varName, varType, that.state);
$(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
type:"instance_editor_selected",
varName: varName,
@@ -130,7 +260,7 @@ define([
$(document).on('click', this.wrapSelector('.' + VP_INS_SELECT_LIST + '.method .' + VP_INS_SELECT_ITEM), function(event) {
var varName = $(this).attr('data-var-name');
var varType = $(this).attr('data-var-type');
- console.log('clicked', varName, varType);
+ // console.log('clicked', varName, varType, that.state);
$(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
type:"instance_editor_selected",
varName: varName,
@@ -158,7 +288,6 @@ define([
});
}
}
-
});
}
@@ -166,6 +295,16 @@ define([
var that = this;
var variable = $(this.pageThis.wrapSelector('#' + this.targetId)).val();
this.state.code = variable;
+
+ if (variable == '') {
+ if (!this.isFirstPage) {
+ this.renderFirstPage();
+ this.isFirstPage = true;
+ }
+ } else {
+ this.isFirstPage = false;
+ this.renderPage();
+ }
var code = vpCommon.formatString('_vp_print(_vp_load_instance("{0}"))', variable);
@@ -190,107 +329,113 @@ define([
// $(that.wrapSelector('#vp_instanceType')).text(varType);
// set dir list
- var attrListTag = new sb.StringBuilder();
- var methodListTag = new sb.StringBuilder();
- var attrList = [];
- var methodList = [];
- varList != undefined && varList.forEach(obj => {
- if (obj.type.includes('Indexer')) {
- methodListTag.appendFormatLine('
{3} {4}'
- , VP_INS_SELECT_ITEM, obj.name + '[]', obj.type, obj.type, obj.name);
- methodList.push({
- label: obj.name + '[]' + ' (' + obj.type + ')',
- value: obj.name + '[]',
- type: obj.type
- });
- }
- // Method/Function... 이면 Method 항목에 표시
- else if (_METHOD_TYPES.includes(obj.type)) {
- methodListTag.appendFormatLine('
{3} {4}'
- , VP_INS_SELECT_ITEM, obj.name + '()', obj.type, obj.type, obj.name);
- methodList.push({
- label: obj.name + '()' + ' (' + obj.type + ')',
- value: obj.name + '()' ,
- type: obj.type
+
+ if (that.isFirstPage) {
+ varType = $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.datatype .' + VP_INS_SELECT_ITEM + '.selected')).attr('data-var-type');
+ that.renderVarList(varType, varList);
+ } else {
+ var attrListTag = new sb.StringBuilder();
+ var methodListTag = new sb.StringBuilder();
+ var attrList = [];
+ var methodList = [];
+ varList != undefined && varList.forEach(obj => {
+ if (obj.type.includes('Indexer')) {
+ methodListTag.appendFormatLine('
{4} '
+ , VP_INS_SELECT_ITEM, obj.name + '[]', obj.type, obj.type, obj.name);
+ methodList.push({
+ label: obj.name + '[]' + ' (' + obj.type + ')',
+ value: obj.name + '[]',
+ type: obj.type
+ });
+ }
+ // Method/Function... 이면 Method 항목에 표시
+ else if (_METHOD_TYPES.includes(obj.type)) {
+ methodListTag.appendFormatLine('
{4} '
+ , VP_INS_SELECT_ITEM, obj.name + '()', obj.type, obj.type, obj.name);
+ methodList.push({
+ label: obj.name + '()' + ' (' + obj.type + ')',
+ value: obj.name + '()' ,
+ type: obj.type
+ });
+ } else {
+ // FIXME: type이 module일 경우엔 pd(pandas) module만 표시
+ // if (obj.type == 'module' && obj.name != 'pd') {
+ // ;
+ // } else {
+ attrListTag.appendFormatLine('
{4} '
+ , VP_INS_SELECT_ITEM, obj.name, obj.type, obj.type, obj.name);
+ attrList.push({
+ label: obj.name + ' (' + obj.type + ')',
+ value: obj.name,
+ type: obj.type
+ });
+ // }
+ }
+ });
+ $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.attr')).html(attrListTag.toString());
+ $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.method')).html(methodListTag.toString());
+
+ // attribute search suggest
+ var suggestInput = new vpSuggestInputText.vpSuggestInputText();
+ suggestInput.addClass('vp-input attr');
+ suggestInput.addClass(VP_INS_SEARCH);
+ suggestInput.setPlaceholder("search attribute");
+ suggestInput.setSuggestList(function() { return attrList; });
+ suggestInput.setSelectEvent(function(value, item) {
+ $(this.wrapSelector()).val(value);
+ $(that.wrapSelector('.' + VP_INS_TYPE + '.attr')).val(item.type);
+
+ $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
+ type:"instance_editor_selected",
+ varName: value,
+ varType: item.type,
+ isMethod: false
});
- } else {
- // FIXME: type이 module일 경우엔 pd(pandas) module만 표시
- // if (obj.type == 'module' && obj.name != 'pd') {
- // ;
- // } else {
- attrListTag.appendFormatLine('
{3} {4}'
- , VP_INS_SELECT_ITEM, obj.name, obj.type, obj.type, obj.name);
- attrList.push({
- label: obj.name + ' (' + obj.type + ')',
- value: obj.name,
- type: obj.type
+ });
+ $(that.wrapSelector('.' + VP_INS_SEARCH + '.attr')).replaceWith(function() {
+ return suggestInput.toTagString();
+ });
+
+ // method search suggest
+ suggestInput = new vpSuggestInputText.vpSuggestInputText();
+ suggestInput.addClass('vp-input method');
+ suggestInput.addClass(VP_INS_SEARCH);
+ suggestInput.setPlaceholder("search method");
+ suggestInput.setSuggestList(function() { return methodList; });
+ suggestInput.setSelectEvent(function(value, item) {
+ $(this.wrapSelector()).val(value);
+ $(that.wrapSelector('.' + VP_INS_TYPE + '.method')).val(item.type);
+
+ $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
+ type:"instance_editor_selected",
+ varName: value,
+ varType: item.type,
+ isMethod: true
});
- // }
- }
- });
- $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.attr')).html(attrListTag.toString());
- $(that.wrapSelector('.' + VP_INS_SELECT_LIST + '.method')).html(methodListTag.toString());
-
- // attribute search suggest
- var suggestInput = new vpSuggestInputText.vpSuggestInputText();
- suggestInput.addClass('vp-input attr');
- suggestInput.addClass(VP_INS_SEARCH);
- suggestInput.setPlaceholder("search attribute");
- suggestInput.setSuggestList(function() { return attrList; });
- suggestInput.setSelectEvent(function(value, item) {
- $(this.wrapSelector()).val(value);
- $(that.wrapSelector('.' + VP_INS_TYPE + '.attr')).val(item.type);
-
- $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
- type:"instance_editor_selected",
- varName: value,
- varType: item.type,
- isMethod: false
});
- });
- $(that.wrapSelector('.' + VP_INS_SEARCH + '.attr')).replaceWith(function() {
- return suggestInput.toTagString();
- });
-
- // method search suggest
- suggestInput = new vpSuggestInputText.vpSuggestInputText();
- suggestInput.addClass('vp-input method');
- suggestInput.addClass(VP_INS_SEARCH);
- suggestInput.setPlaceholder("search method");
- suggestInput.setSuggestList(function() { return methodList; });
- suggestInput.setSelectEvent(function(value, item) {
- $(this.wrapSelector()).val(value);
- $(that.wrapSelector('.' + VP_INS_TYPE + '.method')).val(item.type);
-
- $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
- type:"instance_editor_selected",
- varName: value,
- varType: item.type,
- isMethod: true
+ $(that.wrapSelector('.' + VP_INS_SEARCH + '.method')).replaceWith(function() {
+ return suggestInput.toTagString();
});
- });
- $(that.wrapSelector('.' + VP_INS_SEARCH + '.method')).replaceWith(function() {
- return suggestInput.toTagString();
- });
- // get parameter
- var splitList = variable.split('.');
- if (splitList && splitList.length > 0) {
- var lastSplit = splitList[splitList.length - 1];
- // if bracket is at the end of code
- var matchList = lastSplit.match(/\(.*?\)$/gi);
- if (matchList != null && matchList.length > 0) {
- var lastBracket = matchList[matchList.length - 1];
- // remove first/last brackets
- var parameter = lastBracket.substr(1, lastBracket.length - 2);
- $(that.wrapSelector('.' + VP_INS_PARAMETER)).val(parameter);
- $(that.wrapSelector('.' + VP_INS_PARAMETER)).show();
+ // get parameter
+ var splitList = variable.split('.');
+ if (splitList && splitList.length > 0) {
+ var lastSplit = splitList[splitList.length - 1];
+ // if bracket is at the end of code
+ var matchList = lastSplit.match(/\(.*?\)$/gi);
+ if (matchList != null && matchList.length > 0) {
+ var lastBracket = matchList[matchList.length - 1];
+ // remove first/last brackets
+ var parameter = lastBracket.substr(1, lastBracket.length - 2);
+ $(that.wrapSelector('.' + VP_INS_PARAMETER)).val(parameter);
+ $(that.wrapSelector('.' + VP_INS_PARAMETER)).show();
+ } else {
+ $(that.wrapSelector('.' + VP_INS_PARAMETER)).val('');
+ $(that.wrapSelector('.' + VP_INS_PARAMETER)).hide();
+ }
} else {
- $(that.wrapSelector('.' + VP_INS_PARAMETER)).val('');
$(that.wrapSelector('.' + VP_INS_PARAMETER)).hide();
}
- } else {
- $(that.wrapSelector('.' + VP_INS_PARAMETER)).hide();
}
// callback
diff --git a/src/common/vpSubsetEditor.js b/src/common/vpSubsetEditor.js
index 981b6912..3351d051 100644
--- a/src/common/vpSubsetEditor.js
+++ b/src/common/vpSubsetEditor.js
@@ -192,8 +192,8 @@ define([
// set button next to input tag
var buttonTag = new sb.StringBuilder();
- buttonTag.appendFormat('
{2} '
- , VP_DS_BTN, this.uuid, '...');
+ buttonTag.appendFormat('
{3} '
+ , VP_DS_BTN, this.uuid, 'vp-button', 'Edit');
$(this.pageThis.wrapSelector('#' + this.targetId)).parent().append(buttonTag.toString());
// add popup div
@@ -1144,7 +1144,9 @@ define([
var that = this;
// open popup
$(document).on('click', vpCommon.formatString('.{0}.{1}', VP_DS_BTN, this.uuid), function(event) {
- that.open();
+ if (!$(this).hasClass('disabled')) {
+ that.open();
+ }
});
// close popup
@@ -1659,6 +1661,17 @@ define([
$(this.pageThis.wrapSelector('.' + VP_DS_BTN + '.' + this.uuid)).hide();
}
+ SubsetEditor.prototype.disableButton = function() {
+ var buttonEle = $(this.pageThis.wrapSelector('.' + VP_DS_BTN + '.' + this.uuid));
+ if (!buttonEle.hasClass('disabled')) {
+ buttonEle.addClass('disabled');
+ }
+ }
+
+ SubsetEditor.prototype.enableButton = function() {
+ $(this.pageThis.wrapSelector('.' + VP_DS_BTN + '.' + this.uuid)).removeClass('disabled');
+ }
+
SubsetEditor.prototype.showButton = function() {
$(this.pageThis.wrapSelector('.' + VP_DS_BTN + '.' + this.uuid)).show();
}
diff --git a/src/file_io/instance.html b/src/file_io/instance.html
index 88238ee3..0a7f4acd 100644
--- a/src/file_io/instance.html
+++ b/src/file_io/instance.html
@@ -1,28 +1,26 @@