From bd174d30b4e248e9b2858b5e2beab21422e894ad Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Wed, 10 Apr 2013 16:55:28 +0100 Subject: [PATCH 1/4] Add icon_url to subscriptions for custom feed icons --- app/controllers/subscriptions_controller.rb | 22 +++++++++++++++++++ app/views/layers/show.html.haml | 1 + app/views/subscriptions/_icon_form.html.haml | 21 ++++++++++++++++++ app/views/subscriptions/edit.html.haml | 3 +++ ...410153407_add_icon_url_to_subscriptions.rb | 5 +++++ db/schema.rb | 3 ++- 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/views/subscriptions/_icon_form.html.haml create mode 100644 app/views/subscriptions/edit.html.haml create mode 100644 db/migrate/20130410153407_add_icon_url_to_subscriptions.rb diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 1f1e377..3433b0c 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -33,6 +33,28 @@ class SubscriptionsController < ApplicationController end end + # GET /subscriptions/1/edit + def edit + @subscription = Subscription.find(params[:id]) + end + + # PUT /subscriptions/1 + # PUT /subscriptions/1.json + def update + @subscription = Subscription.find(params[:id]) + + respond_to do |format| + if @subscription.update_attributes(params[:subscription]) + format.html { redirect_to @subscription.layer, notice: 'Subscription updated OK' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @subscription.errors, status: :unprocessable_entity } + end + end + end + + def destroy @subscription = Subscription.find(params[:id]) @layer = @subscription.layer diff --git a/app/views/layers/show.html.haml b/app/views/layers/show.html.haml index 2057340..0b21d10 100644 --- a/app/views/layers/show.html.haml +++ b/app/views/layers/show.html.haml @@ -40,6 +40,7 @@ %td= link_to "Fetch", fetch_feed_url(s.feed), :class => "button" %td= link_to 'Edit', edit_feed_path(s.feed), :class => "button" %td= link_to 'Delete', s, :confirm => "Delete #{s.feed.title}?", :method => :delete, :class => "button" + %td= link_to 'Edit icon', edit_subscription_path(s), :class => "button" %tr %td diff --git a/app/views/subscriptions/_icon_form.html.haml b/app/views/subscriptions/_icon_form.html.haml new file mode 100644 index 0000000..e02677b --- /dev/null +++ b/app/views/subscriptions/_icon_form.html.haml @@ -0,0 +1,21 @@ +%h1 Custom feed icon + +%p + Layer: + = link_to @subscription.layer.name, @subscription.layer + +%p Specify the URL for an icon (JPG or PNG image) and it'll display for all posts in this feed in Layar. + += form_for @subscription do |f| + + -if @subscription.errors.any? + #error_explanation + %h2= "#{pluralize(@subscription.errors.count, "error")} prohibited this feed from being saved:" + %ul + - @subscription.errors.full_messages.each do |msg| + %li= msg + + .field + = f.label "Icon URL" + = f.text_field :icon_url, :size => 120 + = f.submit 'Save', :id => 'submit' diff --git a/app/views/subscriptions/edit.html.haml b/app/views/subscriptions/edit.html.haml new file mode 100644 index 0000000..460c6bc --- /dev/null +++ b/app/views/subscriptions/edit.html.haml @@ -0,0 +1,3 @@ += render 'icon_form' + += link_to 'Back', layer_path(@subscription.layer) diff --git a/db/migrate/20130410153407_add_icon_url_to_subscriptions.rb b/db/migrate/20130410153407_add_icon_url_to_subscriptions.rb new file mode 100644 index 0000000..b41c5ff --- /dev/null +++ b/db/migrate/20130410153407_add_icon_url_to_subscriptions.rb @@ -0,0 +1,5 @@ +class AddIconUrlToSubscriptions < ActiveRecord::Migration + def change + add_column :subscriptions, :icon_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 859b218..484c6e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130408142010) do +ActiveRecord::Schema.define(:version => 20130410153407) do create_table "delayed_jobs", :force => true do |t| t.integer "priority", :default => 0 @@ -66,6 +66,7 @@ ActiveRecord::Schema.define(:version => 20130408142010) do t.integer "layer_id" t.datetime "created_at" t.datetime "updated_at" + t.string "icon_url" end add_index "subscriptions", ["feed_id", "layer_id"], :name => "index_feeds_layers_on_feed_id_and_layer_id", :unique => true From 5348c8fa7d5bc515990b3015de83c134c060048c Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Thu, 11 Apr 2013 12:58:27 +0100 Subject: [PATCH 2/4] Rename feeds_layers table to subscriptions --- app/models/post.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 87661bd..54dde3f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -23,6 +23,7 @@ class Post < ActiveRecord::Base p.lat, p.lon, p.published, + p.feed_id, f.title as feed_title, ( #{EARTH_RADIUS_METRES} * acos( cos( radians('#{lat}') ) @@ -42,15 +43,15 @@ class Post < ActiveRecord::Base ( -- Subquery returns a list of post_ids for posts on this layer SELECT p.id - FROM feeds_layers fl + FROM subscriptions s INNER JOIN feeds f - ON fl.feed_id = f.id + ON s.feed_id = f.id INNER JOIN posts p ON p.feed_id = f.id - WHERE fl.layer_id = #{layer_id} + WHERE s.layer_id = #{layer_id} ) AND From 3edc10195622a63d50bbd12cc29e48f0eb153e0a Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Thu, 11 Apr 2013 12:58:53 +0100 Subject: [PATCH 3/4] Show custom icons per feed --- app/views/layers/show.html.haml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/layers/show.html.haml b/app/views/layers/show.html.haml index 0b21d10..f214047 100644 --- a/app/views/layers/show.html.haml +++ b/app/views/layers/show.html.haml @@ -41,7 +41,11 @@ %td= link_to 'Edit', edit_feed_path(s.feed), :class => "button" %td= link_to 'Delete', s, :confirm => "Delete #{s.feed.title}?", :method => :delete, :class => "button" %td= link_to 'Edit icon', edit_subscription_path(s), :class => "button" - + %td + - unless s.icon_url.nil? + = image_tag s.icon_url + - else +   %tr %td %td.right= @layer_posts From 2a2843948c5064d7510b623a299c10020156117d Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Thu, 11 Apr 2013 12:59:16 +0100 Subject: [PATCH 4/4] JSON output for Layar custom icons per feed --- app/controllers/posts_controller.rb | 2 +- app/helpers/posts_helper.rb | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 7e16799..f7de3e8 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -13,7 +13,7 @@ class PostsController < ApplicationController layar_response = { :layer => @layer.layar_name, - :hotspots => @posts.collect { |p| post_to_poi(p) }, + :hotspots => @posts.collect { |p| post_to_poi(p, Subscription.where(:feed_id => p.feed_id, :layer_id => @layer.id).first) }, :errorCode => 0, # OK :errorString => "OK", :radius => params[:radius].to_f diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 3e77a72..79f3b1e 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -1,8 +1,8 @@ module PostsHelper - def post_to_poi(post) + def post_to_poi(post, subscription) # http://layar.com/documentation/browser/api/getpois-response/ { - :id => post._id, + :id => post.id, :imageURL => "%s%s/assets/layar-icons/tal-logo-100.png" % [ request.protocol, request.env['HTTP_HOST'] ], :anchor => { :geolocation => { @@ -23,8 +23,14 @@ module PostsHelper :contentType => "text/html", :method => "GET", :activityType => 1 - } - ] + }, + ], + :object => { + :contentType => "image/vnd.layar.generic", + :url => subscription.icon_url, + :reducedURL => subscription.icon_url, + :size => 120 + } } end