Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit561630c

Browse files
author
minjk-bl
committed
file navigation - side bar menu path bug fixed
1 parenta8f4cfc commit561630c

File tree

4 files changed

+70
-39
lines changed

4 files changed

+70
-39
lines changed

‎src/api/functions/fileNaviCommand.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _vp_get_documents_path():
5656

5757
def_vp_sizeof_fmt(num,suffix='B'):
5858
"""
59-
파일크기 보기 좋게 변환해서 반환
59+
Return resized image
6060
"""
6161
forunitin ['','K','M','G','T','P','E','Z']:
6262
ifabs(num)<1024.0:
@@ -66,7 +66,7 @@ def _vp_sizeof_fmt(num, suffix='B'):
6666

6767
def_vp_search_path(path):
6868
"""
69-
경로 하위 폴더, 파일 조회
69+
Search child folder and file list under the given path
7070
"""
7171
importdatetimeas_dt
7272
_current=_vp_os.path.abspath(path)
@@ -94,8 +94,20 @@ def _vp_search_path(path):
9494

9595
def_vp_get_image_by_path(path):
9696
"""
97-
경로로 이미지 파일 받아오기
97+
Get image file by path
9898
"""
9999
fromPILimportImage
100100
img=Image.open(path)
101-
returnimg
101+
returnimg
102+
103+
def_vp_get_relative_path(start,path):
104+
"""
105+
Get relative path using start path and current path
106+
start: str
107+
start path
108+
path: str
109+
current path
110+
returns: str
111+
current relative path
112+
"""
113+
return_vp_os.path.relpath(path,start)

