Commit fb3dd19efbc19665e57c832c8bf7e5b07464b398
1 parent
ba17fba9
Exists in
master
and in
1 other branch
Redmine issue tracker setup.
Showing
7 changed files
with
67 additions
and
15 deletions
Show diff stats
app/helpers/application_helper.rb
app/models/app.rb
... | ... | @@ -30,7 +30,7 @@ class App |
30 | 30 | accepts_nested_attributes_for :watchers, :allow_destroy => true, |
31 | 31 | :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } |
32 | 32 | accepts_nested_attributes_for :issue_tracker, :allow_destroy => true, |
33 | - :reject_if => proc { |attrs| !%w( lighthouseapp ).include?(attrs[:issue_tracker_type]) } | |
33 | + :reject_if => proc { |attrs| !%w( lighthouseapp redmine ).include?(attrs[:issue_tracker_type]) } | |
34 | 34 | |
35 | 35 | # Mongoid Bug: find(id) on association proxies returns an Enumerator |
36 | 36 | def self.find_by_id!(app_id) | ... | ... |
app/models/issue_tracker.rb
... | ... | @@ -5,7 +5,7 @@ class IssueTracker |
5 | 5 | include Rails.application.routes.url_helpers |
6 | 6 | default_url_options[:host] = Errbit::Application.config.action_mailer.default_url_options[:host] |
7 | 7 | |
8 | - validate :check_lighthouseapp_params | |
8 | + validate :check_params | |
9 | 9 | |
10 | 10 | embedded_in :app, :inverse_of => :issue_tracker |
11 | 11 | |
... | ... | @@ -87,10 +87,15 @@ class IssueTracker |
87 | 87 | end |
88 | 88 | |
89 | 89 | protected |
90 | - def check_lighthouseapp_params | |
90 | + def check_params | |
91 | 91 | blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? } |
92 | 92 | if blank_flags.any? && !blank_flags.all? |
93 | - errors.add(:base, "You must specify your Lighthouseapp account, token and project id") | |
93 | + message = if issue_tracker_type == 'lighthouseapp' | |
94 | + "You must specify your Lighthouseapp account, api token and project id" | |
95 | + else | |
96 | + "You must specify your Redmine url, api token and project id" | |
97 | + end | |
98 | + errors.add(:base, message) | |
94 | 99 | end |
95 | 100 | end |
96 | 101 | end | ... | ... |
app/views/apps/_fields.html.haml
... | ... | @@ -25,15 +25,24 @@ |
25 | 25 | %fieldset |
26 | 26 | %legend Issue tracker |
27 | 27 | = f.fields_for :issue_tracker do |w| |
28 | - %div.watcher.nested | |
28 | + %div.issue_tracker.nested | |
29 | 29 | %div.choose |
30 | 30 | = w.radio_button :issue_tracker_type, :lighthouseapp |
31 | 31 | = label_tag :issue_tracker_type_lighthouseapp, 'Lighthouse', :for => label_for_attr(w, 'issue_tracker_type_lighthouseapp') |
32 | - %div.lighthouseapp{:class => 'choosen'} | |
32 | + = w.radio_button :issue_tracker_type, :redmine | |
33 | + = label_tag :issue_tracker_type_redmine, 'Redmine', :for => label_for_attr(w, 'issue_tracker_type_redmine') | |
34 | + %div.tracker_params{:class => lighthouse_tracker?(w.object) ? 'choosen' : nil} | |
33 | 35 | = w.label :account, "Account" |
34 | - = w.text_field :account | |
36 | + = w.text_field :account, :placeholder => "abc from abc.lighthouseapp.com" | |
37 | + = w.label :api_token, "API token" | |
38 | + = w.text_field :api_token, :placeholder => "API Token for your account" | |
39 | + = w.label :project_id, "Project ID" | |
40 | + = w.text_field :project_id, :placeholder => "123 from abc from abc.lighthouseapp.com/projects/123" | |
41 | + %div.tracker_params{:class => lighthouse_tracker?(w.object) ? nil : 'choosen'} | |
42 | + = w.label :account, "Redmine URL" | |
43 | + = w.text_field :account, :placeholder => "like http://www.redmine.org/" | |
35 | 44 | = w.label :api_token, "API token" |
36 | - = w.text_field :api_token | |
45 | + = w.text_field :api_token, :placeholder => "API Token for your account" | |
37 | 46 | = w.label :project_id, "Project ID" |
38 | 47 | = w.text_field :project_id |
39 | 48 | ... | ... |
public/javascripts/form.js
... | ... | @@ -3,6 +3,9 @@ $(function(){ |
3 | 3 | |
4 | 4 | if($('div.watcher.nested').length) |
5 | 5 | activateWatcherTypeSelector(); |
6 | + | |
7 | + if($('div.issue_tracker.nested').length) | |
8 | + activateIssueTrackerTypeSelector(); | |
6 | 9 | }); |
7 | 10 | |
8 | 11 | function activateNestedForms() { |
... | ... | @@ -67,4 +70,20 @@ function activateWatcherTypeSelector() { |
67 | 70 | wrapper.find('div.choosen').removeClass('choosen'); |
68 | 71 | wrapper.find('div.'+choosen).addClass('choosen'); |
69 | 72 | }); |
73 | +} | |
74 | + | |
75 | +function activateIssueTrackerTypeSelector() { | |
76 | + var not_choosen = $("div.tracker_params").filter(function () { | |
77 | + return !$(this).hasClass("choosen"); | |
78 | + }); | |
79 | + window.hiddenTracker = not_choosen.html(); | |
80 | + not_choosen.remove(); | |
81 | + $('div.issue_tracker input[name*=issue_tracker_type]').live('click', function(){ | |
82 | + var choosen = $(this).val(); | |
83 | + var wrapper = $(this).closest('.nested'); | |
84 | + var tmp; | |
85 | + tmp = wrapper.find('div.choosen').html(); | |
86 | + wrapper.find('div.choosen').html(window.hiddenTracker); | |
87 | + window.hiddenTracker = tmp; | |
88 | + }); | |
70 | 89 | } |
71 | 90 | \ No newline at end of file | ... | ... |
public/stylesheets/application.css
... | ... | @@ -501,14 +501,15 @@ a.button.active { |
501 | 501 | margin-right: 14px; |
502 | 502 | } |
503 | 503 | |
504 | -/* Watchers Form */ | |
505 | -div.nested.watcher .user, div.nested.watcher .email { | |
504 | +/* Watchers and Issue Tracker Forms */ | |
505 | +div.nested.watcher .user, div.nested.watcher .email, div.issue_tracker.nested .lighthouseapp, div.issue_tracker.nested .redmine { | |
506 | 506 | display: none; |
507 | 507 | } |
508 | -div.nested.watcher .choosen { | |
508 | +div.nested.watcher .choosen, div.nested.issue_tracker .choosen { | |
509 | 509 | display: block; |
510 | 510 | } |
511 | -div.nested.watcher .choose { | |
511 | + | |
512 | +div.nested.watcher .choose, div.nested.issue_tracker .choose { | |
512 | 513 | margin-bottom: 0.5em; |
513 | 514 | } |
514 | 515 | ... | ... |
spec/controllers/apps_controller_spec.rb
... | ... | @@ -211,17 +211,32 @@ describe AppsController do |
211 | 211 | @app.reload |
212 | 212 | |
213 | 213 | @app.issue_tracker.should be_nil |
214 | - response.body.should match(/You must specify your Lighthouseapp account, token and project id/) | |
214 | + response.body.should match(/You must specify your Lighthouseapp account, api token and project id/) | |
215 | + end | |
216 | + end | |
217 | + | |
218 | + context "redmine" do | |
219 | + it "should save tracker params" do | |
220 | + put :update, :id => @app.id, :app => { :issue_tracker_attributes => { | |
221 | + :issue_tracker_type => 'redmine', :project_id => '1234', :api_token => '123123', :account => 'http://myapp.com' | |
222 | + } } | |
223 | + @app.reload | |
224 | + | |
225 | + tracker = @app.issue_tracker | |
226 | + tracker.issue_tracker_type.should == 'redmine' | |
227 | + tracker.project_id.should == '1234' | |
228 | + tracker.api_token.should == '123123' | |
229 | + tracker.account.should == 'http://myapp.com' | |
215 | 230 | end |
216 | 231 | |
217 | 232 | it "should show validation notice when sufficient params are not present" do |
218 | 233 | put :update, :id => @app.id, :app => { :issue_tracker_attributes => { |
219 | - :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123' | |
234 | + :issue_tracker_type => 'redmine', :project_id => '1234', :api_token => '123123' | |
220 | 235 | } } |
221 | 236 | @app.reload |
222 | 237 | |
223 | 238 | @app.issue_tracker.should be_nil |
224 | - response.body.should match(/You must specify your Lighthouseapp account, token and project id/) | |
239 | + response.body.should match(/You must specify your Redmine url, api token and project id/) | |
225 | 240 | end |
226 | 241 | end |
227 | 242 | end | ... | ... |