Skip to content

Commit fc90c85

Browse files
author
minjk-bl
committed
Variable update
1 parent 487803b commit fc90c85

File tree

1 file changed

+39
-59
lines changed

1 file changed

+39
-59
lines changed

src/file_io/variables.js

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define([
88
, 'nbextensions/visualpython/src/pandas/common/commonPandas'
99
, 'nbextensions/visualpython/src/pandas/common/pandasGenerator'
1010
], function (requirejs, $, vpCommon, vpConst, sb, vpFuncJS, libPandas, pdGen) {
11-
// 옵션 속성
11+
// option property
1212
const funcOptProp = {
1313
stepCount : 1
1414
, funcName : "Variables"
@@ -17,74 +17,73 @@ define([
1717
}
1818

1919
/**
20-
* html load 콜백. 고유 id 생성하여 부과하며 js 객체 클래스 생성하여 컨테이너로 전달
21-
* @param {function} callback 호출자(컨테이너) 의 콜백함수
20+
* html load callback. 고유 id 생성하여 부과하며 js 객체 클래스 생성하여 컨테이너로 전달
21+
* @param {function} callback container's callback
2222
*/
2323
var optionLoadCallback = function(callback, meta) {
24-
// document.getElementsByTagName("head")[0].appendChild(link);
25-
// 컨테이너에서 전달된 callback 함수가 존재하면 실행.
24+
// execute callback function if available
2625
if (typeof(callback) === 'function') {
2726
var uuid = 'u' + vpCommon.getUUID();
28-
// 최대 10회 중복되지 않도록 체크
27+
// maximum 10 duplication allowed
2928
for (var idx = 0; idx < 10; idx++) {
30-
// 이미 사용중인 uuid 인 경우 다시 생성
29+
// uuid check and re-generate
3130
if ($(vpConst.VP_CONTAINER_ID).find("." + uuid).length > 0) {
3231
uuid = 'u' + vpCommon.getUUID();
3332
}
3433
}
3534
$(vpCommon.wrapSelector(vpCommon.formatString("#{0}", vpConst.OPTION_GREEN_ROOM))).find(vpCommon.formatString(".{0}", vpConst.API_OPTION_PAGE)).addClass(uuid);
3635

37-
// 옵션 객체 생성
36+
// create object
3837
var varPackage = new VariablePackage(uuid);
3938
varPackage.metadata = meta;
4039

41-
// 옵션 속성 할당.
40+
// set option property
4241
varPackage.setOptionProp(funcOptProp);
43-
// html 설정.
42+
// html setting
4443
varPackage.initHtml();
45-
callback(varPackage); // 공통 객체를 callback 인자로 전달
44+
callback(varPackage);
4645
}
4746
}
4847

4948
/**
50-
* html 로드.
51-
* @param {function} callback 호출자(컨테이너) 의 콜백함수
49+
* Load html
50+
* @param {function} callback container's callback
5251
*/
5352
var initOption = function(callback, meta) {
5453
vpCommon.loadHtml(vpCommon.wrapSelector(vpCommon.formatString("#{0}", vpConst.OPTION_GREEN_ROOM)), "file_io/variables.html", optionLoadCallback, callback, meta);
5554
}
5655

5756
/**
58-
* 본 옵션 처리 위한 클래스
59-
* @param {String} uuid 고유 id
57+
* Option package
58+
* @param {String} uuid unique id
6059
*/
6160
var VariablePackage = function(uuid) {
6261
this.uuid = uuid; // Load html 영역의 uuid.
63-
// pandas 함수
62+
// pandas function
6463
this.package = libPandas._PANDAS_FUNCTION[funcOptProp.libID];
6564
}
6665

6766

6867

6968
/**
70-
* vpFuncJS 에서 상속
69+
* Extend vpFuncJS
7170
*/
7271
VariablePackage.prototype = Object.create(vpFuncJS.VpFuncJS.prototype);
7372

7473
/**
75-
* 유효성 검사
76-
* @returns 유효성 검사 결과. 적합시 true
74+
* Validation
75+
* @returns true if it's valid
7776
*/
7877
VariablePackage.prototype.optionValidation = function() {
7978
return true;
8079

81-
// 부모 클래스 유효성 검사 호출.
80+
// parent's validation
8281
// vpFuncJS.VpFuncJS.prototype.optionValidation.apply(this);
8382
}
8483

8584

8685
/**
87-
* html 내부 binding 처리
86+
* html inner binding
8887
*/
8988
VariablePackage.prototype.initHtml = function() {
9089
this.showFunctionTitle();
@@ -98,7 +97,7 @@ define([
9897
}
9998

10099
/**
101-
* 선택한 패키지명 입력
100+
* package title
102101
*/
103102
VariablePackage.prototype.showFunctionTitle = function() {
104103
$(this.wrapSelector('.vp_functionName')).text(funcOptProp.funcName);
@@ -115,43 +114,43 @@ define([
115114
}
116115

117116
/**
118-
* Variables 조회
117+
* Search variables
119118
*/
120119
VariablePackage.prototype.loadVariables = function() {
121120
var that = this;
122121

123-
// 조회가능한 변수 data type 정의 FIXME: 조회 필요한 변수 유형 추가
122+
// Searchable variable types
124123
var types = [
125-
// pandas 객체
124+
// pandas object
126125
'DataFrame', 'Series', 'Index', 'Period', 'GroupBy', 'Timestamp'
127-
// Index 하위 유형
126+
// Index type object
128127
, 'RangeIndex', 'CategoricalIndex', 'MultiIndex', 'IntervalIndex', 'DatetimeIndex', 'TimedeltaIndex', 'PeriodIndex', 'Int64Index', 'UInt64Index', 'Float64Index'
129-
// GroupBy 하위 유형
128+
// GroupBy type object
130129
, 'DataFrameGroupBy', 'SeriesGroupBy'
131-
// Plot 관련 유형
130+
// Plot type
132131
, 'Figure', 'AxesSubplot'
133132
// Numpy
134133
, 'ndarray'
135-
// Python 변수
134+
// Python variable
136135
, 'str', 'int', 'float', 'bool', 'dict', 'list', 'tuple'
137136
];
138137

139138
var tagTable = this.wrapSelector('#vp_var_variableBox table');
140139

141-
// 변수 정보 표시
140+
// variable list table
142141
var tagDetailTable = this.wrapSelector("#vp_varDetailTable");
143142

144143
// initialize tags
145144
$(tagTable).find('tr:not(:first)').remove();
146145
$(tagDetailTable).html('');
147146

148-
// HTML 구성
147+
// HTML rendering
149148
pdGen.vp_searchVarList(types, function(result) {
150149
// var jsonVars = result.replace(/'/gi, `"`);
151150
// var varList = JSON.parse(jsonVars);
152151
var varList = JSON.parse(result);
153152

154-
// table 에 변수목록 추가
153+
// add variable list in table
155154
varList.forEach(varObj => {
156155
if (types.includes(varObj.varType) && varObj.varName[0] !== '_') {
157156
var tagTr = document.createElement('tr');
@@ -167,30 +166,12 @@ define([
167166
$(tagTr).append(tagTdName);
168167
$(tagTr).append(tagTdType);
169168

170-
$(tagTdName).attr({
171-
'title': 'Click to copy'
172-
});
173-
// 변수이름 클릭 시 클립보드에 복사
174-
$(tagTdName).click(function() {
175-
// // 클립보드 복사 시작
176-
var tempElem = document.createElement('input');
177-
tempElem.value = varObj.varName;
178-
document.body.appendChild(tempElem);
179-
180-
tempElem.select();
181-
document.execCommand("copy");
182-
document.body.removeChild(tempElem);
183-
// 클립보드 복사 완료
184-
vpCommon.renderSuccessMessage('Copied!');
185-
});
186-
187-
// 변수 선택 시 표시
169+
// variable click
188170
$(tagTr).click(function() {
189171
$(this).parent().find('tr').removeClass('selected');
190172
$(this).addClass('selected');
191173

192-
// TEST: 변수 선택 시 변수 정보를 하단에 표시
193-
// vpFuncJS.kernelExecute 에서는 callback에 msg.content["text"]를 전달해주기 때문에 따로 구현함
174+
// show variable information on clicking variable
194175
Jupyter.notebook.kernel.execute(
195176
varObj.varName,
196177
{
@@ -202,14 +183,14 @@ define([
202183

203184
$(tagDetailTable).html('');
204185
if (htmlResult != undefined) {
205-
// 1. HTML 태그로 구성되어 반환되는 경우
186+
// 1. HTML tag
206187
$(tagDetailTable).append(htmlResult);
207188
} else if (imgResult != undefined) {
208-
// 2. 이미지 데이터가 반환되는 경우 (base64)
189+
// 2. Image data (base64)
209190
var imgTag = '<img src="data:image/png;base64, ' + imgResult + '">';
210191
$(tagDetailTable).append(imgTag);
211192
} else if (textResult != undefined) {
212-
// 3. 텍스트 데이터가 반환되는 경우
193+
// 3. Text data
213194
var preTag = document.createElement('pre');
214195
$(preTag).text(textResult);
215196
$(tagDetailTable).html(preTag);
@@ -221,7 +202,6 @@ define([
221202
},
222203
{ silent: false }
223204
);
224-
// TEST: END
225205
})
226206

227207
$(tagTable).append(tagTr);
@@ -231,14 +211,14 @@ define([
231211
};
232212

233213
/**
234-
* 코드 생성
235-
* @param {boolean} exec 실행여부
214+
* Generate code
215+
* @param {boolean} exec do execute
236216
*/
237217
VariablePackage.prototype.generateCode = function(addCell, exec) {
238218

239219
var sbCode = new sb.StringBuilder();
240220

241-
// TODO: 변수 내용 조회
221+
// show selected variable
242222
var selectedVariable = $(this.wrapSelector('#vp_var_variableBox table tr.selected'));
243223
if (selectedVariable) {
244224
var varName = selectedVariable.attr('data-var-name');

0 commit comments

Comments
 (0)