‎src/pandas/fileNavigation/helperFunction.js‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,6 @@ define([
1414
}
1515
varsbCode=newsb.StringBuilder();
1616
sbCode.appendFormat("print(_vp_search_path({0}))",path);
17-
// sbCode.appendLine("import os as _os");
18-
// sbCode.appendLine("import datetime as _dt");
19-
// sbCode.appendFormatLine("_current = _os.path.abspath({0})", path);
20-
// sbCode.appendLine("_parent = _os.path.dirname(_current)");
21-
// sbCode.appendLine("");
22-
// sbCode.appendLine("# 파일크기 보기 좋게 변환");
23-
// sbCode.appendLine("def sizeof_fmt(num, suffix='B'):");
24-
// sbCode.appendLine(" for unit in ['','K','M','G','T','P','E','Z']:");
25-
// sbCode.appendLine(" if abs(num) < 1024.0:");
26-
// sbCode.appendLine(" return '%3.1f%s%s' % (num, unit, suffix)");
27-
// sbCode.appendLine(" num /= 1024.0");
28-
// sbCode.appendLine(" return '%.1f%s%s' % (num, 'Yi', suffix)");
29-
// sbCode.appendLine("");
30-
// sbCode.appendLine("with _os.scandir(_current) as i:");
31-
// sbCode.appendLine(" _info = []");
32-
// sbCode.appendLine(" _info.append({'current':_current,'parent':_parent})");
33-
// sbCode.appendLine(" for _entry in i:");
34-
// sbCode.appendLine(" _name = _entry.name");
35-
// sbCode.appendLine(" _path = _entry.path # 파일 경로");
36-
// sbCode.appendLine(" _stat = _entry.stat()");
37-
// sbCode.appendLine(" _size = sizeof_fmt(_stat.st_size) # 파일 크기");
38-
// sbCode.appendLine(" _a_time = _stat.st_atime # 최근 액세스 시간");
39-
// sbCode.appendLine(" _a_dt = _dt.datetime.fromtimestamp(_a_time).strftime('%Y-%m-%d %H:%M')");
40-
// sbCode.appendLine(" _m_time = _stat.st_mtime # 최근 수정 시간");
41-
// sbCode.appendLine(" _m_dt = _dt.datetime.fromtimestamp(_m_time).strftime('%Y-%m-%d %H:%M')");
42-
// sbCode.appendLine(" _e_type = 'other'");
43-
// sbCode.appendLine(" if _entry.is_file():");
44-
// sbCode.appendLine(" _e_type = 'file'");
45-
// sbCode.appendLine(" elif _entry.is_dir():");
46-
// sbCode.appendLine(" _e_type = 'dir'");
47-
// sbCode.appendLine(" _info.append({'name':_name, 'type':_e_type, 'path':_path, 'size':_size, 'atime':str(_a_dt), 'mtime':str(_m_dt)})");
48-
// sbCode.appendLine(" print(_info)");
4917
returnsbCode.toString();
5018
}
5119
return{

‎src/pandas/fileNavigation/renderer.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ define([
277277

278278
if(baseFolder===notebookFolder&&Jupyter.notebook.notebook_path.indexOf('/')===-1){
279279
varindex=currentRelativePathStrArray.indexOf(baseFolder)
280-
currentRelativePathStrArray.splice(index,1);
280+
if(index>=0){
281+
currentRelativePathStrArray.splice(index,1);
282+
}
281283
}
282284

283285
varcurrentRelativePathDomElement=$(`<div><div>`);
@@ -297,6 +299,13 @@ define([
297299
});
298300

299301
varnestedLength=0;
302+
// if it's outside of notebookPath, ignore notebookPath
303+
varprevLength=notebookPathStrLength;
304+
varuseSidebar=false;
305+
if(currentRelativePathStrArray.includes('..')){
306+
prevLength=0;
307+
useSidebar=true;
308+
}
300309
currentRelativePathStrArray.forEach((pathToken,index)=>{
301310
if(index===0){
302311
slashStr='';
@@ -307,7 +316,8 @@ define([
307316
varspanElement=$(`<span class='vp-filenavigation-nowLocation' value='${pathToken}'>
308317
${slashStr}${pathToken}
309318
</span>`);
310-
varpathLength=notebookPathStrLength+pathToken.length+1+nestedLength;
319+
320+
varpathLength=prevLength+pathToken.length+1+nestedLength;
311321
spanElement.click(function(){
312322
varcurrentRelativePathStr=`${currentDirStr.substring(0,pathLength)}`;
313323

‎src/pandas/fileNavigation/state.js‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ define([
152152
varsplitedDirStrArr=currentDirStr.split('/');
153153
varrootFolderName=splitedDirStrArr[splitedDirStrArr.length-1];
154154

155+
varnotebookFolder=this.getNotebookFolder();//TEST:
155156
varfirstIndex=currentDirStr.indexOf(this.getNotebookFolder());
156157

157158
varcurrentRelativePathStr='';
158159
if(firstIndex===-1){
159-
currentRelativePathStr=currentDirStr.substring(this.getNotebookDir().length+1,currentDirStr.length);
160+
varnotebookDir=this.getNotebookDir();//TEST:
161+
// FIXME: if current path is upper than Jupyter Home, send no permission?
162+
// currentRelativePathStr = currentDirStr.substring(this.getNotebookDir().length + 1, currentDirStr.length);
163+
currentRelativePathStr=getRelativePath(notebookDir,currentDirStr);
160164
}else{
161165
currentRelativePathStr=currentDirStr.substring(firstIndex,currentDirStr.length);
162166
}
@@ -173,5 +177,42 @@ define([
173177
}
174178
}
175179

180+
/**
181+
* Get relative path based on start path
182+
* - referred python os.path.relpath()
183+
*@param {string} start start path (base path)
184+
*@param {string} path current path
185+
*@returns current relative path
186+
*/
187+
vargetRelativePath=function(start,path){
188+
constsep='/';
189+
constcurdir='.';
190+
constpardir='..';
191+
192+
varstartSplit=start.split(sep);
193+
varpathSplit=path.split(sep);
194+
195+
// TODO: check drive: startSplit[0] == pathSplit[0]
196+
197+
varstartList=startSplit.slice(1);
198+
varpathList=pathSplit.slice(1);
199+
200+
varstopIdx=0;
201+
while(stopIdx<startList.length){
202+
vare1=startList[stopIdx];
203+
vare2=pathList[stopIdx];
204+
if(e1!=e2){
205+
break;
206+
}
207+
stopIdx++;
208+
}
209+
varparList=Array(startList.length-stopIdx).fill(pardir);
210+
varrelList=parList.concat(pathList.slice(stopIdx));
211+
if(!relList||relList.length==0){
212+
return'';// curdir
213+
}
214+
returnrelList.join(sep);
215+
}
216+
176217
returnFileNavigationState;
177218
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp