Skip to content

Commit

Permalink
Add ‘Clear all’ review rating button for admins (#323).
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 1, 2024
1 parent 59f1935 commit 013a8a4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
39 changes: 33 additions & 6 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6208,6 +6208,11 @@ function rating_counts(ratings) {
return ct;
}

function closest_rating_url(e) {
const card = e.closest(".revcard");
return hoturl("=api", {p: card.getAttribute("data-pid"), r: card.getAttribute("data-rid"), fn: "reviewrating"});
}

handle_ui.on("js-revrating-unfold", function (evt) {
if (evt.target === this)
foldup.call(this, null, {open: true});
Expand Down Expand Up @@ -6246,15 +6251,29 @@ handle_ui.on("js-revrating", function () {
addClass(modrrg, "want-focus");
fold(rre, false);
}
var $card = $(this).closest(".revcard");
$.post(hoturl("=api", {p: $card.attr("data-pid"), r: $card.data("rid"),
fn: "reviewrating"}),
$.post(closest_rating_url(rre),
{user_rating: haveri.map(function (ri) { return ri.name; }).join(" ")},
function (rv) {
apply_review_ratings(rre, rv);
});
});

handle_ui.on("js-revrating-clearall", function (evt) {
const rre = this.closest(".revrating");
function go() {
$.post(closest_rating_url(rre), {user_rating: "clearall"},
function (rv) {
apply_review_ratings(rre, rv);
});
}
if (evt.shiftKey) {
go();
} else {
this.setAttribute("data-override-text", "Are you sure you want to reset all ratings for this review?");
override_deadlines.call(this, go);
}
});

function apply_review_ratings(rre, rv) {
if (rv && "user_rating" in rv) {
const user_rating = rating_compatibility(rv.user_rating),
Expand Down Expand Up @@ -6350,10 +6369,18 @@ function render_ratings(ratings, user_rating, editable) {
}
}

let edit_fold = editable;
if (hotcrp.status.myperm.can_administer
&& ratings.length > user_rating.length) {
edit_fold = true;
es.push($e("span", "revrating-group revrating-admin fx",
$e("button", {type: "button", "class": "ui js-revrating-clearall"}, "Clear all")));
}

let ex;
if (editable) {
es.push(" ", $e("span", "revrating-group fn", $e("button", {type: "button", "class": "ui js-foldup"}, "…")));
ex = $e("div", "revrating editable has-fold foldc ui js-revrating-unfold" + (user_rating === 2 ? " want-revrating-generalize" : ""),
if (edit_fold) {
es.push($e("span", "revrating-group fn", $e("button", {type: "button", "class": "ui js-foldup"}, "…")));
ex = $e("div", "revrating has-fold foldc" + (editable ? " ui js-revrating-unfold" : ""),
$e("div", "f-c fx", $e("a", {href: hoturl("help", {t: "revrate"}), "class": "q"}, "Review ratings ", $e("span", "n", "(anonymous reviewer feedback)"))),
...es);
$(ex).on("keydown", "button.js-revrating", revrating_key);
Expand Down
22 changes: 16 additions & 6 deletions src/api/api_review.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,23 @@ static function reviewrating(Contact $user, Qrequest $qreq, PaperInfo $prow) {
}
$editable = $user->can_rate_review($prow, $rrow);
if ($qreq->method() !== "GET") {
if (!isset($qreq->user_rating)
|| ($rating = ReviewInfo::parse_rating($qreq->user_rating)) === null) {
return JsonResult::make_error(400, "<0>Bad request");
} else if (!$editable) {
return JsonResult::make_permission_error();
if ($qreq->user_rating === "clearall") {
if (!$user->can_administer($prow)) {
return JsonResult::make_permission_error();
}
$rating = -1;
} else {
if (!$editable) {
return JsonResult::make_permission_error();
}
$rating = ReviewInfo::parse_rating($qreq->user_rating);
}
if ($rating === null) {
return JsonResult::make_parameter_error("user_rating");
}
if ($rating === 0) {
if ($rating < 0) {
$user->conf->qe("delete from ReviewRating where paperId=? and reviewId=?", $prow->paperId, $rrow->reviewId);
} else if ($rating === 0) {
$user->conf->qe("delete from ReviewRating where paperId=? and reviewId=? and contactId=?", $prow->paperId, $rrow->reviewId, $user->contactId);
} else {
$user->conf->qe("insert into ReviewRating set paperId=?, reviewId=?, contactId=?, rating=? on duplicate key update rating=?", $prow->paperId, $rrow->reviewId, $user->contactId, $rating, $rating);
Expand Down
7 changes: 7 additions & 0 deletions stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,10 @@ textarea[name=comment] {
.revrating-unused > button {
color: #e35f5f;
}
.revrating-admin > button {
border-color: #666666;
color: #666666;
}
.revrating-active > button {
border: 1px solid #cc0000;
background: #ff0000;
Expand All @@ -2656,6 +2660,9 @@ textarea[name=comment] {
.revrating-choice.revrating-unused:hover > button {
background: #fff2f3;
}
.revrating-admin:hover > button {
background: #e2e2e2;
}
.revrating-active:hover > button {
color: #ffe080;
}
Expand Down

0 comments on commit 013a8a4

Please sign in to comment.