mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 15:19:06 +00:00
Show draft review info at repo info bar (#2832)
This commit is contained in:
80
frontend/src/components/dialog/list-repo-drafts-dialog.js
Normal file
80
frontend/src/components/dialog/list-repo-drafts-dialog.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import moment from 'moment';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import Draft from '../../models/draft';
|
||||
|
||||
const propTypes = {
|
||||
repoID: PropTypes.string.isRequired,
|
||||
toggle: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class ListRepoDraftsDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
drafts: [],
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
seafileAPI.listRepoDrafts(this.props.repoID).then(res => {
|
||||
let drafts = res.data.drafts.map(item => {
|
||||
let draft = new Draft(item);
|
||||
return draft;
|
||||
})
|
||||
this.setState({
|
||||
drafts: drafts
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggle();
|
||||
}
|
||||
|
||||
render() {
|
||||
let drafts = this.state.drafts;
|
||||
return (
|
||||
<Modal isOpen={true}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Drafts')}</ModalHeader>
|
||||
<ModalBody className="dialog-list-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th width='50%' className="ellipsis">{gettext('Name')}</th>
|
||||
<th width='25%'>{gettext('Owner')}</th>
|
||||
<th width='25%'>{gettext('Last Update')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{this.state.drafts.map((draft) => {
|
||||
let href = siteRoot + 'lib/' + draft.originRepoID + '/file' + Utils.encodePath(draft.draftFilePath);
|
||||
return (
|
||||
<tr key={draft.id}>
|
||||
<td className="name">
|
||||
<a href={href} target='_blank'>{Utils.getFileName(draft.draftFilePath)}</a>
|
||||
</td>
|
||||
<td>{draft.ownerNickname}</td>
|
||||
<td>{moment(draft.createdStr).fromNow()}</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Close')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ListRepoDraftsDialog.propTypes = propTypes;
|
||||
|
||||
export default ListRepoDraftsDialog;
|
81
frontend/src/components/dialog/list-repo-reviews-dialog.js
Normal file
81
frontend/src/components/dialog/list-repo-reviews-dialog.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import moment from 'moment';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import Review from '../../models/review';
|
||||
|
||||
const propTypes = {
|
||||
repoID: PropTypes.string.isRequired,
|
||||
toggle: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
|
||||
class ListRepoReviewsDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
reviews: [],
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
seafileAPI.listRepoReviews(this.props.repoID).then(res => {
|
||||
let reviews = res.data.reviews.map(item =>{
|
||||
let review = new Review(item);
|
||||
return review;
|
||||
})
|
||||
this.setState({
|
||||
reviews: reviews
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggle();
|
||||
}
|
||||
|
||||
render() {
|
||||
let reviews = this.state.reviews;
|
||||
return (
|
||||
<Modal isOpen={true}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Reviews')}</ModalHeader>
|
||||
<ModalBody className="dialog-list-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th width='50%' className="ellipsis">{gettext('Name')}</th>
|
||||
<th width='25%'>{gettext('Owner')}</th>
|
||||
<th width='25%'>{gettext('Last Update')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{this.state.reviews.map((review) => {
|
||||
let href = siteRoot + 'drafts/review/' + review.id;
|
||||
return (
|
||||
<tr key={review.id}>
|
||||
<td className="name">
|
||||
<a href={href} target='_blank'>{Utils.getFileName(review.draftFilePath)}</a>
|
||||
</td>
|
||||
<td>{review.creatorName}</td>
|
||||
<td>{moment(review.createdStr).fromNow()}</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Close')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ListRepoReviewsDialog.propTypes = propTypes;
|
||||
|
||||
export default ListRepoReviewsDialog;
|
@@ -1,4 +1,4 @@
|
||||
import React, { Fragment } from 'react';
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
@@ -44,13 +44,10 @@ class ListTaggedFilesDialog extends React.Component {
|
||||
render() {
|
||||
let taggedFileList = this.state.taggedFileList;
|
||||
return (
|
||||
<Fragment>
|
||||
<ModalHeader toggle={this.props.onClose}>
|
||||
<span className="tag-dialog-back fas fa-sm fa-arrow-left" onClick={this.props.toggleCancel} aria-label={gettext('Back')}></span>
|
||||
{gettext('Tagged Files')}
|
||||
</ModalHeader>
|
||||
<Modal isOpen={true}>
|
||||
<ModalHeader toggle={this.props.onClose}>{gettext('Tagged Files')}</ModalHeader>
|
||||
<ModalBody className="dialog-list-container">
|
||||
<table className="table-thead-hidden">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th width='50%' className="ellipsis">{gettext('Name')}</th>
|
||||
@@ -78,7 +75,7 @@ class ListTaggedFilesDialog extends React.Component {
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.props.toggleCancel}>{gettext('Close')}</Button>
|
||||
</ModalFooter>
|
||||
</Fragment>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -52,6 +52,8 @@ const propTypes = {
|
||||
onFileUploadSuccess: PropTypes.func.isRequired,
|
||||
usedRepoTags: PropTypes.array.isRequired,
|
||||
readmeMarkdown: PropTypes.object,
|
||||
draftCounts: PropTypes.number,
|
||||
reviewCounts: PropTypes.number,
|
||||
};
|
||||
|
||||
class DirPanel extends React.Component {
|
||||
@@ -129,7 +131,9 @@ class DirPanel extends React.Component {
|
||||
|
||||
render() {
|
||||
const errMessage = (<div className="message empty-tip err-message"><h2>{gettext('Folder does not exist.')}</h2></div>);
|
||||
|
||||
const showRepoInfoBar = this.props.path === '/' && (
|
||||
this.props.usedRepoTags.length != 0 || this.props.readmeMarkdown != null ||
|
||||
this.props.draftCounts != 0 || this.props.reviewCounts != 0);
|
||||
return (
|
||||
<div className="main-panel wiki-main-panel o-hidden">
|
||||
<div className="main-panel-north">
|
||||
@@ -191,12 +195,14 @@ class DirPanel extends React.Component {
|
||||
{!this.props.pathExist ?
|
||||
errMessage :
|
||||
<Fragment>
|
||||
{this.props.path === '/' && !(this.props.usedRepoTags.length === 0 && this.props.readmeMarkdown === null) && (
|
||||
{showRepoInfoBar && (
|
||||
<RepoInfoBar
|
||||
repoID={this.props.repoID}
|
||||
currentPath={this.props.path}
|
||||
usedRepoTags={this.props.usedRepoTags}
|
||||
readmeMarkdown={this.props.readmeMarkdown}
|
||||
draftCounts={this.props.draftCounts}
|
||||
reviewCounts={this.props.reviewCounts}
|
||||
/>
|
||||
)}
|
||||
<DirentListView
|
||||
|
@@ -44,6 +44,8 @@ class DirView extends React.Component {
|
||||
errorMsg: '',
|
||||
usedRepoTags: [],
|
||||
readmeMarkdown: null,
|
||||
draftCounts: 0,
|
||||
reviewCounts: 0,
|
||||
};
|
||||
window.onpopstate = this.onpopstate;
|
||||
this.lastModifyTime = new Date();
|
||||
@@ -61,6 +63,12 @@ class DirView extends React.Component {
|
||||
let location = decodeURIComponent(window.location.href);
|
||||
let repoID = this.props.repoID;
|
||||
collabServer.watchRepo(repoID, this.onRepoUpdateEvent);
|
||||
seafileAPI.getRepoDraftReviewCounts(repoID).then(res => {
|
||||
this.setState({
|
||||
draftCounts: res.data.draft_counts,
|
||||
reviewCounts: res.data.review_counts,
|
||||
})
|
||||
})
|
||||
seafileAPI.listRepoTags(repoID).then(res => {
|
||||
let usedRepoTags = [];
|
||||
res.data.repo_tags.forEach(item => {
|
||||
@@ -696,6 +704,8 @@ class DirView extends React.Component {
|
||||
onLibDecryptDialog={this.onLibDecryptDialog}
|
||||
usedRepoTags={this.state.usedRepoTags}
|
||||
readmeMarkdown={this.state.readmeMarkdown}
|
||||
draftCounts={this.state.draftCounts}
|
||||
reviewCounts={this.state.reviewCounts}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ import PropTypes from 'prop-types';
|
||||
import ModalPortal from './modal-portal';
|
||||
import { Modal } from 'reactstrap';
|
||||
import ListTaggedFilesDialog from './dialog/list-taggedfiles-dialog';
|
||||
import { siteRoot } from '../utils/constants';
|
||||
import ListRepoDraftsDialog from './dialog/list-repo-drafts-dialog';
|
||||
import ListRepoReviewsDialog from './dialog/list-repo-reviews-dialog';
|
||||
import { siteRoot, gettext } from '../utils/constants';
|
||||
import { Utils } from '../utils/utils';
|
||||
|
||||
import '../css/repo-info-bar.css';
|
||||
@@ -13,6 +15,8 @@ const propTypes = {
|
||||
currentPath: PropTypes.string.isRequired,
|
||||
usedRepoTags: PropTypes.array.isRequired,
|
||||
readmeMarkdown: PropTypes.object,
|
||||
draftCounts: PropTypes.number,
|
||||
reviewCounts: PropTypes.number,
|
||||
};
|
||||
|
||||
class RepoInfoBar extends React.Component {
|
||||
@@ -22,6 +26,8 @@ class RepoInfoBar extends React.Component {
|
||||
this.state = {
|
||||
currentTag: null,
|
||||
isListTaggedFileShow: false,
|
||||
showRepoDrafts: false,
|
||||
showRepoReviews: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,6 +44,18 @@ class RepoInfoBar extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
toggleDrafts = () => {
|
||||
this.setState({
|
||||
showRepoDrafts: !this.state.showRepoDrafts
|
||||
});
|
||||
}
|
||||
|
||||
toggleReviews = () => {
|
||||
this.setState({
|
||||
showRepoReviews: !this.state.showRepoReviews
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
let {repoID, currentPath, usedRepoTags, readmeMarkdown} = this.props;
|
||||
let href = readmeMarkdown !== null ? siteRoot + 'lib/' + repoID + '/file' + Utils.joinPath(currentPath, readmeMarkdown.name) : '';
|
||||
@@ -59,24 +77,61 @@ class RepoInfoBar extends React.Component {
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
{readmeMarkdown !== null && (
|
||||
<div className="readme-file">
|
||||
<i className="readme-flag fa fa-flag"></i>
|
||||
<a className="readme-name" href={href} target='_blank'>{readmeMarkdown.name}</a>
|
||||
</div>
|
||||
)}
|
||||
<div className="readme-files">
|
||||
{readmeMarkdown !== null && (
|
||||
<span className="readme-file">
|
||||
<i className="readme-flag fa fa-flag"></i>
|
||||
<a className="readme-name" href={href} target='_blank'>{readmeMarkdown.name}</a>
|
||||
</span>
|
||||
)}
|
||||
{this.props.draftCounts > 0 &&
|
||||
<span className="readme-file">
|
||||
<i className="readme-flag fa fa-pen"></i>
|
||||
<span className="used-tag-name">{gettext('draft')}</span>
|
||||
<span className="used-tag-files" onClick={this.toggleDrafts}>
|
||||
{this.props.draftCounts > 1 ? this.props.draftCounts + ' files' : this.props.draftCounts + ' file'}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
{this.props.reviewCounts > 0 &&
|
||||
<span className="readme-file">
|
||||
<i className="readme-flag fa fa-clipboard"></i>
|
||||
<span className="used-tag-name">{gettext('review')}</span>
|
||||
<span className="used-tag-files" onClick={this.toggleReviews}>
|
||||
{this.props.reviewCounts > 1 ? this.props.reviewCounts + ' files' : this.props.reviewCounts + ' file'}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
{this.state.isListTaggedFileShow && (
|
||||
<ModalPortal>
|
||||
<Modal isOpen={true}>
|
||||
<ListTaggedFilesDialog
|
||||
repoID={repoID}
|
||||
currentTag={this.state.currentTag}
|
||||
onClose={this.onCloseDialog}
|
||||
toggleCancel={this.onListTaggedFiles}
|
||||
/>
|
||||
</Modal>
|
||||
<ListTaggedFilesDialog
|
||||
repoID={repoID}
|
||||
currentTag={this.state.currentTag}
|
||||
onClose={this.onCloseDialog}
|
||||
toggleCancel={this.onListTaggedFiles}
|
||||
/>
|
||||
</ModalPortal>
|
||||
)}
|
||||
|
||||
{this.state.showRepoDrafts && (
|
||||
<ModalPortal>
|
||||
<ListRepoDraftsDialog
|
||||
toggle={this.toggleDrafts}
|
||||
repoID={this.props.repoID}
|
||||
/>
|
||||
</ModalPortal>
|
||||
)}
|
||||
|
||||
{this.state.showRepoReviews && (
|
||||
<ModalPortal>
|
||||
<ListRepoReviewsDialog
|
||||
toggle={this.toggleReviews}
|
||||
repoID={this.props.repoID}
|
||||
/>
|
||||
</ModalPortal>
|
||||
)}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user