1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-12 13:24:52 +00:00

fix draft button show logic

This commit is contained in:
LeoSirius
2019-06-05 13:57:25 +08:00
parent ed3084b51e
commit 7f28095fdc
2 changed files with 13 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ class Draft extends React.Component {
reviewers: [], reviewers: [],
inResizing: false, inResizing: false,
rightPartWidth: 30, rightPartWidth: 30,
freezePublish: false draftStatus: window.draft.config.draftStatus,
}; };
this.quote = ''; this.quote = '';
this.newIndex = null; this.newIndex = null;
@@ -410,7 +410,7 @@ class Draft extends React.Component {
onPublishDraft = () => { onPublishDraft = () => {
seafileAPI.publishDraft(draftID).then(res => { seafileAPI.publishDraft(draftID).then(res => {
this.setState({ this.setState({
freezePublish: !this.state.freezePublish draftStatus: res.data.draft_status,
}); });
}); });
} }
@@ -734,8 +734,9 @@ class Draft extends React.Component {
const { draftInfo, reviewers, originRepoName } = this.state; const { draftInfo, reviewers, originRepoName } = this.state;
const onResizeMove = this.state.inResizing ? this.onResizeMouseMove : null; const onResizeMove = this.state.inResizing ? this.onResizeMouseMove : null;
const draftLink = siteRoot + 'lib/' + draftRepoID + '/file' + draftFilePath + '?mode=edit'; const draftLink = siteRoot + 'lib/' + draftRepoID + '/file' + draftFilePath + '?mode=edit';
const freezePublish = (this.state.freezePublish || draftStatus === 'published') ? true : false; const showPublishedButton = this.state.draftStatus == 'published';
const canPublish = !this.state.freezePublish && draftFileExists && filePermission == 'rw'; const showPublishButton = this.state.draftStatus == 'open' && filePermission == 'rw';
const showEditButton = this.state.draftStatus == 'open' && filePermission == 'rw';
const time = moment(draftInfo.mtime * 1000).format('YYYY-MM-DD HH:mm'); const time = moment(draftInfo.mtime * 1000).format('YYYY-MM-DD HH:mm');
const url = `${siteRoot}profile/${encodeURIComponent(draftInfo.last_modifier_email)}/`; const url = `${siteRoot}profile/${encodeURIComponent(draftInfo.last_modifier_email)}/`;
return( return(
@@ -750,7 +751,7 @@ class Draft extends React.Component {
<span className="file-name">{draftFileName}</span> <span className="file-name">{draftFileName}</span>
<span className="mx-2 file-review">{gettext('Review')}</span> <span className="mx-2 file-review">{gettext('Review')}</span>
</div> </div>
{(!freezePublish && draftInfo.mtime) && {(!showPublishedButton && draftInfo.mtime) &&
<div className="last-modification"> <div className="last-modification">
<a href={url}>{draftInfo.last_modifier_name}</a><span className="mx-1">{time}</span> <a href={url}>{draftInfo.last_modifier_name}</a><span className="mx-1">{time}</span>
</div> </div>
@@ -759,17 +760,17 @@ class Draft extends React.Component {
</div> </div>
<div className="button-group"> <div className="button-group">
{this.renderDiffButton()} {this.renderDiffButton()}
{(draftFileExists && !freezePublish) && {showEditButton &&
<a href={draftLink} className="mx-1"> <a href={draftLink} className="mx-1">
<Button className="file-operation-btn" color="secondary">{gettext('Edit Draft')}</Button> <Button className="file-operation-btn" color="secondary">{gettext('Edit Draft')}</Button>
</a> </a>
} }
{canPublish && {showPublishButton &&
<button className='btn btn-success file-operation-btn' title={gettext('Publish draft')} onClick={this.onPublishDraft}> <button className='btn btn-success file-operation-btn' title={gettext('Publish draft')} onClick={this.onPublishDraft}>
{gettext('Publish')} {gettext('Publish')}
</button> </button>
} }
{freezePublish && {showPublishedButton &&
<button className='btn btn-success file-operation-btn' title={gettext('Published')} disabled> <button className='btn btn-success file-operation-btn' title={gettext('Published')} disabled>
{gettext('Published')} {gettext('Published')}
</button> </button>

View File

@@ -173,7 +173,10 @@ class DraftView(APIView):
# 3. Send draft file publish msg. # 3. Send draft file publish msg.
send_draft_publish_msg(draft, username, dst_file_path) send_draft_publish_msg(draft, username, dst_file_path)
return Response({'published_file_path': dst_file_path}) result = {}
result['published_file_path'] = dst_file_path
result['draft_status'] = draft.status
return Response(result)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
error_msg = 'Internal Server Error' error_msg = 'Internal Server Error'