aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm34
-rw-r--r--perllib/FixMyStreet/App/Model/PhotoSet.pm22
-rw-r--r--t/app/controller/admin.t3
-rw-r--r--templates/web/base/admin/report_edit.html32
4 files changed, 74 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 0fc87c2f6..f2d6040ae 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -790,11 +790,12 @@ sub report_edit : Path('report_edit') : Args(1) {
}
# Deal with photos
- if ( $c->get_param('remove_photo') ) {
- $problem->photo(undef);
+ my $remove_photo_param = $self->_get_remove_photo_param($c);
+ if ($remove_photo_param) {
+ $self->remove_photo($c, $problem, $remove_photo_param);
}
- if ( $c->get_param('remove_photo') || $new_state eq 'hidden' ) {
+ if ( $remove_photo_param || $new_state eq 'hidden' ) {
unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' );
}
@@ -1507,6 +1508,33 @@ sub rotate_photo : Private {
return 1;
}
+=head2 remove_photo
+
+Remove a photo from a report
+
+=cut
+
+# Returns index of photo(s) to remove, if any
+sub _get_remove_photo_param {
+ my ($self, $c) = @_;
+
+ return 'ALL' if $c->get_param('remove_photo');
+
+ my @keys = map { /(\d+)$/ } grep { /^remove_photo_/ } keys %{ $c->req->params } or return;
+ return \@keys;
+}
+
+sub remove_photo : Private {
+ my ($self, $c, $object, $keys) = @_;
+ if ($keys eq 'ALL') {
+ $object->photo(undef);
+ } else {
+ my $fileids = $object->get_photoset($c)->remove_images($keys);
+ $object->photo($fileids);
+ }
+ return 1;
+}
+
=head2 check_page_allowed
Checks if the current catalyst action is in the list of allowed pages and
diff --git a/perllib/FixMyStreet/App/Model/PhotoSet.pm b/perllib/FixMyStreet/App/Model/PhotoSet.pm
index e8396b5aa..7b95e93d4 100644
--- a/perllib/FixMyStreet/App/Model/PhotoSet.pm
+++ b/perllib/FixMyStreet/App/Model/PhotoSet.pm
@@ -239,6 +239,28 @@ sub delete_cached {
);
}
+sub remove_images {
+ my ($self, $ids) = @_;
+
+ my @images = $self->all_images;
+ my $dec = 0;
+ for (sort { $a <=> $b } @$ids) {
+ splice(@images, $_ + $dec, 1);
+ --$dec;
+ }
+ my @items = map $_->[0], @images;
+
+ my $new_set = (ref $self)->new({
+ data_items => \@items,
+ c => $self->c,
+ object => $self->object,
+ });
+
+ $self->delete_cached();
+
+ return $new_set->data; # e.g. new comma-separated fileid
+}
+
sub rotate_image {
my ($self, $index, $direction) = @_;
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 07d72de96..42fd076c7 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -8,8 +8,9 @@ my $mech = FixMyStreet::TestMech->new;
my $user =
FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+ ->find_or_create( { email => 'test@example.com' } );
ok $user, "created test user";
+$user->update({ name => 'Test User' });
my $user2 =
FixMyStreet::App->model('DB::User')
diff --git a/templates/web/base/admin/report_edit.html b/templates/web/base/admin/report_edit.html
index d04a1a82b..8cb513be8 100644
--- a/templates/web/base/admin/report_edit.html
+++ b/templates/web/base/admin/report_edit.html
@@ -77,20 +77,26 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a>
<li><label class="inline" for="non_public">[% loc('Private') %]:</label> <input type="checkbox" name="non_public"[% ' checked' IF problem.non_public %]></li>
[% IF problem.photo %]
-[% photo = problem.get_photo_params %]
-<li><img alt="Photo of this report" height="[% photo.height %]" width="[% photo.width %]" src="[% c.cobrand.base_url %]
- [%~ IF problem.photo.length == 40 ~%]
- /photo/[% problem.photo %].temp.jpeg
- [%~ ELSE ~%]
- [% photo.url %]
- [%~ END %]">
-<br>
-<input type="submit" name="rotate_photo" value="[% loc('Rotate Left') %]">
-<input type="submit" name="rotate_photo" value="[% loc('Rotate Right') %]">
-<br>
-<input type="checkbox" id="remove_photo" name="remove_photo" value="1">
-<label class="inline" for="remove_photo">[% loc("Remove photo (can't be undone!)") %]</label></li>
+<li>
+<ul>
+ [% FOR photo IN problem.get_photoset(c).images %]
+ <li>
+ <div class="update-img">
+ <a href="[% c.cobrand.base_url %]/photo/[% photo.0 %].fulltemp.jpeg" rel="fancy">
+ <img alt="Photo of this report" src="[% c.cobrand.base_url %]/photo/[% photo.0 %].temp.jpeg">
+ <span>zoom</span>
+ </a>
+ </div>
+ <input type="submit" name="rotate_photo_[% loop.index %]" value="[% loc('Rotate Left') %]">
+ <input type="submit" name="rotate_photo_[% loop.index %]" value="[% loc('Rotate Right') %]">
+ <input type="checkbox" id="remove_photo_[% loop.index %]" name="remove_photo_[% loop.index %]" value="1">
+ <label class="inline" for="remove_photo_[% loop.index %]">[% loc("Remove photo (can't be undone!)") %]</label></li>
+ </li>
+ [% END %]
+</ul>
+</li>
[% END %]
+
</ul>
<input type="submit" name="Submit changes" value="[% loc('Submit changes') %]" ></form>