mirror of https://github.com/Evolix/chexpire.git
Notification: optional label, enforce interval requirement
This commit is contained in:
parent
294bb83cc2
commit
cb57fee73c
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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| %>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue