mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-10 03:11:07 +00:00
Wiki publish (#6512)
* add wiki publish publish wiki permission optimize code * optimize code * optimize code * update * Update wiki2.py * Update wiki2.py * Update urls.py * Update wiki_publish.html --------- Co-authored-by: 孙永强 <11704063+s-yongqiang@user.noreply.gitee.com> Co-authored-by: r350178982 <32759763+r350178982@users.noreply.github.com>
This commit is contained in:
126
frontend/src/components/dialog/publish-wiki-dialog.js
Normal file
126
frontend/src/components/dialog/publish-wiki-dialog.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import copy from 'copy-to-clipboard';
|
||||
import { gettext, serviceURL } from '../../utils/constants';
|
||||
import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Alert, InputGroup, InputGroupAddon } from 'reactstrap';
|
||||
import toaster from '../toast';
|
||||
import wikiAPI from '../../utils/wiki-api';
|
||||
|
||||
const propTypes = {
|
||||
wiki: PropTypes.object,
|
||||
onPublish: PropTypes.func.isRequired,
|
||||
toggleCancel: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class PublishWikiDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
url: serviceURL + '/wiki/publish/' + this.props.customUrl,
|
||||
errMessage: '',
|
||||
isSubmitBtnActive: false,
|
||||
};
|
||||
this.newInput = React.createRef();
|
||||
}
|
||||
|
||||
handleChange = (e) => {
|
||||
this.setState({
|
||||
isSubmitBtnActive: !!e.target.value.trim(),
|
||||
url: e.target.value
|
||||
});
|
||||
};
|
||||
|
||||
handleSubmit = () => {
|
||||
let { isValid, errMessage } = this.validateInput();
|
||||
if (!isValid) {
|
||||
this.setState({
|
||||
errMessage: errMessage,
|
||||
url: serviceURL + '/wiki/publish/',
|
||||
});
|
||||
} else {
|
||||
this.props.onPublish(this.state.url.trim());
|
||||
}
|
||||
};
|
||||
|
||||
deleteCustomUrl = () => {
|
||||
let wiki_id = this.props.wiki.id;
|
||||
wikiAPI.deletePublishWikiLink(wiki_id).then((res) => {
|
||||
this.setState({ url: serviceURL + '/wiki/publish/' });
|
||||
toaster.success(gettext('Successfully.'));
|
||||
}).catch((error) => {
|
||||
if (error.response) {
|
||||
let errorMsg = error.response.data.error_msg;
|
||||
toaster.danger(errorMsg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
handleKeyDown = (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
this.handleSubmit();
|
||||
}
|
||||
};
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggleCancel();
|
||||
};
|
||||
|
||||
validateInput = () => {
|
||||
let url = this.state.url.trim();
|
||||
let isValid = true;
|
||||
let errMessage = '';
|
||||
if (!url) {
|
||||
isValid = false;
|
||||
errMessage = gettext('url is required.');
|
||||
return { isValid, errMessage };
|
||||
}
|
||||
if (!(url.includes(serviceURL + '/wiki/publish/'))) {
|
||||
isValid = false;
|
||||
errMessage = gettext('url need include specific prefix.');
|
||||
return { isValid, errMessage };
|
||||
}
|
||||
return { isValid, errMessage };
|
||||
};
|
||||
|
||||
copyLink = () => {
|
||||
copy(this.state.url);
|
||||
toaster.success(gettext('URL is copied to the clipboard'));
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} toggle={this.toggle}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Publish Wiki')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<p>{gettext('Customize URL')}</p>
|
||||
<InputGroup>
|
||||
<Input
|
||||
onKeyDown={this.handleKeyDown}
|
||||
innerRef={this.newInput}
|
||||
placeholder="customize url"
|
||||
value={this.state.url}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
<InputGroupAddon addonType="append">
|
||||
<Button color="primary" onClick={this.copyLink} className="border-0">{gettext('Copy')}</Button>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
<span className='tip mb-1' style={{ fontSize: '14px' }}>
|
||||
{gettext('The custom part of the URL must be between 5 and 30 characters long and may only contain letters (a-z), numbers, and hyphens.')}
|
||||
</span>
|
||||
{this.state.errMessage && <Alert color="danger" className="mt-2">{this.state.errMessage}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.deleteCustomUrl} disabled={this.props.customUrl === ''}>{gettext('Delete')}</Button>
|
||||
<Button color="primary" onClick={this.handleSubmit} disabled={!this.state.isSubmitBtnActive}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PublishWikiDialog.propTypes = propTypes;
|
||||
|
||||
export default PublishWikiDialog;
|
@@ -7,6 +7,9 @@ import ModalPortal from '../modal-portal';
|
||||
import DeleteWikiDialog from '../dialog/delete-wiki-dialog';
|
||||
import RenameWikiDialog from '../dialog/rename-wiki-dialog';
|
||||
import ShareWikiDialog from '../dialog/share-wiki-dialog';
|
||||
import PublishWikiDialog from '../dialog/publish-wiki-dialog';
|
||||
import wikiAPI from '../../utils/wiki-api';
|
||||
import toaster from '../toast';
|
||||
|
||||
const propTypes = {
|
||||
wiki: PropTypes.object.isRequired,
|
||||
@@ -26,6 +29,8 @@ class WikiCardItem extends Component {
|
||||
isShowRenameDialog: false,
|
||||
isItemMenuShow: false,
|
||||
isShowShareDialog: false,
|
||||
isShowPublishDialog: false,
|
||||
customUrl: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,6 +53,10 @@ class WikiCardItem extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
onPublishToggle = (e) => {
|
||||
this.getPublishWikiLink();
|
||||
};
|
||||
|
||||
onDeleteCancel = () => {
|
||||
this.setState({
|
||||
isShowDeleteDialog: !this.state.isShowDeleteDialog,
|
||||
@@ -77,6 +86,39 @@ class WikiCardItem extends Component {
|
||||
this.setState({ isShowRenameDialog: false });
|
||||
};
|
||||
|
||||
publishWiki = (url) => {
|
||||
const urlIndex = url.indexOf('/publish/');
|
||||
const publish_url = url.substring(urlIndex + '/publish/'.length);
|
||||
wikiAPI.publishWiki(this.props.wiki.id, publish_url).then((res) => {
|
||||
const { publish_url } = res.data;
|
||||
this.setState({ customUrl: publish_url });
|
||||
toaster.success(gettext('Successfully.'));
|
||||
}).catch((error) => {
|
||||
if (error.response) {
|
||||
let errorMsg = error.response.data.error_msg;
|
||||
toaster.danger(errorMsg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
getPublishWikiLink = () => {
|
||||
wikiAPI.getPublishWikiLink(this.props.wiki.id).then((res) => {
|
||||
const { publish_url } = res.data;
|
||||
this.setState({
|
||||
customUrl: publish_url,
|
||||
isShowPublishDialog: !this.state.isShowPublishDialog,
|
||||
});
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
isShowPublishDialog: !this.state.isShowPublishDialog,
|
||||
});
|
||||
if (error.response) {
|
||||
let errorMsg = error.response.data.error_msg;
|
||||
toaster.danger(errorMsg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
clickWikiCard = (link) => {
|
||||
window.open(link);
|
||||
};
|
||||
@@ -130,6 +172,7 @@ class WikiCardItem extends Component {
|
||||
let showDelete = false;
|
||||
let showLeaveShare = false;
|
||||
let showDropdownMenu = false;
|
||||
let showPublish = false;
|
||||
|
||||
if (isDepartment) {
|
||||
if (isAdmin) {
|
||||
@@ -137,6 +180,7 @@ class WikiCardItem extends Component {
|
||||
showDelete = true;
|
||||
showShare = true;
|
||||
showRename = true;
|
||||
showPublish = true;
|
||||
} else {
|
||||
showLeaveShare = true;
|
||||
}
|
||||
@@ -146,6 +190,7 @@ class WikiCardItem extends Component {
|
||||
showShare = true;
|
||||
showDelete = true;
|
||||
showRename = true;
|
||||
showPublish = true;
|
||||
} else {
|
||||
showLeaveShare = true;
|
||||
}
|
||||
@@ -180,6 +225,8 @@ class WikiCardItem extends Component {
|
||||
<DropdownMenu right={true} className="dtable-dropdown-menu">
|
||||
{showRename &&
|
||||
<DropdownItem onClick={this.onRenameToggle}>{gettext('Rename')}</DropdownItem>}
|
||||
{showPublish &&
|
||||
<DropdownItem onClick={this.onPublishToggle}>{gettext('Publish')}</DropdownItem>}
|
||||
{showShare &&
|
||||
<DropdownItem onClick={this.onShareToggle}>{gettext('Share')}</DropdownItem>
|
||||
}
|
||||
@@ -200,7 +247,12 @@ class WikiCardItem extends Component {
|
||||
<div className="wiki-item-owner">
|
||||
{isShowAvatar && (isDepartment ? this.renderDept() : this.renderAvatar())}
|
||||
</div>
|
||||
<div className="wiki-item-updated-time">{moment(wiki.updated_at).fromNow()}</div>
|
||||
<div className="wiki-item-updated-time">
|
||||
{moment(wiki.updated_at).fromNow()}
|
||||
{wiki.is_published &&
|
||||
<span style={{ marginLeft: '25%' }}>published</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
{this.state.isShowDeleteDialog &&
|
||||
<ModalPortal>
|
||||
@@ -264,6 +316,16 @@ class WikiCardItem extends Component {
|
||||
/>
|
||||
</ModalPortal>
|
||||
}
|
||||
{this.state.isShowPublishDialog &&
|
||||
<ModalPortal>
|
||||
<PublishWikiDialog
|
||||
toggleCancel={this.onPublishToggle}
|
||||
onPublish={this.publishWiki}
|
||||
wiki={wiki}
|
||||
customUrl={this.state.customUrl}
|
||||
/>
|
||||
</ModalPortal>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user