1 class SegmentController < ApplicationController
4 before_filter :authorize
5 after_filter :compress_output
8 response.headers["Content-Type"] = 'application/xml'
10 segment = Segment.from_xml(request.raw_post, true)
14 segment.user_id = @user.id
16 segment.from_node = Node.find(segment.node_a.to_i)
17 segment.to_node = Node.find(segment.node_b.to_i)
19 unless segment.precondtions_ok? # are the nodes visible?
20 render :nothing => true, :status => 412
23 if segment.save_with_history
24 render :text => segment.id
26 render :nothing => true, :status => 500
31 render :nothing => true, :status => 400 # if we got here the doc didnt parse
36 render :nothing => true, :status => 500 # something went very wrong
40 response.headers["Content-Type"] = 'application/xml'
41 unless Segment.exists?(params[:id])
42 render :nothing => true, :status => 404
46 segment = Segment.find(params[:id])
51 render :text => segment.to_xml.to_s
57 segment.save_with_history
58 render :nothing => true
60 render :nothing => true, :status => 410
64 new_segment = Segment.from_xml(request.raw_post)
66 segment.timestamp = Time.now
67 segment.user_id = @user.id
69 segment.node_a = new_segment.node_a
70 segment.node_b = new_segment.node_b
71 segment.tags = new_segment.tags
72 segment.visible = new_segment.visible
74 if segment.id == new_segment.id and segment.save_with_history
75 render :nothing => true, :status => 200
77 render :nothing => true, :status => 500
85 response.headers["Content-Type"] = 'application/xml'
86 ids = params['segments'].split(',').collect {|s| s.to_i }
88 segmentlist = Segment.find(ids)
90 segmentlist.each do |segment|
91 doc.root << segment.to_xml_node
93 render :text => doc.to_s
95 render :nothing => true, :status => 400