Class: DitzStr::DitzStrServlet

Inherits:
HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/ditzstr/brick.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, options) ⇒ DitzStrServlet

Returns a new instance of DitzStrServlet.



126
127
128
129
130
131
132
133
# File 'lib/ditzstr/brick.rb', line 126

def initialize(server, options)
	super(server)
	@project = options[:project]
	@config = options[:config]
	@brickview = options[:brickview]
	@sharedir = options[:dir]
	@user = options[:user]
end

Instance Method Details

#do_GET(req, resp) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ditzstr/brick.rb', line 135

def do_GET(req,resp)
	if req.path=="/index.html" or req.path=="/"
		#puts req.query['wee']
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_index 
	elsif req.path.start_with? '/release-'
		relname = req.path.sub('/release-','').sub('.html','')
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_release relname
	elsif req.path.start_with? '/component-'
		compname = req.path.sub('/component-','').sub('.html','')
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_component compname
	elsif req.path.start_with? '/issue-'
		issuename = req.path.sub('/issue-','').sub('.html','')
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_issue issuename
	elsif req.path=='/new_issue.html'
		options = {}
		if req.query['component']!=nil
			options[:component] = req.query['component']
		end
		if req.query['release']!=nil
			options[:release] = req.query['release']
		end
		options[:creator] = @user
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_new_issue options
	elsif req.path=='/new_component.html'
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_new_component
	elsif req.path=='/new_release.html'
		resp['content-type'] = 'text/html'
		resp.body = @brickview.generate_new_release
	elsif req.path=='/close.html'
		resp['content-type'] = 'text/html'
		if req.query['issue']==nil
			resp.body = 'Error, no such issue found.'
		else
			resp.body = @brickview.generate_close_issue req.query['issue'], req.query['disposition']
		end
	else
		HTTPServlet::FileHandler.new(@server,@sharedir).do_GET(req,resp)
	end
end

#do_POST(req, resp) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ditzstr/brick.rb', line 181

def do_POST(req,resp)
	resp['content-type'] = 'text/html'

	if req.path.start_with? '/new_issue.html'
		issue = Issue.create({:project => @project, :config=> @config},{:title => req.query['title'], :desc => req.query['description'], :type => req.query['type'], 
			      :component => req.query['component'], :release => req.query['release'], :reporter => 'poop', :comments => req.query['comments']});
		issue.log "created", @config.user, req.query['comments']
		resp.body = "<html><head><meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=/component-#{req.query['component']}.html\"></head><body>Redirecting...</body></html>"
		@project.add_issue issue
		@project.assign_issue_names!
	elsif req.path.start_with? '/edit_issue.html'

	elsif req.path.start_with? '/new_component.html'
		component = Component.create({:project => @project, :config=>@config},{:name => req.query['name']});
		@project.add_component component
		resp.body = "<html><head><meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=/index.html\"></head><body>Redirecting...</body></html>"
	elsif req.path.start_with? '/new_release.html'
		release = Release.create({:project => @project, :config=>@config},{:name => req.query['name']})
		release.log "created", @config.user, req.query['comments']
		@project.add_release release
		resp.body = "<html><head><meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=/index.html\"></head><body>Redirecting...</body></html>"
	elsif req.path.start_with? '/issue-'

		issue = "#{req.path}"
		issue = issue.gsub('/issue-','')
		issue = issue.gsub('.html','')
		resp.body = @brickview.comment_on_issue issue, req.query['comment']
	elsif req.path.start_with? '/close.html'
		issue_id = req.query['issue']
		comment = req.query['comment']
		closer = req.query['closer']
		disp = req.query['disposition']

		issue_res = @brickview.get_issue_by_name issue_id
		
		if issue_res[0]
			iss = issue_res[1]
			iss.close disp.to_sym, closer, comment
			resp.body = "<html><head><meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=/issue-#{issue_id}.html\"></head><body>Redirecting...</body></html>"
		else
			return issue_res[1]
		end
	end
end