diff options
author | 2011-08-20 12:26:41 +0200 | |
---|---|---|
committer | 2011-08-20 12:26:41 +0200 | |
commit | f632b8226c8f11dbb5a263c34cf5f1d618bdf5ff (patch) | |
tree | e4885e213ff500b12d956d20324a310067cd1b7a | |
parent | Reset vertical align of box header graphics (diff) | |
download | glsamaker-f632b8226c8f11dbb5a263c34cf5f1d618bdf5ff.tar.gz glsamaker-f632b8226c8f11dbb5a263c34cf5f1d618bdf5ff.tar.bz2 glsamaker-f632b8226c8f11dbb5a263c34cf5f1d618bdf5ff.zip |
Add BugsController to replace the addbug{,save} hack in GLSAController
-rw-r--r-- | app/assets/javascripts/glsamaker_edit.js | 2 | ||||
-rw-r--r-- | app/controllers/bugs_controller.rb | 53 | ||||
-rw-r--r-- | app/helpers/bugs_helper.rb | 2 | ||||
-rw-r--r-- | app/views/bugs/create.html.erb | 2 | ||||
-rw-r--r-- | app/views/bugs/create.js.erb | 6 | ||||
-rw-r--r-- | app/views/bugs/destroy.html.erb | 2 | ||||
-rw-r--r-- | app/views/bugs/new.html.erb | 34 | ||||
-rw-r--r-- | app/views/bugs/show.html.erb | 2 | ||||
-rw-r--r-- | config/routes.rb | 9 | ||||
-rw-r--r-- | test/functional/bugs_controller_test.rb | 24 | ||||
-rw-r--r-- | test/unit/helpers/bugs_helper_test.rb | 4 |
11 files changed, 139 insertions, 1 deletions
diff --git a/app/assets/javascripts/glsamaker_edit.js b/app/assets/javascripts/glsamaker_edit.js index 9b36725..d74f297 100644 --- a/app/assets/javascripts/glsamaker_edit.js +++ b/app/assets/javascripts/glsamaker_edit.js @@ -35,7 +35,7 @@ GLSAMaker.editing.bugs = function() { * Opens a dialog to add bugs */ add_dialog : function(glsa_id) { - Modalbox.show("/glsa/addbug/" + glsa_id, {title: "Add bugs", width: 600}); + Modalbox.show("/glsas/" + glsa_id + "/bugs/new", {title: "Add bugs", width: 600}); } }; }(); diff --git a/app/controllers/bugs_controller.rb b/app/controllers/bugs_controller.rb new file mode 100644 index 0000000..ddac693 --- /dev/null +++ b/app/controllers/bugs_controller.rb @@ -0,0 +1,53 @@ +# ===GLSAMaker v2 +# Copyright (C) 2011 Alex Legler <a3li@gentoo.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# For more information, see the LICENSE file. + +# BugsController handles bugs attached to GLSAs +class BugsController < ApplicationController + layout false + + def new + begin + @glsa = Glsa.find(Integer(params[:glsa_id])) + @bug = Bug.new + rescue Exception + @glsa = nil + end + end + + def create + @glsa = Glsa.find(params[:glsa_id].to_i) + return unless check_object_access(@glsa) + + unless @glsa.nil? + @added_bugs = [] + Bugzilla::Bug.str2bugIDs(params[:addbugs]).map do |bugid| + begin + @added_bugs << Glsamaker::Bugs::Bug.load_from_id(bugid) + rescue Exception => e + # Silently ignore invalid bugs + end + end + + begin + @bugs_text = render_to_string :partial => '/glsa/edit_bug_row', :collection => @added_bugs, :as => :bug + rescue Exception => e + @error = "Error: #{e.message}" + end + else + @error = "Cannot find GLSA" + end + end + + def destroy + end + + def show + end +end
\ No newline at end of file diff --git a/app/helpers/bugs_helper.rb b/app/helpers/bugs_helper.rb new file mode 100644 index 0000000..8d70fcb --- /dev/null +++ b/app/helpers/bugs_helper.rb @@ -0,0 +1,2 @@ +module BugsHelper +end diff --git a/app/views/bugs/create.html.erb b/app/views/bugs/create.html.erb new file mode 100644 index 0000000..aa3490b --- /dev/null +++ b/app/views/bugs/create.html.erb @@ -0,0 +1,2 @@ +<h1>Bugs#create</h1> +<p>Find me in app/views/bugs/create.html.erb</p> diff --git a/app/views/bugs/create.js.erb b/app/views/bugs/create.js.erb new file mode 100644 index 0000000..13a466b --- /dev/null +++ b/app/views/bugs/create.js.erb @@ -0,0 +1,6 @@ +<% if @error == nil %> +Element.insert('bugtable', { bottom: '<%= escape_javascript(@bugs_text).html_safe %>'}); +Modalbox.hide(); +<% else %> +alert('<%= escape_javascript(@error).html_safe %>'); +<% end %>
\ No newline at end of file diff --git a/app/views/bugs/destroy.html.erb b/app/views/bugs/destroy.html.erb new file mode 100644 index 0000000..b08c545 --- /dev/null +++ b/app/views/bugs/destroy.html.erb @@ -0,0 +1,2 @@ +<h1>Bugs#destroy</h1> +<p>Find me in app/views/bugs/destroy.html.erb</p> diff --git a/app/views/bugs/new.html.erb b/app/views/bugs/new.html.erb new file mode 100644 index 0000000..bf04b22 --- /dev/null +++ b/app/views/bugs/new.html.erb @@ -0,0 +1,34 @@ +<% if @glsa.nil? %> +<p>No or invalid GLSA ID specified.</p> +<% else %> +<%= form_tag(glsa_bugs_path(@glsa, @bug), :remote => true) do -%> +<%# form_remote_tag( + :url => { :controller => :glsa, :action => :addbugsave, :id => @glsa_id.to_s }, + :update => {:success => 'bugtable'}, + :position => :bottom, + :before => '$("addbugsubmit").value="Loading...";', + :after => '$("addbugsubmit").value="Add bugs";', + :success => 'Modalbox.hide();', + :failure => 'alert(request.responseText);') do -%> +<p><label for="addbugs"> + <%= image_tag 'icons/bug.png' %> + Please enter the relevant bug ID(s), separate more than one bug with a comma:</label> +</p> + +<p><input type="text" name="addbugs" id="addbugs" class="hugetext nice"/></p> +<script language="javascript"> +new Form.Element.Observer('addbugs', 4, function(element, value) { + new Ajax.Request("<%= url_for :controller => 'tools', :action => 'file_req_ajax_info' %>", { + method: 'get', + parameters: { bugs: $('addbugs').getValue() }, + onComplete : function(transport) { + $('ajaxbugs').update(transport.responseJSON.buginfo); + Modalbox.resizeToContent(); + } + }); +}); +</script> +<div id="ajaxbugs"></div> +<p style="text-align: right;"><input type="submit" class="button" value="Add bugs" id="addbugsubmit" /></p> +<% end -%> +<% end %>
\ No newline at end of file diff --git a/app/views/bugs/show.html.erb b/app/views/bugs/show.html.erb new file mode 100644 index 0000000..736728a --- /dev/null +++ b/app/views/bugs/show.html.erb @@ -0,0 +1,2 @@ +<h1>Bugs#show</h1> +<p>Find me in app/views/bugs/show.html.erb</p> diff --git a/config/routes.rb b/config/routes.rb index 6fdb34e..6716d81 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,13 @@ Glsamaker::Application.routes.draw do + get "bugs/new" + + get "bugs/create" + + get "bugs/destroy" + + get "bugs/show" + match 'bug/:id' => 'bug#bug', :as => :bug match 'bug/:id/history' => 'bug#history', :as => :bughistory match 'tools/bug/:id/:what' => 'tools#bugzie', :as => :bugzie @@ -10,6 +18,7 @@ Glsamaker::Application.routes.draw do resources :glsas, :controller => 'glsa' do resources :comments + resources :bugs get 'requests', :on => :collection get 'drafts' , :on => :collection diff --git a/test/functional/bugs_controller_test.rb b/test/functional/bugs_controller_test.rb new file mode 100644 index 0000000..4637e04 --- /dev/null +++ b/test/functional/bugs_controller_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class BugsControllerTest < ActionController::TestCase + test "should get new" do + get :new + assert_response :success + end + + test "should get create" do + get :create + assert_response :success + end + + test "should get destroy" do + get :destroy + assert_response :success + end + + test "should get show" do + get :show + assert_response :success + end + +end diff --git a/test/unit/helpers/bugs_helper_test.rb b/test/unit/helpers/bugs_helper_test.rb new file mode 100644 index 0000000..1f3a2a5 --- /dev/null +++ b/test/unit/helpers/bugs_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class BugsHelperTest < ActionView::TestCase +end |