Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 6 commits
  • 15 files changed
  • 0 comments
  • 1 contributor
1  .gitignore
@@ -4,3 +4,4 @@ tmp
4 4 bin
5 5 WEB-INF
6 6 doc
  7 +.sass-cache
2  Gemfile
@@ -4,5 +4,7 @@ gem 'sinatra'
4 4 gem 'sinatra-static-assets'
5 5 gem 'emk-sinatra-url-for'
6 6 gem 'haml'
  7 +gem 'sass'
7 8 gem 'flickraw-cached'
8 9 gem 'json'
  10 +gem 'rack-flash3'
6 Gemfile.lock
@@ -10,8 +10,12 @@ GEM
10 10 json (1.6.5)
11 11 json (1.6.5-java)
12 12 rack (1.4.1)
  13 + rack-flash3 (1.0.1)
  14 + rack
  15 + rack
13 16 rack-protection (1.2.0)
14 17 rack
  18 + sass (3.1.18)
15 19 sinatra (1.3.2)
16 20 rack (~> 1.3, >= 1.3.6)
17 21 rack-protection (~> 1.2)
@@ -29,5 +33,7 @@ DEPENDENCIES
29 33 flickraw-cached
30 34 haml
31 35 json
  36 + rack-flash3
  37 + sass
32 38 sinatra
33 39 sinatra-static-assets
3  config.ru
... ... @@ -1,5 +1,8 @@
1 1 require 'rubygems'
2 2 require 'rack'
  3 +require 'bundler'
  4 +Bundler.require
  5 +
3 6 require 'init'
4 7
5 8 run Sinatra::Application
32 init.rb
... ... @@ -1,11 +1,16 @@
1 1 require 'rubygems'
2 2 require 'sinatra'
3 3 require 'haml'
  4 +require 'sass'
4 5 require 'sinatra/static_assets'
5 6 require 'sinatra/url_for'
  7 +require 'rack-flash'
6 8
7 9 require 'lib/pickr'
8 10
  11 +enable :sessions
  12 +use Rack::Flash
  13 +
9 14 get '/thumbnail/:id' do
10 15 @photo = Pickr::Photo.get(params[:id])
11 16
@@ -21,25 +26,44 @@
21 26 ""
22 27 end
23 28
  29 +get '/style/default.css' do
  30 + sass :style
  31 +end
  32 +
24 33 get '/?' do
25 34 haml :entry
26 35 end
27 36
28 37 get '/sets' do
29   - @person = Pickr::Person.get(params[:u])
  38 + begin
  39 + @person = Pickr::Person.get(params[:u])
  40 + rescue Pickr::Error => e
  41 + flash[:error] = e.message
  42 + redirect to('/')
  43 + end
30 44
31 45 haml :gallery
32 46 end
33 47
34 48 get '/:user_id/sets' do
35   - @person = Pickr::Person.get(params[:user_id])
  49 + begin
  50 + @person = Pickr::Person.get(params[:user_id])
  51 + rescue Pickr::Error => e
  52 + flash[:error] = e.message
  53 + redirect to('/')
  54 + end
36 55
37 56 haml :gallery
38 57 end
39 58
40 59 get '/:user_id/sets/:set_id' do
41   - @person = Pickr::Person.get(params[:user_id])
42   - @set = Pickr::PhotoSet.get(params[:set_id])
  60 + begin
  61 + @person = Pickr::Person.get(params[:user_id])
  62 + @set = Pickr::PhotoSet.get(params[:set_id])
  63 + rescue Pickr::Error => e
  64 + flash[:error] = e.message
  65 + redirect to("/#{params[:user_id]}/sets")
  66 + end
43 67
44 68 haml :set
45 69 end
72 lib/pickr.rb
@@ -60,14 +60,14 @@ def initialize(nsid, username, realname, location)
60 60
61 61 def username(opt=nil)
62 62 if opt == :urlencoded
63   - ::URL::Escape.encode(@username)
  63 + ::URI.escape(@username)
64 64 else
65 65 @username
66 66 end
67 67 end
68 68
69 69 def self.get(username)
70   - cache_by username do
  70 + cache_by :"person-#{username}" do
