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

Display photo changes in report moderation updates. #4266

Merged
merged 1 commit into from
Jan 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Add role filter to dashboard interface.
- Alerts are paginated on user edit page. #4158
- Restrict flagging users and reports to superusers.
- Display photos in report moderation updates, rather than just the image hashes.
- Development improvements:
- Default make_css to `web/cobrands` rather than `web`.
- Ability to pass custom arguments (eg: SSL config) to server when running via Docker
Expand Down
38 changes: 21 additions & 17 deletions perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,30 @@ sub compare_coords {
sub compare_photo {
my ($self, $other) = @_;

my $old = $self->photo || '';
my $new = $other->photo || '';
return '' if $old eq $new;

$old = [ split /,/, $old ];
$new = [ split /,/, $new ];
my $old = $self->photos;
my $new = $other->photos;

my $diff = Algorithm::Diff->new( $old, $new );
my (@added, @deleted);
while ( $diff->Next ) {
next if $diff->Same;
push @deleted, $diff->Items(1);
push @added, $diff->Items(2);

my %old_photo_ids_set = map { $_->{id} => 1 } @$old;

my %new_photo_ids_set;
foreach (@$new) {
$new_photo_ids_set{ $_->{id} } = 1;
push @added, $_ unless $old_photo_ids_set{ $_->{id} };
}
my $s = (join ', ', map {
"<del style='background-color:#fcc'>$_</del>";
} @deleted) . (join ', ', map {
"<ins style='background-color:#cfc'>$_</ins>";
} @added);
return FixMyStreet::Template::SafeString->new($s);
foreach (@$old) {
push @deleted, $_ unless $new_photo_ids_set{ $_->{id} };
}

if (!@added && !@deleted) {
return "";
}

return {
added => \@added,
deleted => \@deleted,
};
}

# This is a list of extra keys that could be set on a report after a moderation
Expand Down
2 changes: 1 addition & 1 deletion templates/web/base/report/update/moderation_diff.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul>
[% IF diff.title %]<li>[% loc('Subject:') %] [% diff.title %][% END %]
[% IF diff.detail %]<li>[% loc('Details:') %] [% diff.detail %][% END %]
[% IF diff.photo %]<li>[% loc('Photo') %]: [% diff.photo %][% END %]
[% IF diff.photo %]<li>[% INCLUDE 'report/update/moderation_photo_diff.html' added=diff.photo.added deleted=diff.photo.deleted %][% END %]
[% IF diff.anonymous %]<li>[% loc('Anonymous:') %] [% diff.anonymous %][% END %]
[% IF diff.coords %]<li>[% loc('Latitude/Longitude:') %] [% diff.coords %][% END %]
[% IF diff.category %]<li>[% loc('Category:') %] [% diff.category %][% END %]
Expand Down
26 changes: 26 additions & 0 deletions templates/web/base/report/update/moderation_photo_diff.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[% IF added %]
[% loc('Photos added') %]:
<div class="update-img-set">
[% FOR photo IN added %]
<div class="update-img">
<a href="[% photo.url_temp_full %]" rel="fancy">
<img alt="[% loc('Photo added to this report in this moderation update') %]" src="[% photo.url_temp %]">
<span>zoom</span>
</a>
</div>
[% END %]
</div>
[% END %]
[% IF deleted %]
[% loc('Photos deleted') %]:
<div class="update-img-set">
[% FOR photo IN deleted %]
<div class="update-img">
<a href="[% photo.url_temp_full %]" rel="fancy">
<img alt="[% loc('Photo deleted from this report in this moderation update') %]" src="[% photo.url_temp %]">
<span>zoom</span>
</a>
</div>
[% END %]
</div>
[% END %]