mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-11 20:01:10 +00:00
Wiki show dir bug (#2337)
This commit is contained in:
committed by
Daniel Pan
parent
7015929a33
commit
cece038dec
@@ -1,9 +1,9 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { gettext, repoID, serviceUrl, slug, siteRoot } from './constance';
|
import { gettext, repoID, serviceUrl, slug, siteRoot } from '../../components/constance';
|
||||||
import Search from './search';
|
import Search from '../../components/search';
|
||||||
import Account from './account';
|
import Account from '../../components/account';
|
||||||
import MarkdownViewer from './markdown-viewer';
|
import MarkdownViewer from '../../components/markdown-viewer';
|
||||||
import TreeDirView from './tree-dir-view/tree-dir-view';
|
import TreeDirView from '../../components/tree-dir-view/tree-dir-view';
|
||||||
|
|
||||||
class MainPanel extends Component {
|
class MainPanel extends Component {
|
||||||
|
|
@@ -1,8 +1,8 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import TreeView from './tree-view/tree-view';
|
import TreeView from '../../components/tree-view/tree-view';
|
||||||
import { siteRoot, logoPath, mediaUrl, siteTitle, logoWidth, logoHeight } from './constance';
|
import { siteRoot, logoPath, mediaUrl, siteTitle, logoWidth, logoHeight } from '../../components/constance';
|
||||||
import NodeMenu from './menu-component/node-menu';
|
import NodeMenu from '../../components/menu-component/node-menu';
|
||||||
import MenuControl from './menu-component/node-menu-control';
|
import MenuControl from '../../components/menu-component/node-menu-control';
|
||||||
|
|
||||||
const gettext = window.gettext;
|
const gettext = window.gettext;
|
||||||
|
|
@@ -3,8 +3,8 @@ import ReactDOM from 'react-dom';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { slug, repoID, serviceUrl, initialFilePath } from './components/constance';
|
import { slug, repoID, serviceUrl, initialFilePath } from './components/constance';
|
||||||
import editorUtilities from './utils/editor-utilties';
|
import editorUtilities from './utils/editor-utilties';
|
||||||
import SidePanel from './components/side-panel';
|
import SidePanel from './pages/wiki/side-panel';
|
||||||
import MainPanel from './components/main-panel';
|
import MainPanel from './pages/wiki/main-panel';
|
||||||
import Node from './components/tree-view/node'
|
import Node from './components/tree-view/node'
|
||||||
import Tree from './components/tree-view/tree'
|
import Tree from './components/tree-view/tree'
|
||||||
import 'seafile-ui';
|
import 'seafile-ui';
|
||||||
@@ -34,14 +34,45 @@ class Wiki extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.initSidePanelData();
|
this.initWikiData(initialFilePath);
|
||||||
this.initMainPanelData(initialFilePath);
|
}
|
||||||
|
|
||||||
|
initWikiData(filePath){
|
||||||
|
this.setState({isFileLoading: true});
|
||||||
|
editorUtilities.getFiles().then((files) => {
|
||||||
|
// construct the tree object
|
||||||
|
var treeData = new Tree();
|
||||||
|
treeData.parseListToTree(files);
|
||||||
|
|
||||||
|
let node = treeData.getNodeByPath(filePath);
|
||||||
|
if (node.isDir()) {
|
||||||
|
this.exitViewFileState(treeData, node);
|
||||||
|
this.setState({isFileLoading: false});
|
||||||
|
} else {
|
||||||
|
editorUtilities.getWikiFileContent(slug, filePath).then(res => {
|
||||||
|
this.setState({
|
||||||
|
tree_data: treeData,
|
||||||
|
content: res.data.content,
|
||||||
|
latestContributor: res.data.latest_contributor,
|
||||||
|
lastModified: moment.unix(res.data.last_modified).fromNow(),
|
||||||
|
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) {
|
initMainPanelData(filePath) {
|
||||||
if (!this.isMarkdownFile(filePath)) {
|
|
||||||
filePath = "/home.md";
|
|
||||||
}
|
|
||||||
this.setState({isFileLoading: true});
|
this.setState({isFileLoading: true});
|
||||||
editorUtilities.getWikiFileContent(slug, filePath)
|
editorUtilities.getWikiFileContent(slug, filePath)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@@ -60,24 +91,6 @@ class Wiki extends Component {
|
|||||||
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
|
window.history.pushState({urlPath: fileUrl, filePath: filePath}, filePath, fileUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
initSidePanelData() {
|
|
||||||
editorUtilities.getFiles().then((files) => {
|
|
||||||
// construct the tree object
|
|
||||||
var treeData = new Tree();
|
|
||||||
treeData.parseListToTree(files);
|
|
||||||
let homeNode = this.getHomeNode(treeData);
|
|
||||||
this.setState({
|
|
||||||
tree_data: treeData,
|
|
||||||
changedNode: homeNode
|
|
||||||
});
|
|
||||||
}, () => {
|
|
||||||
console.log("failed to load files");
|
|
||||||
this.setState({
|
|
||||||
isLoadFailed: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
onLinkClick = (event) => {
|
onLinkClick = (event) => {
|
||||||
const url = event.target.href;
|
const url = event.target.href;
|
||||||
if (this.isInternalMarkdownLink(url)) {
|
if (this.isInternalMarkdownLink(url)) {
|
||||||
@@ -244,14 +257,16 @@ class Wiki extends Component {
|
|||||||
})
|
})
|
||||||
} else if (node.isDir()) {
|
} else if (node.isDir()) {
|
||||||
editorUtilities.renameDir(filePath, newName).then(res => {
|
editorUtilities.renameDir(filePath, newName).then(res => {
|
||||||
|
|
||||||
let currentFilePath = this.state.filePath;// the sequence is must right
|
let currentFilePath = this.state.filePath;// the sequence is must right
|
||||||
let currentFileNode = tree.getNodeByPath(currentFilePath);
|
let currentFileNode = tree.getNodeByPath(currentFilePath);
|
||||||
|
let isPathEqual = (node.path === currentFilePath);
|
||||||
let date = new Date().getTime()/1000;
|
let date = new Date().getTime()/1000;
|
||||||
tree.updateNodeParam(node, "name", newName);
|
tree.updateNodeParam(node, "name", newName);
|
||||||
node.name = newName; // just synchronization node data && tree data;
|
node.name = newName; // just synchronization node data && tree data;
|
||||||
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();
|
node.last_update_time = moment.unix(date).fromNow();
|
||||||
|
|
||||||
if (this.state.isViewFileState) {
|
if (this.state.isViewFileState) {
|
||||||
if (this.isModifyContainsCurrentFile(node)) {
|
if (this.isModifyContainsCurrentFile(node)) {
|
||||||
tree.setNodeToActivated(currentFileNode);
|
tree.setNodeToActivated(currentFileNode);
|
||||||
@@ -264,7 +279,7 @@ class Wiki extends Component {
|
|||||||
this.setState({tree_data: tree});
|
this.setState({tree_data: tree});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (node.path.indexOf(currentFilePath) > -1) {
|
if (isPathEqual || node.path.indexOf(currentFilePath) > -1) {
|
||||||
tree.setNodeToActivated(currentFileNode);
|
tree.setNodeToActivated(currentFileNode);
|
||||||
this.exitViewFileState(tree, currentFileNode);
|
this.exitViewFileState(tree, currentFileNode);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user