Permalink
Browse files

Redmine issue tracker setup.

  • Loading branch information...
1 parent ba17fba commit fb3dd19efbc19665e57c832c8bf7e5b07464b398 @oruen oruen committed Apr 1, 2011
@@ -1,2 +1,5 @@
module ApplicationHelper
+ def lighthouse_tracker? object
+ object.issue_tracker_type == "lighthouseapp"
+ end
end
View
@@ -30,7 +30,7 @@ class App
accepts_nested_attributes_for :watchers, :allow_destroy => true,
:reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? }
accepts_nested_attributes_for :issue_tracker, :allow_destroy => true,
- :reject_if => proc { |attrs| !%w( lighthouseapp ).include?(attrs[:issue_tracker_type]) }
+ :reject_if => proc { |attrs| !%w( lighthouseapp redmine ).include?(attrs[:issue_tracker_type]) }
# Mongoid Bug: find(id) on association proxies returns an Enumerator
def self.find_by_id!(app_id)
@@ -5,7 +5,7 @@ class IssueTracker
include Rails.application.routes.url_helpers
default_url_options[:host] = Errbit::Application.config.action_mailer.default_url_options[:host]
- validate :check_lighthouseapp_params
+ validate :check_params
embedded_in :app, :inverse_of => :issue_tracker
@@ -87,10 +87,15 @@ def create_issue err
end
protected
- def check_lighthouseapp_params
+ def check_params
blank_flags = %w( api_token project_id account ).map {|m| self[m].blank? }
if blank_flags.any? && !blank_flags.all?
- errors.add(:base, "You must specify your Lighthouseapp account, token and project id")
+ message = if issue_tracker_type == 'lighthouseapp'
+ "You must specify your Lighthouseapp account, api token and project id"
+ else
+ "You must specify your Redmine url, api token and project id"
+ end
+ errors.add(:base, message)
end
end
end
@@ -25,15 +25,24 @@
%fieldset
%legend Issue tracker
= f.fields_for :issue_tracker do |w|
- %div.watcher.nested
+ %div.issue_tracker.nested
%div.choose
= w.radio_button :issue_tracker_type, :lighthouseapp
= label_tag :issue_tracker_type_lighthouseapp, 'Lighthouse', :for => label_for_attr(w, 'issue_tracker_type_lighthouseapp')
- %div.lighthouseapp{:class => 'choosen'}
+ = w.radio_button :issue_tracker_type, :redmine
+ = label_tag :issue_tracker_type_redmine, 'Redmine', :for => label_for_attr(w, 'issue_tracker_type_redmine')
+ %div.tracker_params{:class => lighthouse_tracker?(w.object) ? 'choosen' : nil}
= w.label :account, "Account"
- = w.text_field :account
+ = w.text_field :account, :placeholder => "abc from abc.lighthouseapp.com"
+ = w.label :api_token, "API token"
+ = w.text_field :api_token, :placeholder => "API Token for your account"
+ = w.label :project_id, "Project ID"
+ = w.text_field :project_id, :placeholder => "123 from abc from abc.lighthouseapp.com/projects/123"
+ %div.tracker_params{:class => lighthouse_tracker?(w.object) ? nil : 'choosen'}
+ = w.label :account, "Redmine URL"
+ = w.text_field :account, :placeholder => "like http://www.redmine.org/"
= w.label :api_token, "API token"
- = w.text_field :api_token
+ = w.text_field :api_token, :placeholder => "API Token for your account"
= w.label :project_id, "Project ID"
= w.text_field :project_id
View
@@ -3,6 +3,9 @@ $(function(){
if($('div.watcher.nested').length)
activateWatcherTypeSelector();
+
+ if($('div.issue_tracker.nested').length)
+ activateIssueTrackerTypeSelector();
});
function activateNestedForms() {
@@ -67,4 +70,20 @@ function activateWatcherTypeSelector() {
wrapper.find('div.choosen').removeClass('choosen');
wrapper.find('div.'+choosen).addClass('choosen');
});
+}
+
+function activateIssueTrackerTypeSelector() {
+ var not_choosen = $("div.tracker_params").filter(function () {
+ return !$(this).hasClass("choosen");
+ });
+ window.hiddenTracker = not_choosen.html();
+ not_choosen.remove();
+ $('div.issue_tracker input[name*=issue_tracker_type]').live('click', function(){
+ var choosen = $(this).val();
+ var wrapper = $(this).closest('.nested');
+ var tmp;
+ tmp = wrapper.find('div.choosen').html();
+ wrapper.find('div.choosen').html(window.hiddenTracker);
+ window.hiddenTracker = tmp;
+ });
}
@@ -501,14 +501,15 @@ a.button.active {
margin-right: 14px;
}
-/* Watchers Form */
-div.nested.watcher .user, div.nested.watcher .email {
+/* Watchers and Issue Tracker Forms */
+div.nested.watcher .user, div.nested.watcher .email, div.issue_tracker.nested .lighthouseapp, div.issue_tracker.nested .redmine {
display: none;
}
-div.nested.watcher .choosen {
+div.nested.watcher .choosen, div.nested.issue_tracker .choosen {
display: block;
}
-div.nested.watcher .choose {
+
+div.nested.watcher .choose, div.nested.issue_tracker .choose {
margin-bottom: 0.5em;
}
@@ -211,17 +211,32 @@
@app.reload
@app.issue_tracker.should be_nil
- response.body.should match(/You must specify your Lighthouseapp account, token and project id/)
+ response.body.should match(/You must specify your Lighthouseapp account, api token and project id/)
+ end
+ end
+
+ context "redmine" do
+ it "should save tracker params" do
+ put :update, :id => @app.id, :app => { :issue_tracker_attributes => {
+ :issue_tracker_type => 'redmine', :project_id => '1234', :api_token => '123123', :account => 'http://myapp.com'
+ } }
+ @app.reload
+
+ tracker = @app.issue_tracker
+ tracker.issue_tracker_type.should == 'redmine'
+ tracker.project_id.should == '1234'
+ tracker.api_token.should == '123123'
+ tracker.account.should == 'http://myapp.com'
end
it "should show validation notice when sufficient params are not present" do
put :update, :id => @app.id, :app => { :issue_tracker_attributes => {
- :issue_tracker_type => 'lighthouseapp', :project_id => '1234', :api_token => '123123'
+ :issue_tracker_type => 'redmine', :project_id => '1234', :api_token => '123123'
} }
@app.reload
@app.issue_tracker.should be_nil
- response.body.should match(/You must specify your Lighthouseapp account, token and project id/)
+ response.body.should match(/You must specify your Redmine url, api token and project id/)
end
end
end

0 comments on commit fb3dd19

Please sign in to comment.