-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathexecutor.js
More file actions
155 lines (140 loc) · 6.49 KB
/
Copy pathexecutor.js
File metadata and controls
155 lines (140 loc) · 6.49 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
define([
'require'
, 'jquery'
,'nbextensions/visualpython/src/common/vpCommon'
, 'nbextensions/visualpython/src/pandas/fileNavigation/helperFunction'
, 'nbextensions/visualpython/src/pandas/fileNavigation/constData'
], function (requirejs, $, vpCommon,
helperFunction, constData) {
const { makeKernelCurrentPath } = helperFunction;
const { NAVIGATION_DIRECTION_TYPE
, FILE_EXTENSION_TYPE } = constData;
/**
* @private
* 파이썬 커널에서
1. 디렉토리 정보를 string으로 받아옴
이 함수가 디렉토리를 찾는 direction 가짓수는 총 4가지
before 상위 디렉토리 검색
to 특정 폴더 디렉토리 검색
prev 이전 디렉토리 검색
init 파일네비게이션 처음 시작할 때 기본 디렉토리 검색
2. string을 자바스크립트 객체로 파싱
2. 파싱된 객체정보를 <div/> 형식으로 바꿔 화면에 동적 렌더링
*/
var _executeKernelFromDir = function(dirObj, callback, fileNavigationRendererThis) {
const { direction } = dirObj;
if (direction === NAVIGATION_DIRECTION_TYPE.TO
|| direction === NAVIGATION_DIRECTION_TYPE.PREV) {
_executeCurrentPath(dirObj, callback, fileNavigationRendererThis);
} else if (direction === NAVIGATION_DIRECTION_TYPE.TOP) {
dirObj.destDir = '..';
_executeCurrentPath(dirObj, callback, fileNavigationRendererThis);
} else {
dirObj.destDir = '.';
_executeCurrentPath(dirObj, callback, fileNavigationRendererThis);
}
}
/**
* @private
* 파이썬 커널로 현재 디렉토리의 폴더 및 파일 목록 가져오기 */
var _executeCurrentPath = function(dirObj, callback, fileNavigationRendererThis) {
const { destDir, useFunction } = dirObj;
var currentPathStr = makeKernelCurrentPath(destDir, (useFunction? true : false));
var fileNavigationState = fileNavigationRendererThis.getFileNavigationState();
var dataOption = fileNavigationState.getFileOptionData();
fileNavigationRendererThis.vpFuncJS.kernelExecute(currentPathStr, (result) => {
// var jsonVars = result.replace(/'/gi, `"`);
// jsonVars = jsonVars.replace(/\\/gi, `/`);
/** 주의 : 만약 아래의 코드 "$1"을 '$1' single quote로 바꾸면 json parsing 에러 발생 */
var jsonVars = result.replace(/'([^']+)': /g, `"$1": `); // 객체 앞부분 대체
jsonVars = jsonVars.replace(/: '([^']+)'([,}])/g, `: "$1"$2`); // 객체 뒷부분 대체
jsonVars = jsonVars.replace(/\\/g, `/`);
var varList = JSON.parse(jsonVars);
/** 폴더나 파일 이름에 . 이 들어간 폴더, 파일 제거 */
var filterd_varList = varList.filter(data => {
if (data.name && data.name[0] == '.') {
return false;
} else {
return true;
}
/** 오름차순으로 가져옴 */
}).sort((a,b) => {
return a - b;
});
/** vp 파일을 열기 위해 file navigation을 열였을 때,
*
* 파일 확장자는 .vp .txt
* 파일 타입은 dir(폴더를 의미)
* 인 경우만 filtering해서 가져옴
*/
if (dataOption.fileExtension == FILE_EXTENSION_TYPE.VP) {
filterd_varList = filterd_varList.filter((data, index) => {
if (index == 0) {
return true;
}
if (data.type && data.type == 'dir') {
// 폴더인 경우 표시
return true;
} else if (data.name) {
var extension = data.name.substring(data.name.lastIndexOf('.') + 1);
var allowExtensionList = ['vp', 'txt'];
if (allowExtensionList.includes(extension)) {
return true;
} else {
return false;
}
} else {
return false;
}
// if (data.name && data.name.indexOf('vp') != -1
// || data.name && data.name.indexOf('txt') != -1
// || data.type && data.type.indexOf('dir') != -1) {
// return true;
// } else {
// return false;
// }
});
}
/**
* 확장자가 여러 개 입력되었다면,
* 해당 확장자 list에 포함된 확장자의 파일 목록 & 폴더 반환
*/
if (Array.isArray(dataOption.fileExtension)) {
filterd_varList = filterd_varList.filter((data, index) => {
if (index == 0) {
return true;
}
if (data.type && data.type == 'dir') {
// 폴더인 경우 표시
return true;
} else if (data.name) {
var extension = data.name.substring(data.name.lastIndexOf('.') + 1);
if (dataOption.fileExtension.includes(extension)) {
return true;
} else {
return false;
}
} else {
return false;
}
});
}
callback(filterd_varList);
});
}
/**
* @param {object} dirObj
* @param {fileNavigationRenderer This} fileNavigationRendererThis
*/
var executeKernelFromDirBody = function(dirObj, fileNavigationRendererThis) {
_executeKernelFromDir(dirObj , (resultInfoArr) => {
var { currentDirStr, currentRelativePathStr }
= fileNavigationRendererThis.fileNavigationState.splitPathStrAndSetStack(dirObj, resultInfoArr);
fileNavigationRendererThis.renderNowLocation(currentDirStr, currentRelativePathStr);
fileNavigationRendererThis.renderCurrentDirPathInfoRightBody(resultInfoArr);
}, fileNavigationRendererThis);
}
return {
executeKernelFromDirBody
}
});