From cf79a291c720525457422b2522106b523080d7ad Mon Sep 17 00:00:00 2001 From: Ryan Jones Date: Tue, 7 Aug 2012 12:57:30 -0600 Subject: [PATCH] added new notification partial, model tweaks to get fields working --- app/models/app.rb | 5 +++-- app/models/notification_service.rb | 2 ++ app/models/notification_services/campfire_service.rb | 2 +- app/views/apps/_fields.html.haml | 1 + app/views/apps/_service_notification_fields.html.haml | 26 ++++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 app/views/apps/_service_notification_fields.html.haml diff --git a/app/models/app.rb b/app/models/app.rb index fb0f809..1aedfeb 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -35,7 +35,8 @@ class App :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? } accepts_nested_attributes_for :issue_tracker, :allow_destroy => true, :reject_if => proc { |attrs| !IssueTracker.subclasses.map(&:to_s).include?(attrs[:type].to_s) } - + accepts_nested_attributes_for :notification_service, :allow_destroy => true, + :reject_if => proc { |attrs| !NotificationService.subclasses.map(&:to_s).include?(attrs[:type].to_s) } # Processes a new error report. # @@ -139,7 +140,7 @@ class App self.send("#{k}=", copy_app.send(k)) end # Clone the embedded objects that can be changed via apps/edit (ignore errs & deploys, etc.) - %w(watchers issue_tracker).each do |relation| + %w(watchers issue_tracker notification_service).each do |relation| if obj = copy_app.send(relation) self.send("#{relation}=", obj.is_a?(Array) ? obj.map(&:clone) : obj.clone) end diff --git a/app/models/notification_service.rb b/app/models/notification_service.rb index beaa886..93db32c 100644 --- a/app/models/notification_service.rb +++ b/app/models/notification_service.rb @@ -5,6 +5,8 @@ class NotificationService field :api_token, :type => String field :subdomain, :type => String + embedded_in :app, :inverse_of => :notfication_service + validate :check_params # Subclasses are responsible for overwriting this method. diff --git a/app/models/notification_services/campfire_service.rb b/app/models/notification_services/campfire_service.rb index 9623d02..8b6d65e 100644 --- a/app/models/notification_services/campfire_service.rb +++ b/app/models/notification_services/campfire_service.rb @@ -1,4 +1,4 @@ -class NotificationService::CampfireService < IssueTracker +class NotificationService::CampfireService < NotificationService Label = "campfire" Fields = [ [:subdomain, { diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index 0dd8a33..0f008f3 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -46,4 +46,5 @@ = f.label :resolve_errs_on_deploy, 'Resolve errs on deploy' = render "issue_tracker_fields", :f => f += render "service_notification_fields", :f => f diff --git a/app/views/apps/_service_notification_fields.html.haml b/app/views/apps/_service_notification_fields.html.haml new file mode 100644 index 0000000..542b5a6 --- /dev/null +++ b/app/views/apps/_service_notification_fields.html.haml @@ -0,0 +1,26 @@ +%fieldset + %legend Notification Service + = f.fields_for :notification_service do |w| + %div.notification.nested + %div.choose + = label_tag :type_none, :for => label_for_attr(w, 'type_notificationservice'), :class => "label_radio none" do + = w.radio_button :type, "NotificationService", 'data-section' => 'none' + (None) + - NotificationService.subclasses.each do |notification_service| + = label_tag "type_#{notification_service.label}:", :for => label_for_attr(w, "type_#{notification_service.name.downcase.gsub(':','')}"), :class => "label_radio #{notification_service.label}" do + = w.radio_button :type, notification_service.name, 'data-section' => notification_service.label + = notification_service.name[/::(.*)Service/,1].titleize + + %div.notification_params.none{:class => (w.object && !(w.object.class < NotificationService)) ? 'chosen' : nil} + %p When no issue tracker has been configured, you will be able to leave comments on errors. + - NotificationService.subclasses.each do |notification_service| + %div.notification_params{:class => (w.object.is_a?(notification_service) ? 'chosen ' : '') << notification_service.label} + - notification_service::Fields.each do |field, field_info| + = w.label field, field_info[:label] || field.to_s.titleize + - field_type = field == :password ? :password_field : :text_field + = w.send field_type, field, :placeholder => field_info[:placeholder], :value => w.object.send(field) + + .image_preloader + - (NotificationService.subclasses.map{|t| t.label } << 'none').each do |notification_service| + = image_tag "#{notification_service}_inactive.png" + = image_tag "#{notification_service}_create.png" -- libgit2 0.21.2