Commit cf79a291c720525457422b2522106b523080d7ad

Authored by Ryan Jones
1 parent c54c7abf
Exists in master and in 1 other branch production

added new notification partial, model tweaks to get fields working

app/models/app.rb
... ... @@ -35,7 +35,8 @@ class App
35 35 :reject_if => proc { |attrs| attrs[:user_id].blank? && attrs[:email].blank? }
36 36 accepts_nested_attributes_for :issue_tracker, :allow_destroy => true,
37 37 :reject_if => proc { |attrs| !IssueTracker.subclasses.map(&:to_s).include?(attrs[:type].to_s) }
38   -
  38 + accepts_nested_attributes_for :notification_service, :allow_destroy => true,
  39 + :reject_if => proc { |attrs| !NotificationService.subclasses.map(&:to_s).include?(attrs[:type].to_s) }
39 40  
40 41 # Processes a new error report.
41 42 #
... ... @@ -139,7 +140,7 @@ class App
139 140 self.send("#{k}=", copy_app.send(k))
140 141 end
141 142 # Clone the embedded objects that can be changed via apps/edit (ignore errs & deploys, etc.)
142   - %w(watchers issue_tracker).each do |relation|
  143 + %w(watchers issue_tracker notification_service).each do |relation|
143 144 if obj = copy_app.send(relation)
144 145 self.send("#{relation}=", obj.is_a?(Array) ? obj.map(&:clone) : obj.clone)
145 146 end
... ...
app/models/notification_service.rb
... ... @@ -5,6 +5,8 @@ class NotificationService
5 5 field :api_token, :type => String
6 6 field :subdomain, :type => String
7 7  
  8 + embedded_in :app, :inverse_of => :notfication_service
  9 +
8 10 validate :check_params
9 11  
10 12 # Subclasses are responsible for overwriting this method.
... ...
app/models/notification_services/campfire_service.rb
1   -class NotificationService::CampfireService < IssueTracker
  1 +class NotificationService::CampfireService < NotificationService
2 2 Label = "campfire"
3 3 Fields = [
4 4 [:subdomain, {
... ...
app/views/apps/_fields.html.haml
... ... @@ -46,4 +46,5 @@
46 46 = f.label :resolve_errs_on_deploy, 'Resolve errs on deploy'
47 47  
48 48 = render "issue_tracker_fields", :f => f
  49 += render "service_notification_fields", :f => f
49 50  
... ...
app/views/apps/_service_notification_fields.html.haml 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +%fieldset
  2 + %legend Notification Service
  3 + = f.fields_for :notification_service do |w|
  4 + %div.notification.nested
  5 + %div.choose
  6 + = label_tag :type_none, :for => label_for_attr(w, 'type_notificationservice'), :class => "label_radio none" do
  7 + = w.radio_button :type, "NotificationService", 'data-section' => 'none'
  8 + (None)
  9 + - NotificationService.subclasses.each do |notification_service|
  10 + = label_tag "type_#{notification_service.label}:", :for => label_for_attr(w, "type_#{notification_service.name.downcase.gsub(':','')}"), :class => "label_radio #{notification_service.label}" do
  11 + = w.radio_button :type, notification_service.name, 'data-section' => notification_service.label
  12 + = notification_service.name[/::(.*)Service/,1].titleize
  13 +
  14 + %div.notification_params.none{:class => (w.object && !(w.object.class < NotificationService)) ? 'chosen' : nil}
  15 + %p When no issue tracker has been configured, you will be able to leave comments on errors.
  16 + - NotificationService.subclasses.each do |notification_service|
  17 + %div.notification_params{:class => (w.object.is_a?(notification_service) ? 'chosen ' : '') << notification_service.label}
  18 + - notification_service::Fields.each do |field, field_info|
  19 + = w.label field, field_info[:label] || field.to_s.titleize
  20 + - field_type = field == :password ? :password_field : :text_field
  21 + = w.send field_type, field, :placeholder => field_info[:placeholder], :value => w.object.send(field)
  22 +
  23 + .image_preloader
  24 + - (NotificationService.subclasses.map{|t| t.label } << 'none').each do |notification_service|
  25 + = image_tag "#{notification_service}_inactive.png"
  26 + = image_tag "#{notification_service}_create.png"
... ...