Browse Source

Add buttons and dropdowns for the UI

Douglas Thrift 6 years ago
parent
commit
16d089f02e
3 changed files with 76 additions and 3 deletions
  1. 36 0
      app.rb
  2. 34 2
      views/index.erb
  3. 6 1
      views/layout.erb

+ 36 - 0
app.rb

@@ -13,11 +13,15 @@ enable :sessions
 
 set :database, 'sqlite://db.sqlite3'
 
+FlickRaw.api_key = settings.flickr_api_key
+FlickRaw.shared_secret = settings.flickr_shared_secret
+
 migration 'create users, licenses, and photos tables' do
   database.create_table :users do
     column :nsid, String, primary_key: true
     column :username, String
     column :fullname, String
+    # column :json, 'text'
   end
 
   database.create_table :licenses do
@@ -64,9 +68,37 @@ migration 'add not null constraint to photo user_id and license_id' do
   end
 end
 
+migration 'add json field to user' do
+  database.alter_table :users do
+    add_column :json, 'text'
+  end
+  database.select(:nsid).from(:users).select_map(:nsid).each do |nsid|
+    info = OpenStruct.new(flickr.people.getInfo(user_id: nsid).to_hash)
+    info.timezone = info.timezone.to_hash
+    info.photos = info.photos.to_hash
+    database.from(:users).where(nsid: nsid).update(json: info.to_h.to_json)
+  end
+end
+
 class User < Sequel::Model
   one_to_many :photos
   unrestrict_primary_key
+
+  def flickraw
+    @flickraw ||= OpenStruct.new(JSON.parse(json))
+  end
+
+  def buddyicon
+    if flickraw.iconserver.to_i > 0
+      "https://farm#{flickraw.iconfarm}.staticflickr.com/#{flickraw.iconserver}/buddyicons/#{nsid}.jpg"
+    else
+      "https://www.flickr.com/images/buddyicon.gif"
+    end
+  end
+
+  def photosurl
+    flickraw.photosurl
+  end
 end
 
 class License < Sequel::Model
@@ -130,6 +162,10 @@ before do
   @user = User.find_or_create(nsid: flickr_user[:user_nsid]) do |user|
     user.username = flickr_user[:username]
     user.fullname = flickr_user[:fullname]
+    info = OpenStruct.new(flickr.people.getInfo(user_id: user.nsid).to_hash)
+    info.timezone = info.timezone.to_hash
+    info.photos = info.photos.to_hash
+    user.json = info.to_h.to_json
   end
 end
 

+ 34 - 2
views/index.erb

@@ -1,7 +1,39 @@
-<p>Hello <%= @user.fullname %>!</p>
+<div>
+    <button id="reload_photos" type="button">reload photos</button>
+    <select id="show_license">
+        <option value="all" selected>show photos with any license</option>
+        <% @licenses.each do |license| %>
+            <option value="<%= license.id %>"><%= license.name %></option>
+        <% end %>
+    </select>
+    <select id="show_privacy">
+        <option value="all" selected>show public and private photos</option>
+        <option value="public">show only public photos</option>
+        <option value="friends/family">show photos visible to friends and family</option>
+        <option value="friends">show photos visible to only friends</option>
+        <option value="family">show photos visible to only family</option>
+        <option value="private">show completely private photos</option>
+    </select>
+    <select id="show_ignored">
+        <option value="true" selected>show ignored photos</option>
+        <option value="false">hide ignored photos</option>
+    </select>
+</div>
+
+<div id="photos" grid style="height: 66vh; overflow-y: auto;"></div>
+
+<div>
+    <select id="select_license">
+        <option value="unselected" selected>select license</option>
+        <% @licenses.each do |license| %>
+            <option value="<%= license.id %>"><%= license.name %></option>
+        <% end %>
+    </select>
+    <button disabled id="apply_license" type="button">apply license</button>
+</div>
 
 <script>
-  var licenses = <%= @licenses.to_json %>;
+var licenses = <%= @licenses.to_json %>;
 </script>
 <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
 <script src="/js/app.js"></script>

+ 6 - 1
views/layout.erb

@@ -7,9 +7,14 @@
         <meta name="HandheldFriendly" content="True">
         <meta name="MobileOptimized" content="320">
 
-        <title><% if @title %><%= @title %> &middot; <% end %>Flickr License</title>
+        <title>flickr license</title>
+
+        <link rel="stylesheet" href="https://cdn.concisecss.com/v4.1/concise.min.css">
     </head>
     <body>
+        <header container>
+            <div><span style="color: #0063dc;">flick</span><span style="color: #ff0084;">r</span> license <a href="<%= @user.photosurl %>"><img src="<%= @user.buddyicon %>"> <%= @user.username %></a> (<%= @user.fullname %>) | <a href="/logout">logout</a></div>
+        </header>
         <main container>
             <%= yield %>
         </main>