Skip to content

Commit

Permalink
API spec for clickthrough and formatcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 13, 2024
1 parent 490f311 commit 2c6977b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
28 changes: 18 additions & 10 deletions etc/apifunctions.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{
"name": "clickthrough", "post": true,
"function": "User_API::clickthrough",
"parameters": "accept clickthrough_id"
"parameters": "?p ?=accept =clickthrough_id =clickthrough_type =clickthrough_time"
},
{
"name": "comment", "paper": true, "get": true,
Expand Down Expand Up @@ -92,7 +92,8 @@
"name": "formatcheck", "get": true, "post": true,
"function": "FormatCheck_API::run",
"parameters": "?p ?doc ?soft ?dt ?docid",
"response": "npages nwords result problem_fields has_error docid"
"response": "npages nwords problem_fields has_error docid",
"response_deprecated": "result"
},
{
"name": "graphdata", "get": true,
Expand Down Expand Up @@ -125,7 +126,7 @@
"name": "mailtext", "get": true, "post": true,
"function": "Mail_API::mailtext",
"parameters": "?template ?p ?r ?email ?given_name ?family_name ?affiliation ?reason ?width ?text ?subject ?body",
"response": "?templates"
"response": "?templates ?subject ?body"
},
{
"name": "manager", "paper": true, "get": true,
Expand Down Expand Up @@ -201,7 +202,8 @@
},
{
"name": "reviewfieldlibrary", "get": true, "allow_if": "chair",
"function": "Settings_API::reviewfieldlibrary"
"function": "Settings_API::reviewfieldlibrary",
"response": "samples types"
},
{
"name": "reviewrating", "paper": true, "get": true,
Expand Down Expand Up @@ -277,12 +279,14 @@
},
{
"name": "settingdescriptions", "get": true,
"function": "Settings_API::descriptions"
"function": "Settings_API::descriptions",
"response": "setting_descriptions"
},
{
"name": "settings", "get": true, "post": true,
"function": "Settings_API::run",
"parameters": "?=settings ?dryrun"
"parameters": "?=settings ?dryrun",
"response": "?dry_run ?changes"
},
{
"name": "shepherd", "paper": true, "get": true,
Expand All @@ -298,7 +302,8 @@
},
{
"name": "submissionfieldlibrary", "get": true, "allow_if": "chair",
"function": "Settings_API::submissionfieldlibrary"
"function": "Settings_API::submissionfieldlibrary",
"response": "samples types"
},
{
"name": "taganno", "get": true,
Expand All @@ -325,7 +330,7 @@
{
"name": "trackerconfig", "post": true,
"function": "TrackerConfig_API::run",
"parameters": "=:tr ?=:has_tr",
"parameters": "?=stopall ?=:tr ?=:has_tr",
"response": "?tracker ?tracker_recent ?tracker_status ?now tracker_status_at tracker_eventid ?new_trackerid ?tracker_site"
},
{
Expand Down Expand Up @@ -362,10 +367,13 @@
},
{
"name": "votereport", "paper": true, "get": true, "post": true,
"function": "Tags_API::votereport_api"
"function": "Tags_API::votereport_api",
"parameters": "tag",
"response": "tag report"
},
{
"name": "whoami", "get": true,
"function": "User_API::whoami"
"function": "User_API::whoami",
"response": "?email ?given_name ?family_name ?affiliation"
}
]
12 changes: 6 additions & 6 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8289,7 +8289,7 @@ hotcrp.tooltip.add_builder("votereport", function (info) {
if (pid && tag)
info.content = demand_load.make(function (resolve) {
$.get(hoturl("api/votereport", {p: pid, tag: tag}), function (rv) {
resolve(rv.ok ? rv.result || "" : rv.error);
resolve(rv.vote_report || "");
});
})();
});
Expand Down Expand Up @@ -11857,8 +11857,8 @@ handle_ui.on("js-check-format", function () {
},
success: function (data) {
clearTimeout(running);
if (data.ok || data.result)
$cf.html(data.result);
if (data.message_list && data.message_list.length)
$cf.html(feedback.render_alert(data.message_list));
}
});
});
Expand Down Expand Up @@ -12235,15 +12235,15 @@ handle_ui.on("js-clickthrough", function () {
$container = $(this).closest(".js-clickthrough-container");
if (!$container.length)
$container = $(this).closest(".pcontainer");
$.post(hoturl("=api/clickthrough", {accept: 1, p: siteinfo.paperid}),
$(this.form).serialize(),
$.post(hoturl("=api/clickthrough", {p: siteinfo.paperid}),
$(this.form).serialize() + "&accept=1",
function (data) {
if (data && data.ok) {
$container.find(".need-clickthrough-show").removeClass("need-clickthrough-show hidden");
$container.find(".need-clickthrough-enable").prop("disabled", false).removeClass("need-clickthrough-enable");
$container.find(".js-clickthrough-terms").slideUp();
} else {
make_bubble((data && data.error) || "You can’t continue to review until you accept these terms.", "errorbubble")
make_bubble("You can’t continue to review until you accept these terms.", "errorbubble")
.anchor("w").near(self);
}
});
Expand Down
6 changes: 4 additions & 2 deletions src/api/api_formatcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ static function run(Contact $user, Qrequest $qreq) {
$runflag = $qreq->soft ? CheckFormat::RUN_IF_NECESSARY : CheckFormat::RUN_ALWAYS;
$cf = new CheckFormat($user->conf, $runflag);
$cf->check_document($doc);
$ms = $cf->document_messages($doc);
return [
"ok" => $cf->check_ok(),
"npages" => $cf->npages,
"nwords" => $cf->nwords,
"result" => $cf->document_report($doc),
"result" => $ms->has_message() ? Ht::feedback_msg($ms) : "",
"problem_fields" => $cf->problem_fields(),
"has_error" => $cf->has_error(),
"docid" => $doc->paperStorageId
"docid" => $doc->paperStorageId,
"message_list" => $ms->message_list()
];
} else {
return JsonResult::make_error(404, "<0>Document not found");
Expand Down
6 changes: 3 additions & 3 deletions src/api/api_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ static function votereport_api(Contact $user, Qrequest $qreq, PaperInfo $prow) {
if ($is_approval) {
$result[] = $user->reviewer_html_for($k);
} else {
$result[] = $user->reviewer_html_for($k) . " ($v)";
$result[] = $user->reviewer_html_for($k) . " ({$v})";
}
}
if (empty($result)) {
return ["ok" => true, "result" => ""];
return ["ok" => true, "vote_report" => ""];
} else {
return ["ok" => true, "result" => '<span class="nw">' . join(',</span> <span class="nw">', $result) . '</span>'];
return ["ok" => true, "vote_report" => '<span class="nw">' . join(',</span> <span class="nw">', $result) . '</span>'];
}
}
}
44 changes: 31 additions & 13 deletions src/checkformat.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,21 @@ function front_report_item() {
}
}

/** @return string */
function document_report(DocumentInfo $doc) {
/** @return MessageSet */
function document_messages(DocumentInfo $doc) {
$spec = $doc->conf->format_spec($doc->documentType);
$report = null;
$ms = new MessageSet;
foreach ($this->spec_checkers($spec) as $checker) {
$report = $report ?? $checker->report($this, $spec, $doc);
if ($checker->append_report($this, $spec, $doc, $ms))
break;
}
return $report ?? "";
return $ms;
}

/** @return string */
function document_report(DocumentInfo $doc) {
$ms = $this->document_messages($doc);
return $ms->has_message() ? Ht::feedback_msg($ms) : "";
}

/** @param int $dtype
Expand Down Expand Up @@ -789,16 +796,27 @@ static private function truncate_banal_json($bj, CheckFormat $cf, $nmsg0, Format
return $xj;
}


/** @return string */
function report(CheckFormat $cf, FormatSpec $spec, DocumentInfo $doc) {
$msgs = [$cf->front_report_item()];
if ($cf->has_error()) {
$msgs[0]->message = "<5><strong>" . $msgs[0]->message_as(5) . ".</strong> The most serious errors are marked with <span class=\"error-mark\"></span>.";
/** @return bool */
function append_report(CheckFormat $cf, FormatSpec $spec, DocumentInfo $doc,
MessageSet $ms) {
if (!$ms->has_message()) {
$mi = $cf->front_report_item();
if ($cf->has_error()) {
$mi->message = "<5><strong>" . $mi->message_as(5) . ".</strong> The most serious errors are marked with <span class=\"error-mark\"></span>.";
}
$ms->append_item($mi);
}
if ($cf->has_problem()) {
$msgs[] = new MessageItem(null, "<5>Submissions that violate the requirements will not be considered. However, some violation reports may be false positives (for instance, the checker can miscalculate margins and text sizes for figures). If you are confident that the current document respects all format requirements, keep it as is.", MessageSet::INFORM);
$ms->append_item(new MessageItem(null, "<5>Submissions that violate the requirements will not be considered. However, some violation reports may be false positives (for instance, the checker can miscalculate margins and text sizes for figures). If you are confident that the current document respects all format requirements, keep it as is.", MessageSet::INFORM));
}
return Ht::feedback_msg(array_merge($msgs, $cf->message_list()));
$ms->append_list($cf->message_list());
return true;
}

/** @return string */
function report(CheckFormat $cf, FormatSpec $spec, DocumentInfo $doc) {
$ms = new MessageSet;
$this->append_report($cf, $spec, $doc, $ms);
return Ht::feedback_msg($ms);
}
}
3 changes: 3 additions & 0 deletions src/formatspec.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ function known_fields(FormatSpec $spec);
function prepare(CheckFormat $cf, FormatSpec $spec);
/** @return void */
function check(CheckFormat $cf, FormatSpec $spec, DocumentInfo $doc);
/** @return bool */
function append_report(CheckFormat $cf, FormatSpec $spec, DocumentInfo $doc,
MessageSet $ms);
/** @return ?string */
function report(CheckFormat $cf, FormatSpec $spec, DocumentInfo $doc);
}

0 comments on commit 2c6977b

Please sign in to comment.