1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-30 21:50:59 +00:00

show reviewer avatar (#2514)

This commit is contained in:
C_Q 2018-11-14 11:02:07 +08:00 committed by Daniel Pan
parent 360bd739ce
commit 6f690e6ba3
6 changed files with 104 additions and 49 deletions

View File

@ -9,6 +9,16 @@ const propTypes = {
item: PropTypes.object.isRequired,
};
function Reviewers(props) {
return (
<div>
{props.reviewers.map((item, index) => (
<img key={index} className="avatar avatar-sm" alt={item.username} src={item.avatar_url} />
))}
</div>
);
}
class ReviewListItem extends React.Component {
constructor(props) {
@ -54,10 +64,11 @@ class ReviewListItem extends React.Component {
return (
<tr className={this.state.highlight} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
<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='library'>{item.draft_origin_repo_name}</td>
<td className="name a-simulate" style={{width: '26%'}} onClick={this.onReviewsClick}>{fileName}</td>
<td className='library' style={{width: '25%'}}>{item.draft_origin_repo_name}</td>
<td className="update" style={{width: '20%'}}>{localTime}</td>
<td className="menu-toggle"></td>
<td className="author" style={{width: '10%'}}><img className="avatar avatar-sm" src={item.author.avatar_url} /></td>
<td className="reviewer" style={{width: '15%'}}><Reviewers reviewers={item.reviewers}/></td>
</tr>
);
}

View File

@ -14,30 +14,23 @@ 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
});
if (this.props.activeTab !== tab) {
this.props.getReviewList(tab)
}
}
render() {
let items = this.props.itemsList;
let { activeTab } = this.state;
return (
<div className="table-container">
<Nav tabs>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === 'open' })}
className={classnames({ active: this.props.activeTab === 'open' })}
onClick={() => { this.toggle('open');}}
>
{gettext('Open')}
@ -45,7 +38,7 @@ class ReviewListView extends React.Component {
</NavItem>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === 'finished' })}
className={classnames({ active: this.props.activeTab === 'finished' })}
onClick={() => { this.toggle('finished');}}
>
{gettext('Published')}
@ -53,7 +46,7 @@ class ReviewListView extends React.Component {
</NavItem>
<NavItem>
<NavLink
className={classnames({ active: this.state.activeTab === 'closed' })}
className={classnames({ active: this.props.activeTab === 'closed' })}
onClick={() => { this.toggle('closed');}}
>
{gettext('Closed')}
@ -65,22 +58,21 @@ class ReviewListView extends React.Component {
<tr>
<th style={{width: '4%'}}>{/*img*/}</th>
<th style={{width: '26%'}}>{gettext('Name')}</th>
<th style={{width: '20%'}}>{gettext('Library')}</th>
<th style={{width: '25%'}}>{gettext('Library')}</th>
<th style={{width: '20%'}}>{gettext('Last Update')}</th>
<th style={{width: '10%'}}></th>
<th style={{width: '10%'}}>{gettext('Author')}</th>
<th style={{width: '15%'}}>{gettext('Reviewers')}</th>
</tr>
</thead>
<tbody>
{ items && items.map((item) => {
if(item.status === activeTab) {
return (
<ReviewListItem
key={item.id}
item={item}
isItemFreezed={this.props.isItemFreezed}
/>
);
}
return (
<ReviewListItem
key={item.id}
item={item}
isItemFreezed={this.props.isItemFreezed}
/>
);
})}
</tbody>
</table>

View File

@ -1,6 +1,6 @@
import React from 'react';
import { gettext } from '../../utils/constants';
import editUtilties from '../../utils/editor-utilties';
import { seafileAPI } from '../../utils/seafile-api';
import Loading from '../../components/loading';
import ReviewListView from '../../components/review-list-view/review-list-view';
@ -12,19 +12,21 @@ class ReviewContent extends React.Component {
reviewsList: [],
isLoadingReviews: true,
isItemFreezed: false,
activeTab: 'open',
};
}
componentDidMount() {
this.initReviewList();
this.getReviewList('open');
}
initReviewList() {
this.setState({isLoadingReviews: true});
editUtilties.listReviews().then(res => {
getReviewList = (reviewStatus) => {
this.setState({isLoadingReviews: true})
seafileAPI.listReviews(reviewStatus).then(res => {
this.setState({
reviewsList: res.data.data,
isLoadingReviews: false,
activeTab: reviewStatus,
});
});
}
@ -33,17 +35,14 @@ class ReviewContent extends React.Component {
return (
<div className="cur-view-content">
{this.state.isLoadingReviews && <Loading /> }
{(!this.state.isLoadingReviews && this.state.reviewsList.length !==0) &&
{!this.state.isLoadingReviews &&
<ReviewListView
itemsList={this.state.reviewsList}
isItemFreezed={this.state.isItemFreezed}
getReviewList={this.getReviewList}
activeTab={this.state.activeTab}
/>
}
{(!this.state.isLoadingReviews && this.state.reviewsList.length === 0) &&
<div className="message empty-tip">
<h2>{gettext('There is no Review file existing')}</h2>
</div>
}
</div>
);
}

View File

@ -123,10 +123,6 @@ class EditorUtilities {
return seafileAPI.createDraftReview(id);
}
listReviews() {
return seafileAPI.listReviews();
}
}
const editorUtilities = new EditorUtilities();

View File

@ -28,11 +28,26 @@ class DraftReviewsView(APIView):
throttle_classes = (UserRateThrottle, )
def get(self, request, format=None):
"""List all user draft review
""" List all reviews related to the user and their corresponding reviewers based on the review status
case1: List the reviews created by the user and their associated reviewers by status
case2: List the reviews of the user as reviewer and their associated reviewers by status
status: open / finished / closed
"""
username = request.user.username
data = [x.to_dict() for x in DraftReview.objects.filter(creator=username)]
data += [x.review_id.to_dict() for x in ReviewReviewer.objects.filter(reviewer=username)]
st = request.GET.get('status', 'open')
if st not in ('open', 'finished', 'closed'):
error_msg = 'Status invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
# case1: List the reviews created by the user and their associated reviewers by status
reviews_1 = DraftReview.objects.get_reviews_by_creator_and_status(creator=username, status=st)
# case2: List the reviews of the user as reviewer and their associated reviewers by status
reviews_2 = DraftReview.objects.get_reviews_by_reviewer_and_status(reviewer=username, status=st)
data = reviews_1 + reviews_2
return Response({'data': data})
@ -64,7 +79,7 @@ class DraftReviewView(APIView):
throttle_classes = (UserRateThrottle, )
def put(self, request, pk, format=None):
"""update review status
"""update review status
"""
st = request.data.get('status', '')

View File

@ -175,6 +175,52 @@ class DraftReviewManager(models.Manager):
return draft_review
def get_reviews_by_creator_and_status(self, creator, status):
from seahub.api2.utils import user_to_dict
reviews = self.filter(creator=creator, status=status)
reviewers = ReviewReviewer.objects.filter(review_id__in=reviews)
data = []
for review in reviews:
reviewer_list = []
for r in reviewers:
if review.id == r.review_id_id:
reviewer = user_to_dict(r.reviewer, avatar_size=64)
reviewer_list.append(reviewer)
author = user_to_dict(review.creator, avatar_size=64)
review = review.to_dict()
review.update({'reviewers': reviewer_list})
review.update({'author': author})
data.append(review)
return data
def get_reviews_by_reviewer_and_status(self, reviewer, status):
from seahub.api2.utils import user_to_dict
reviews = self.filter(reviewreviewer__reviewer=reviewer, status=status)
reviewers = ReviewReviewer.objects.filter(review_id__in=reviews)
data = []
for review in reviews:
reviewer_list = []
for r in reviewers:
if review.id == r.review_id_id:
reviewer = user_to_dict(r.reviewer, avatar_size=64)
reviewer_list.append(reviewer)
author = user_to_dict(review.creator, avatar_size=64)
review = review.to_dict()
review.update({'author': author})
review.update({'reviewers': reviewer_list})
data.append(review)
return data
class DraftReview(TimestampedModel):
creator = LowerCaseCharField(max_length=255, db_index=True)
@ -193,9 +239,6 @@ class DraftReview(TimestampedModel):
if not r_repo:
raise DraftFileConflict
uuid = self.origin_file_uuid
file_path = posixpath.join(uuid.parent_path, uuid.filename)
return {
'id': self.pk,
'creator': self.creator,
@ -203,7 +246,6 @@ class DraftReview(TimestampedModel):
'creator_name': email2nickname(self.creator),
'draft_origin_repo_id': self.origin_repo_id,
'draft_origin_repo_name': r_repo.name,
'draft_origin_file_path': file_path,
'draft_origin_file_version': self.origin_file_version,
'draft_publish_file_version': self.publish_file_version,
'draft_file_path': self.draft_file_path,