-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathnumpyImport.js
More file actions
160 lines (139 loc) · 5.97 KB
/
numpyImport.js
File metadata and controls
160 lines (139 loc) · 5.97 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
157
158
159
160
define([
'require'
, 'jquery'
, 'nbextensions/visualpython/src/common/vpCommon'
, 'nbextensions/visualpython/src/common/constant'
, 'nbextensions/visualpython/src/common/StringBuilder'
, 'nbextensions/visualpython/src/common/vpFuncJS'
// numpy 패키지를 위한 라이브러리import
, 'nbextensions/visualpython/src/numpy/constant_numpy'
, 'nbextensions/visualpython/src/numpy/api/numpyValidatorApi'
, 'nbextensions/visualpython/src/numpy/common/NumpyCodeGenerator/child/numpyImportCodegenerator'
, 'nbextensions/visualpython/src/numpy/common/NumpyPageRender/child/npImportRender'
, 'nbextensions/visualpython/src/numpy/common/numpyState'
], function (requirejs, $, vpCommon, vpConst, sb, vpFuncJS,
vpNumpyConst, numpyValidatorApi,
NumpyCodeGenerator, NumpyPageRender, NumpyStateGenerator ) {
// 옵션 속성
const funcOptProp = {
stepCount : 1
, funcName : "numpy import"
, funcID : "JY0" // TODO: ID 규칙 생성 필요
}
const { VP_ID_PREFIX, VP_CLASS_PREFIX } = vpNumpyConst;
const { validateNumpyState } = numpyValidatorApi;
/**
* html load 콜백. 고유 id 생성하여 부과하며 js 객체 클래스 생성하여 컨테이너로 전달
* @param {function} callback 호출자(컨테이너) 의 콜백함수
*/
var optionLoadCallback = function(callback, meta) {
// document.getElementsByTagName("head")[0].appendChild(link);
// 컨테이너에서 전달된 callback 함수가 존재하면 실행.
if (typeof(callback) === 'function') {
var uuid = vpCommon.getUUID();
// 최대 10회 중복되지 않도록 체크
for (var idx = 0; idx < 10; idx++) {
// 이미 사용중인 uuid 인 경우 다시 생성
if ($(vpConst.VP_CONTAINER_ID).find("." + uuid).length > 0) {
uuid = vpCommon.getUUID();
}
}
$(vpCommon.wrapSelector(VP_ID_PREFIX + vpConst.OPTION_GREEN_ROOM)).find(VP_CLASS_PREFIX + vpConst.API_OPTION_PAGE).addClass(uuid);
// 옵션 객체 생성
var ipImport = new ImportPackage(uuid);
ipImport.metadata = meta;
// 옵션 속성 할당.
ipImport.setOptionProp(funcOptProp);
// html 설정.
ipImport.initHtml();
callback(ipImport); // 공통 객체를 callback 인자로 전달
}
}
/**
* html 로드.
* @param {function} callback 호출자(컨테이너) 의 콜백함수
*/
var initOption = function(callback, meta) {
var htmlUrlPath = vpNumpyConst.STR_NUMPY_HTML_URL_PATH;
vpCommon.loadHtml(vpCommon.wrapSelector(`${VP_ID_PREFIX}${vpConst.OPTION_GREEN_ROOM}`), htmlUrlPath, optionLoadCallback, callback, meta);
}
/**
* 본 옵션 처리 위한 클래스
* @param {String} uuid 고유 id
*/
var ImportPackage = function(uuid) {
this.uuid = uuid; // Load html 영역의 uuid.
this.numpyCodeGenerator // numpyCodeGenerator은 코드를 만듬
// this.numpyCodeValidator // numpyCodeValidator은 코드 실행 전 입력된 state 값을 검증
this.numpyPageRender // numpyPageRender는 동적 html을 index.html에 렌더링
this.numpyStateGenerator // numpyStateGenerator는 state를 생성, 변경
this.state = {
acronyms: 'np'
}
this.metadata;
}
/**
* vpFuncJS 에서 상속
*/
ImportPackage.prototype = Object.create(vpFuncJS.VpFuncJS.prototype);
/**
* 유효성 검사
* @returns 유효성 검사 결과. 적합시 true
*/
ImportPackage.prototype.optionValidation = function() {
// state 데이터를 validation 한다
return validateNumpyState(funcOptProp.funcID);
}
/**
* html 내부 binding 처리
*/
ImportPackage.prototype.initHtml = function() {
this.numpyCodeGenerator = new NumpyCodeGenerator();
this.numpyPageRender = new NumpyPageRender( vpNumpyConst.NUMPY_OPTION_OBJ);
this.numpyStateGenerator = new NumpyStateGenerator();
this.numpyStateGenerator.setImportPackageThis(this);
this.numpyStateGenerator.makeState(this.state);
this.numpyCodeGenerator.setStateGenerator(this.numpyStateGenerator);
this.numpyPageRender.setStateGenerator(this.numpyStateGenerator);
//importPackageThis와 동적 html 태그들을 index.html에 렌더링
this.numpyPageRender.setImportPackageThis(this);
if (this.metadata) {
this.numpyStateGenerator.setMetadata(this.metadata);
this.numpyPageRender.pageRender();
} else {
this.numpyPageRender.pageRender();
// this.numpyStateGenerator.setMetadata(this.metadata);
}
this.numpyStateGenerator.setAPIBlockMetadataHandler();
this.numpyPageRender.renderFuncName(funcOptProp.funcName);
// import load css
this.loadCss(Jupyter.notebook.base_url + vpConst.BASE_PATH + vpConst.STYLE_PATH + vpNumpyConst.NUMPY_BASE_CSS_PATH);
}
/**
* 페이지에 생성된 uuid를 가져온다
*/
ImportPackage.prototype.getUUID = function() {
return this.uuid;
}
/**
* 코드 생성
* @param {boolean} exec 실행여부
*/
ImportPackage.prototype.generateCode = function(exec, addCell) {
/** 코드 생성 make code */
this.numpyCodeGenerator.makeCode();
var result = this.numpyCodeGenerator.getCodeAndClear();
if (result == null) return "BREAK_RUN"; // 코드 생성 중 오류 발생
/** 코드 add만 실행 */
if ( !addCell ) {
this.numpyStateGenerator.saveMetadata(this.metadata);
return result;
}
/** 코드 run 실행 */
this.cellExecute(result, exec);
this.numpyStateGenerator.saveMetadata(this.metadata);
}
return {
initOption: initOption
};
});