1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

remove wiki2 markdown viewer and apis

This commit is contained in:
Michael An
2024-05-29 15:19:42 +08:00
parent 96aa207802
commit 94c92ad22b
7 changed files with 36 additions and 849 deletions

View File

@@ -1,114 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
import { mdStringToSlate } from '@seafile/seafile-editor';
import { isPublicWiki, repoID, serviceURL, slug } from '../../../utils/constants';
import { Utils } from '../../../utils/utils';
import { generateNavItems } from '../utils/generate-navs';
import NavItem from './nav-item';
import'./style.css';
const viewerPropTypes = {
indexContent: PropTypes.string.isRequired,
onLinkClick: PropTypes.func.isRequired,
};
class IndexMdViewer extends React.Component {
constructor(props) {
super(props);
this.links = [];
this.state = {
currentPath: '',
treeRoot: { name: '', href: '', children: [], isRoot: true },
};
}
componentDidMount() {
const { indexContent } = this.props;
const slateNodes = mdStringToSlate(indexContent);
const newSlateNodes = Utils.changeMarkdownNodes(slateNodes, this.changeInlineNode);
const treeRoot = generateNavItems(newSlateNodes);
this.setState({
treeRoot: treeRoot,
});
}
onLinkClick = (node) => {
const { currentPath } = this.state;
if (node.path === currentPath) return;
if (node.path) {
this.setState({ currentPath: node.path });
}
if (node.href) this.props.onLinkClick(node.href);
};
changeInlineNode = (item) => {
if (item.type == 'link' || item.type === 'image') {
let url;
// change image url
if (item.type == 'image' && isPublicWiki) {
url = item.data.src;
const re = new RegExp(serviceURL + '/lib/' + repoID +'/file.*raw=1');
// different repo
if (!re.test(url)) {
return;
}
// get image path
let index = url.indexOf('/file');
let index2 = url.indexOf('?');
const imagePath = url.substring(index + 5, index2);
// replace url
item.data.src = serviceURL + '/view-image-via-public-wiki/?slug=' + slug + '&path=' + imagePath;
}
else if (item.type == 'link') {
url = item.url;
/* eslint-disable */
let expression = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/
/* eslint-enable */
let re = new RegExp(expression);
// Solving relative paths
if (!re.test(url)) {
if (url.startsWith('./')) {
url = url.slice(2);
}
item.url = serviceURL + '/published/' + slug + '/' + url;
}
// change file url
else if (Utils.isInternalMarkdownLink(url, repoID)) {
let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
// replace url
item.url = serviceURL + '/published/' + slug + path;
}
// change dir url
else if (Utils.isInternalDirLink(url, repoID)) {
let path = Utils.getPathFromInternalDirLink(url, repoID);
// replace url
item.url = serviceURL + '/published/' + slug + path;
}
}
}
return item;
};
render() {
const { treeRoot, currentPath } = this.state;
return (
<div className="mx-4 o-hidden">
{treeRoot.children.map(node => {
return (
<NavItem key={node.path} node={node} currentPath={currentPath} onLinkClick={this.onLinkClick} />
);
})}
</div>
);
}
}
IndexMdViewer.propTypes = viewerPropTypes;
export default IndexMdViewer;

View File

@@ -1,91 +0,0 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
const propTypes = {
node: PropTypes.object.isRequired,
currentPath: PropTypes.string,
onLinkClick: PropTypes.func.isRequired,
};
class NavItem extends React.Component {
constructor(props) {
super(props);
this.state = {
expanded: false
};
}
toggleExpanded = () => {
const { expanded } = this.state;
this.setState({ expanded: !expanded });
};
onLinkClick = (event) => {
event.preventDefault();
const { node } = this.props;
const { expanded } = this.state;
if (node.children && node.children.length > 0 && !expanded) {
this.setState({expanded: !expanded});
return;
}
this.props.onLinkClick(node);
};
itemClick = () => {
const { node } = this.props;
const { expanded } = this.state;
if (node.children && node.children.length > 0) {
this.setState({expanded: !expanded});
return;
}
};
renderLink = ({ href, name, path, children }) => {
const { currentPath } = this.props;
const className = classNames('wiki-nav-content', {
'no-children': !children || children.length === 0,
'wiki-nav-content-highlight': currentPath === path,
});
if (href && name) {
return (
<div className={className}>
<a href={href} data-path={path} onClick={this.onLinkClick} title={name}>{name}</a>
</div>
);
}
if (name) {
return <div className={className} onClick={this.itemClick}><span title={name}>{name}</span></div>;
}
return null;
};
render() {
const { node } = this.props;
const { expanded } = this.state;
if (node.children.length > 0) {
return (
<div className="pl-4 position-relative">
<span className="switch-btn" onClick={this.toggleExpanded}>
{<i className={`fa fa-caret-${expanded ? 'down': 'right'}`}></i>}
</span>
{this.renderLink(node)}
{expanded && node.children.map((child, index) => {
return (
<NavItem key={index} node={child} currentPath={this.props.currentPath} onLinkClick={this.props.onLinkClick} />
);
})}
</div>
);
}
return this.renderLink(node);
}
}
NavItem.propTypes = propTypes;
export default NavItem;