71 71 id =
72 72 if username =~ /\d{8,8}\@N\d\d/
73 73 username
@@ -91,7 +91,12 @@ def self.get(username)
91 91
92 92 username = info.username if id == username
93 93
94   - cache[username] = new(id, username, info.realname, info.location)
  94 + cache[username] =
  95 + if info.respond_to?(:realname) && info.respond_to?(:location)
  96 + Person.new(id, username, info.realname, info.location)
  97 + else
  98 + Person.new(id, username, '', '')
  99 + end
95 100 end
96 101 end
97 102
@@ -107,6 +112,7 @@ class PhotoSet < Cached
107 112 def initialize(set, photos=[])
108 113 @set = set
109 114 @id = set.id
  115 + @user_id = set.respond_to?(:owner) && set.owner
110 116 @title = set.title
111 117 @description = set.description
112 118 @photos = construct_photos(photos)
@@ -116,25 +122,29 @@ def initialize(set, photos=[])
116 122 private
117 123
118 124 def construct_photos(photos)
119   - photos.map {|p| Photo.new(p.id, p.title, p.server, p.secret) }
  125 + photos.map { |p| Photo.new(:id => p.id, :nsid => @user_id, :title => p.title, :server => p.server, :secret => p.secret) }
120 126 end
121 127
122 128 public
123 129
124 130 def primary_photo
125   - @primary_photo ||= Photo.new(@set.primary, @set.title, @set.server, @set.secret)
  131 + @primary_photo ||= Photo.new(:id => @set.primary, :title => @set.title, :server => @set.server, :secret => @set.secret, :nsid => @user_id)
126 132 end
127 133
128 134 def self.get(id)
129   - cache_by id do
130   - set = flickr.photosets.getPhotos :photoset_id => id
131   - info = flickr.photosets.getInfo :photoset_id => id
  135 + cache_by :"photoset-#{id}" do
  136 + begin
  137 + set = flickr.photosets.getPhotos :photoset_id => id
  138 + info = flickr.photosets.getInfo :photoset_id => id
  139 + rescue
  140 + raise Error, "Couldn't retrieve photoset #{id}"
  141 + end
132 142 cache[id] = new(info, set.photo)
133 143 end
134 144 end
135 145
136 146 def url
137   - "#{FLICKR_PHOTO_URL}/#{USER_ID}/sets/#{@id}"
  147 + "#{FLICKR_PHOTO_URL}/#{@user_id}/sets/#{@id}"
138 148 end
139 149
140 150 def to_hash
@@ -143,26 +153,36 @@ def to_hash
143 153 end
144 154
145 155 class Photo < Cached
146   - attr_reader :title
  156 + attr_reader :title, :nsid
147 157 attr_accessor :id, :secret, :server
148 158
149   - def initialize(id, title, server, secret)
150   - @id = id
151   - @title = title != '' ? title : "Untitled"
152   - @server = server
153   - @secret = secret
  159 + def initialize(args)
  160 + @id = args[:id] || raise(Error, "id is required")
  161 + @server = args[:server] || raise(Error, "server is required")
  162 + @secret = args[:secret] || raise(Error, "secret is required")
  163 + @user_id = args[:nsid]
  164 + @title = args[:title] != '' ? title : "Untitled"
154 165 end
155 166
156 167 def self.get(id)
157   - cache_by id do
158   - photo = flickr.photos.getInfo :photo_id => id
159   - cache[id] = new(id, photo.title, photo.server, photo.secret)
  168 + cache_by :"photo-#{id}" do
  169 + begin
  170 + photo = flickr.photos.getInfo :photo_id => id
  171 + rescue
  172 + raise Error, "Couldn't retrieve photo #{id}"
  173 + end
  174 +
  175 + user_id = photo.respond_to?(:owner) && photo.owner.respond_to?(:nsid) && photo.owner.nsid
  176 +
  177 + cache[id] = new(:id => id, :title => photo.title, :server => photo.server, :secret => photo.secret, :nsid => user_id)
160 178 end
161 179 end
162 180
163 181 #
164 182 # Generates url for photo of type:
165 183 # - square
  184 + # - square75
  185 + # - square150
