Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'rails32' of github.com:dawanda/sheriff into rails32

  • Loading branch information...
commit fdf898fcad21500e386cea547e288bf58c93e293 2 parents 8851a5a + bb275ac
Roman Heinrich mindreframer authored
1  Gemfile
View
@@ -16,6 +16,7 @@ gem 'key_value', :require => false
gem "therubyracer", :require => false
gem 'sass-rails', "~> 3.2.1", :require => false
gem 'uglifier', :require => false
+gem 'coffee-script', '2.2.0', :require => false
gem "twitter-bootstrap-rails", :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'ace-rails-ap'
5 Gemfile.lock
View
@@ -58,6 +58,10 @@ GEM
net-ssh-gateway (>= 1.1.0)
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.2.0)
commonjs (0.2.0)
therubyracer (~> 0.9.9)
diff-lcs (1.1.3)
@@ -195,6 +199,7 @@ DEPENDENCIES
ar_serialized_array (>= 0.3.0)
capistrano
capistrano-ext
+ coffee-script (= 2.2.0)
factory_girl!
hoptoad_notifier
inherited_resources
3  app/assets/javascripts/application.js
View
@@ -1,9 +1,10 @@
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
+//= require bootstrap
//= require ace
//= require theme-solarized_light
//= require mode-ruby
//= require sheriff
//= require groups
-//= require_self
+//= require_self
5 app/assets/javascripts/bootstrap.js.coffee
View
@@ -4,13 +4,10 @@
$(".carousel").carousel()
$(".collapse").collapse()
$(".dropdown-toggle").dropdown()
- $(".modal").modal()
- ## duplication?
- $("a[rel]").popover()
+ #$(".modal").modal()
$("a[rel=popover]").popover()
$(".navbar").scrollspy()
$(".tab").tab "show"
- ## duplication?
$(".tooltip").tooltip()
$("a[rel=tooltip]").tooltip()
$(".typeahead").typeahead()
6 app/controllers/reports_controller.rb
View
@@ -23,6 +23,12 @@ def batch_validate
redirect_back_or_default '/reports'
end
+ def clear_alerts
+ report = Report.find(params[:id])
+ report.alerts.delete_all
+ redirect_back_or_default '/reports'
+ end
+
private
def mark_inactive_validations_for_destroy
22 app/helpers/application_helper.rb
View
@@ -37,6 +37,12 @@ def short_validations(report)
end.sort.join(' ').html_safe
end
+ def human_validation_display(report)
+ report.validations.map do |v|
+ v.human_display
+ end.join(' <br/> ').html_safe
+ end
+
def uppercase_letters(name)
letters = name.split('').select{|c|c =~ /[A-Z]/}[0..-2].join('')
"<span title='#{name}'>#{letters}</span>"
@@ -94,6 +100,22 @@ def fields_for_sti(form, many, add)
end
end
+ def help_for_validations(validation)
+ case validation.class.to_s
+ when 'ValueValidation' then
+ { :title => 'Check the value range/type',
+ :content => "Fill the values for positive outcome."}
+ when 'RunEveryValidation' then
+ { :title => 'Check how often it should run',
+ :content => "Choose the period, how often a report should come in. Check only_once-checkbox, if only one report is expected."}
+ when 'RunBetweenValidation' then
+ { :title => 'Check when (night/special hours) it should run',
+ :content => "If some reports are expected in special daily hours, set them here."}
+ else
+ raise validation.class
+ end
+ end
+
def select_options_tag(name,list,options={})
selected = options[:value] || h(params[name])
select_tag(name, options_for_select(list,selected), options)
6 app/models/run_between_validation.rb
View
@@ -17,6 +17,10 @@ def end_hms=(x)
self.end_seconds = Time.parse(x).seconds_after_midnight
end
+ def human_display
+ "runs between #{start_hms} and #{end_hms} (#{human_error_level})"
+ end
+
def check!
if report.reported_at.seconds_after_midnight.between?(start_seconds, end_seconds)
validation_passed!
@@ -24,4 +28,4 @@ def check!
validation_failed! "Did not run in expected interval #{Time.seconds_after_midnight.to_hms} <-> #{start_hms}..#{end_hms}"
end
end
-end
+end
5 app/models/run_every_validation.rb
View
@@ -1,5 +1,6 @@
class RunEveryValidation < Validation
include IntervalAccessors
+ include ActionView::Helpers::DateHelper
belongs_to :report
def check!
@@ -17,6 +18,10 @@ def check!
end
end
+ def human_display
+ "runs every #{distance_of_time_in_words(interval)} (#{human_error_level})"
+ end
+
def self.check_all!
all.each(&:check!)
end
7 app/models/validation.rb
View
@@ -1,5 +1,6 @@
class Validation < ActiveRecord::Base
include ErrorLevelPropagation
+ ERROR_LEVELS = {0 => 'Ignore', 1 => 'Log', 2 => 'Email', 3 => 'Sms'}
before_update :adjust_current_error_level
validates_format_of :ignore_start, :ignore_end, :with => /^\d\d:\d\d$/, :allow_blank => true
@@ -27,6 +28,10 @@ def in_ignore_interval?
now.between?(start_time, end_time)
end
+ def human_error_level
+ ERROR_LEVELS[error_level]
+ end
+
protected
def validation_failed!(message)
@@ -46,4 +51,4 @@ def validation_passed!
def adjust_current_error_level
self.current_error_level = error_level if error_level_changed? and current_error_level != 0
end
-end
+end
8 app/models/value_validation.rb
View
@@ -1,6 +1,6 @@
class ValueValidation < Validation
include SerializedValue
-
+
belongs_to :report
def value_as_text=(x)
@@ -9,6 +9,10 @@ def value_as_text=(x)
self.value = eval(x) # this is evil, but dont tell anyone ok ?
end
+ def human_display
+ "expects values #{value} (#{human_error_level})"
+ end
+
def check!
matches = case value
when Regexp then report.value.to_s =~ value
@@ -22,4 +26,4 @@ def check!
validation_failed! "Value did not match #{report.value.inspect} <-> #{value.inspect}"
end
end
-end
+end
15 app/views/groups/edit.erb
View
@@ -5,7 +5,20 @@
<% end %>
<% hide_group = !@group.level1? %>
-<h3>Is running on following deputies: </h3>
+<% if @group.current_error_level != 0 %>
+ <%= form_for @group do |f| %>
+ <%= f.hidden_field :id %>
+ <%= f.hidden_field :current_error_level, {:value => 0} %>
+ <%= submit_tag 'reset error level', :class => 'btn btn-primary' %>
+ <a rel="popover"
+ title="Reset Error Level"
+ data-content='sometimes error level needs manual resetting'>
+ <i class='icon-question-sign'></i>
+ </a>
+ <% end %>
+
+<% end %>
+<h3>Is running on following Deputies: </h3>
<%= form_for Report.new, :url => '/reports/batch_validate' do |f| %>
<table class="sharp">
<tr>
4 app/views/reports/_report_row.erb
View
@@ -8,8 +8,8 @@
<% end %>
<%= link_to_edit report, :text => 'Change Validations', :class => 'btn btn-mini' %><br>
- <% if short_validations(report) != '' %>
- <span class="label"><%= short_validations(report) %></span>
+ <% if report.validations.size > 0 %>
+ <span style='font-size:10px;font-weight: bold;'><%= human_validation_display(report) %></span>
<% end %>
</td>
<% unless hide_group %>
10 app/views/reports/_validation_form.erb
View
@@ -8,6 +8,13 @@
<td>
<% key = "report[validations_attributes][#{index}][active]" %>
<%= check_box_with_label(key, true, !validation.new_record?, validation.type.to_s.sub('Validation',''), {:class => 'checkbox inline'} )%>
+
+ <a rel="popover"
+ title="<%= help_for_validations(validation)[:title] %>"
+ data-content='<%= help_for_validations(validation)[:content] %>'>
+ <i class='icon-question-sign'></i>
+ </a>
+
</td>
<td>
<% case validation
@@ -16,7 +23,7 @@
<% when RunEveryValidation %>
<%= vf.text_field :interval_value, :class => 'span1' %>
<%= vf.select :interval_unit, time_units_for_select, {}, {:class => 'span2'} %>
- <%= vf.label :only_run_once, vf.check_box(:only_run_once)+ " once", {:class => 'checkbox inline'}%>
+ <%= vf.label :only_run_once, vf.check_box(:only_run_once)+ "only once/period", {:class => 'checkbox inline'}%>
<% when RunBetweenValidation %>
<%= vf.text_field :start_hms, {:class => 'span1'} %>
@@ -33,6 +40,7 @@
<%= fields %>
<% else %>
<% id = "_#{rand(111111111111)}" %>
+ <%= nbsp(2) %>
<%= link_to_function 'ignore?', "$('##{id}').toggle()", :class => 'btn btn-warning' %>
<br />
<span style="display:none" id="<%=id%>">
44 app/views/reports/edit.erb
View
@@ -8,22 +8,34 @@ in group: <%= link_to_object @report.group %>
<hr>
-<a class="btn btn-primary" data-toggle="modal" href="#validationForm" >Add Validation</a>
+<a class="btn btn-primary" data-toggle="modal" href="#validationForm" >Edit Validations</a>
<br>
+<div class="well">
+ <%= human_validation_display(@report) %>
+</div>
<div class="well">
- <h3>Alerts</h3>
- <div style="max-height:200px; overflow:auto">
- <table class="sharp">
- <% @report.alerts.each do |alert| %>
- <tr <%= error_attribute alert %>>
- <td><%= detailed_time alert.created_at %></td>
- <td><%= alert.message %></td>
- <td><%= button_to_delete alert, :text => 'x' %></td>
- </tr>
- <% end %>
- </table>
- </div>
+ <% if @report.alerts.size > 0 %>
+ <% alerts = @report.alerts %>
+ <h3>Alerts (<%= alerts.size %> in last <%= distance_of_time_in_words_to_now(alerts.last.created_at) %>)</h3>
+ <div style="max-height:200px; overflow:auto">
+ <table class="sharp">
+ <% alerts.each do |alert| %>
+ <tr <%= error_attribute alert %>>
+ <td><%= detailed_time alert.created_at %></td>
+ <td><%= alert.message %></td>
+ <td><%= button_to_delete alert, :text => 'x' %></td>
+ </tr>
+ <% end %>
+ </table>
+ </div>
+ <%= form_tag '/reports/clear_alerts' do %>
+ <%= hidden_field_tag :id, @report.id %>
+ <%= submit_tag 'Clear Alerts', :class => 'btn btn-primary' %>
+ <% end %>
+ <% else %>
+ <h3>No Recent Alerts</h3>
+ <% end %>
</div>
<div class="well">
@@ -48,15 +60,11 @@ in group: <%= link_to_object @report.group %>
<div id='validationForm' class='modal fade well'>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
- <h3>Add Validation</h3>
+ <h3>Edit Validations</h3>
</div>
<%= form_for @report do |f| %>
<%= render 'validation_form', :f => f %>
<%= submit_tag 'Save', :class => 'btn btn-primary' %>
<a href="#" class="btn" data-dismiss="modal">Close</a>
<% end %>
- <!-- <div class="modal-footer">
- <a href="#" class="btn btn-primary" data-dismiss="modal">Save changes</a>
- <a href="#" class="btn" data-dismiss="modal">Close</a>
- </div> -->
</div>
1  config/routes.rb
View
@@ -11,6 +11,7 @@
resources :reports do
collection do
post :batch_validate
+ post :clear_alerts
end
end
resources :validations
11 spec/controllers/reports_controller_spec.rb
View
@@ -115,4 +115,15 @@ def get_it(params={})
reports.each(&:reload).map{|r| r.validations.map(&:interval) }.should == [[3.days], [3.days]]
end
end
+
+ describe '#clear_alerts' do
+ let(:alert){Factory(:alert)}
+
+ it "removes alerts for this report" do
+ report = alert.report
+ report.alerts.size.should > 0
+ post :clear_alerts, :id => report.id
+ report.reload.alerts.size.should == 0
+ end
+ end
end
9 spec/support/factories.rb
View
@@ -38,6 +38,15 @@
f.interval 60*60
end
+Factory.define(:alert) do |f|
+ f.error_level 1
+ f.message 'Value did not match 1 <-> 0'
+ f.validation_type 'Validation'
+ f.association :validation, :factory => :value_validation
+ f.association :report
+end
+
+
Factory.define(:plugin) do |f|
f.code "class Bla < Scout::Plugin;def build_report;puts 'fooo';end;end"
f.name{ "useless plugin #{rand(111111111)}" }
Please sign in to comment.
Something went wrong with that request. Please try again.