diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-07 18:08:58 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-07 18:09:05 +0000 |
commit | 3d631a9ee48fbff1741525f7ad9e9a530854d03b (patch) | |
tree | 0a1f2ad022fe90145fe78938fb7ca844dadb370f | |
parent | 54aeaf92acf5091c3b90d91848005893371e9590 (diff) |
Add hash as query parameter on photos so that rotating instantly works, no cache issues (fixes a3).
-rw-r--r-- | perllib/FixMyStreet/App.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 31 | ||||
-rw-r--r-- | templates/web/default/alert/index.html | 6 | ||||
-rw-r--r-- | templates/web/default/alert/list.html | 6 | ||||
-rw-r--r-- | templates/web/default/index.html | 6 | ||||
-rw-r--r-- | templates/web/fixmybarangay/alert/index.html | 6 | ||||
-rw-r--r-- | templates/web/fixmystreet/index.html | 3 | ||||
-rw-r--r-- | templates/web/fixmystreet/report/_item.html | 6 | ||||
-rw-r--r-- | templates/web/zurich/report/_item.html | 6 |
9 files changed, 54 insertions, 37 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index b76f4d3ba..b57e78a9e 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -443,18 +443,27 @@ Hashref contains height, width and url keys. sub get_photo_params { my ($self, $key) = @_; - $key = ($key eq 'id') ? '' : "/$key"; return {} unless $self->photo; + $key = ($key eq 'id') ? '' : "/$key"; + + my $pre = "/photo$key/" . $self->id; + my $post = '.jpeg'; + my $str = \$self->photo; my $photo = {}; + if (length($self->photo) == 40) { - $photo->{url_full} = '/photo' . $key . '/' . $self->id . '.full.jpeg'; - } else { - ( $photo->{width}, $photo->{height} ) = - Image::Size::imgsize( \$self->photo ); + $post .= '?' . $self->photo; + $photo->{url_full} = "$pre.full$post"; + $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg'; } - $photo->{url} = '/photo' . $key . '/' . $self->id . '.jpeg'; + + ( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str ); + + $photo->{url} = "$pre$post"; + $photo->{url_tn} = "$pre.tn$post"; + $photo->{url_fp} = "$pre.fp$post"; return $photo; } diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 10c0f3ce3..4fa9992f2 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -621,13 +621,7 @@ sub report_edit : Path('report_edit') : Args(1) { $c->forward('get_token'); - if ( $c->req->param('rotate_photo') ) { - $c->forward('rotate_photo'); - return 1; - } - if ( $c->cobrand->moniker eq 'zurich' ) { - FixMyStreet::Map::display_map( $c, latitude => $problem->latitude, @@ -641,7 +635,14 @@ sub report_edit : Path('report_edit') : Args(1) { } ] : [], ); + } + if ( $c->req->param('rotate_photo') ) { + $c->forward('rotate_photo'); + return 1; + } + + if ( $c->cobrand->moniker eq 'zurich' ) { my $done = $c->cobrand->admin_report_edit(); return if $done; } @@ -1320,7 +1321,7 @@ sub rotate_photo : Private { my ( $self, $c ) =@_; my $direction = $c->req->param('rotate_photo'); - return unless $direction =~ /Left/ or $direction =~ /Right/; + return unless $direction eq _('Rotate Left') or $direction eq _('Rotate Right'); my $photo = $c->stash->{problem}->photo; my $file; @@ -1331,14 +1332,12 @@ sub rotate_photo : Private { $photo = $file->slurp; } - $photo = _rotate_image( $photo, $direction =~ /Left/ ? -90 : 90 ); + $photo = _rotate_image( $photo, $direction eq _('Rotate Left') ? -90 : 90 ); return unless $photo; - my $fileid; - if ( !$file ) { - $fileid = sha1_hex($photo); - $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - } + # Write out to new location + my $fileid = sha1_hex($photo); + $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); $c->stash->{rotated} = 1; @@ -1348,10 +1347,8 @@ sub rotate_photo : Private { unlink glob FixMyStreet->path_to( 'web', 'photo', $c->stash->{problem}->id . '.*' ); - if ( $fileid ) { - $c->stash->{problem}->photo( $fileid ); - $c->stash->{problem}->update(); - } + $c->stash->{problem}->photo( $fileid ); + $c->stash->{problem}->update(); return 1; } diff --git a/templates/web/default/alert/index.html b/templates/web/default/alert/index.html index 1f0635ae4..36c0daf91 100644 --- a/templates/web/default/alert/index.html +++ b/templates/web/default/alert/index.html @@ -40,9 +40,11 @@ To find out what local alerts we have for you, please enter your [% c.cobrand.co <div class="sticky-sidebar" id="alert_recent"> <aside> <h2>[% loc('Some photos of recent reports') %]</h2> - [% FOREACH p IN photos %] + [% FOREACH p IN photos; + photo = p.get_photo_params; + %] <a href="/report/[% p.id %]"><img border="0" height="100" - src="/photo/[% p.id %].tn.jpeg" alt="[% p.title | html %]" title="[% p.title | html %]"></a> + src="[% photo.url_tn %]" alt="[% p.title | html %]" title="[% p.title | html %]"></a> [% END %] </aside> </div> diff --git a/templates/web/default/alert/list.html b/templates/web/default/alert/list.html index 20ebbf455..447bfcd76 100644 --- a/templates/web/default/alert/list.html +++ b/templates/web/default/alert/list.html @@ -24,9 +24,11 @@ <div id="alert_photos" class="sticky-sidebar"> <aside> <h2>[% loc('Photos of recent nearby reports') %]</h2> - [% FOREACH p IN photos %] + [% FOREACH p IN photos; + photo = p.get_photo_params; + %] <a href="/report/[% p.id %]"><img border="0" height="100" - src="/photo/[% p.id %].tn.jpeg" alt="[% p.title | html %]" title="[% p.title | html %]"></a> + src="[% photo.url_tn %]" alt="[% p.title | html %]" title="[% p.title | html %]"></a> [% END %] </aside> </div> diff --git a/templates/web/default/index.html b/templates/web/default/index.html index beaeefb20..9dc6f54b2 100644 --- a/templates/web/default/index.html +++ b/templates/web/default/index.html @@ -41,9 +41,11 @@ <h2>[% loc('Recently reported problems') %]</h2> [% IF recent_photos.size %] <p id="front_photos"> - [% FOREACH p IN recent_photos %] + [% FOREACH p IN recent_photos; + photo = p.get_photo_params; + %] <a href="/report/[% p.id %]"><img border="0" height="100" - src="/photo/[% p.id %].tn.jpeg" alt="[% p.title | html %]" title="[% p.title | html %]"></a> + src="[% photo.url_tn %]" alt="[% p.title | html %]" title="[% p.title | html %]"></a> [% END %] </p> [% END %] diff --git a/templates/web/fixmybarangay/alert/index.html b/templates/web/fixmybarangay/alert/index.html index d9bb74ee9..8e2ce7518 100644 --- a/templates/web/fixmybarangay/alert/index.html +++ b/templates/web/fixmybarangay/alert/index.html @@ -30,9 +30,11 @@ FixMyBarangay has a RSS feeds and email alerts for local problems. <div class="sticky-sidebar" id="alert_recent"> <aside> <h2>[% loc('Some photos of recent reports') %]</h2> - [% FOREACH p IN photos %] + [% FOREACH p IN photos; + photo = p.get_photo_params + %] <a href="/report/[% p.id %]"><img border="0" height="100" - src="/photo/[% p.id %].tn.jpeg" alt="[% p.title | html %]" title="[% p.title | html %]"></a> + src="[% photo.url_tn %]" alt="[% p.title | html %]" title="[% p.title | html %]"></a> [% END %] </aside> </div> diff --git a/templates/web/fixmystreet/index.html b/templates/web/fixmystreet/index.html index 5d7d31baa..f45509891 100644 --- a/templates/web/fixmystreet/index.html +++ b/templates/web/fixmystreet/index.html @@ -47,8 +47,7 @@ kinds of problems like missed bins use our <section class="full-width"> <ul class="issue-list-a"> [% FOREACH problem IN recent_photos %] - [% problem.photo = 1; # Definitely is - INCLUDE 'report/_item.html', no_fixed = 1 %] + [% INCLUDE 'report/_item.html', no_fixed = 1 %] [% END %] </ul> </section> diff --git a/templates/web/fixmystreet/report/_item.html b/templates/web/fixmystreet/report/_item.html index 508b02614..f910d0f8c 100644 --- a/templates/web/fixmystreet/report/_item.html +++ b/templates/web/fixmystreet/report/_item.html @@ -1,7 +1,9 @@ <li> <a class="text" href="[% c.uri_for('/report', problem.id ) %]"> - [% IF problem.photo %] - <img class="img" height="60" width="90" src="/photo/[% problem.id %].fp.jpeg" alt=""> + [% IF problem.photo; + photo = problem.get_photo_params + %] + <img class="img" height="60" width="90" src="[% photo.url_fp %]" alt=""> [% END %] <h4>[% problem.title | html %]</h4> <small>[% prettify_dt( problem.confirmed_local, 1 ) %] diff --git a/templates/web/zurich/report/_item.html b/templates/web/zurich/report/_item.html index 41164cdd1..cd44a1b67 100644 --- a/templates/web/zurich/report/_item.html +++ b/templates/web/zurich/report/_item.html @@ -1,7 +1,9 @@ <li> <a class="text" href="[% c.uri_for('/report', problem.id ) %]"> - [% IF problem.state != 'unconfirmed' AND problem.photo AND problem.extra.publish_photo %] - <img class="img" height="60" width="90" src="/photo/[% problem.id %].fp.jpeg" alt=""> + [% IF problem.state != 'unconfirmed' AND problem.photo AND problem.extra.publish_photo; + photo = problem.get_photo_params + %] + <img class="img" height="60" width="90" src="[% photo.url_fp %]" alt=""> [% END %] [% IF problem.state != 'unconfirmed' %] <h4>[% problem.title | html %]</h4> |