166 186 # - thumbnail
167 187 # - original
168 188 # - medium
@@ -172,17 +192,23 @@ def self.get(id)
172 192 def url(type=SET_PHOTO_SIZE)
173 193 return @url unless @url.nil? # allows us to override url generation
174 194
  195 + @user_id ||= Photo.get(@id).nsid
  196 +
175 197 base_url = "#{FLICKR_STATIC_URL}/#{@server}/#{@id}_#{@secret}"
176   - page_url = "#{FLICKR_PHOTO_URL}/#{USER_ID}/#{@id}"
  198 + page_url = "#{FLICKR_PHOTO_URL}/#{@user_id}/#{@id}"
177 199
178 200 sizes = {
179 201 :square => "#{base_url}_s.jpg",
  202 + :square150 => "#{base_url}_q.jpg",
180 203 :thumbnail => "#{base_url}_t.jpg",
181 204 :original => "#{base_url}.jpg",
182 205 :medium => "#{base_url}_m.jpg",
183 206 :page => page_url,
184 207 :lightbox => "#{page_url}/lightbox"
185 208 }
  209 +
  210 + # alias for :square
  211 + sizes[:square75] = sizes[:square]
186 212
187 213 unless sizes.keys.include?(type.to_sym)
188 214 raise Error, "'#{type}' is not a valid URL type"
@@ -207,8 +233,12 @@ def initialize(user_id, sets)
207 233 end
208 234
209 235 def self.get(user_id)
210   - cache_by user_id do
211   - sets = flickr.photosets.getList :user_id => user_id
  236 + cache_by :"gallery-#{user_id}" do
  237 + begin
  238 + sets = flickr.photosets.getList :user_id => user_id
  239 + rescue
  240 + raise Error, "Couldn't retrieve photosets for user #{user_id}"
  241 + end
