
https://svn.lrde.epita.fr/svn/ranch/trunk Index: ChangeLog from Nicolas Despr�s <nicolas.despres@gmail.com> Check revision input format. * web/ranch/app/controllers/graph_form_controller.rb: Extract the start revision and the stop revision from the input field using a regular expression. * web/ranch/app/views/graph_form/index.rhtml: Only one text field is needed now (the new format is start_rev-stop_rev). controllers/graph_form_controller.rb | 31 ++++++++++++++++++++++--------- views/graph_form/index.rhtml | 10 ++++------ 2 files changed, 26 insertions(+), 15 deletions(-) Index: web/ranch/app/controllers/graph_form_controller.rb --- web/ranch/app/controllers/graph_form_controller.rb (revision 40) +++ web/ranch/app/controllers/graph_form_controller.rb (working copy) @@ -37,20 +37,33 @@ "ORDER BY outputs.arg_num " @output_arg_nb = @output_arg_nb.size end - @revision = params[:revision] - head_rev = @project.head_revision - @revision[:stop] = @revision[:stop].to_i - @revision[:stop] = head_rev if @revision[:stop] > head_rev - @revision[:start] = @revision[:start].to_i - @revision[:start] = 1 if @revision[:start] < 1 - if @revision[:start] < @revision[:stop] + @revision = get_revision_range(params[:revision][:range]) + if flash[:error].nil? @draw_on = true render :action => 'index' else - flash[:error] = 'The start revision must be lesser than ' + - 'the stop revision.' redirect_to(:action => 'index', :bench_id => @bench.id) end end + protected + + def get_revision_range(revision, head_rev=@project.head_revision) + result = {} + if revision =~ /^(-?\d+)-(-?\d+)$/ + result[:start] = $1 + result[:stop] = $2 + result[:stop] = result[:stop].to_i + result[:stop] = head_rev if result[:stop] > head_rev + result[:start] = result[:start].to_i + result[:start] = 1 if result[:start] < 1 + if result[:start] > result[:stop] + flash[:error] = 'Start revision greater than stop revision.' + end + else + flash[:error] = "Bad revision range format." + end + result + end + end Index: web/ranch/app/views/graph_form/index.rhtml --- web/ranch/app/views/graph_form/index.rhtml (revision 40) +++ web/ranch/app/views/graph_form/index.rhtml (working copy) @@ -12,12 +12,10 @@ <td> <table> <tr> - <td>from</td> - <td><%= text_field "revision", "start", "size" => 8, - "value" => @revision[:start] %></td> - <td>to</td> - <td><%= text_field "revision", "stop", "size" => 8, - "value" => @revision[:stop] %></td> + <td> + <%= text_field "revision", "range", "size" => 16, + "value" => "#{@revision[:start]}-#{@revision[:stop]}" %> + </td> </tr> </table> </td>