-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathVariable.js
More file actions
156 lines (133 loc) · 6.04 KB
/
Variable.js
File metadata and controls
156 lines (133 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Project Name : Visual Python
* Description : GUI-based Python code generator
* File Name : Variable.js
* Author : Black Logic
* Note : Apps > Variable
* License : GNU GPLv3 with Visual Python special exception
* Date : 2021. 11. 18
* Change Date :
*/
//============================================================================
// [CLASS] Variable
//============================================================================
define([
__VP_TEXT_LOADER__('vp_base/html/m_apps/variable.html'), // INTEGRATION: unified version of text loader
__VP_CSS_LOADER__('vp_base/css/m_apps/variable'), // INTEGRATION: unified version of css loader
'vp_base/js/com/com_String',
'vp_base/js/com/component/PopupComponent'
], function(varHtml, varCss, com_String, PopupComponent) {
/**
* Variable
*/
class Variable extends PopupComponent {
_init() {
super._init();
/** Write codes executed before rendering */
this.config.dataview = false;
this.config.sizeLevel = 3;
this.state = {
variable: '',
...this.state
}
}
_bindEvent() {
super._bindEvent();
/** Implement binding events */
let that = this;
// load variables on refresh
$(this.wrapSelector('#vp_varRefresh')).click(function(event) {
event.stopPropagation();
that.loadVariables();
});
}
templateForBody() {
/** Implement generating template */
return varHtml;
}
render() {
super.render();
this.loadVariables();
}
generateCode() {
return this.state.variable;
}
loadVariables() {
var that = this;
// Searchable variable types
var types = [
...vpConfig.getDataTypes(),
// ML Data types
...vpConfig.getMLDataTypes()
];
var tagTable = this.wrapSelector('#vp_var_variableBox table tbody');
// variable list table
var tagDetailTable = this.wrapSelector("#vp_varDetailTable");
// initialize tags
$(tagTable).find('tr').remove();
$(tagDetailTable).html('');
// HTML rendering
vpKernel.getDataList(types).then(function(resultObj) {
let varListStr = resultObj.result;
var varList = JSON.parse(varListStr);
// add variable list in table
varList.forEach((varObj, idx) => {
if (types.includes(varObj.varType) && varObj.varName[0] !== '_') {
let selected = false;
if ((that.state.variable == varObj.varName)) {
selected = true;
}
var tagTr = document.createElement('tr');
var tagTdName = document.createElement('td');
var tagTdType = document.createElement('td');
$(tagTr).attr({
'data-var-name': varObj.varName,
'data-var-type': varObj.varType,
'class': selected?'vp-selected':''
});
tagTdName.innerText = varObj.varName;
tagTdType.innerText = varObj.varType;
$(tagTr).append(tagTdName);
$(tagTr).append(tagTdType);
// variable click
$(tagTr).click(function() {
$(this).parent().find('tr').removeClass('vp-selected');
$(this).addClass('vp-selected');
that.state.variable = varObj.varName;
// show variable information on clicking variable
vpKernel.execute(varObj.varName).then(function(resultObj) {
let { result, type, msg } = resultObj;
var textResult = msg.content.data["text/plain"];
var htmlResult = msg.content.data["text/html"];
var imgResult = msg.content.data["image/png"];
$(tagDetailTable).html('');
if (htmlResult != undefined) {
// 1. HTML tag
$(tagDetailTable).append(htmlResult);
} else if (imgResult != undefined) {
// 2. Image data (base64)
var imgTag = '<img src="data:image/png;base64, ' + imgResult + '">';
$(tagDetailTable).append(imgTag);
} else if (textResult != undefined) {
// 3. Text data
var preTag = document.createElement('pre');
$(preTag).text(textResult);
$(tagDetailTable).html(preTag);
} else {
$(tagDetailTable).append('(Select variables to preview the data.)');
}
});
});
$(tagTable).append(tagTr);
}
});
if ($(that.wrapSelector('.vp-selected')).length == 0) {
$(that.wrapSelector('#vp_var_variableBox tbody tr:nth(0)')).addClass('vp-selected');
}
// trigger click of selected variable
$(that.wrapSelector('.vp-selected')).click();
});
}
}
return Variable;
});