From c29cc0984dc1934b3298a4d21f821a87b34ad85f Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Wed, 24 Apr 2013 15:11:29 +0100 Subject: [PATCH] Add custom imageURL icon for each layer --- app/helpers/posts_helper.rb | 9 ++++++++- app/models/layer.rb | 2 +- app/views/layers/_form.html.haml | 7 +++++++ db/migrate/20130424113732_add_icon_url_to_layers.rb | 5 +++++ db/schema.rb | 3 ++- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20130424113732_add_icon_url_to_layers.rb diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index c8a42c4..3498f26 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -1,9 +1,16 @@ module PostsHelper def post_to_poi(post, subscription) # http://layar.com/documentation/browser/api/getpois-response/ + + if subscription.layer.icon_url.blank? + image_url = "%s%s/assets/layar-icons/tal-logo-100.png" % [ request.protocol, request.env['HTTP_HOST'] ] + else + image_url = subscription.layer.icon_url + end + res = { :id => post.id, - :imageURL => "%s%s/assets/layar-icons/tal-logo-100.png" % [ request.protocol, request.env['HTTP_HOST'] ], + :imageURL => image_url, :anchor => { :geolocation => { :lat => post.lat, diff --git a/app/models/layer.rb b/app/models/layer.rb index 4e3b48a..ad59418 100644 --- a/app/models/layer.rb +++ b/app/models/layer.rb @@ -2,7 +2,7 @@ class Layer < ActiveRecord::Base has_many :subscriptions has_many :feeds, :through => :subscriptions, :uniq => true - attr_accessible :name + attr_accessible :name, :icon_url # Unique name for Layar layer def layar_name diff --git a/app/views/layers/_form.html.haml b/app/views/layers/_form.html.haml index 27bc898..c382b0a 100644 --- a/app/views/layers/_form.html.haml +++ b/app/views/layers/_form.html.haml @@ -8,6 +8,13 @@ .field = f.label :name + %br = f.text_field :name + %br + .field + = f.label "Icon URL (optional)" + %br + = f.text_field :icon_url, :size => 60 + %br .actions = f.submit 'Save' diff --git a/db/migrate/20130424113732_add_icon_url_to_layers.rb b/db/migrate/20130424113732_add_icon_url_to_layers.rb new file mode 100644 index 0000000..eea3e20 --- /dev/null +++ b/db/migrate/20130424113732_add_icon_url_to_layers.rb @@ -0,0 +1,5 @@ +class AddIconUrlToLayers < ActiveRecord::Migration + def change + add_column :layers, :icon_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index b8ec01f..d0604b8 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 => 20130417153542) do +ActiveRecord::Schema.define(:version => 20130424113732) do create_table "delayed_jobs", :force => true do |t| t.integer "priority", :default => 0 @@ -45,6 +45,7 @@ ActiveRecord::Schema.define(:version => 20130417153542) do t.string "name" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.string "icon_url" end create_table "posts", :force => true do |t|