Notification: optional label, enforce interval requirement

This commit is contained in:
Colin Darie 2018-08-30 20:09:52 +02:00
parent 294bb83cc2
commit cb57fee73c
No known key found for this signature in database
GPG Key ID: 4FB865FDBCA4BCC4
6 changed files with 20 additions and 15 deletions

View File

@ -39,7 +39,7 @@ class Check < ApplicationRecord
through: :check_notifications, validate: true
accepts_nested_attributes_for :notifications,
reject_if: lambda { |att| att["label"].blank? && att["interval"].blank? }
reject_if: lambda { |att| att["interval"].blank? }
enum kind: [:domain, :ssl]
enum mode: [:auto, :manual]

View File

@ -33,8 +33,13 @@ class Notification < ApplicationRecord
enum channel: [:email]
validates :label, presence: true
validates :channel, presence: true
validates :interval, numericality: { only_integer: true, greater_than_or_equal_to: 1 }
validates :recipient, presence: true
def notifical_label
return label if label.present?
"#{recipient} (#{interval})"
end
end

View File

@ -45,7 +45,7 @@
<%= f.association :notifications, as: :check_boxes,
collection: policy_scope(Notification),
label_method: :label,
label_method: :notifical_label,
label_text: false %>
<%= f.fields_for :notifications, new_notification do |nf| %>

View File

@ -1,13 +1,13 @@
<% # Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr> %>
<% # License: GNU AGPL-3+ (see full text in LICENSE file) %>
<%= simple_form_for(notification) do |f| %>
<%= f.input :label, hint: t(".label_hint")%>
<%= f.input :recipient, as: :email,
input_html: { autocapitalize: :none, autocorrect: :off }
%>
<%= f.input :interval, as: :integer, required: true %>
<%= f.input :interval, as: :integer, required: true %>
<%= f.input :label, hint: t(".label_hint") %>
<%= f.button :submit, class: "btn-primary mt-3" %>
<% end %>

View File

@ -12,10 +12,6 @@
</div>
<% end %>
<div class="form-group <%= notification_variable_col_class %>">
<%= f.input :label, label: false %>
</div>
<div class="form-group <%= notification_variable_col_class %>">
<%= f.input :recipient, as: :email, label: false %>
</div>
@ -23,5 +19,9 @@
<div class="form-group col-md-2">
<%= f.input :interval, as: :integer, label: false, required: true %>
</div>
<div class="form-group <%= notification_variable_col_class %>">
<%= f.input :label, label: false %>
</div>
</div>
</fieldset>

View File

@ -7,15 +7,15 @@
</div>
<% end %>
<div class="<%= notification_variable_col_class %>">
<%= f.label :label %>
</div>
<div class="<%= notification_variable_col_class %>">
<%= f.label :recipient %>
</div>
<div class="col-md-2">
<%= f.label :interval %>
<%= f.label :interval, required: true %>
</div>
<div class="<%= notification_variable_col_class %>">
<%= f.label :label %>
</div>
</div>