From fb3dd19efbc19665e57c832c8bf7e5b07464b398 Mon Sep 17 00:00:00 2001 From: Nick Recobra Date: Fri, 1 Apr 2011 12:52:54 +0400 Subject: [PATCH] Redmine issue tracker setup. --- app/helpers/application_helper.rb | 3 +++ app/models/app.rb | 2 +- app/models/issue_tracker.rb | 11 ++++++++--- app/views/apps/_fields.html.haml | 17 +++++++++++++---- public/javascripts/form.js | 19 +++++++++++++++++++ public/stylesheets/application.css | 9 +++++---- spec/controllers/apps_controller_spec.rb | 21 ++++++++++++++++++--- 7 files changed, 67 insertions(+), 15 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..a5ba883 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def lighthouse_tracker? object + object.issue_tracker_type == "lighthouseapp" + end end diff --git a/app/models/app.rb b/app/models/app.rb index b960121..9550be4 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -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) diff --git a/app/models/issue_tracker.rb b/app/models/issue_tracker.rb index 3ce6360..a770c57 100644 --- a/app/models/issue_tracker.rb +++ b/app/models/issue_tracker.rb @@ -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 @@ class IssueTracker 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 diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index 2d3b763..99ba854 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -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 diff --git a/public/javascripts/form.js b/public/javascripts/form.js index a7b6aeb..b2e1eef 100644 --- a/public/javascripts/form.js +++ b/public/javascripts/form.js @@ -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; + }); } \ No newline at end of file diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index e6e4809..628d807 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -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; } diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index d477eab..38eb9c7 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -211,17 +211,32 @@ describe AppsController do @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 -- libgit2 0.21.2