Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templatization of display_recent_changes() in Display.pm #5530

Merged
merged 2 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10536,7 +10536,7 @@ XML
sub display_recent_changes {

my ($request_ref, $query_ref, $limit, $page) = @_;

add_params_to_query($request_ref, $query_ref);

add_country_and_owner_filters_to_query($request_ref, $query_ref);
Expand Down Expand Up @@ -10586,9 +10586,13 @@ sub display_recent_changes {
});
$log->info("MongoDB query ok", { error => $@ }) if $log->is_info();

my $html = "<ul>\n";
my $html = '';
my $last_change_ref = undef;
my @cumulate_changes = ();
my $template_data_ref_changes = {};
my @changes;


while (my $change_ref = $cursor->next) {
# Conversion for JSON, because the $change_ref cannot be passed to encode_json.
my $change_hash = {
Expand All @@ -10602,13 +10606,16 @@ sub display_recent_changes {
diffs => $change_ref->{diffs}
};

my $changes_ref = {};

# security: Do not expose IP addresses to non-admin or anonymous users.
delete $change_hash->{ip} unless $admin;

push @{$request_ref->{structured_response}{changes}}, $change_hash;
my $diffs = compute_changes_diff_text($change_ref);
$change_hash->{diffs_text} = $diffs;

$changes_ref->{cumulate_changes} = @cumulate_changes;
if (defined $last_change_ref and $last_change_ref->{code} == $change_ref->{code}
and $change_ref->{userid} == $last_change_ref->{userid} and $change_ref->{userid} ne 'kiliweb') {

Expand All @@ -10618,24 +10625,29 @@ sub display_recent_changes {
}
elsif (@cumulate_changes > 0) {

$html.= "<details class='recent'><summary>" . lang('collapsed_changes') . "</summary>";
my @cumulate_changes_display;

foreach (@cumulate_changes) {
$html.= display_change($_, compute_changes_diff_text($_));
push(@cumulate_changes_display, {
display_change => display_change($_, compute_changes_diff_text($_)),
});
}
$html.= "</details>";

$changes_ref->{cumulate_changes_display} = \@cumulate_changes_display;
@cumulate_changes = ();

}
$html.= display_change($change_ref, $diffs);

$changes_ref->{display_change} = display_change($change_ref, $diffs);
push(@changes, $changes_ref);

$last_change_ref = $change_ref;
}

# Display...

$html .= "</ul>";
$html .= "\n<hr>" . display_pagination($request_ref, $count, $limit, $page);
$template_data_ref_changes->{changes} = \@changes;
$template_data_ref_changes->{display_pagination} = display_pagination($request_ref, $count, $limit, $page);
process_template('web/common/includes/display_recent_changes.tt.html', $template_data_ref_changes, \$html) || ($html .= 'template error: ' . $tt->error());

${$request_ref->{content_ref}} .= $html;
$request_ref->{title} = lang("recent_changes");
Expand Down
19 changes: 19 additions & 0 deletions templates/web/common/includes/display_recent_changes.tt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- start templates/[% template.name %] -->

<ul>
[% FOREACH change IN changes %]
[% FOREACH cumulate_change IN change.cumulate_changes_display %]
<details class='recent'>
<summary> [% lang('collapsed_changes') %]
</summary>
[% cumulate_change.display_change %]
</details>
[% END %]

[% change.display_change %]
[% END %]
</ul>
<hr>
[% display_pagination %]

<!-- end templates/[% template.name %] -->