Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
99a6a60d
A
algorithm-visualizer
项目概览
tianyazhichiC
/
algorithm-visualizer
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
algorithm-visualizer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
99a6a60d
编写于
4月 30, 2018
作者:
J
Jason Park
提交者:
Jason
4月 30, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename api 'directory' to 'hierarchy'
上级
e8b6b0fe
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
58 addition
and
39 deletion
+58
-39
.gitmodules
.gitmodules
+3
-0
environment.js
environment.js
+15
-0
src/backend/controllers/auth.js
src/backend/controllers/auth.js
+1
-1
src/backend/controllers/hierarchy.js
src/backend/controllers/hierarchy.js
+9
-9
src/backend/controllers/index.js
src/backend/controllers/index.js
+2
-2
src/backend/public/algorithms
src/backend/public/algorithms
+1
-0
src/frontend/apis/index.js
src/frontend/apis/index.js
+7
-7
src/frontend/components/App/index.jsx
src/frontend/components/App/index.jsx
+8
-8
src/frontend/components/DescriptionViewer/index.jsx
src/frontend/components/DescriptionViewer/index.jsx
+2
-2
src/frontend/components/Header/index.jsx
src/frontend/components/Header/index.jsx
+2
-2
src/frontend/components/Navigator/index.jsx
src/frontend/components/Navigator/index.jsx
+4
-4
src/frontend/reducers/env.js
src/frontend/reducers/env.js
+4
-4
未找到文件。
.gitmodules
0 → 100644
浏览文件 @
99a6a60d
[submodule "src/backend/public/algorithms"]
path = src/backend/public/algorithms
url = git@github.com:algorithm-visualizer/algorithms.git
environment.js
浏览文件 @
99a6a60d
...
...
@@ -8,6 +8,10 @@ const {
GITHUB_CLIENT_ID
,
GITHUB_CLIENT_SECRET
,
GITHUB_BOT_USERNAME
,
GITHUB_BOT_PASSWORD
,
GITHUB_ORG
=
'
algorithm-visualizer
'
,
GITHUB_REPO_ALGORITHMS
=
'
algorithms
'
,
}
=
process
.
env
;
const
__PROD__
=
NODE_ENV
===
'
production
'
;
...
...
@@ -18,6 +22,14 @@ const proxyPort = parseInt(PROXY_PORT);
const
githubClientId
=
GITHUB_CLIENT_ID
;
const
githubClientSecret
=
GITHUB_CLIENT_SECRET
;
const
githubBotAuth
=
{
username
:
GITHUB_BOT_USERNAME
,
password
:
GITHUB_BOT_PASSWORD
,
};
const
githubOrg
=
GITHUB_ORG
;
const
githubRepos
=
{
algorithms
:
GITHUB_REPO_ALGORITHMS
};
const
builtPath
=
path
.
resolve
(
__dirname
,
'
built
'
);
const
frontendBuiltPath
=
path
.
resolve
(
builtPath
,
'
frontend
'
);
...
...
@@ -36,6 +48,9 @@ module.exports = {
proxyPort
,
githubClientId
,
githubClientSecret
,
githubBotAuth
,
githubOrg
,
githubRepos
,
frontendBuiltPath
,
backendBuiltPath
,
frontendSrcPath
,
...
...
src/backend/controllers/auth.js
浏览文件 @
99a6a60d
...
...
@@ -21,7 +21,7 @@ const response = (req, res, next) => {
const
{
access_token
}
=
response
.
data
;
res
.
cookie
(
'
access_token
'
,
access_token
);
res
.
redirect
(
'
/
'
);
});
})
.
catch
(
next
)
;
};
const
destroy
=
(
req
,
res
,
next
)
=>
{
...
...
src/backend/controllers/
director
y.js
→
src/backend/controllers/
hierarch
y.js
浏览文件 @
99a6a60d
...
...
@@ -5,11 +5,11 @@ import { NotFoundError } from '/common/error';
const
router
=
express
.
Router
();
const
getPath
=
(...
args
)
=>
path
.
resolve
(
__dirname
,
'
..
'
,
'
..
'
,
'
..
'
,
'
algorithm
'
,
...
args
);
const
getPath
=
(...
args
)
=>
path
.
resolve
(
__dirname
,
'
..
'
,
'
public
'
,
'
algorithms
'
,
...
args
);
const
createKey
=
name
=>
name
.
toLowerCase
().
replace
(
/ /g
,
'
-
'
);
const
list
=
dirPath
=>
fs
.
readdirSync
(
dirPath
).
filter
(
filename
=>
!
filename
.
startsWith
(
'
.
'
));
const
readCategories
=
()
=>
{
const
createKey
=
name
=>
name
.
toLowerCase
().
replace
(
/ /g
,
'
-
'
);
const
list
=
dirPath
=>
fs
.
readdirSync
(
dirPath
).
filter
(
filename
=>
!
filename
.
startsWith
(
'
.
'
));
const
cacheHierarchy
=
()
=>
{
const
getCategory
=
categoryName
=>
{
const
categoryKey
=
createKey
(
categoryName
);
const
categoryPath
=
getPath
(
categoryName
);
...
...
@@ -33,16 +33,16 @@ const readCategories = () => {
return
list
(
getPath
()).
map
(
getCategory
);
};
const
categories
=
readCategories
();
const
hierarchy
=
cacheHierarchy
();
const
get
Categories
=
(
req
,
res
,
next
)
=>
{
res
.
json
({
categories
});
const
get
Hierarchy
=
(
req
,
res
,
next
)
=>
{
res
.
json
({
hierarchy
});
};
const
getFile
=
(
req
,
res
,
next
)
=>
{
const
{
categoryKey
,
algorithmKey
,
fileName
}
=
req
.
params
;
const
category
=
categories
.
find
(
category
=>
category
.
key
===
categoryKey
);
const
category
=
hierarchy
.
find
(
category
=>
category
.
key
===
categoryKey
);
if
(
!
category
)
return
next
(
new
NotFoundError
());
const
algorithm
=
category
.
algorithms
.
find
(
algorithm
=>
algorithm
.
key
===
algorithmKey
);
if
(
!
algorithm
)
return
next
(
new
NotFoundError
());
...
...
@@ -53,7 +53,7 @@ const getFile = (req, res, next) => {
};
router
.
route
(
'
/
'
)
.
get
(
get
Categories
);
.
get
(
get
Hierarchy
);
router
.
route
(
'
/:categoryKey/:algorithmKey/:fileName
'
)
.
get
(
getFile
);
...
...
src/backend/controllers/index.js
浏览文件 @
99a6a60d
import
express
from
'
express
'
;
import
{
AuthorizationError
,
NotFoundError
,
PermissionError
}
from
'
/common/error
'
;
import
auth
from
'
./auth
'
;
import
directory
from
'
./director
y
'
;
import
hierarchy
from
'
./hierarch
y
'
;
import
wiki
from
'
./wiki
'
;
const
router
=
new
express
.
Router
();
router
.
use
(
'
/auth
'
,
auth
);
router
.
use
(
'
/
directory
'
,
director
y
);
router
.
use
(
'
/
hierarchy
'
,
hierarch
y
);
router
.
use
(
'
/wiki
'
,
wiki
);
router
.
use
((
req
,
res
,
next
)
=>
next
(
new
NotFoundError
()));
router
.
use
((
err
,
req
,
res
,
next
)
=>
{
...
...
algorithms
@
417e8c9f
Subproject commit 417e8c9ffe9bf8411f0099ea01098c0919468a07
src/frontend/apis/index.js
浏览文件 @
99a6a60d
...
...
@@ -2,7 +2,7 @@ import Promise from 'bluebird';
import
axios
from
'
axios
'
;
import
GitHub
from
'
github-api
'
;
let
g
itHub
=
new
GitHub
();
let
g
h
=
new
GitHub
();
axios
.
interceptors
.
response
.
use
(
response
=>
{
return
response
.
data
;
...
...
@@ -49,9 +49,9 @@ const PUT = URL => {
});
};
const
Director
yApi
=
{
get
Categories
:
GET
(
'
/director
y
'
),
getFile
:
GET
(
'
/
director
y/:categoryKey/:algorithmKey/:fileName
'
),
const
Hierarch
yApi
=
{
get
Hierarchy
:
GET
(
'
/hierarch
y
'
),
getFile
:
GET
(
'
/
hierarch
y/:categoryKey/:algorithmKey/:fileName
'
),
};
const
WikiApi
=
{
...
...
@@ -60,12 +60,12 @@ const WikiApi = {
};
const
GitHubApi
=
{
auth
:
token
=>
g
itHub
=
new
GitHub
({
token
}),
getProfile
:
()
=>
g
itHub
.
getUser
().
getProfile
(),
auth
:
token
=>
g
h
=
new
GitHub
({
token
}),
getProfile
:
()
=>
g
h
.
getUser
().
getProfile
(),
};
export
{
Director
yApi
,
Hierarch
yApi
,
WikiApi
,
GitHubApi
,
};
\ No newline at end of file
src/frontend/components/App/index.jsx
浏览文件 @
99a6a60d
...
...
@@ -6,7 +6,7 @@ import { Workspace, WSSectionContainer, WSTabContainer } from '/workspace/compon
import
{
Section
}
from
'
/workspace/core
'
;
import
{
actions
as
toastActions
}
from
'
/reducers/toast
'
;
import
{
actions
as
envActions
}
from
'
/reducers/env
'
;
import
{
Director
yApi
,
GitHubApi
}
from
'
/apis
'
;
import
{
Hierarch
yApi
,
GitHubApi
}
from
'
/apis
'
;
import
{
tracerManager
}
from
'
/core
'
;
import
styles
from
'
./stylesheet.scss
'
;
import
'
axios-progress-bar/dist/nprogress.css
'
...
...
@@ -33,11 +33,11 @@ class App extends React.Component {
componentDidMount
()
{
this
.
updateDirectory
(
this
.
props
.
match
.
params
);
DirectoryApi
.
getCategories
()
.
then
(({
categories
})
=>
{
this
.
props
.
set
Categories
(
categories
);
HierarchyApi
.
getHierarchy
()
.
then
(({
hierarchy
})
=>
{
this
.
props
.
set
Hierarchy
(
hierarchy
);
const
{
categoryKey
,
algorithmKey
}
=
this
.
props
.
env
;
const
category
=
categories
.
find
(
category
=>
category
.
key
===
categoryKey
)
||
categories
[
0
];
const
category
=
hierarchy
.
find
(
category
=>
category
.
key
===
categoryKey
)
||
hierarchy
[
0
];
const
algorithm
=
category
.
algorithms
.
find
(
algorithm
=>
algorithm
.
key
===
algorithmKey
)
||
category
.
algorithms
[
0
];
this
.
props
.
history
.
push
(
`/
${
category
.
key
}
/
${
algorithm
.
key
}
`
);
});
...
...
@@ -63,7 +63,7 @@ class App extends React.Component {
updateDirectory
({
categoryKey
=
null
,
algorithmKey
=
null
})
{
if
(
categoryKey
&&
algorithmKey
)
{
this
.
props
.
setDirectory
(
categoryKey
,
algorithmKey
);
Director
yApi
.
getFile
(
categoryKey
,
algorithmKey
,
'
code.js
'
).
then
(
code
=>
tracerManager
.
setCode
(
code
));
Hierarch
yApi
.
getFile
(
categoryKey
,
algorithmKey
,
'
code.js
'
).
then
(
code
=>
tracerManager
.
setCode
(
code
));
}
}
...
...
@@ -88,11 +88,11 @@ class App extends React.Component {
}
render
()
{
const
{
categories
,
categoryKey
,
algorithmKey
}
=
this
.
props
.
env
;
const
{
hierarchy
,
categoryKey
,
algorithmKey
}
=
this
.
props
.
env
;
const
navigatorOpened
=
true
;
return
categories
&&
categoryKey
&&
algorithmKey
&&
(
return
hierarchy
&&
categoryKey
&&
algorithmKey
&&
(
<
div
className
=
{
styles
.
app
}
>
<
Workspace
className
=
{
styles
.
workspace
}
wsProps
=
{
{
horizontal
:
false
}
}
>
<
Header
wsProps
=
{
{
...
...
src/frontend/components/DescriptionViewer/index.jsx
浏览文件 @
99a6a60d
import
React
from
'
react
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
actions
as
envActions
}
from
'
/reducers/env
'
;
import
{
Director
yApi
}
from
'
/apis/index
'
;
import
{
Hierarch
yApi
}
from
'
/apis/index
'
;
import
{
MarkdownViewer
}
from
'
/components
'
;
@
connect
(
...
...
@@ -37,7 +37,7 @@ class DescriptionViewer extends React.Component {
loadMarkdown
(
href
)
{
const
[,
,
categoryKey
,
algorithmKey
]
=
href
.
split
(
'
/
'
);
Director
yApi
.
getFile
(
categoryKey
,
algorithmKey
,
'
desc.md
'
)
Hierarch
yApi
.
getFile
(
categoryKey
,
algorithmKey
,
'
desc.md
'
)
.
then
(
source
=>
this
.
setState
({
source
}))
.
catch
(()
=>
this
.
setState
({
source
:
null
}));
}
...
...
src/frontend/components/Header/index.jsx
浏览文件 @
99a6a60d
...
...
@@ -70,9 +70,9 @@ class Header extends React.Component {
render
()
{
const
{
interval
,
paused
,
started
,
profile
}
=
this
.
state
;
const
{
className
,
onClickTitleBar
,
navigatorOpened
}
=
this
.
props
;
const
{
categories
,
categoryKey
,
algorithmKey
,
signedIn
}
=
this
.
props
.
env
;
const
{
hierarchy
,
categoryKey
,
algorithmKey
,
signedIn
}
=
this
.
props
.
env
;
const
category
=
categories
.
find
(
category
=>
category
.
key
===
categoryKey
);
const
category
=
hierarchy
.
find
(
category
=>
category
.
key
===
categoryKey
);
const
algorithm
=
category
.
algorithms
.
find
(
algorithm
=>
algorithm
.
key
===
algorithmKey
);
return
(
...
...
src/frontend/components/Navigator/index.jsx
浏览文件 @
99a6a60d
...
...
@@ -40,10 +40,10 @@ class Navigator extends React.Component {
}
handleChangeQuery
(
e
)
{
const
{
categories
}
=
this
.
props
.
env
;
const
{
hierarchy
}
=
this
.
props
.
env
;
const
categoriesOpened
=
{};
const
query
=
e
.
target
.
value
;
categories
.
forEach
(
category
=>
{
hierarchy
.
forEach
(
category
=>
{
if
(
this
.
testQuery
(
name
)
||
category
.
algorithms
.
find
(
algorithm
=>
this
.
testQuery
(
algorithm
.
name
)))
{
categoriesOpened
[
category
.
key
]
=
true
;
}
...
...
@@ -60,7 +60,7 @@ class Navigator extends React.Component {
render
()
{
const
{
categoriesOpened
,
query
}
=
this
.
state
;
const
{
className
,
style
}
=
this
.
props
;
const
{
categoryKey
:
selectedCategoryKey
,
algorithmKey
:
selectedAlgorithmKey
,
categories
}
=
this
.
props
.
env
;
const
{
hierarchy
,
categoryKey
:
selectedCategoryKey
,
algorithmKey
:
selectedAlgorithmKey
}
=
this
.
props
.
env
;
return
(
<
nav
className
=
{
classes
(
styles
.
navigator
,
className
)
}
style
=
{
style
}
>
...
...
@@ -71,7 +71,7 @@ class Navigator extends React.Component {
</
div
>
<
div
className
=
{
styles
.
algorithm_list
}
>
{
categories
.
map
(
category
=>
{
hierarchy
.
map
(
category
=>
{
const
categoryOpened
=
categoriesOpened
[
category
.
key
];
let
algorithms
=
category
.
algorithms
;
if
(
!
this
.
testQuery
(
category
.
name
))
{
...
...
src/frontend/reducers/env.js
浏览文件 @
99a6a60d
...
...
@@ -3,20 +3,20 @@ import { combineActions, createAction, handleActions } from 'redux-actions';
const
prefix
=
'
ENV
'
;
const
set
Categories
=
createAction
(
`
${
prefix
}
/SET_CATEGORIES`
,
categories
=>
({
categories
}));
const
set
Hierarchy
=
createAction
(
`
${
prefix
}
/SET_HIERARCHY`
,
hierarchy
=>
({
hierarchy
}));
const
setDirectory
=
createAction
(
`
${
prefix
}
/SET_DIRECTORY`
,
(
categoryKey
,
algorithmKey
)
=>
({
categoryKey
,
algorithmKey
,
}));
export
const
actions
=
{
set
Categories
,
set
Hierarchy
,
setDirectory
,
};
const
accessToken
=
Cookies
.
get
(
'
access_token
'
);
const
defaultState
=
{
categories
:
null
,
hierarchy
:
null
,
categoryKey
:
null
,
algorithmKey
:
null
,
accessToken
,
...
...
@@ -25,7 +25,7 @@ const defaultState = {
export
default
handleActions
({
[
combineActions
(
set
Categories
,
set
Hierarchy
,
setDirectory
,
)]:
(
state
,
{
payload
})
=>
({
...
state
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录