1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 15:38:15 +00:00

update draft&review dispaly (#2505)

* replace draft.id with draft_name

* add updateDraftsList function

* Repair operation display

* update review dispaly

* refactor code
This commit is contained in:
C_Q
2018-11-08 10:36:41 +08:00
committed by Daniel Pan
parent 9f8b522fac
commit 8dcf88c32a
7 changed files with 95 additions and 42 deletions

View File

@@ -27,21 +27,30 @@ class App extends Component {
isOpen: false, isOpen: false,
isSidePanelClosed: false, isSidePanelClosed: false,
draftCounts: 0, draftCounts: 0,
draftList:[] draftList:[],
isLoadingDraft: true,
}; };
} }
componentDidMount() { componentDidMount() {
this.getDrafts() this.getDrafts();
} }
getDrafts = () => { getDrafts = () => {
editUtilties.listDrafts().then(res => { editUtilties.listDrafts().then(res => {
this.setState({ this.setState({
draftCounts: res.data.draft_counts, draftCounts: res.data.draft_counts,
draftList: res.data.data draftList: res.data.data,
}) isLoadingDraft: false,
}) });
});
}
updateDraftsList = (draft_id) => {
this.setState({
draftCounts: this.state.draftCounts - 1,
draftList: this.state.draftList.filter(draft => draft.id != draft_id),
});
} }
onCloseSidePanel = () => { onCloseSidePanel = () => {
@@ -69,7 +78,11 @@ class App extends Component {
<Router> <Router>
<FilesActivities path={siteRoot + 'dashboard'} /> <FilesActivities path={siteRoot + 'dashboard'} />
<DraftsView path={siteRoot + 'drafts'} currentTab={currentTab}> <DraftsView path={siteRoot + 'drafts'} currentTab={currentTab}>
<DraftContent path='/' getDrafts={this.getDrafts} draftList={this.state.draftList}/> <DraftContent path='/' getDrafts={this.getDrafts}
isLoadingDraft={this.state.isLoadingDraft}
draftList={this.state.draftList}
updateDraftsList={this.updateDraftsList}
/>
<ReviewContent path='reviews' /> <ReviewContent path='reviews' />
</DraftsView> </DraftsView>
<Starred path={siteRoot + 'starred'} /> <Starred path={siteRoot + 'starred'} />

View File

@@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { siteRoot, lang } from '../../utils/constants'; import { siteRoot, lang } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import MenuControl from '../menu-control'; import MenuControl from '../menu-control';
import moment from 'moment'; import moment from 'moment';
@@ -66,14 +67,9 @@ class DraftListItem extends React.Component {
window.open(url); window.open(url);
} }
getFileName(filePath) {
let lastIndex = filePath.lastIndexOf('/');
return filePath.slice(lastIndex+1);
}
render() { render() {
let draft = this.props.draft; let draft = this.props.draft;
let fileName = this.getFileName(draft.draft_file_path); let fileName = Utils.getFileName(draft.draft_file_path);
let localTime = moment.utc(draft.updated_at).toDate(); let localTime = moment.utc(draft.updated_at).toDate();
localTime = moment(localTime).fromNow(); localTime = moment(localTime).fromNow();
return ( return (

View File

@@ -10,7 +10,7 @@ class MenuControl extends React.Component {
render() { render() {
return ( return (
<i className={`fas fa-ellipsis-v ${this.props.isShow ? '' : 'hide'}`} onClick={this.props.onClick}></i> <i className={`fas fa-ellipsis-v ${this.props.isShow ? '' : 'invisible'}`} onClick={this.props.onClick}></i>
); );
} }
} }

View File

@@ -56,7 +56,6 @@ class ReviewListItem extends React.Component {
<td className="icon" style={{width: '4%'}}><img src={siteRoot + 'media/img/file/192/txt.png'} alt="icon"/></td> <td className="icon" style={{width: '4%'}}><img src={siteRoot + 'media/img/file/192/txt.png'} alt="icon"/></td>
<td className="name a-simulate" style={{width: '46%'}} onClick={this.onReviewsClick}>{fileName}</td> <td className="name a-simulate" style={{width: '46%'}} onClick={this.onReviewsClick}>{fileName}</td>
<td className='library'>{item.draft_origin_repo_name}</td> <td className='library'>{item.draft_origin_repo_name}</td>
<td className="status" style={{width: '20%'}}>{item.status}</td>
<td className="update" style={{width: '20%'}}>{localTime}</td> <td className="update" style={{width: '20%'}}>{localTime}</td>
<td className="menu-toggle"></td> <td className="menu-toggle"></td>
</tr> </tr>

View File

@@ -1,5 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Nav, NavItem, NavLink } from 'reactstrap';
import classnames from 'classnames';
import { gettext } from '../../utils/constants'; import { gettext } from '../../utils/constants';
import ReviewListItem from './review-list-item'; import ReviewListItem from './review-list-item';
@@ -10,23 +12,67 @@ const propTypes = {
class ReviewListView extends React.Component { class ReviewListView extends React.Component {
constructor(props) {
super(props);
this.toggle = this.toggle.bind(this);
this.state = {
activeTab: 'open'
};
}
toggle(tab) {
if (this.state.activeTab !== tab) {
this.setState({
activeTab: tab
});
}
}
render() { render() {
let items = this.props.itemsList; let items = this.props.itemsList;
let { activeTab } = this.state;
return ( return (
<div className="table-container"> <div className="table-container">
<Nav tabs>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === 'open' })}
onClick={() => { this.toggle('open');}}
>
Open
</NavLink>
</NavItem>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === 'finished' })}
onClick={() => { this.toggle('finished');}}
>
Published
</NavLink>
</NavItem>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === 'closed' })}
onClick={() => { this.toggle('closed');}}
>
Closed
</NavLink>
</NavItem>
</Nav>
<table> <table>
<thead> <thead>
<tr> <tr>
<th style={{width: '4%'}}>{/*img*/}</th> <th style={{width: '4%'}}>{/*img*/}</th>
<th style={{width: '26%'}}>{gettext('Name')}</th> <th style={{width: '26%'}}>{gettext('Name')}</th>
<th style={{width: '20%'}}>{gettext('Library')}</th> <th style={{width: '20%'}}>{gettext('Library')}</th>
<th style={{width: '20%'}}>{gettext('Status')}</th>
<th style={{width: '20%'}}>{gettext('Last Update')}</th> <th style={{width: '20%'}}>{gettext('Last Update')}</th>
<th style={{width: '10%'}}></th> <th style={{width: '10%'}}></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{ items && items.map((item) => { { items && items.map((item) => {
if(item.status === activeTab) {
return ( return (
<ReviewListItem <ReviewListItem
key={item.id} key={item.id}
@@ -34,6 +80,7 @@ class ReviewListView extends React.Component {
isItemFreezed={this.props.isItemFreezed} isItemFreezed={this.props.isItemFreezed}
/> />
); );
}
})} })}
</tbody> </tbody>
</table> </table>

View File

@@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import { siteRoot, gettext } from '../../utils/constants'; import { siteRoot, gettext } from '../../utils/constants';
import editUtilties from '../../utils/editor-utilties'; import editUtilties from '../../utils/editor-utilties';
import { Utils } from '../../utils/utils';
import Toast from '../../components/toast'; import Toast from '../../components/toast';
import Loading from '../../components/loading'; import Loading from '../../components/loading';
import DraftListView from '../../components/draft-list-view/draft-list-view'; import DraftListView from '../../components/draft-list-view/draft-list-view';
@@ -12,7 +13,6 @@ class DraftContent extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
isLoadingDraft: true,
isMenuShow: false, isMenuShow: false,
menuPosition: {top:'', left: ''}, menuPosition: {top:'', left: ''},
currentDraft: null, currentDraft: null,
@@ -21,7 +21,6 @@ class DraftContent extends React.Component {
} }
componentDidMount() { componentDidMount() {
this.initDraftList();
document.addEventListener('click', this.onHideContextMenu); document.addEventListener('click', this.onHideContextMenu);
} }
@@ -29,38 +28,32 @@ class DraftContent extends React.Component {
document.removeEventListener('click', this.onHideContextMenu); document.removeEventListener('click', this.onHideContextMenu);
} }
initDraftList() {
this.setState({isLoadingDraft: true});
this.props.getDrafts();
this.setState({
isLoadingDraft: false,
});
}
onDeleteHandler = () => { onDeleteHandler = () => {
let draft = this.state.currentDraft; let draft = this.state.currentDraft;
let draft_name = Utils.getFileName(draft.draft_file_path);
editUtilties.deleteDraft(draft.id).then(res => { editUtilties.deleteDraft(draft.id).then(res => {
this.initDraftList(); this.props.updateDraftsList(draft.id);
let msg_s = gettext('Successfully deleted draft %(draft)s.'); let msg_s = gettext('Successfully deleted draft %(draft)s.');
msg_s = msg_s.replace('%(draft)s', draft.id); msg_s = msg_s.replace('%(draft)s', draft_name);
Toast.success(msg_s); Toast.success(msg_s);
}).catch(() => { }).catch(() => {
let msg_s = gettext('Failed to delete draft %(draft)s.'); let msg_s = gettext('Failed to delete draft %(draft)s.');
msg_s = msg_s.replace('%(draft)s', draft.id); msg_s = msg_s.replace('%(draft)s', draft_name);
Toast.error(msg_s); Toast.error(msg_s);
}); });
} }
onPublishHandler = () => { onPublishHandler = () => {
let draft = this.state.currentDraft; let draft = this.state.currentDraft;
let draft_name = Utils.getFileName(draft.draft_file_path);
editUtilties.publishDraft(draft.id).then(res => { editUtilties.publishDraft(draft.id).then(res => {
this.initDraftList(); this.props.updateDraftsList(draft.id);
let msg_s = gettext('Successfully published draft %(draft)s.'); let msg_s = gettext('Successfully published draft %(draft)s.');
msg_s = msg_s.replace('%(draft)s', draft.id); msg_s = msg_s.replace('%(draft)s', draft_name);
Toast.success(msg_s); Toast.success(msg_s);
}).catch(() => { }).catch(() => {
let msg_s = gettext('Failed to publish draft %(draft)s.'); let msg_s = gettext('Failed to publish draft %(draft)s.');
msg_s = msg_s.replace('%(draft)s', draft.id); msg_s = msg_s.replace('%(draft)s', draft_name);
Toast.error(msg_s); Toast.error(msg_s);
}); });
} }
@@ -109,15 +102,15 @@ class DraftContent extends React.Component {
render() { render() {
return ( return (
<div className="cur-view-content"> <div className="cur-view-content">
{this.state.isLoadingDraft && <Loading /> } {this.props.isLoadingDraft && <Loading /> }
{(!this.state.isLoadingDraft && this.props.draftList.length !==0) && {(!this.props.isLoadingDraft && this.props.draftList.length !==0) &&
<DraftListView <DraftListView
draftList={this.props.draftList} draftList={this.props.draftList}
isItemFreezed={this.state.isItemFreezed} isItemFreezed={this.state.isItemFreezed}
onMenuToggleClick={this.onMenuToggleClick} onMenuToggleClick={this.onMenuToggleClick}
/> />
} }
{(!this.state.isLoadingDraft && this.props.draftList.length === 0) && {(!this.props.isLoadingDraft && this.props.draftList.length === 0) &&
<div className="message empty-tip"> <div className="message empty-tip">
<h2>{gettext('No draft yet')}</h2> <h2>{gettext('No draft yet')}</h2>
<p>{gettext('Draft is a way to let you collaborate with others on files. You can create a draft from a file, edit the draft and then ask for a review. The original file will be updated only after the draft be reviewed.')}</p> <p>{gettext('Draft is a way to let you collaborate with others on files. You can create a draft from a file, edit the draft and then ask for a review. The original file will be updated only after the draft be reviewed.')}</p>

View File

@@ -162,4 +162,9 @@ export const Utils = {
.parentNode .parentNode
.innerHTML; .innerHTML;
}, },
getFileName: function(filePath) {
let lastIndex = filePath.lastIndexOf('/');
return filePath.slice(lastIndex+1);
}
}; };