This commit is contained in:
Mayank Tankhiwale 2019-11-23 20:32:47 +05:30
commit 11cd1c9fc1
93 changed files with 1266 additions and 846 deletions

View file

@ -34,7 +34,7 @@ class ApiAbility
can [:new, :create], Report
can [:create, :show, :update, :destroy, :data], Trace
can [:details, :gpx_files], User
can [:read, :read_one, :update, :update_one, :delete_one], UserPreference
can [:index, :show, :update, :update_all, :destroy], UserPreference
if user.terms_agreed?
can [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox], Changeset

View file

@ -10,8 +10,8 @@ class ApiCapability
can [:create, :update, :destroy], Trace if capability?(token, :allow_write_gpx)
can [:details], User if capability?(token, :allow_read_prefs)
can [:gpx_files], User if capability?(token, :allow_read_gpx)
can [:read, :read_one], UserPreference if capability?(token, :allow_read_prefs)
can [:update, :update_one, :delete_one], UserPreference if capability?(token, :allow_write_prefs)
can [:index, :show], UserPreference if capability?(token, :allow_read_prefs)
can [:update, :update_all, :destroy], UserPreference if capability?(token, :allow_write_prefs)
if token&.user&.terms_agreed?
can [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox], Changeset if capability?(token, :allow_write_api)

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 480 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 527 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 527 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 527 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 112 B

Before After
Before After

View file

@ -121,7 +121,7 @@
.shop.shoes::before { content: image-url('browse/shop_shoes.16.png'); }
.shop.supermarket::before { content: image-url('browse/shop_supermarket.p.16.png'); }
.tourism.alpine_hut::before { content: image-url('browse/alpinehut.p.16.png'); }
.tourism.alpine_hut::before { content: image-url('browse/tourism_alpine_hut.16.png'); }
.tourism.camp_site::before { content: image-url('browse/tourism_camp_site.16.png'); }
.tourism.caravan_site::before { content: image-url('browse/tourism_caravan_site.16.png'); }
.tourism.hostel::before { content: image-url('browse/tourism_hostel.16.png'); }
@ -130,6 +130,7 @@
.tourism.museum::before { content: image-url('browse/tourism_museum.16.png'); }
.tourism.picnic_site::before { content: image-url('browse/tourism_picnic_site.16.png'); }
.tourism.viewpoint::before { content: image-url('browse/view_point.p.16.png'); }
.tourism.wilderness_hut::before { content: image-url('browse/tourism_wilderness_hut.16.png'); }
/* Ways */
@ -184,6 +185,7 @@
.natural.grassland::before { content: image-url('browse/grassland.png'); }
.natural.heath::before { content: image-url('browse/heathland.png'); }
.natural.scrub::before { content: image-url('browse/scrub.png'); }
.natural.water::before { content: image-url('browse/lake.png'); }
.natural.wood::before { content: image-url('browse/wood.png'); }

View file

@ -9,31 +9,22 @@ module Api
##
# return all the preferences as an XML document
def read
doc = OSM::API.new.get_xml_doc
def index
@user_preferences = current_user.preferences
prefs = current_user.preferences
el1 = XML::Node.new "preferences"
prefs.each do |pref|
el1 << pref.to_xml_node
end
doc.root << el1
render :xml => doc.to_s
render :formats => [:xml]
end
##
# return the value for a single preference
def read_one
def show
pref = UserPreference.find([current_user.id, params[:preference_key]])
render :plain => pref.v.to_s
end
# update the entire set of preferences
def update
def update_all
old_preferences = current_user.preferences.each_with_object({}) do |preference, preferences|
preferences[preference.k] = preference
end
@ -63,7 +54,7 @@ module Api
##
# update the value of a single preference
def update_one
def update
begin
pref = UserPreference.find([current_user.id, params[:preference_key]])
rescue ActiveRecord::RecordNotFound
@ -80,7 +71,7 @@ module Api
##
# delete a single preference
def delete_one
def destroy
UserPreference.find([current_user.id, params[:preference_key]]).delete
render :plain => ""

View file

@ -17,6 +17,8 @@ module BrowseTagsHelper
link_to(w[:title], w[:url], :title => t("browse.tag_details.wikidata_link", :page => w[:title].strip))
end
safe_join(wdt, ";")
elsif wmc = wikimedia_commons_link(key, value)
link_to h(wmc[:title]), wmc[:url], :title => t("browse.tag_details.wikimedia_commons_link", :page => wmc[:title])
elsif url = wiki_link("tag", "#{key}=#{value}")
link_to h(value), url, :title => t("browse.tag_details.wiki_link.tag", :key => key, :value => value)
elsif phones = telephone_links(key, value)
@ -111,6 +113,16 @@ module BrowseTagsHelper
nil
end
def wikimedia_commons_link(key, value)
if key == "wikimedia_commons" && value =~ /^(?:file|category):/i
return {
:url => "//commons.wikimedia.org/wiki/#{value}?uselang=#{I18n.locale}",
:title => value
}
end
nil
end
def telephone_links(_key, value)
# Does it look like a global phone number? eg "+1 (234) 567-8901 "
# or a list of alternate numbers separated by ;

