Skip to content

Commit

Permalink
photos working wo javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
tempire committed Apr 3, 2011
1 parent 1aa5d2c commit dde184c
Show file tree
Hide file tree
Showing 10 changed files with 945 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/Nempire.pm
Expand Up @@ -35,6 +35,7 @@ sub startup {

$r->get('/photos')->to('photos#index');
$r->get('/photos/:id')->over('photoset')->to('photos#show_set');
$r->get('/photos/:id')->to('photos#show');
}

1;
14 changes: 14 additions & 0 deletions lib/Nempire/Photos.pm
Expand Up @@ -13,6 +13,19 @@ sub index {
$self->render(template => 'photos/index');
}

sub show {
my $self = shift;
my $id = $self->stash->{id};

my $photo = $self->db->resultset('Photo')->find($id)
or $self->redirect_to("/photos")
and return;

$self->stash(photo => $photo);

$self->render(template => 'photos/show');
}

sub show_set {
my $self = shift;
my $id = $self->stash->{id};
Expand All @@ -25,4 +38,5 @@ sub show_set {

$self->render(template => 'photos/show_set');
}

1;
63 changes: 63 additions & 0 deletions lib/Nempire/Schema/Result/Photo.pm
Expand Up @@ -217,6 +217,28 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-12 21:00:40
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tE5yRrWVQRn/KUo9euKbRA

=head2 set
Type: belongs_to
Related object: L<Nempire::Schema::Result::Photoset>
Alias for L<Nempire::Schema::Result::Photo/photoset>
=cut

__PACKAGE__->belongs_to(
"set",
"Nempire::Schema::Result::Photoset",
{ id => "photoset" },
{
is_deferrable => 1,
join_type => "LEFT",
on_delete => "CASCADE",
on_update => "CASCADE",
},
);

sub location {
my $self = shift;

Expand All @@ -225,12 +247,53 @@ sub location {
$location .= $self->region if $self->region;
}

sub next {
my $self = shift;

return if !$self->idx;

return $self->result_source->resultset->find(
{ photoset => $self->set->id,
idx => $self->idx + 1
}
);
}

sub previous {
my $self = shift;

return if !$self->idx;

return $self->result_source->resultset->find(
{ photoset => $self->set->id,
idx => $self->idx - 1
}
);
}

sub time_since {
my $self = shift;
return Time::Duration::ago(time - $self->taken->epoch) if $self->taken;
}

=head1 METHODS
=head2 location
City, State
=head2 previous
Previous photo in set according to idx
=head2 next
Next photo in set according to idx
=head2 time_since
Time since photo was taken
=cut

1;
733 changes: 733 additions & 0 deletions log/development.log

Large diffs are not rendered by default.

53 changes: 52 additions & 1 deletion t/fixtures/Photoset → t/fixtures/Photoset.pl
Expand Up @@ -52,6 +52,31 @@
timestamp => "2011-03-13 03:07:59",
videos => 0,
photos => [
{ country => "United States",
description => "",
id => 4839640560,
idx => 11,
is_glen => undef,
isprimary => undef,
large => undef,
lat => "29.7633",
locality => "Houston",
lon => "-95.363297",
medium =>
"http://farm5.static.flickr.com/4130/4839640560_991ac99663.jpg",
original =>
"http://farm5.static.flickr.com/4130/4839640560_d9ded10dc6_o.jpg",
original_url => undef,
photoset => "72157624605770036",
region => "Texas",
small =>
"http://farm5.static.flickr.com/4130/4839640560_991ac99663_m.jpg",
square =>
"http://farm5.static.flickr.com/4130/4839640560_991ac99663_s.jpg",
taken => "2010-07-19 15:49:39",
thumbnail =>
"http://farm5.static.flickr.com/4130/4839640560_991ac99663_t.jpg",
},
{ country => "United States",
description => "",
id => 4839028825,
Expand All @@ -76,7 +101,33 @@
taken => "2010-07-13 13:57:42",
thumbnail =>
"http://farm5.static.flickr.com/4149/4839028825_4dbcdb0b0e_t.jpg",
}
},
{ country => "United States",
description => "Fancy Sunday!",
id => 4839028523,
idx => 13,
is_glen => undef,
isprimary => undef,
large => undef,
lat => "29.7633",
locality => "Houston",
lon => "-95.363297",
medium =>
"http://farm5.static.flickr.com/4085/4839028523_d233aa78e2.jpg",
original =>
"http://farm5.static.flickr.com/4085/4839028523_47228e35fb_o.jpg",
original_url => undef,
photoset => "72157624605770036",
region => "Texas",
small =>
"http://farm5.static.flickr.com/4085/4839028523_d233aa78e2_m.jpg",
square =>
"http://farm5.static.flickr.com/4085/4839028523_d233aa78e2_s.jpg",
taken => "2010-07-25 19:04:50",
thumbnail =>
"http://farm5.static.flickr.com/4085/4839028523_d233aa78e2_t.jpg",
},

]
},
Photoset => {
Expand Down
10 changes: 9 additions & 1 deletion t/nempire/schema/result/photo.t
Expand Up @@ -5,11 +5,19 @@ use Devel::Dwarn;
use Test::Most;
use Test::Database;

my $photo_id = '4839028825';
my $photo_id = '4839028825';
my $next_photo_id = '4839028523';
my $prev_photo_id = '4839640560';
my $photoset_id = '72157624605770036';

my $schema = Test::Database->new_test->schema;
my $photo = $schema->resultset('Photo')->find($photo_id);

is $photo->location => 'League City, Texas';
is $photo->set->id => $photoset_id, 'photoset id';
is $photo->previous->id => $prev_photo_id, 'previous photo';
is $photo->next->id => $next_photo_id, 'next photo';

like $photo->time_since => qr/\d+ days and \d+ hours ago/;

done_testing;
2 changes: 1 addition & 1 deletion t/nempire/schema/result/photoset.t
Expand Up @@ -26,7 +26,7 @@ is $set->primary->id => $set->primary_photo->id, 'primary photo alias';
is $set->region => 'Texas';
is $set->url_title => $photoset_title;
is $set->location => 'League City, Texas';
is $set->time_since => 1;
like $set->time_since => qr/\d+ days and \d+ hours ago/;

is $set->previous->id => $prev_photoset_id, 'previous photoset';
is $set->next->id => $next_photoset_id, 'next photoset';
Expand Down
30 changes: 18 additions & 12 deletions t/photos.t
Expand Up @@ -10,23 +10,29 @@ $t->get_ok('/photos')->status_is(200)
->element_exists('div#photosets[class*="thumbnails"]')
->content_like(qr/\d+\s+photos in\s+\d+\s+albums/i);

ok my $album_id =
ok my $set_id =
$t->tx->res->dom('div#photosets > div.photo')->[0]->attrs('id'),
'album id';
ok my $album_url =
'set id';
ok my $set_url =
$t->tx->res->dom('div#photosets > div.photo > a')->[0]->attrs('href'),
'album url';
ok my $album_title =
'set url';
ok my $set_title =
$t->tx->res->dom('div#photosets > div.photo > a div.title')->[0]->text,
'album title';
'set title';


is length $album_id => 17;
is length $set_id => 17;

# Show set
$t->get_ok($album_url)->status_is(200)->text_is(h1 => $album_title);
$t->get_ok("/photos/$album_id")->status_is(200)->text_is(h1 => $album_title);
$t->get_ok("/photos/$album_title")->status_is(200)
->text_is(h1 => $album_title);
$t->get_ok($set_url)->status_is(200)->text_is(h1 => $set_title);
$t->get_ok("/photos/$set_id")->status_is(200)->text_is(h1 => $set_title);
$t->get_ok("/photos/$set_title")->status_is(200)->text_is(h1 => $set_title);

ok my $photo_url =
$t->tx->res->dom('div.photoset a.slide')->[0]->attrs('href'), 'photo url';

like $photo_url => qr|^/photos/\d+$|;

warn $photo_url;
$t->get_ok($photo_url)->status_is(200)->text_like('h1 a.title' => qr/$set_title/);

done_testing;
51 changes: 51 additions & 0 deletions templates/photos/show.html.ep
@@ -0,0 +1,51 @@
% layout 'default';
% my $title = $photo->set->title . '-' . $photo->idx . ' of ' . $photo->set->photos->count;
% title $title;


<div id="<%= $photo->id %>" class="photo wide slide">
<span class="pagetitle hidden"><%= $title %></span>
<h1><a
class="title"
href="/photos/<%= $photo->set->url_title %>"
title="<%= $photo->set->id %>">
%= $photo->set->title
</a>
</h1>

<div class="nav">
% if ($photo->previous) {
<a class="previous" href="/photos/<%= $photo->previous->id %>">
Previous</a>
% }
% if ($photo->next) {
<a class="previous" href="/photos/<%= $photo->next->id %>">
Next</a>
% }
</div>

<ul class="horizontal-list">
<li><span class="location">
<%= $photo->location %></span></li>
<li><span class="time">
<%= $photo->taken->month_name %>, <%= $photo->taken->year %></span></li>
<li><span class="time_since">
<%= $photo->time_since %></span></li>
<li><span class="count">
<%= $photo->idx %> of <%= $photo->set->photos->count %></span></li>
</ul>

<br />

<div class="photos">
% if ($photo->next) {
<a class="photo next" href="/photos/<%= $photo->next->id %>">
<img src="<%= $photo->medium %>" alt="<%= $photo->description %>" /></a>
% }
% else {
<a class="photo" href="/photosets/<%= $photo->set->url_title %>">
<img src="<%= $photo->medium %>" alt="<%= $photo->description %>" /></a>
% }
</div>

</div>
6 changes: 3 additions & 3 deletions templates/photos/show_set.html.ep
@@ -1,7 +1,7 @@
% layout 'default';
% title $set->title . ' Phased albums';

<div id="<%= $set->url_title %>" class="set thumbnails slide">
<div id="<%= $set->url_title %>" class="photoset thumbnails slide">
<div class="toolbar">
% if ($set->previous) {
<a href="/photos/<%= $set->previous->url_title %>" class="previous">Previous</a>
Expand All @@ -18,12 +18,12 @@
<li><span class="time_since">
<%= $set->time_since %></span></li>
<li><span class="count">
<%= $set->photo_count %> Photos</span></li>
<%= $set->photos->count %> Photos</span></li>
</ul>
</div>
<div>
% foreach my $photo ( $set->photos->all ) {
<a href="#<%= $set->url_title %>"
<a href="/photos/<%= $photo->id %>"
class="slide"
rel:index="<%= $photo->idx %>"
rel:medium="<%= $photo->medium %>">
Expand Down

0 comments on commit dde184c

Please sign in to comment.