浏览代码

Merge branch 'refs/heads/custom-icons'

master
Adrian Short 11 年前
父节点
当前提交
79ffb54907
共有 9 个文件被更改,包括 71 次插入7 次删除
  1. +1
    -1
      app/controllers/posts_controller.rb
  2. +22
    -0
      app/controllers/subscriptions_controller.rb
  3. +10
    -4
      app/helpers/posts_helper.rb
  4. +1
    -0
      app/models/post.rb
  5. +6
    -1
      app/views/layers/show.html.haml
  6. +21
    -0
      app/views/subscriptions/_icon_form.html.haml
  7. +3
    -0
      app/views/subscriptions/edit.html.haml
  8. +5
    -0
      db/migrate/20130410153407_add_icon_url_to_subscriptions.rb
  9. +2
    -1
      db/schema.rb

+ 1
- 1
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


+ 22
- 0
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


+ 10
- 4
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


+ 1
- 0
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}') )


+ 6
- 1
app/views/layers/show.html.haml 查看文件

@@ -40,7 +40,12 @@
%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"
%td
- unless s.icon_url.nil?
= image_tag s.icon_url
- else
&nbsp;
%tr
%td
%td.right= @layer_posts


+ 21
- 0
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'

+ 3
- 0
app/views/subscriptions/edit.html.haml 查看文件

@@ -0,0 +1,3 @@
= render 'icon_form'

= link_to 'Back', layer_path(@subscription.layer)

+ 5
- 0
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

+ 2
- 1
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


正在加载...
取消
保存