View file

@ -200,28 +200,6 @@ class Node < ActiveRecord::Base
save_with_history!
end
def to_xml
doc = OSM::API.new.get_xml_doc
doc.root << to_xml_node
doc
end
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
el = XML::Node.new "node"
el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
if visible?
el["lat"] = lat.to_s
el["lon"] = lon.to_s
end
add_tags_to_xml_node(el, node_tags)
el
end
def tags_as_hash
tags
end

View file

@ -121,31 +121,6 @@ class Relation < ActiveRecord::Base
relation
end
def to_xml
doc = OSM::API.new.get_xml_doc
doc.root << to_xml_node
doc
end
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
el = XML::Node.new "relation"
el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
relation_members.each do |member|
member_el = XML::Node.new "member"
member_el["type"] = member.member_type.downcase
member_el["ref"] = member.member_id.to_s
member_el["role"] = member.member_role
el << member_el
end
add_tags_to_xml_node(el, relation_tags)
el
end
# FIXME: is this really needed?
def members
@members ||= relation_members.map do |member|

View file

@ -46,6 +46,8 @@
class User < ActiveRecord::Base
require "xml/libxml"
self.ignored_columns = ["nearby"]
has_many :traces, -> { where(:visible => true) }
has_many :diary_entries, -> { order(:created_at => :desc) }
has_many :diary_comments, -> { order(:created_at => :desc) }

View file

@ -18,13 +18,4 @@ class UserPreference < ActiveRecord::Base
validates :user, :presence => true, :associated => true
validates :k, :v, :length => 1..255, :characters => true
# Turn this Node in to an XML Node without the <osm> wrapper.
def to_xml_node
el1 = XML::Node.new "preference"
el1["k"] = k
el1["v"] = v
el1
end
end

View file

@ -106,44 +106,6 @@ class Way < ActiveRecord::Base
way
end
# Find a way given it's ID, and in a single SQL call also grab its nodes and tags
def to_xml
doc = OSM::API.new.get_xml_doc
doc.root << to_xml_node
doc
end
def to_xml_node(visible_nodes = nil, changeset_cache = {}, user_display_name_cache = {})
el = XML::Node.new "way"
el["id"] = id.to_s
add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
# make sure nodes are output in sequence_id order
ordered_nodes = []
way_nodes.each do |nd|
if visible_nodes
# if there is a list of visible nodes then use that to weed out deleted nodes
ordered_nodes[nd.sequence_id] = nd.node_id.to_s if visible_nodes[nd.node_id]
else
# otherwise, manually go to the db to check things
ordered_nodes[nd.sequence_id] = nd.node_id.to_s if nd.node&.visible?
end
end
ordered_nodes.each do |nd_id|
next unless nd_id && nd_id != "0"
node_el = XML::Node.new "nd"
node_el["ref"] = nd_id
el << node_el
end
add_tags_to_xml_node(el, way_tags)
el
end
def nds
@nds ||= way_nodes.collect(&:node_id)
end

View file

@ -2,7 +2,7 @@ json.type "Feature"
json.geometry do
json.type "Point"
json.coordinates [ note.lon.to_f, note.lat.to_f ]
json.coordinates [note.lon.to_f, note.lat.to_f]
end
json.properties do
@ -16,12 +16,12 @@ json.properties do
json.close_url close_note_url(note, :format => params[:format])
end
json.date_created note.created_at
json.date_created note.created_at.to_s
json.status note.status
json.closed_at note.closed_at if note.closed?
json.closed_at note.closed_at.to_s if note.closed?
json.comments(note.comments) do |comment|
json.date comment.created_at
json.date comment.created_at.to_s
if comment.author
json.uid comment.author.id

View file

@ -1,5 +1,5 @@
json.type "FeatureCollection"
json.features(@notes) do |note|
json.ingest! render(note)
json.partial! note
end

View file

@ -0,0 +1 @@
json.partial! @note

View file

@ -1 +0,0 @@
json.ingest! render(@note)

View file

@ -0,0 +1,6 @@
attrs = {
"k" => user_preference.k,
"v" => user_preference.v
}
xml.preference(attrs)

View file

@ -0,0 +1,7 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm.preferences do |preferences|
preferences << (render(@user_preferences) || "")
end
end