1 class SegmentController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_availability, :only => [:create, :update, :delete]
7 after_filter :compress_output
11 segment = Segment.from_xml(request.raw_post, true)
14 if segment.node_a == segment.node_b
15 render :nothing => true, :status => :expectation_failed
16 elsif !segment.preconditions_ok?
17 render :nothing => true, :status => :precondition_failed
19 segment.user_id = @user.id
20 segment.from_node = Node.find(segment.node_a.to_i)
21 segment.to_node = Node.find(segment.node_b.to_i)
22 segment.save_with_history!
24 render :text => segment.id.to_s, :content_type => "text/plain"
27 render :nothing => true, :status => :bad_request
30 render :nothing => true, :status => :method_not_allowed
36 segment = Segment.find(params[:id])
39 render :text => segment.to_xml.to_s, :content_type => "text/xml"
41 render :nothing => true, :status => :gone
43 rescue ActiveRecord::RecordNotFound
44 render :nothing => true, :status => :not_found
50 segment = Segment.find(params[:id])
53 new_segment = Segment.from_xml(request.raw_post)
55 if new_segment and new_segment.id == segment.id
56 if new_segment.node_a == new_segment.node_b
57 render :nothing => true, :status => :expectation_failed
58 elsif !new_segment.preconditions_ok?
59 render :nothing => true, :status => :precondition_failed
61 segment.user_id = @user.id
62 segment.node_a = new_segment.node_a
63 segment.node_b = new_segment.node_b
64 segment.tags = new_segment.tags
65 segment.visible = new_segment.visible
66 segment.save_with_history!
68 render :nothing => true
71 render :nothing => true, :status => :bad_request
74 render :nothing => true, :status => :gone
76 rescue ActiveRecord::RecordNotFound
77 render :nothing => true, :status => :not_found
83 segment = Segment.find(params[:id])
86 if WaySegment.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_segments.id", :conditions => [ "current_ways.visible = 1 AND current_way_segments.segment_id = ?", segment.id ])
87 render :nothing => true, :status => :precondition_failed
89 segment.user_id = @user.id
91 segment.save_with_history!
93 render :nothing => true
96 render :nothing => true, :status => :gone
98 rescue ActiveRecord::RecordNotFound
99 render :nothing => true, :status => :not_found
104 ids = params['segments'].split(',').collect { |s| s.to_i }
107 doc = OSM::API.new.get_xml_doc
109 Segment.find(ids).each do |segment|
110 doc.root << segment.to_xml_node
113 render :text => doc.to_s, :content_type => "text/xml"
115 render :nothing => true, :status => :bad_request
119 def segments_for_node
120 segmentids = Segment.find(:all, :conditions => ['node_a = ? OR node_b = ?', params[:id], params[:id]]).collect { |s| s.id }.uniq
122 if segmentids.length > 0
123 doc = OSM::API.new.get_xml_doc
125 Segment.find(segmentids).each do |segment|
126 doc.root << segment.to_xml_node
129 render :text => doc.to_s, :content_type => "text/xml"
131 render :nothing => true, :status => :bad_request