mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-23 12:27:48 +00:00
12.0 change add existing file in wiki edit (#6057)
* 12.0 change add existing file in wiki edit * 01 delete create wiki from existing library * 02 change click wiki name jump to edit page and delete edit icon * 03 delete select existing file to create new page * optimize edit wiki * 04 old wiki page use the early version 11.x features * optimize wiki permission * wiki add wiki2 * delete page file * fix wiki test --------- Co-authored-by: ‘JoinTyang’ <yangtong1009@163.com>
This commit is contained in:
@@ -1,34 +1,27 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input } from 'reactstrap';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label } from 'reactstrap';
|
||||
|
||||
const propTypes = {
|
||||
toggleCancel: PropTypes.func.isRequired,
|
||||
addWiki: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class NewWikiDialog extends React.Component {
|
||||
class AddWikiDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isExist: false,
|
||||
name: '',
|
||||
repoID: '',
|
||||
isSubmitBtnActive: false,
|
||||
};
|
||||
}
|
||||
|
||||
inputNewName = (e) => {
|
||||
if (!event.target.value.trim()) {
|
||||
this.setState({isSubmitBtnActive: false});
|
||||
} else {
|
||||
this.setState({isSubmitBtnActive: true});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
name: e.target.value,
|
||||
isSubmitBtnActive: !!e.target.value.trim(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -39,8 +32,9 @@ class NewWikiDialog extends React.Component {
|
||||
};
|
||||
|
||||
handleSubmit = () => {
|
||||
let { isExist, name, repoID } = this.state;
|
||||
this.props.addWiki(isExist, name, repoID);
|
||||
const wikiName = this.state.name.trim();
|
||||
if (!wikiName) return;
|
||||
this.props.addWiki(wikiName);
|
||||
this.props.toggleCancel();
|
||||
};
|
||||
|
||||
@@ -51,9 +45,9 @@ class NewWikiDialog extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} autoFocus={false} toggle={this.toggle}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('New Wiki')}</ModalHeader>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Add Wiki')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<label className="form-label">{gettext('Name')}</label>
|
||||
<Label>{gettext('Name')}</Label>
|
||||
<Input onKeyDown={this.handleKeyDown} autoFocus={true} value={this.state.name} onChange={this.inputNewName}/>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
@@ -65,6 +59,6 @@ class NewWikiDialog extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
NewWikiDialog.propTypes = propTypes;
|
||||
AddWikiDialog.propTypes = propTypes;
|
||||
|
||||
export default NewWikiDialog;
|
||||
export default AddWikiDialog;
|
@@ -1,110 +0,0 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import moment from 'moment';
|
||||
import Repo from '../../models/repo';
|
||||
import { Utils } from '../../utils/utils';
|
||||
|
||||
const propTypes = {
|
||||
toggleCancel: PropTypes.func.isRequired,
|
||||
addWiki: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
class WikiSelectDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
repos: [],
|
||||
repoID: '',
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
seafileAPI.listRepos().then(res => {
|
||||
let repoList = res.data.repos
|
||||
.filter(item => {
|
||||
switch (item.type) {
|
||||
case 'mine': // my libraries
|
||||
return !item.encrypted;
|
||||
case 'shared': // libraries shared with me
|
||||
// 'is_admin': the library is shared with 'admin' permission
|
||||
return !item.encrypted && item.is_admin;
|
||||
case 'group':
|
||||
default:
|
||||
return !item.encrypted && !res.data.repos.some(repo => {
|
||||
// just remove the duplicated libraries
|
||||
return repo.type != item.type && repo.repo_id == item.repo_id;
|
||||
});
|
||||
}
|
||||
})
|
||||
.map(item => {
|
||||
let repo = new Repo(item);
|
||||
return repo;
|
||||
});
|
||||
repoList = Utils.sortRepos(repoList, 'name', 'asc');
|
||||
this.setState({repos: repoList});
|
||||
});
|
||||
}
|
||||
|
||||
onChange = (repo) => {
|
||||
this.setState({
|
||||
repoID: repo.repo_id,
|
||||
});
|
||||
};
|
||||
|
||||
handleSubmit = () => {
|
||||
let { repoID } = this.state;
|
||||
this.props.addWiki(repoID);
|
||||
this.props.toggleCancel();
|
||||
};
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggleCancel();
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} toggle={this.toggle}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Create Wiki from existing library')}</ModalHeader>
|
||||
<ModalBody className="dialog-list-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th width='6%'>{/* select */}</th>
|
||||
<th width='9%'>{/* icon */}</th>
|
||||
<th width='55%'>{gettext('Name')}</th>
|
||||
<th width='30%'>{gettext('Last Update')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{this.state.repos.map((repo, index) => {
|
||||
return (
|
||||
<tr key={index}>
|
||||
<td className="text-center"><input type="radio" className="vam" name="repo" value={repo.repo_id} onChange={this.onChange.bind(this, repo)} /></td>
|
||||
<td className="text-center"><img src={Utils.getLibIconUrl(repo, false)} width="24" title={Utils.getLibIconTitle(repo)} alt={Utils.getLibIconTitle(repo)} /></td>
|
||||
<td>{repo.repo_name}</td>
|
||||
<td>{moment(repo.last_modified).fromNow()}</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
{this.state.repoID ?
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>:
|
||||
<Button color="primary" disabled>{gettext('Submit')}</Button>
|
||||
}
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
WikiSelectDialog.propTypes = propTypes;
|
||||
|
||||
export default WikiSelectDialog;
|
@@ -2,17 +2,13 @@ import React, { Component } from 'react';
|
||||
import { Dropdown, DropdownToggle, DropdownItem } from 'reactstrap';
|
||||
import PropTypes from 'prop-types';
|
||||
import moment from 'moment';
|
||||
import { siteRoot, gettext, username } from '../../utils/constants';
|
||||
import { siteRoot, gettext } from '../../utils/constants';
|
||||
import { Utils } from '../../utils/utils';
|
||||
// import { seafileAPI } from '../../utils/seafile-api';
|
||||
// import Toast from '../toast';
|
||||
import ModalPortal from '../modal-portal';
|
||||
import WikiDeleteDialog from '../dialog/wiki-delete-dialog';
|
||||
// import Rename from '../rename';
|
||||
|
||||
const propTypes = {
|
||||
wiki: PropTypes.object.isRequired,
|
||||
// renameWiki: PropTypes.func.isRequired,
|
||||
deleteWiki: PropTypes.func.isRequired,
|
||||
isItemFreezed: PropTypes.bool.isRequired,
|
||||
onFreezedItem: PropTypes.func.isRequired,
|
||||
@@ -25,9 +21,7 @@ class WikiListItem extends Component {
|
||||
this.state = {
|
||||
isOpMenuOpen: false, // for mobile
|
||||
isShowDeleteDialog: false,
|
||||
// isRenameing: false,
|
||||
highlight: false,
|
||||
// permission: this.props.wiki.permission,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,30 +31,6 @@ class WikiListItem extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
// clickMenuToggle = (e) => {
|
||||
// e.preventDefault();
|
||||
// this.onMenuToggle(e);
|
||||
// }
|
||||
|
||||
// onMenuToggle = (e) => {
|
||||
// let targetType = e.target.dataset.toggle;
|
||||
// if (targetType !== 'item') {
|
||||
// if (this.props.isItemFreezed) {
|
||||
// this.setState({
|
||||
// highlight: false,
|
||||
// isShowMenuControl: false,
|
||||
// isShowWikiMenu: !this.state.isShowWikiMenu
|
||||
// });
|
||||
// this.props.onUnfreezedItem();
|
||||
// } else {
|
||||
// this.setState({
|
||||
// isShowWikiMenu: !this.state.isShowWikiMenu
|
||||
// });
|
||||
// this.props.onFreezedItem();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
onMouseEnter = () => {
|
||||
if (!this.props.isItemFreezed) {
|
||||
this.setState({ highlight: true });
|
||||
@@ -73,37 +43,6 @@ class WikiListItem extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
// changePerm = (permission) => {
|
||||
// let wiki = this.props.wiki;
|
||||
// seafileAPI.updateWikiPermission(wiki.slug, permission).then(() => {
|
||||
// this.setState({permission: permission});
|
||||
// }).catch((error) => {
|
||||
// if(error.response) {
|
||||
// let errorMsg = error.response.data.error_msg;
|
||||
// Toast.danger(errorMsg);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// onRenameToggle = (e) => {
|
||||
// this.props.onFreezedItem();
|
||||
// this.setState({
|
||||
// isShowWikiMenu: false,
|
||||
// isShowMenuControl: false,
|
||||
// isRenameing: true,
|
||||
// });
|
||||
// }
|
||||
|
||||
// onRenameConfirm = (newName) => {
|
||||
// this.renameWiki(newName);
|
||||
// this.onRenameCancel();
|
||||
// }
|
||||
|
||||
// onRenameCancel = () => {
|
||||
// this.props.onUnfreezedItem();
|
||||
// this.setState({isRenameing: false});
|
||||
// }
|
||||
|
||||
onDeleteToggle = (e) => {
|
||||
e.preventDefault();
|
||||
this.props.onUnfreezedItem();
|
||||
@@ -119,11 +58,6 @@ class WikiListItem extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
// renameWiki = (newName) => {
|
||||
// let wiki = this.props.wiki;
|
||||
// this.props.renameWiki(wiki, newName);
|
||||
// }
|
||||
|
||||
deleteWiki = () => {
|
||||
let wiki = this.props.wiki;
|
||||
this.props.deleteWiki(wiki);
|
||||
@@ -136,7 +70,9 @@ class WikiListItem extends Component {
|
||||
let wiki = this.props.wiki;
|
||||
let userProfileURL = `${siteRoot}profile/${encodeURIComponent(wiki.owner)}/`;
|
||||
let fileIconUrl = Utils.getDefaultLibIconUrl(false);
|
||||
const isWikiOwner = wiki.owner === username;
|
||||
let isOldVersion = wiki.version !== 'v2';
|
||||
let publishedUrl = `${siteRoot}published/${encodeURIComponent(wiki.slug)}/`;
|
||||
let editUrl = `${siteRoot}edit-wiki/${wiki.id}/`;
|
||||
|
||||
const desktopItem = (
|
||||
<tr
|
||||
@@ -147,24 +83,12 @@ class WikiListItem extends Component {
|
||||
>
|
||||
<td><img src={fileIconUrl} width="24" alt="" /></td>
|
||||
<td className="name">
|
||||
<a href={wiki.link}>{wiki.name}</a>
|
||||
{/*this.state.isRenameing ?
|
||||
<Rename wiki={wiki} name={wiki.name} onRenameConfirm={this.onRenameConfirm} onRenameCancel={this.onRenameCancel}/> :
|
||||
<a href={wiki.link}>{wiki.name}</a>
|
||||
*/}
|
||||
{isOldVersion && <a href={publishedUrl}>{wiki.name} (old version)</a>}
|
||||
{!isOldVersion && <a href={editUrl}>{wiki.name}</a>}
|
||||
</td>
|
||||
<td><a href={userProfileURL} target='_blank' rel="noreferrer">{wiki.owner_nickname}</a></td>
|
||||
<td>{moment(wiki.updated_at).fromNow()}</td>
|
||||
<td className="text-center cursor-pointer align-top">
|
||||
{isWikiOwner &&
|
||||
<span
|
||||
className={`iconfont icon-edit mr-4 action-icon ${this.state.highlight ? '' : 'invisible'}`}
|
||||
onClick={() => window.open(wiki.link.replace('/published/', '/edit-wiki/'))}
|
||||
title={gettext('Edit')}
|
||||
aria-label={gettext('Edit')}
|
||||
style={{color: '#999', fontSize: '20px'}}
|
||||
></span>
|
||||
}
|
||||
<a
|
||||
href="#"
|
||||
role="button"
|
||||
@@ -181,7 +105,8 @@ class WikiListItem extends Component {
|
||||
<tr>
|
||||
<td><img src={fileIconUrl} width="24" alt="" /></td>
|
||||
<td>
|
||||
<a href={wiki.link}>{wiki.name}</a><br />
|
||||
{isOldVersion && <a href={publishedUrl}>{wiki.name} (old version)</a>}
|
||||
{!isOldVersion && <a href={editUrl}>{wiki.name}</a>}<br />
|
||||
<a href={userProfileURL} target='_blank' className="item-meta-info" rel="noreferrer">{wiki.owner_nickname}</a>
|
||||
<span className="item-meta-info">{moment(wiki.updated_at).fromNow()}</span>
|
||||
</td>
|
||||
|
@@ -7,7 +7,6 @@ import LibsMobileThead from '../libs-mobile-thead';
|
||||
|
||||
const propTypes = {
|
||||
data: PropTypes.object.isRequired,
|
||||
renameWiki: PropTypes.func.isRequired,
|
||||
deleteWiki: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
@@ -57,7 +56,6 @@ class WikiListView extends Component {
|
||||
<WikiListItem
|
||||
key={index}
|
||||
wiki={wiki}
|
||||
renameWiki={this.props.renameWiki}
|
||||
deleteWiki={this.props.deleteWiki}
|
||||
isItemFreezed={this.state.isItemFreezed}
|
||||
onFreezedItem={this.onFreezedItem}
|
||||
|
Reference in New Issue
Block a user