View File

@@ -1,37 +0,0 @@
.wiki-nav-content {
margin-top: 18px;
}
.wiki-nav-content.no-children {
margin-left: 1rem;
}
.wiki-nav-content a,
.wiki-nav-content span {
color: #4d5156;
font-size: 14px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
display: block;
}
.wiki-nav-content a:hover {
text-decoration: none;
color: #eb8205;
}
.wiki-nav-content-highlight a {
text-decoration: none;
color: #eb8205;
}
.switch-btn {
position: absolute;
left: 0;
top: 2px;
color: #c0c0c0;
cursor: pointer;
font-size: 12px;
padding-right: 10px;
}

View File

@@ -5,15 +5,11 @@ import { Modal } from 'reactstrap';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import wikiAPI from '../../utils/wiki-api'; import wikiAPI from '../../utils/wiki-api';
import SDocServerApi from '../../utils/sdoc-server-api'; import SDocServerApi from '../../utils/sdoc-server-api';
import { slug, wikiId, siteRoot, initialPath, isDir, sharedToken, hasIndex, lang, isWiki2, seadocServerUrl } from '../../utils/constants'; import { wikiId, siteRoot, lang, isWiki2, seadocServerUrl } from '../../utils/constants';
import Dirent from '../../models/dirent';
import WikiConfig from './models/wiki-config'; import WikiConfig from './models/wiki-config';
import TreeNode from '../../components/tree-view/tree-node';
import treeHelper from '../../components/tree-view/tree-helper';
import toaster from '../../components/toast'; import toaster from '../../components/toast';
import SidePanel from './side-panel'; import SidePanel from './side-panel';
import MainPanel from './main-panel'; import MainPanel from './main-panel';
// import WikiLeftBar from './wiki-left-bar/wiki-left-bar';
import PageUtils from './view-structure/page-utils'; import PageUtils from './view-structure/page-utils';
import '../../css/layout.css'; import '../../css/layout.css';
@@ -33,17 +29,9 @@ class Wiki extends Component {
closeSideBar: false, closeSideBar: false,
isViewFile: true, isViewFile: true,
isDataLoading: false, isDataLoading: false,
direntList: [],
editorContent: {}, editorContent: {},
permission: '', permission: '',
lastModified: '',
latestContributor: '',
isTreeDataLoading: true,
isConfigLoading: true, isConfigLoading: true,
treeData: treeHelper.buildTree(),
currentNode: null,
indexNode: null,
indexContent: '',
currentPageId: '', currentPageId: '',
config: new WikiConfig({}), config: new WikiConfig({}),
repoId: '', repoId: '',
@@ -51,9 +39,6 @@ class Wiki extends Component {
assets_url: '', assets_url: '',
}; };
window.onpopstate = this.onpopstate;
this.indexPath = '/index.md';
this.homePath = '/home.md';
this.pythonWrapper = null; this.pythonWrapper = null;
} }
@@ -65,15 +50,6 @@ class Wiki extends Component {
componentDidMount() { componentDidMount() {
this.getWikiConfig(); this.getWikiConfig();
this.loadSidePanel(initialPath);
this.loadWikiData(initialPath);
this.links = document.querySelectorAll('#wiki-file-content a');
this.links.forEach(link => link.addEventListener('click', this.onConentLinkClick));
}
componentWillUnmount() {
this.links.forEach(link => link.removeEventListener('click', this.onConentLinkClick));
} }
handlePath = () => { handlePath = () => {
@@ -129,77 +105,6 @@ class Wiki extends Component {
} }
}; };
loadSidePanel = (initialPath) => {
if (hasIndex) {
this.loadIndexNode();
return;
}
// load dir list
initialPath = (isDir === 'None' || Utils.isSdocFile(initialPath)) ? '/' : initialPath;
this.loadNodeAndParentsByPath(initialPath);
};
loadWikiData = (initialPath) => {
this.pythonWrapper = document.getElementById('wiki-file-content');
if (isDir === 'False' && Utils.isSdocFile(initialPath)) {
this.showDir('/');
return;
}
if (isDir === 'False') {
// this.showFile(initialPath);
this.setState({ path: initialPath });
return;
}
// if it is a file list, remove the template content provided by python
this.removePythonWrapper();
if (isDir === 'True') {
this.showDir(initialPath);
return;
}
if (isDir === 'None' && initialPath === '/home.md') {
this.showDir('/');
return;
}
if (isDir === 'None') {
this.setState({ pathExist: false });
let fileUrl = siteRoot + this.handlePath() + wikiId + Utils.encodePath(initialPath);
window.history.pushState({ url: fileUrl, path: initialPath }, initialPath, fileUrl);
}
};
loadIndexNode = () => {
wikiAPI.listWiki2Dir(wikiId, '/').then(res => {
let tree = this.state.treeData;
this.addFirstResponseListToNode(res.data.dirent_list, tree.root);
let indexNode = tree.getNodeByPath(this.indexPath);
wikiAPI.getWiki2FileContent(wikiId, indexNode.path).then(res => {
this.setState({
treeData: tree,
indexNode: indexNode,
indexContent: res.data.content,
isTreeDataLoading: false,
});
});
}).catch(() => {
this.setState({ isLoadFailed: true });
});
};
showDir = (dirPath) => {
this.removePythonWrapper();
this.loadDirentList(dirPath);
// update location url
let fileUrl = siteRoot + this.handlePath() + wikiId + Utils.encodePath(dirPath);
window.history.pushState({ url: fileUrl, path: dirPath }, dirPath, fileUrl);
};
getSdocFileContent = (docUuid, accessToken) => { getSdocFileContent = (docUuid, accessToken) => {
const config = { const config = {
docUuid, docUuid,
@@ -218,118 +123,6 @@ class Wiki extends Component {
}); });
}; };
showFile = (filePath) => {
this.setState({
isDataLoading: true,
});
wikiAPI.getWiki2FileContent(wikiId, filePath).then(res => {
const { permission, last_modified, latest_contributor, seadoc_access_token, assets_url } = res.data;
this.setState({
permission,
lastModified: moment.unix(last_modified).fromNow(),
latestContributor: latest_contributor,
seadoc_access_token,
assets_url,
isViewFile: true,
path: filePath,
});
const docUuid = assets_url.slice(assets_url.lastIndexOf('/') + 1);
this.getSdocFileContent(docUuid, seadoc_access_token);
}).catch(error => {
let errorMsg = Utils.getErrorMsg(error);
toaster.danger(errorMsg);
});
const hash = window.location.hash;
let fileUrl = `${siteRoot}${this.handlePath()}${wikiId}${Utils.encodePath(filePath)}${hash}`;
if (filePath === '/home.md') {
window.history.replaceState({ url: fileUrl, path: filePath }, filePath, fileUrl);
} else {
window.history.pushState({ url: fileUrl, path: filePath }, filePath, fileUrl);
}
};
loadDirentList = (dirPath) => {
this.setState({ isDataLoading: true });
wikiAPI.listWiki2Dir(wikiId, dirPath).then(res => {
let direntList = res.data.dirent_list.map(item => {
let dirent = new Dirent(item);
return dirent;
});
if (dirPath === '/') {
direntList = direntList.filter(item => {
if (item.type === 'dir') {
let name = item.name.toLowerCase();
return name !== 'drafts' && name !== 'images' && name !== 'downloads';
}
return true;
});
}
direntList = Utils.sortDirents(direntList, 'name', 'asc');
this.setState({
path: dirPath,
isViewFile: false,
direntList: direntList,
isDataLoading: false,
});
}).catch(() => {
this.setState({ isLoadFailed: true });
});
};
loadTreeNodeByPath = (path) => {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(path);
if (!node.isLoaded) {
wikiAPI.listWiki2Dir(wikiId, node.path).then(res => {
this.addResponseListToNode(res.data.dirent_list, node);
let parentNode = tree.getNodeByPath(node.parentNode.path);
parentNode.isExpanded = true;
this.setState({
treeData: tree,
currentNode: node
});
});
} else {
let parentNode = tree.getNodeByPath(node.parentNode.path);
parentNode.isExpanded = true;
this.setState({ treeData: tree, currentNode: node }); //tree
}
};
loadNodeAndParentsByPath = (path) => {
let tree = this.state.treeData.clone();
if (Utils.isMarkdownFile(path)) {
path = Utils.getDirName(path);
}
wikiAPI.listWiki2Dir(wikiId, path, true).then(res => {
let direntList = res.data.dirent_list;
let results = {};
for (let i = 0; i < direntList.length; i++) {
let object = direntList[i];
let key = object.parent_dir;
if (!results[key]) {
results[key] = [];
}
results[key].push(object);
}
for (let key in results) {
let node = tree.getNodeByPath(key);
if (!node.isLoaded && node.path === '/') {
this.addFirstResponseListToNode(results[key], node);
} else if (!node.isLoaded) {
this.addResponseListToNode(results[key], node);
}
}
this.setState({
isTreeDataLoading: false,
treeData: tree
});
}).catch(() => {
this.setState({ isLoadFailed: true });
});
};
removePythonWrapper = () => { removePythonWrapper = () => {
if (this.pythonWrapper) { if (this.pythonWrapper) {
document.body.removeChild(this.pythonWrapper); document.body.removeChild(this.pythonWrapper);
@@ -337,227 +130,10 @@ class Wiki extends Component {
} }
}; };
onConentLinkClick = (event) => {
event.preventDefault();
event.stopPropagation();
let link = '';
if (event.target.tagName !== 'A') {
let target = event.target.parentNode;
while (target.tagName !== 'A') {
target = target.parentNode;
}
link = target.href;
} else {
link = event.target.href;
}
this.onLinkClick(link);
};
onLinkClick = (link) => {
const url = link;
if (Utils.isWikiInternalMarkdownLink(url, slug)) {
let path = Utils.getPathFromWikiInternalMarkdownLink(url, slug);
this.showFile(path);
} else if (Utils.isWikiInternalDirLink(url, slug)) {
let path = Utils.getPathFromWikiInternalDirLink(url, slug);
this.showDir(path);
} else {
window.location.href = url;
}
if (!this.state.closeSideBar) {
this.setState({ closeSideBar: true });
}
};
onpopstate = (event) => {
if (event.state && event.state.path) {
let path = event.state.path;
if (Utils.isMarkdownFile(path)) {
this.showFile(path);
} else {
this.loadDirentList(path);
this.setState({
path: path,
isViewFile: false
});
}
}
};
onSearchedClick = (item) => {
let path = item.is_dir ? item.path.slice(0, item.path.length - 1) : item.path;
if (this.state.currentPath === path) {
return;
}
// load sidePanel
let index = -1;
let paths = Utils.getPaths(path);
for (let i = 0; i < paths.length; i++) {
// eslint-disable-next-line no-use-before-define
let node = this.state.treeData.getNodeByPath(node);
if (!node) {
index = i;
break;
}
}
if (index === -1) { // all the data has been loaded already.
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(item.path);
treeHelper.expandNode(node);
this.setState({ treeData: tree });
} else {
this.loadNodeAndParentsByPath(path);
}
// load mainPanel
if (item.is_dir) {
this.showDir(path);
} else {
if (Utils.isMarkdownFile(path)) {
this.showFile(path);
} else {
let url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(path);
let newWindow = window.open('about:blank');
newWindow.location.href = url;
}
}
};
onMenuClick = () => {
this.setState({ closeSideBar: !this.state.closeSideBar });
};
onMainNavBarClick = (nodePath) => {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(nodePath);
tree.expandNode(node);
this.setState({ treeData: tree, currentNode: node });
this.showDir(node.path);
};
onDirentClick = (dirent) => {
let direntPath = Utils.joinPath(this.state.path, dirent.name);
if (dirent.isDir()) { // is dir
this.loadTreeNodeByPath(direntPath);
this.showDir(direntPath);
} else { // is file
if (Utils.isMarkdownFile(direntPath)) {
this.showFile(direntPath);
} else {
const w = window.open('about:blank');
const url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(direntPath);
w.location.href = url;
}
}
};
onCloseSide = () => { onCloseSide = () => {
this.setState({ closeSideBar: !this.state.closeSideBar }); this.setState({ closeSideBar: !this.state.closeSideBar });
}; };
onNodeClick = (node) => {
if (!this.state.pathExist) {
this.setState({ pathExist: true });
}
if (node.object.isDir()) {
if (!node.isLoaded) {
let tree = this.state.treeData.clone();
node = tree.getNodeByPath(node.path);
wikiAPI.listWiki2Dir(wikiId, node.path).then(res => {
this.addResponseListToNode(res.data.dirent_list, node);
tree.collapseNode(node);
this.setState({ treeData: tree });
});
}
if (node.path === this.state.path) {
if (node.isExpanded) {
let tree = treeHelper.collapseNode(this.state.treeData, node);
this.setState({ treeData: tree });
} else {
let tree = this.state.treeData.clone();
node = tree.getNodeByPath(node.path);
tree.expandNode(node);
this.setState({ treeData: tree });
}
}
}
if (node.path === this.state.path) {
return;
}
if (node.object.isDir()) { // isDir
this.showDir(node.path);
} else {
if (Utils.isMarkdownFile(node.path) || Utils.isSdocFile(node.path)) {
if (node.path !== this.state.path) {
this.showFile(node.path);
}
this.onCloseSide();
} else {
const w = window.open('about:blank');
const url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(node.path);
w.location.href = url;
}
}
};
onNodeCollapse = (node) => {
let tree = treeHelper.collapseNode(this.state.treeData, node);
this.setState({ treeData: tree });
};
onNodeExpanded = (node) => {
let tree = this.state.treeData.clone();
node = tree.getNodeByPath(node.path);
if (!node.isLoaded) {
wikiAPI.listWiki2Dir(wikiId, node.path).then(res => {
this.addResponseListToNode(res.data.dirent_list, node);
this.setState({ treeData: tree });
});
} else {
tree.expandNode(node);
this.setState({ treeData: tree });
}
};
addFirstResponseListToNode = (list, node) => {
node.isLoaded = true;
node.isExpanded = true;
let direntList = list.map(item => {
return new Dirent(item);
});
direntList = direntList.filter(item => {
if (item.type === 'dir') {
let name = item.name.toLowerCase();
return name !== 'drafts' && name !== 'images' && name !== 'downloads';
}
return true;
});
direntList = Utils.sortDirents(direntList, 'name', 'asc');
let nodeList = direntList.map(object => {
return new TreeNode({ object });
});
node.addChildren(nodeList);
};
addResponseListToNode = (list, node) => {
node.isLoaded = true;
node.isExpanded = true;
let direntList = list.map(item => {
return new Dirent(item);
});
direntList = Utils.sortDirents(direntList, 'name', 'asc');
let nodeList = direntList.map(object => {
return new TreeNode({ object });
});
node.addChildren(nodeList);
};
showPage = (pageId, filePath) => { showPage = (pageId, filePath) => {
this.setState({ this.setState({
isDataLoading: true, isDataLoading: true,
@@ -565,11 +141,9 @@ class Wiki extends Component {
this.removePythonWrapper(); this.removePythonWrapper();
wikiAPI.getWiki2Page(wikiId, pageId).then(res => { wikiAPI.getWiki2Page(wikiId, pageId).then(res => {
const { permission, last_modified, latest_contributor, seadoc_access_token, assets_url } = res.data; const { permission, seadoc_access_token, assets_url } = res.data;
this.setState({ this.setState({
permission, permission,
lastModified: moment.unix(last_modified).fromNow(),
latestContributor: latest_contributor,
seadoc_access_token, seadoc_access_token,
assets_url, assets_url,
isViewFile: true, isViewFile: true,
@@ -597,16 +171,10 @@ class Wiki extends Component {
const { pages } = config; const { pages } = config;
const currentPage = PageUtils.getPageById(pages, pageId); const currentPage = PageUtils.getPageById(pages, pageId);
const path = currentPage.path; const path = currentPage.path;
if (Utils.isMarkdownFile(path) || Utils.isSdocFile(path)) { if (path !== this.state.path) {
if (path !== this.state.path) { this.showPage(pageId, path);
this.showPage(pageId, path);
}
this.onCloseSide();
} else {
const w = window.open('about:blank');
const url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(path);
w.location.href = url;
} }
this.onCloseSide();
this.setState({ this.setState({
currentPageId: pageId, currentPageId: pageId,
path: path, path: path,
@@ -618,25 +186,10 @@ class Wiki extends Component {
render() { render() {
return ( return (
<div id="main" className="wiki-main"> <div id="main" className="wiki-main">
{/* {isWiki2 &&
<WikiLeftBar
config={this.state.config}
repoId={this.state.repoId}
updateConfig={(data) => this.saveWikiConfig(Object.assign({}, this.state.config, data))}
/>
} */}
<SidePanel <SidePanel
isLoading={this.state.isTreeDataLoading || this.state.isConfigLoading} isLoading={this.state.isConfigLoading}
closeSideBar={this.state.closeSideBar} closeSideBar={this.state.closeSideBar}
currentPath={this.state.path}
treeData={this.state.treeData}
indexNode={this.state.indexNode}
indexContent={this.state.indexContent}
onCloseSide={this.onCloseSide} onCloseSide={this.onCloseSide}
onNodeClick={this.onNodeClick}
onNodeCollapse={this.onNodeCollapse}
onNodeExpanded={this.onNodeExpanded}
onLinkClick={this.onLinkClick}
config={this.state.config} config={this.state.config}
saveWikiConfig={this.saveWikiConfig} saveWikiConfig={this.saveWikiConfig}
setCurrentPage={this.setCurrentPage} setCurrentPage={this.setCurrentPage}
@@ -651,12 +204,6 @@ class Wiki extends Component {
isDataLoading={this.state.isDataLoading} isDataLoading={this.state.isDataLoading}
editorContent={this.state.editorContent} editorContent={this.state.editorContent}
permission={this.state.permission} permission={this.state.permission}
lastModified={this.state.lastModified}
latestContributor={this.state.latestContributor}
onLinkClick={this.onLinkClick}
onMenuClick={this.onMenuClick}
onSearchedClick={this.onSearchedClick}
onMainNavBarClick={this.onMainNavBarClick}
seadoc_access_token={this.state.seadoc_access_token} seadoc_access_token={this.state.seadoc_access_token}
assets_url={this.state.assets_url} assets_url={this.state.assets_url}
/> />

View File

@@ -1,7 +1,7 @@
import React, { Component, Fragment } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { SdocWikiViewer } from '@seafile/sdoc-editor'; import { SdocWikiViewer } from '@seafile/sdoc-editor';
import { gettext, repoID, siteRoot, username } from '../../utils/constants'; import { gettext, username } from '../../utils/constants';
import Loading from '../../components/loading'; import Loading from '../../components/loading';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import Account from '../../components/common/account'; import Account from '../../components/common/account';
@@ -14,12 +14,6 @@ const propTypes = {
isDataLoading: PropTypes.bool.isRequired, isDataLoading: PropTypes.bool.isRequired,
editorContent: PropTypes.object, editorContent: PropTypes.object,
permission: PropTypes.string, permission: PropTypes.string,
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
onMenuClick: PropTypes.func.isRequired,
onSearchedClick: PropTypes.func.isRequired,
onMainNavBarClick: PropTypes.func.isRequired,
onLinkClick: PropTypes.func.isRequired,
seadoc_access_token: PropTypes.string, seadoc_access_token: PropTypes.string,
assets_url: PropTypes.string, assets_url: PropTypes.string,
config: PropTypes.object, config: PropTypes.object,
@@ -30,59 +24,11 @@ class MainPanel extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
docUuid: '', docUuid: '',
}; };
} }
onMenuClick = () => {
this.props.onMenuClick();
};
onEditClick = (e) => {
e.preventDefault();
let url = siteRoot + 'lib/' + repoID + '/file' + this.props.path + '?mode=edit';
window.open(url);
};
onMainNavBarClick = (e) => {
let path = Utils.getEventData(e, 'path');
this.props.onMainNavBarClick(path);
};
renderNavPath = () => {
let paths = this.props.path.split('/');
let nodePath = '';
let pathElem = paths.map((item, index) => {
if (item === '') {
return null;
}
if (index === (paths.length - 1)) {
return (
<Fragment key={index}>
<span className="path-split">/</span>
<span className="path-file-name">{item}</span>
</Fragment>
);
} else {
nodePath += '/' + item;
return (
<Fragment key={index} >
<span className="path-split">/</span>
<a
className="path-link"
data-path={nodePath}
onClick={this.onMainNavBarClick}>
{item}
</a>
</Fragment>
);
}
});
return pathElem;
};
static getDerivedStateFromProps(props, state) { static getDerivedStateFromProps(props, state) {
const { seadoc_access_token } = props; const { seadoc_access_token } = props;
const config = window.app.config; const config = window.app.config;
@@ -102,7 +48,6 @@ class MainPanel extends Component {
} }
render() { render() {
const errMessage = (<div className="message err-tip">{gettext('Folder does not exist.')}</div>);
const { permission, pathExist, isDataLoading, isViewFile } = this.props; const { permission, pathExist, isDataLoading, isViewFile } = this.props;
const isViewingFile = pathExist && !isDataLoading && isViewFile; const isViewingFile = pathExist && !isDataLoading && isViewFile;
const isReadOnly = !(permission === 'rw'); const isReadOnly = !(permission === 'rw');
@@ -119,7 +64,9 @@ class MainPanel extends Component {
</div> </div>
<div className="main-panel-center"> <div className="main-panel-center">
<div className={`cur-view-content ${isViewingFile ? 'o-hidden' : ''}`}> <div className={`cur-view-content ${isViewingFile ? 'o-hidden' : ''}`}>
{!this.props.pathExist && errMessage} {!this.props.pathExist &&
<div className="message err-tip">{gettext('Folder does not exist.')}</div>
}
{this.props.pathExist && this.props.isDataLoading && <Loading />} {this.props.pathExist && this.props.isDataLoading && <Loading />}
{isViewingFile && Utils.isSdocFile(this.props.path) && ( {isViewingFile && Utils.isSdocFile(this.props.path) && (
<SdocWikiViewer <SdocWikiViewer

View File

@@ -4,9 +4,7 @@ import deepCopy from 'deep-copy';
import { gettext, isWiki2, wikiId } from '../../utils/constants'; import { gettext, isWiki2, wikiId } from '../../utils/constants';
import toaster from '../../components/toast'; import toaster from '../../components/toast';
import Loading from '../../components/loading'; import Loading from '../../components/loading';
// import TreeView from '../../components/tree-view/tree-view';
import ViewStructure from './view-structure'; import ViewStructure from './view-structure';
import IndexMdViewer from './index-md-viewer';
import PageUtils from './view-structure/page-utils'; import PageUtils from './view-structure/page-utils';
import NewFolderDialog from './view-structure/new-folder-dialog'; import NewFolderDialog from './view-structure/new-folder-dialog';
import AddNewPageDialog from './view-structure/add-new-page-dialog'; import AddNewPageDialog from './view-structure/add-new-page-dialog';
@@ -24,15 +22,6 @@ const { repoName } = window.wiki.config;
const propTypes = { const propTypes = {
closeSideBar: PropTypes.bool.isRequired, closeSideBar: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired,
treeData: PropTypes.object.isRequired,
indexNode: PropTypes.object,
indexContent: PropTypes.string.isRequired,
currentPath: PropTypes.string.isRequired,
onCloseSide: PropTypes.func.isRequired,
onNodeClick: PropTypes.func.isRequired,
onNodeCollapse: PropTypes.func.isRequired,
onNodeExpanded: PropTypes.func.isRequired,
onLinkClick: PropTypes.func.isRequired,
config: PropTypes.object.isRequired, config: PropTypes.object.isRequired,
saveWikiConfig: PropTypes.func.isRequired, saveWikiConfig: PropTypes.func.isRequired,
setCurrentPage: PropTypes.func.isRequired, setCurrentPage: PropTypes.func.isRequired,
@@ -43,60 +32,12 @@ class SidePanel extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.isNodeMenuShow = false;
this.state = { this.state = {
isShowNewFolderDialog: false, isShowNewFolderDialog: false,
isShowAddNewPageDialog: false, isShowAddNewPageDialog: false,
}; };
} }
renderIndexView = () => {
return (
<div className="wiki2-pages-container">
<div style={{ marginTop: '2px' }}></div>
<IndexMdViewer
indexContent={this.props.indexContent}
onLinkClick={this.props.onLinkClick}
/>
</div>
);
};
renderTreeView = () => {
return (
<div className="wiki2-pages-container">
{/* {this.props.treeData && (
<TreeView
treeData={this.props.treeData}
currentPath={this.props.currentPath}
isNodeMenuShow={this.isNodeMenuShow}
onNodeClick={this.props.onNodeClick}
onNodeCollapse={this.props.onNodeCollapse}
onNodeExpanded={this.props.onNodeExpanded}
/>
)} */}
{isWiki2 &&
<ViewStructureFooter
onToggleAddView={this.openAddPageDialog}
onToggleAddFolder={this.onToggleAddFolder}
/>
}
{this.state.isShowNewFolderDialog &&
<NewFolderDialog
onAddFolder={this.addPageFolder}
onToggleAddFolderDialog={this.onToggleAddFolder}
/>
}
{this.state.isShowAddNewPageDialog &&
<AddNewPageDialog
toggle={this.closeAddNewPageDialog}
onAddNewPage={this.onAddNewPage}
/>
}
</div>
);
};
confirmDeletePage = (pageId) => { confirmDeletePage = (pageId) => {
const config = deepCopy(this.props.config); const config = deepCopy(this.props.config);
const { pages, navigation } = config; const { pages, navigation } = config;
@@ -373,28 +314,40 @@ class SidePanel extends Component {
); );
}; };
renderContent = () => { renderNoFolder = () => {
const { isLoading, indexNode, config } = this.props; return (
if (isLoading) { <div className="wiki2-pages-container">
return <Loading />; {isWiki2 &&
} <ViewStructureFooter
if (indexNode) { onToggleAddView={this.openAddPageDialog}
return this.renderIndexView(); onToggleAddFolder={this.onToggleAddFolder}
} />
if (isObjectNotEmpty(config)) { }
return this.renderFolderView(); {this.state.isShowNewFolderDialog &&
} <NewFolderDialog
return this.renderTreeView(); onAddFolder={this.addPageFolder}
onToggleAddFolderDialog={this.onToggleAddFolder}
/>
}
{this.state.isShowAddNewPageDialog &&
<AddNewPageDialog
toggle={this.closeAddNewPageDialog}
onAddNewPage={this.onAddNewPage}
/>
}
</div>
);
}; };
render() { render() {
const { isLoading, config } = this.props;
return ( return (
<div className={`wiki2-side-panel${this.props.closeSideBar ? '' : ' left-zero'}`}> <div className={`wiki2-side-panel${this.props.closeSideBar ? '' : ' left-zero'}`}>
<div className="wiki2-side-panel-top"> <div className="wiki2-side-panel-top">
<h4 className="text-truncate ml-0 mb-0" title={repoName}>{repoName}</h4> <h4 className="text-truncate ml-0 mb-0" title={repoName}>{repoName}</h4>
</div> </div>
<div className="wiki2-side-nav"> <div className="wiki2-side-nav">
{this.renderContent()} {isLoading ? <Loading /> : (isObjectNotEmpty(config) ? this.renderFolderView() : this.renderNoFolder())}
</div> </div>
</div> </div>
); );

View File

@@ -106,24 +106,6 @@ class WikiAPI {
// for wiki2 // for wiki2
listWiki2Dir(wikiId, dirPath, withParents) {
const path = encodeURIComponent(dirPath);
let url = this.server + '/api/v2.1/wiki2/' + wikiId + '/page-dir/?p=' + path;
if (withParents) {
url = this.server + '/api/v2.1/wiki2/' + wikiId + '/page-dir/?p=' + path + '&with_parents=' + withParents;
}
return this.req.get(url);
}
getWiki2FileContent(wikiId, filePath) {
const path = encodeURIComponent(filePath);
const time = new Date().getTime();
const url = this.server + '/api/v2.1/wiki2/' + wikiId + '/content/' + '?p=' + path + '&_=' + time;
return this.req.get(url);
}
listWikis2(options) { listWikis2(options) {
/* /*
* options: `{type: 'shared'}`, `{type: ['mine', 'shared', ...]}` * options: `{type: 'shared'}`, `{type: ['mine', 'shared', ...]}`