-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathcreateBlockBtn_old.js
More file actions
297 lines (237 loc) · 11.9 KB
/
createBlockBtn_old.js
File metadata and controls
297 lines (237 loc) · 11.9 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
define([
'nbextensions/visualpython/src/common/StringBuilder'
, './api.js'
, './constData.js'
], function ( sb, api, constData ) {
const { MapTypeToName
, RenderHTMLDomColor
, IsDefineBlockType
, IsControlBlockType
, GenerateDefCode } = api;
const { BLOCK_CODELINE_TYPE
, BLOCK_DIRECTION
, STR_CLICK
, VP_CLASS_PREFIX
, VP_CLASS_APIBLOCK_MAIN
, VP_CLASS_APIBLOCK_BOARD
, STR_EMPTY
, DEF_BLOCK_ARG6_TYPE
, STATE_defInParamList } = constData;
var CreateBlockBtn = function(blockContainerThis, type) {
this.blockContainerThis = blockContainerThis;
this.type = type;
this.name = MapTypeToName(type)
this.createBlockBtnDom = null;
this.render();
this.bindBtnDragEvent();
this.bindBtnClickEvent();
}
CreateBlockBtn.prototype.getBlockContainerThis = function() {
return this.blockContainerThis;
}
CreateBlockBtn.prototype.getBlockName = function() {
return this.name;
}
CreateBlockBtn.prototype.setBlockName = function(name) {
this.name = name;
}
CreateBlockBtn.prototype.getBlockType = function() {
return this.type;
}
CreateBlockBtn.prototype.getBlockMainDom = function() {
return this.createBlockBtnDom;
}
CreateBlockBtn.prototype.setBlockMainDom = function(createBlockBtnDom) {
this.createBlockBtnDom = createBlockBtnDom;
}
CreateBlockBtn.prototype.getBlockMainDomPosition = function() {
var createBlockDom = this.getBlockMainDom();
var clientRect = $(createBlockDom)[0].getBoundingClientRect();
return clientRect;
}
CreateBlockBtn.prototype.render = function() {
var sbCreateBlockBtn = new sb.StringBuilder();
sbCreateBlockBtn.appendFormatLine("<div class='{0}'>",'vp-apiblock-tab-navigation-node-block-body-btn');
sbCreateBlockBtn.appendFormatLine("<span class='{0}'>",'vp-block-name');
sbCreateBlockBtn.appendFormatLine("{0}", this.getBlockName());
sbCreateBlockBtn.appendLine("</span>");
sbCreateBlockBtn.appendLine("</div>");
var createBlockContainer = null;
var blockType = this.getBlockType();
/** LOGIC - define */
if ( IsDefineBlockType(blockType) == true ) {
createBlockContainer = $(`.vp-apiblock-left-tab-1`);
/** LOGIC - control */
} else if ( IsControlBlockType(blockType) == true) {
createBlockContainer = $(`.vp-apiblock-left-tab-2`);
/** LOGIC - Execute */
} else {
createBlockContainer = $(`.vp-apiblock-left-tab-3`);
}
var createBlockBtnDom = $(sbCreateBlockBtn.toString());
this.setBlockMainDom(createBlockBtnDom);
createBlockBtnDom = RenderHTMLDomColor(this, createBlockBtnDom);
createBlockContainer.append(createBlockBtnDom);
}
/**
* 메뉴 블럭 클릭 시 Board에 생성하는 이벤트
*/
CreateBlockBtn.prototype.bindBtnClickEvent = function() {
var blockContainerThis = this.blockContainerThis;
var blockCodeLineType = this.getBlockType();
// var funcID = this.funcID;
// var naviInfo = getNavigationInfo(funcID);
$(this.createBlockBtnDom).on(STR_CLICK, function(event) {
event.stopPropagation();
/** board에 선택한 API List 블럭 생성 */
blockContainerThis.resetBlockList();
var isFirstBlock = false;
const blockList = blockContainerThis.getBlockList();
/** board에 블럭이 0개 일때
* 즉 블럭이 처음으로 생성되는 경우
*/
if (blockList.length == 0) {
isFirstBlock = true;
}
var createdBlock_api = blockContainerThis.createBlock(blockCodeLineType);
// createdBlock_api.setFuncID(funcID);
// createdBlock_api.setState({
// [STATE_codeLine]: naviInfo
// });
// createdBlock_api.setOptionPageLoadCallback(optionPageLoadCallback_block);
// createdBlock_api.setLoadOption(loadOption_block);
var createdBlock_node;
/** board에 블럭이 0개 있을 때
* 즉 블럭을 board에 처음 생성 할 때
*/
if (isFirstBlock == true) {
createdBlock_node = blockContainerThis.createNodeBlock();
/** 최초 생성된 root 블럭 set root direction */
createdBlock_node.setDirection(BLOCK_DIRECTION.ROOT);
createdBlock_node.appendBlock(createdBlock_api, BLOCK_DIRECTION.DOWN);
blockContainerThis.reNewContainerDom();
blockContainerThis.reRenderAllBlock_asc();
createdBlock_node.writeCode('Node');
/** board에 블럭이 1개 이상 있을 때 */
} else {
var selectedBlock = blockContainerThis.getSelectBlock();
/** board에 선택한 블럭이 있고,
* 선택한 블럭이 Text 블럭이 아닐 때
*/
if (selectedBlock
&& selectedBlock.getBlockType() != BLOCK_CODELINE_TYPE.TEXT) {
selectedBlock = blockContainerThis.findNodeBlock(selectedBlock);
selectedBlock.getLastBlock_from_thisBlockArea().appendBlock(createdBlock_api, BLOCK_DIRECTION.DOWN);
selectedBlock.renderSelectedBlockColor(true);
blockContainerThis.reRenderAllBlock_asc();
/** 그 외의 경우 */
} else {
createdBlock_node = blockContainerThis.createNodeBlock();
createdBlock_node.appendBlock(createdBlock_api, BLOCK_DIRECTION.DOWN);
const nodeBlockAndTextBlockList = blockContainerThis.getNodeBlockAndTextBlockList_asc();
nodeBlockAndTextBlockList[nodeBlockAndTextBlockList.length -1].getLastBlock_from_thisBlockArea().appendBlock(createdBlock_node, BLOCK_DIRECTION.DOWN);
blockContainerThis.reRenderAllBlock_asc();
createdBlock_node.writeCode('Node');
}
}
// createdBlock_api.writeCode(naviInfo);
// setClosureBlock(createdBlock_api);
// loadOption_block(funcID, optionPageLoadCallback_block);
blockContainerThis.resetBlockListAndRenderThisBlock(createdBlock_api);
});
}
CreateBlockBtn.prototype.bindBtnDragEvent = function() {
var thisBlockBtn = this;
var createBlockDom = this.getBlockMainDom();
var blockContainerThis = this.getBlockContainerThis();
var blockCodeLineType = this.getBlockType();
var currCursorX = 0;
var currCursorY = 0;
var newPointX = 0;
var newPointY = 0;
var selectedBlockDirection = null;
var shadowBlock = null;
var newBlock = null;
var width = 0;
$(createBlockDom).draggable({
appendTo: VP_CLASS_PREFIX + VP_CLASS_APIBLOCK_MAIN,
containment: VP_CLASS_PREFIX + VP_CLASS_APIBLOCK_MAIN,
cursor: 'move',
helper: 'clone',
start: function(event, ui) {
/** shadow 블럭 생성 */
shadowBlock = blockContainerThis.createShadowBlock( blockCodeLineType);
blockContainerThis.reLoadBlockListLeftHolderHeight();
/** width 길이 결정 */
var clientRect = thisBlockBtn.getBlockMainDomPosition();
width = clientRect.width;
},
drag: async function(event, ui) {
currCursorX = event.clientX;
currCursorY = event.clientY;
/** 만약 아래 로직에서 + thisBlockWidth + 10이 없다면 마우스 커서 오른쪽으로 이동 됨*/
newPointX = currCursorX - $(VP_CLASS_PREFIX + VP_CLASS_APIBLOCK_BOARD).offset().left + width + 80 ;
newPointY = currCursorY - $(VP_CLASS_PREFIX + VP_CLASS_APIBLOCK_BOARD).offset().top + 50 ;
/** drag Block 생성 버튼 마우스 커서 왼쪽 위로 이동 구현 */
ui.position = {
top: newPointY,
left: newPointX
};
({ selectedBlock, selectedBlockDirection } = blockContainerThis.dragBlock(false, null, shadowBlock,
null, selectedBlockDirection, currCursorX, currCursorY));
},
stop: function() {
var selectedBlock = null;
if (shadowBlock) {
selectedBlock = shadowBlock.getSelectBlock();
shadowBlock.deleteShadowBlock();
}
/** Board에 생성된 Block에 연결한 경우 */
if (selectedBlock) {
newBlock = blockContainerThis.createBlock(blockCodeLineType );
selectedBlock.appendBlock(newBlock, selectedBlockDirection);
// console.log('Board에 생성된 Block에 연결한 경우');
/** Board에 생성된 Block에 연결하지 못한 경우
* 즉 어떤 블럭에도 연결하지 못하고 생성한 경우
*/
} else {
/**
* ----------------Board에 생성된 Block이 1개도 없을 때----------------------------
*/
var blockList = blockContainerThis.getBlockList();
if (blockList.length == 0) {
blockContainerThis.reNewContainerDom();
blockContainerThis.reRenderAllBlock_asc();
newBlock = blockContainerThis.createNodeBlock();
var createdBlock = blockContainerThis.createBlock( blockCodeLineType );
newBlock.appendBlock(createdBlock, BLOCK_DIRECTION.DOWN);
/** 최초 생성된 root 블럭 set root direction */
newBlock.setDirection(BLOCK_DIRECTION.ROOT);
/** `
* -----------------Board에 생성된 Block이 적어도 1개는 있을 때---------------------
*/
/** 선택한 블럭이 있을때 */
} else if (blockContainerThis.getSelectBlock()
&& blockContainerThis.getSelectBlock().getBlockType() != BLOCK_CODELINE_TYPE.TEXT) {
// console.log('선택한 블럭이 있을때');
newBlock = blockContainerThis.createBlock(blockCodeLineType );
var findedNodeBlock = blockContainerThis.findNodeBlock();
findedNodeBlock.getLastBlock_from_thisBlockArea().appendBlock(newBlock, BLOCK_DIRECTION.DOWN);
/** 선택한 블럭이 없을때 */
} else {
// console.log('선택한 블럭이 없을때');
newBlock = blockContainerThis.createNodeBlock();
var createdBlock = blockContainerThis.createBlock( blockCodeLineType );
newBlock.appendBlock(createdBlock, BLOCK_DIRECTION.DOWN);
var lastBottomBlock = blockContainerThis.getRootToLastBottomBlock();
lastBottomBlock.appendBlock(newBlock, BLOCK_DIRECTION.DOWN);
}
}
blockContainerThis.stopDragBlock(false, newBlock);
shadowBlock = null;
newBlock = null;
}
});
}
return CreateBlockBtn;
});