Skip to content

Commit

Permalink
PaperList internals.
Browse files Browse the repository at this point in the history
* Set all view columns before calling a render function.
* More types.
  • Loading branch information
kohler committed Oct 26, 2020
1 parent 3923856 commit a0cb37b
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 142 deletions.
4 changes: 2 additions & 2 deletions autoassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ function divClass($name, $classes = null) {
}

echo '<div class="g"></div>';
echo $plist->table_html(["nofooter" => true]),
Ht::hidden("prevt", $Qreq->t), Ht::hidden("prevq", $Qreq->q),
$plist->echo_table_html(["nofooter" => true]);
echo Ht::hidden("prevt", $Qreq->t), Ht::hidden("prevq", $Qreq->q),
Ht::hidden("has_pap", 1);
}
echo "</div>\n";
Expand Down
3 changes: 2 additions & 1 deletion conflictassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
if ($pc->affiliation) {
$t .= " <span class=\"auaff\">(" . htmlspecialchars($pc->affiliation) . ")</span>";
}
echo $tr->heading_row($t, ["no_titlecol" => true]), $tr->body_rows();
echo $tr->heading_row($t, ["no_titlecol" => true]);
$tr->echo_tbody_rows();
$any = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion manualassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function show_ass_elements($pl) {
echo '</div>';

$pl->set_table_id_class("foldpl", "pltable-fullw");
echo $pl->table_html(["nofooter" => true, "list" => true, "live" => true]);
$pl->echo_table_html(["nofooter" => true, "list" => true, "live" => true]);

echo '<div class="aab aabr aabig"><div class="aabut">',
Ht::submit("update", "Save assignments", ["class" => "btn-primary"]),
Expand Down
11 changes: 5 additions & 6 deletions reviewprefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ function parseUploadedPreferences($text, $filename, $apply) {
$pl->apply_view_session();
$pl->apply_view_qreq();
$pl->set_table_id_class("foldpl", "pltable-fullw", "p#");
$pl_text = $pl->table_html(["fold_session_prefix" => "pfdisplay.",
"footer_extra" => "<div id=\"plactr\">" . Ht::submit("fn", "Save changes", ["data-default-submit-all" => 1, "value" => "saveprefs"]) . "</div>",
"list" => true, "live" => true]);


// DISPLAY OPTIONS
Expand Down Expand Up @@ -323,8 +320,10 @@ function show_pref_element($pl, $name, $text, $extra = []) {
Ht::hidden("defaultact", "", array("id" => "defaultact")),
Ht::hidden_default_submit("default", 1);
echo "<div class=\"pltable-fullw-container\">\n",
'<noscript><div style="text-align:center">', Ht::submit("fn", "Save changes", ["value" => "saveprefs"]), '</div></noscript>',
$pl_text,
"</div></form>\n";
'<noscript><div style="text-align:center">', Ht::submit("fn", "Save changes", ["value" => "saveprefs"]), '</div></noscript>';
$pl->echo_table_html(["fold_session_prefix" => "pfdisplay.",
"footer_extra" => "<div id=\"plactr\">" . Ht::submit("fn", "Save changes", ["data-default-submit-all" => 1, "value" => "saveprefs"]) . "</div>",
"list" => true, "live" => true]);
echo "</div></form>\n";

$Conf->footer();
20 changes: 12 additions & 8 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ function checkbox_item($column, $type, $title, $options = []) {

// Options
foreach ($Conf->options() as $ox) {
if ($pl->has("opt$ox->id")
&& $ox->supports_list_display(PaperOption::LIST_DISPLAY_SUGGEST)) {
if ($ox->supports_list_display(PaperOption::LIST_DISPLAY_SUGGEST)
&& $pl->has("opt$ox->id")) {
$display_options->checkbox_item(10, $ox->search_keyword(), $ox->name);
}
}
Expand Down Expand Up @@ -366,15 +366,17 @@ function checkbox_item($column, $type, $title, $options = []) {

echo "</div>";

function echo_request_as_hidden_inputs($specialscore = false) {
function echo_request_as_hidden_inputs($specialscore) {
global $pl, $pl_text, $Qreq;
foreach (array("q", "qa", "qo", "qx", "qt", "t", "sort") as $x)
foreach (array("q", "qa", "qo", "qx", "qt", "t", "sort") as $x) {
if (isset($Qreq[$x])
&& ($x !== "q" || !isset($Qreq->qa))
&& ($x !== "sort" || !$specialscore || !$pl_text))
echo Ht::hidden($x, $Qreq[$x]);
if ($specialscore && $pl_text)
}
if ($specialscore && $pl_text) {
echo Ht::hidden("sort", $pl->sortdef(true));
}
}

// Saved searches
Expand Down Expand Up @@ -436,7 +438,7 @@ function echo_request_as_hidden_inputs($specialscore = false) {
echo '<div class="tld is-tla" id="tla-view" style="padding-bottom:1ex">';

echo Ht::form($Conf->hoturl_post("search", "redisplay=1"), ["id" => "foldredisplay", "class" => "fn3 fold5c"]);
echo_request_as_hidden_inputs();
echo_request_as_hidden_inputs(false);

echo '<div class="search-ctable">';
ksort($display_options->items);
Expand Down Expand Up @@ -481,10 +483,12 @@ function echo_request_as_hidden_inputs($specialscore = false) {
echo '<div class="tllx"><table><tr>',
'<td><div class="tll active"><a class="ui tla" href="">Search</a></div></td>
<td><div class="tll"><a class="ui tla nw" href="#advanced">Advanced search</a></div></td>', "\n";
if ($ss)
if ($ss) {
echo ' <td><div class="tll"><a class="ui tla nw" href="#saved-searches">Saved searches</a></div></td>', "\n";
if ($pl->count > 0)
}
if ($pl->count > 0) {
echo ' <td><div class="tll"><a class="ui tla nw" href="#view">View options</a></div></td>', "\n";
}
echo "</tr></table></div></div>\n\n";
if ($pl->count == 0) {
Ht::stash_script("addClass(document.body,\"want-hash-focus\")");
Expand Down
6 changes: 4 additions & 2 deletions src/api/api_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ static function fieldhtml(Contact $user, Qrequest $qreq, PaperInfo $prow = null)
if (isset($qreq->aufull)) {
$pl->set_view("aufull", (bool) $qreq->aufull);
}
$response = $pl->column_json($qreq->f);
$pl->parse_view($qreq->f, null);
$response = $pl->table_html_json();

$j = ["ok" => !empty($response["fields"])] + $response;
foreach ($pl->message_set()->message_texts() as $m) {
Expand All @@ -79,7 +80,8 @@ static function fieldtext(Contact $user, Qrequest $qreq, PaperInfo $prow = null)
}
$search = new PaperSearch($user, $qreq);
$pl = new PaperList("empty", $search);
$response = $pl->text_json($qreq->f);
$pl->parse_view($qreq->f, null);
$response = $pl->text_json();

$j = ["ok" => !empty($response), "data" => $response];
foreach ($pl->message_set()->message_texts() as $m) {
Expand Down
5 changes: 3 additions & 2 deletions src/conference.php
Original file line number Diff line number Diff line change
Expand Up @@ -4281,11 +4281,12 @@ function footer() {
'<a class="uu" href="https://hotcrp.com/">HotCRP</a>';
if (!$this->opt("noFooterVersion")) {
if ($Me && $Me->privChair) {
echo " v", HOTCRP_VERSION;
echo " v", HOTCRP_VERSION, " [";
if (($git_data = self::git_status())
&& $git_data[0] !== $git_data[1]) {
echo " [", substr($git_data[0], 0, 7), "...]";
echo substr($git_data[0], 0, 7), "... ";
}
echo round(memory_get_peak_usage() / (1 << 20)), "M]";
} else {
echo "<!-- Version ", HOTCRP_VERSION, " -->";
}
Expand Down
21 changes: 12 additions & 9 deletions src/papercolumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class PaperColumn extends Column {
/** @var int */
public $override = 0;

const PREP_SORT = -1;
const PREP_FOLDED = 0; // value matters
const PREP_VISIBLE = 1; // value matters
const PREP_CHECK = 0;
const PREP_SORT = 1;
const PREP_VISIBLE = 2;
const PREP_TEXT = 4;

/** @param object $cj */
function __construct(Conf $conf, $cj) {
Expand Down Expand Up @@ -57,6 +58,7 @@ final function add_user_sort_decoration($decor) {
}
}

/** @param int $visible */
function prepare(PaperList $pl, $visible) {
return true;
}
Expand Down Expand Up @@ -106,11 +108,11 @@ function compare(PaperInfo $a, PaperInfo $b, PaperList $pl) {
return $a->paperId - $b->paperId;
}

/** @param list<PaperColumn> $columns */
function analyze(PaperList $pl, $columns) {
function analyze(PaperList $pl) {
}

/** @return string */
/** @param bool $is_text
* @return string */
function header(PaperList $pl, $is_text) {
if (isset($this->title_html) && !$is_text) {
return $this->title_html;
Expand All @@ -122,16 +124,17 @@ function header(PaperList $pl, $is_text) {
return "&lt;" . htmlspecialchars($this->name) . "&gt;";
}
}
/** @return string|false */
/** @return ?string */
function completion_name() {
if (!$this->completion) {
return false;
return null;
} else if (is_string($this->completion)) {
return $this->completion;
} else {
return $this->name;
}
}
/** @return string */
function sort_name() {
$decor = $this->decorations;
if (!empty($decor)) {
Expand Down Expand Up @@ -295,7 +298,7 @@ function prepare_sort(PaperList $pl, $sortindex) {
}
}
}
function analyze(PaperList $pl, $columns) {
function analyze(PaperList $pl) {
foreach ($pl->rowset() as $row) {
if ($row->outcome != 0 || $row->paperStorageId <= 1) {
$t = ($pl->user->paper_status_info($row))[1];
Expand Down
2 changes: 1 addition & 1 deletion src/papercolumns/pc_formula.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function compare(PaperInfo $a, PaperInfo $b, PaperList $pl) {
return $as == $bs ? 0 : ($as < $bs ? -1 : 1);
}
}
function analyze(PaperList $pl, $fields) {
function analyze(PaperList $pl) {
$formulaf = $this->formula_function;
$this->results = $this->override_results = [];
$isreal = $this->formula->result_format_is_real();
Expand Down
4 changes: 2 additions & 2 deletions src/papercolumns/pc_preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ function compare(PaperInfo $a, PaperInfo $b, PaperList $pl) {
}
return 0;
}
function analyze(PaperList $pl, $fields) {
function analyze(PaperList $pl) {
$pfcol = $rtcol = [];
foreach ($fields as $fdef) {
foreach ($pl->vcolumns() as $fdef) {
if ($fdef instanceof ReviewerType_PaperColumn) {
$rtcol[] = $fdef;
} else if ($fdef instanceof Preference_PaperColumn) {
Expand Down
2 changes: 1 addition & 1 deletion src/papercolumns/pc_tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function prepare(PaperList $pl, $visible) {
&& count($dt->emoji) === 1) {
$this->emoji = $dt->emoji[0];
}
if ($this->editable && $visible > 0 && $pl->table_id()) {
if ($this->editable && ($visible & PaperColumn::PREP_VISIBLE) && $pl->table_id()) {
$pl->has_editable_tags = true;
if (strcasecmp($this->etag, $pl->sort_etag()) === 0
&& $this->is_value) {
Expand Down
Loading

0 comments on commit a0cb37b

Please sign in to comment.