212 242 cache[user_id] = new(user_id, sets)
213 243 end
214 244 end
1  public/javascripts/pickr.js
@@ -6,7 +6,6 @@ $(document).ready(function(){
6 6 $('#selector #close-button').click(hideSelector);
7 7
8 8 $('input[name=photo]').change(function(){
9   - alert("changed");
10 9 if ( $(this).attr('checked') == true ) { selectPhoto($(this).val()) }
11 10 else { deSelectPhoto($(this).val()) }
12 11 });
4 public/stylesheets/screen.css
... ... @@ -1,4 +0,0 @@
1   -.set-photo, .photo {
2   - background: url(/images/loading.gif) center no-repeat;
3   - background-color: white;
4   -}
6 views/entry.haml
... ... @@ -1,5 +1,5 @@
1   -- if @error
2   - %p{ :class => 'message error' }= @error
  1 +- if flash[:error]
  2 + %p{ :class => 'message error' }= flash[:error]
3 3
4 4 %form{ :action => url_for('/sets'), :method => 'GET' }
5   - %input{ :value => 'Enter Flickr ID', :name => 'u', :type => 'text' }
  5 + %input{ :value => (@person && @person.username) || 'Enter Flickr ID', :name => 'u', :type => 'text' }
16 views/gallery.haml
... ... @@ -1,8 +1,14 @@
10 views/layout.haml
@@ -4,6 +4,12 @@
4 4 %title Pickr
5 5 - scripts = %w{ jquery jquery.flickr pickr }.map {|s| "/javascripts/#{s}.js" }
6 6 = javascript_script_tag *scripts
7   - = stylesheet_link_tag '/stylesheets/screen.css'
  7 + = stylesheet_link_tag '/style/default.css'
8 8 %body
9   - = yield
  9 + #selector
  10 + =haml :selector
  11 + #container
  12 + #header
  13 + #main
  14 + = yield
  15 + #footer
2  views/selector.haml
@@ -3,7 +3,7 @@
3 3 / currently selected images go here
4 4
5 5 %form{ :action => '/complete-selection', :method => 'POST' }
6   - %input{ :type => 'submit', :value => 'Go to Request Form&gt;&gt;' }
  6 + %input{ :type => 'submit', :value => 'Go to Request Form>>' }
7 7 /
8 8 %form{ :action => '#', :method => 'POST' }
9 9 %p
32 views/set.haml
... ... @@ -1,20 +1,4 @@
1   -:css
2   - #selector {
3   - position: relative;
4   - top: 0px;
5   - left: 0px;
6   - width: 100%;
7   - background: grey;
8   - padding: 10px;
9   - display: none;
10   - }
11   -
12   - .selector-thumb { display: inline }
13   -
14   -#selector
15   - =haml :selector
16   -
17   -%a{ :href => "/#{@person.username}/sets" } &lt;&lt;Back to Index
  1 +%a{ :href => "/#{@person.nsid}/sets" } &lt;&lt;Back to Index
18 2
19 3 %h1= @set.title
20 4 %span
@@ -24,12 +8,10 @@
24 8 #photo-list
25 9 - @set.photos.each do |photo|
26 10 .photo-region
27   - %a{ :href => '#', :onclick => "toogleCheckBox($('#select_#{photo.id}'));",
28   - :class => 'photo-link' }
29   -
30   - %img{ :class => 'photo', :id => "photo_#{photo.id}", :src => photo.url, :title => photo.title }
  11 + %a{ :href => '#', :onclick => "toogleCheckBox($('#select_#{photo.id}'));", :class => 'photo-link' }
  12 + %img{ :class => 'photo', :id => "photo_#{photo.id}", :src => photo.url(:square150), :title => photo.title, :width => 150, :height => 150 }
31 13
32   - %br
33   - %input{ :type => 'checkbox', :name => 'photo', :id => "select_#{photo.id}", :value => photo.id }
34   - %label{ :for => "select_#{photo.id}" } Select
35   - %a{ :href => photo.url(:lightbox), :target => "__page-#{photo.id}" } view on flickr
  14 + .controls
  15 + %input{ :type => 'checkbox', :name => 'photo', :id => "select_#{photo.id}", :value => photo.id }
  16 + %label{ :for => "select_#{photo.id}" } Select
  17 + %a{ :href => photo.url(:lightbox), :target => "__page-#{photo.id}" } view on flickr
38 views/style.sass
... ... @@ -0,0 +1,38 @@
  1 +body
  2 + font-family: Ubuntu, sans-serif
  3 + font-size: 10pt
  4 + margin: 0
  5 + padding: 0
  6 +
  7 +#container
  8 + margin: 10px
  9 +
  10 +.set-photo, .photo
  11 + background: url(/images/loading.gif) center no-repeat
  12 + background-color: white
  13 +
  14 +.photo-region
  15 + width: 160px
  16 + display: inline-block
  17 + margin: 5px
  18 +
  19 +#selector
  20 + position: fixed
  21 + top: 0
  22 + width: 100%
  23 + background: grey
  24 + opacity: 0.9
  25 +
  26 + padding: 10px
  27 + display: none
  28 + z-index: 9999
  29 +
  30 +.selector-thumb
  31 + display: inline
  32 +
  33 +img
  34 + background: white url(/images/loading.gif) center no-repeat
  35 +
  36 +input[name=u]
  37 + font-size: 36pt
  38 + border: 2pt solid #aaa
5 views/thumbnail.haml
... ... @@ -1,8 +1,7 @@
1 1 .selector-thumb{ :id => "selector-thumb-#{@photo.id}" }
2 2 %input{ :type => 'hidden', :class => 'url', :name => "url_#{@photo.id}",
3   - :id => "url_#{@photo.id}", :value => @photo.url(:thumb) }
  3 + :id => "url_#{@photo.id}", :value => @photo.url(:thumbnail) }
4 4
5 5 / TODO: create a javascript function for "onclick" stuff
6 6 %a{ :class => "selected_photo", :id => @photo.id, :onclick => "deSelectPhoto('#{@photo.id}')" }
7   - %img{ :width => 75, :height => 75, :src => @photo.url(:square),
8   - :style => 'background: url(/images/loading.gif) center no-repeat; background-color: white' }
  7 + %img{ :width => 75, :height => 75, :src => @photo.url(:square) }

No commit comments for this range

Something went wrong with that request. Please try again.