mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
Wiki coding style improve (#2380)
This commit is contained in:
committed by
Daniel Pan
parent
3d165ec733
commit
db47fb34a7
@@ -5,14 +5,15 @@ import MainPanel from './pages/wiki/main-panel';
|
||||
import moment from 'moment';
|
||||
import { slug, repoID, serviceUrl, initialFilePath } from './components/constants';
|
||||
import editorUtilities from './utils/editor-utilties';
|
||||
import Node from './components/tree-view/node'
|
||||
import Tree from './components/tree-view/tree'
|
||||
import Node from './components/tree-view/node';
|
||||
import Tree from './components/tree-view/tree';
|
||||
import 'seafile-ui';
|
||||
import './assets/css/fa-solid.css';
|
||||
import './assets/css/fa-regular.css';
|
||||
import './assets/css/fontawesome.css';
|
||||
import './css/side-panel.css';
|
||||
import './css/wiki.css';
|
||||
import './css/toolbar.css';
|
||||
import './css/search.css';
|
||||
|
||||
class Wiki extends Component {
|
||||
@@ -60,18 +61,17 @@ class Wiki extends Component {
|
||||
permission: res.data.permission,
|
||||
filePath: filePath,
|
||||
isFileLoading: false
|
||||
})
|
||||
});
|
||||
});
|
||||
const hash = window.location.hash;
|
||||
let fileUrl = serviceUrl + '/wikis/' + slug + filePath + hash;
|
||||
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
|
||||
}
|
||||
}, () => {
|
||||
console.log("failed to load files");
|
||||
this.setState({
|
||||
isLoadFailed: true
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
initMainPanelData(filePath){
|
||||
@@ -85,12 +85,12 @@ class Wiki extends Component {
|
||||
permission: res.data.permission,
|
||||
filePath: filePath,
|
||||
isFileLoading: false
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
const hash = window.location.hash;
|
||||
let fileUrl = serviceUrl + '/wikis/' + slug + filePath + hash;
|
||||
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
|
||||
const hash = window.location.hash;
|
||||
let fileUrl = serviceUrl + '/wikis/' + slug + filePath + hash;
|
||||
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
|
||||
}
|
||||
|
||||
onLinkClick = (event) => {
|
||||
@@ -183,25 +183,25 @@ class Wiki extends Component {
|
||||
onMenuClick = () => {
|
||||
this.setState({
|
||||
closeSideBar: !this.state.closeSideBar,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onCloseSide = () => {
|
||||
this.setState({
|
||||
closeSideBar: !this.state.closeSideBar,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onAddFolderNode = (dirPath) => {
|
||||
editorUtilities.createDir(dirPath).then(res => {
|
||||
let tree = this.state.tree_data.clone();
|
||||
let name = this.getFileNameByPath(dirPath);
|
||||
let index = dirPath.lastIndexOf("/");
|
||||
let index = dirPath.lastIndexOf('/');
|
||||
let parentPath = dirPath.substring(0, index);
|
||||
if (!parentPath) {
|
||||
parentPath = "/";
|
||||
parentPath = '/';
|
||||
}
|
||||
let node = this.buildNewNode(name, "dir");
|
||||
let node = this.buildNewNode(name, 'dir');
|
||||
let parentNode = tree.getNodeByPath(parentPath);
|
||||
tree.addNodeToParent(node, parentNode);
|
||||
if (this.state.isViewFileState) {
|
||||
@@ -209,23 +209,23 @@ class Wiki extends Component {
|
||||
this.setState({
|
||||
tree_data: tree,
|
||||
changedNode: node
|
||||
})
|
||||
});
|
||||
} else {
|
||||
this.exitViewFileState(tree, parentNode);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onAddFileNode = (filePath) => {
|
||||
editorUtilities.createFile(filePath).then(res => {
|
||||
let tree = this.state.tree_data.clone();
|
||||
let name = this.getFileNameByPath(filePath);
|
||||
let index = filePath.lastIndexOf("/");
|
||||
let index = filePath.lastIndexOf('/');
|
||||
let parentPath = filePath.substring(0, index);
|
||||
if (!parentPath) {
|
||||
parentPath = "/";
|
||||
parentPath = '/';
|
||||
}
|
||||
let node = this.buildNewNode(name, "file");
|
||||
let node = this.buildNewNode(name, 'file');
|
||||
let parentNode = tree.getNodeByPath(parentPath);
|
||||
tree.addNodeToParent(node, parentNode);
|
||||
if (this.state.isViewFileState) {
|
||||
@@ -233,11 +233,11 @@ class Wiki extends Component {
|
||||
this.setState({
|
||||
tree_data: tree,
|
||||
changedNode: node
|
||||
})
|
||||
});
|
||||
} else {
|
||||
this.exitViewFileState(tree, parentNode);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
onRenameNode = (node, newName) => {
|
||||
@@ -247,10 +247,10 @@ class Wiki extends Component {
|
||||
editorUtilities.renameFile(filePath, newName).then(res => {
|
||||
let cloneNode = node.clone();
|
||||
|
||||
tree.updateNodeParam(node, "name", newName);
|
||||
tree.updateNodeParam(node, 'name', newName);
|
||||
node.name = newName;
|
||||
let date = new Date().getTime()/1000;
|
||||
tree.updateNodeParam(node, "last_update_time", moment.unix(date).fromNow());
|
||||
tree.updateNodeParam(node, 'last_update_time', moment.unix(date).fromNow());
|
||||
node.last_update_time = moment.unix(date).fromNow();
|
||||
|
||||
if (this.state.isViewFileState) {
|
||||
@@ -271,7 +271,7 @@ class Wiki extends Component {
|
||||
changedNode: parentNode
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
} else if (node.isDir()) {
|
||||
editorUtilities.renameDir(filePath, newName).then(res => {
|
||||
|
||||
@@ -279,10 +279,10 @@ class Wiki extends Component {
|
||||
let currentFileNode = tree.getNodeByPath(currentFilePath);
|
||||
let nodePath = node.path;
|
||||
|
||||
tree.updateNodeParam(node, "name", newName);
|
||||
tree.updateNodeParam(node, 'name', newName);
|
||||
node.name = newName;
|
||||
let date = new Date().getTime()/1000;
|
||||
tree.updateNodeParam(node, "last_update_time", moment.unix(date).fromNow());
|
||||
tree.updateNodeParam(node, 'last_update_time', moment.unix(date).fromNow());
|
||||
node.last_update_time = moment.unix(date).fromNow();
|
||||
|
||||
if (this.state.isViewFileState) {
|
||||
@@ -307,7 +307,7 @@ class Wiki extends Component {
|
||||
this.setState({tree_data: tree});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,10 +337,10 @@ class Wiki extends Component {
|
||||
this.setState({
|
||||
tree_data: tree,
|
||||
changedNode: homeNode
|
||||
})
|
||||
});
|
||||
this.initMainPanelData(homeNode.path);
|
||||
} else {
|
||||
this.setState({tree_data: tree})
|
||||
this.setState({tree_data: tree});
|
||||
}
|
||||
} else {
|
||||
let parentNode = tree.getNodeByPath(this.state.filePath);
|
||||
@@ -376,26 +376,26 @@ class Wiki extends Component {
|
||||
}
|
||||
|
||||
getFileNameByPath(path) {
|
||||
let index = path.lastIndexOf("/");
|
||||
let index = path.lastIndexOf('/');
|
||||
if (index === -1) {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
return path.slice(index+1);
|
||||
}
|
||||
|
||||
getHomeNode(treeData) {
|
||||
return treeData.getNodeByPath("/home.md");
|
||||
return treeData.getNodeByPath('/home.md');
|
||||
}
|
||||
|
||||
buildNewNode(name, type) {
|
||||
let date = new Date().getTime()/1000;
|
||||
let node = new Node({
|
||||
name : name,
|
||||
type: type,
|
||||
size: '0',
|
||||
last_update_time: moment.unix(date).fromNow(),
|
||||
isExpanded: false,
|
||||
children: []
|
||||
name : name,
|
||||
type: type,
|
||||
size: '0',
|
||||
last_update_time: moment.unix(date).fromNow(),
|
||||
isExpanded: false,
|
||||
children: []
|
||||
});
|
||||
return node;
|
||||
}
|
||||
@@ -417,12 +417,12 @@ class Wiki extends Component {
|
||||
}
|
||||
|
||||
isMarkdownFile(filePath) {
|
||||
let index = filePath.lastIndexOf(".");
|
||||
let index = filePath.lastIndexOf('.');
|
||||
if (index === -1) {
|
||||
return false;
|
||||
} else {
|
||||
let type = filePath.substring(index).toLowerCase();
|
||||
if (type === ".md" || type === ".markdown") {
|
||||
if (type === '.md' || type === '.markdown') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -441,23 +441,23 @@ class Wiki extends Component {
|
||||
}
|
||||
|
||||
getPathFromInternalMarkdownLink(url) {
|
||||
var re = new RegExp(serviceUrl + '/lib/' + repoID + '/file' + "(.*\.md)");
|
||||
var re = new RegExp(serviceUrl + '/lib/' + repoID + '/file' + '(.*\.md)');
|
||||
var array = re.exec(url);
|
||||
var path = decodeURIComponent(array[1]);
|
||||
return path;
|
||||
}
|
||||
|
||||
getPathFromInternalDirLink(url) {
|
||||
var re = new RegExp(serviceUrl + '/#[a-z\-]*?/lib/' + repoID + "(/.*)");
|
||||
var re = new RegExp(serviceUrl + '/#[a-z\-]*?/lib/' + repoID + '(/.*)');
|
||||
var array = re.exec(url);
|
||||
var path = decodeURIComponent(array[1]);
|
||||
|
||||
var dirPath = path.substring(1);
|
||||
var re = new RegExp("(^/.*)");
|
||||
re = new RegExp('(^/.*)');
|
||||
if (re.test(dirPath)) {
|
||||
path = dirPath;
|
||||
} else {
|
||||
path = '/' + dirPath
|
||||
path = '/' + dirPath;
|
||||
}
|
||||
|
||||
return path;
|
||||
@@ -495,11 +495,11 @@ class Wiki extends Component {
|
||||
onMainNodeClick={this.onMainNodeClick}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render (
|
||||
<Wiki />,
|
||||
document.getElementById('wrapper')
|
||||
)
|
||||
);
|
||||
|
Reference in New Issue
Block a user