...
 
Commits (2)
......@@ -18,8 +18,14 @@ module.exports = function(dependencies) {
return Proposal.create(proposal);
}
function getById(id) {
return Proposal.findOne({ _id: id });
function getById(id, options) {
const query = Proposal.findOne({ _id: id });
if (options.populations) {
query.populate(options.populations);
}
return query.exec();
}
function list(options = {}) {
......
......@@ -25,22 +25,27 @@ module.exports = function(dependencies) {
}
function list(options = {}) {
const query = {};
const findQuery = {};
if (options.creator) {
query.creator = options.creator;
if (options.proposal) {
findQuery.proposal = options.proposal;
}
if (options.status) {
query.status = options.status;
findQuery.status = options.status;
}
return Review
.find(query)
const query = Review
.find(findQuery)
.skip(+options.offset || DEFAULT_OFFSET)
.limit(+options.limit || DEFAULT_LIMIT)
.sort({ _id: -1 })
.exec();
.sort({ _id: -1 });
if (options.populations) {
query.populate(options.populations);
}
return query.exec();
}
function updateById(proposalId, modified) {
......
module.exports = function(dependencies, lib) {
const logger = dependencies('logger');
const coreUser = dependencies('coreUser');
return {
load
};
function load(req, res, next) {
lib.proposal.getById(req.params.proposalId)
const populations = [{
path: 'reviewers'
}];
lib.proposal.getById(req.params.proposalId, { populations })
.then(proposal => {
if (proposal) {
proposal.reviewers = proposal.reviewers.map(
reviewer => coreUser.denormalize.denormalize(reviewer)
);
req.proposal = proposal;
next();
} else {
......
module.exports = function(dependencies, lib) {
const logger = dependencies('logger');
const coreUser = dependencies('coreUser');
return {
createReview,
......@@ -37,15 +38,26 @@ module.exports = function(dependencies, lib) {
function getReviews(req, res) {
var listOptions = {
creator: req.user.id,
proposal: req.query.proposal,
status: req.query.status,
limit: Number(req.query.limit),
offset: Number(req.query.offset)
offset: Number(req.query.offset),
populations: [{
path: 'creator'
}]
};
lib.review.list(listOptions)
.then(reviews => reviews.map(lib.review.denormalize))
.then(denormalizedReviews => res.status(200).json(denormalizedReviews))
.then(denormalizedReviews => {
const result = denormalizedReviews.map(review => {
review.creator = coreUser.denormalize.denormalize(review.creator);
return review;
});
return res.status(200).json(result);
})
.catch(err => {
const details = 'Error while gettings review';
......
......@@ -7,6 +7,15 @@ sub-header
on-accept-btn-click="$ctrl.onAcceptBtnClick()",
on-review-btn-click="$ctrl.onReviewBtnClick()"
)
.card(ng-if="$ctrl.proposal && $ctrl.userRole==='moderator'")
.card-body.p-30
.row
h3 Ý kiến từ chuyên gia
.row
most-review-list(
proposal-id="$ctrl.proposal.id",
reviewers="$ctrl.proposal.reviewers"
)
.card
.card-body.p-20
.form-container(ng-switch="$ctrl.proposal.type")
......
(function(angular) {
'use strict';
angular.module('linagora.esn.most')
.component('mostReviewList', {
templateUrl: '/linagora.esn.most/app/review/list/most-review-list.html',
controller: 'MostReviewListController',
bindings: {
proposalId: '<',
reviewers: '<'
}
});
})(angular);
(function(angular) {
'use strict';
angular.module('linagora.esn.most')
.controller('MostReviewListController', MostReviewListController);
function MostReviewListController(
mostReviewApiClient
) {
var self = this;
self.$onInit = $onInit;
function $onInit() {
mostReviewApiClient.getReviews({ proposal: self.proposalId })
.then(function(reviews) {
self.reviews = reviews;
self.pendingReviewers = buildPendingReviewers(reviews);
});
}
function buildPendingReviewers(reviews) {
var reviewedExperts = reviews.map(function(review) {
return review.creator._id;
});
return self.reviewers.map(function(reviewer) {
if (reviewedExperts.indexOf(reviewer._id)) {
return reviewer;
}
}).filter(Boolean);
}
}
})(angular);
.flex.flex-space-between
h5 Chuyên gia
h5 File đánh giá
hr.m-15
div(ng-repeat="review in $ctrl.reviews")
.flex.flex-space-between
| {{::review.creator.firstname}} {{::review.creator.lastname}}
a(href='{{"/api/files/" + review.attachments[0]._id}}', esn-download-file='{{review.attachments[0].name}}') Tải về
hr.m-10
div(ng-repeat="pendingReviewer in $ctrl.pendingReviewers")
.flex.flex-space-between
| {{::pendingReviewer.firstname}} {{::pendingReviewer.lastname}}
small Chưa đánh giá
hr.m-10
......@@ -12,6 +12,7 @@ const myAwesomeModule = new AwesomeModule(AWESOME_MODULE_NAME, {
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.logger', 'logger'),
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.webserver.wrapper', 'webserver-wrapper'),
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.db', 'db'),
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.user', 'coreUser'),
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.i18n', 'i18n'),
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.webserver.middleware.authorization', 'authorizationMW'),
new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.webserver.middleware.helper', 'helperMW')
......