From 2ea1c75544a2ffc5b0cc065432f9d3e6d2670b81 Mon Sep 17 00:00:00 2001 From: hatz Date: Sun, 11 May 2025 12:46:20 -0500 Subject: [PATCH] Add primary_condition_title field to rule model --- app/models/rule.rb | 12 ++++++++++++ app/views/rules/_rule.html.erb | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/rule.rb b/app/models/rule.rb index db8a99ae..ec15d64b 100644 --- a/app/models/rule.rb +++ b/app/models/rule.rb @@ -46,6 +46,18 @@ class Rule < ApplicationRecord RuleJob.perform_later(self, ignore_attribute_locks: ignore_attribute_locks) end + def primary_condition_title + return "No conditions" if conditions.none? + + first_condition = conditions.first + if first_condition.compound? && first_condition.sub_conditions.any? + first_sub_condition = first_condition.sub_conditions.first + "If #{first_sub_condition.filter.label.downcase} #{first_sub_condition.operator} #{first_sub_condition.value_display}" + else + "If #{first_condition.filter.label.downcase} #{first_condition.operator} #{first_condition.value_display}" + end + end + private def matching_resources_scope scope = registry.resource_scope diff --git a/app/views/rules/_rule.html.erb b/app/views/rules/_rule.html.erb index e2b01b74..5ef51440 100644 --- a/app/views/rules/_rule.html.erb +++ b/app/views/rules/_rule.html.erb @@ -4,12 +4,8 @@
<% if rule.conditions.any? %>

- - <% if rule.conditions.first.compound? %> - If <%= rule.conditions.first.sub_conditions.first.filter.label %> <%= rule.conditions.first.sub_conditions.first.operator %> <%= rule.conditions.first.sub_conditions.first.value_display %> - <% else %> - If <%= rule.conditions.first.filter.label %> <%= rule.conditions.first.operator %> <%= rule.conditions.first.value_display %> - <% end %> + + <%= rule.primary_condition_title %> <% if rule.conditions.count > 1 %>