Skip to content

Commit

Permalink
Merge pull request #44 from solver-it-sro/GO-123/automation_rules
Browse files Browse the repository at this point in the history
GO-123/automation_rules
  • Loading branch information
stage-rl authored Sep 8, 2023
2 parents 30625df + 1ae4e77 commit a14d6f1
Show file tree
Hide file tree
Showing 67 changed files with 813 additions and 1,784 deletions.
6 changes: 6 additions & 0 deletions app/components/common/add_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="flex justify-center items-center flex-grow-0 flex-shrink-0 relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-blue-600">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" class="flex-grow-0 flex-shrink-0 w-5 h-5 relative" preserveAspectRatio="xMidYMid meet">
<path d="M10 10H5H10Z" fill="white"></path>
<path d="M10 5V10M10 10V15M10 10H15M10 10H5" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
4 changes: 4 additions & 0 deletions app/components/common/add_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Common
class AddButtonComponent < ViewComponent::Base
end
end
6 changes: 6 additions & 0 deletions app/components/common/close_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="flex justify-center items-center flex-grow-0 flex-shrink-0 relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-white">
<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg" class="flex-grow-0 flex-shrink-0 w-5 h-5 relative" preserveAspectRatio="xMidYMid meet">
<path d="M5 15.5L15 5.5L5 15.5ZM5 5.5L15 15.5L5 5.5Z" fill="#111827"></path>
<path d="M5 5.5L15 15.5M5 15.5L15 5.5L5 15.5Z" stroke="#9CA3AF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
4 changes: 4 additions & 0 deletions app/components/common/close_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Common
class CloseButtonComponent < ViewComponent::Base
end
end
5 changes: 5 additions & 0 deletions app/components/common/delete_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="flex justify-center items-center flex-grow-0 flex-shrink-0 relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-white border border-gray-300">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" class="flex-grow-0 flex-shrink-0 w-5 h-5 relative" preserveAspectRatio="xMidYMid meet">
<path d="M8.33301 9.16667V14.1667M11.6663 9.16667V14.1667M3.33301 5.83333H16.6663M15.833 5.83333L15.1105 15.9517C15.0806 16.3722 14.8924 16.7657 14.5839 17.053C14.2755 17.3403 13.8696 17.5 13.448 17.5H6.55134C6.12979 17.5 5.7239 17.3403 5.41541 17.053C5.10693 16.7657 4.91877 16.3722 4.88884 15.9517L4.16634 5.83333H15.833ZM12.4997 5.83333V3.33333C12.4997 3.11232 12.4119 2.90036 12.2556 2.74408C12.0993 2.5878 11.8874 2.5 11.6663 2.5H8.33301C8.11199 2.5 7.90003 2.5878 7.74375 2.74408C7.58747 2.90036 7.49967 3.11232 7.49967 3.33333V5.83333H12.4997Z" stroke="#DC2626" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
4 changes: 4 additions & 0 deletions app/components/common/delete_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Common
class DeleteButtonComponent < ViewComponent::Base
end
end
3 changes: 3 additions & 0 deletions app/components/common/edit_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="flex justify-center items-center flex-grow-0 flex-shrink-0 relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-white border border-gray-300">
<%= render Icons::PencilComponent.new %>
</div>
4 changes: 4 additions & 0 deletions app/components/common/edit_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Common
class EditButtonComponent < ViewComponent::Base
end
end
3 changes: 3 additions & 0 deletions app/components/icons/info_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" class="flex-grow-0 flex-shrink-0 w-8 h-8 relative" preserveAspectRatio="xMidYMid meet">
<path d="M17.3333 21.3333H16V16H14.6667M16 10.6667H16.0133M28 16C28 17.5759 27.6896 19.1363 27.0866 20.5922C26.4835 22.0481 25.5996 23.371 24.4853 24.4853C23.371 25.5996 22.0481 26.4835 20.5922 27.0866C19.1363 27.6896 17.5759 28 16 28C14.4241 28 12.8637 27.6896 11.4078 27.0866C9.95189 26.4835 8.62902 25.5996 7.51472 24.4853C6.40042 23.371 5.5165 22.0481 4.91345 20.5922C4.31039 19.1363 4 17.5759 4 16C4 12.8174 5.26428 9.76516 7.51472 7.51472C9.76516 5.26428 12.8174 4 16 4C19.1826 4 22.2348 5.26428 24.4853 7.51472C26.7357 9.76516 28 12.8174 28 16Z" stroke="#9CA3AF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
2 changes: 2 additions & 0 deletions app/components/icons/info_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Icons::InfoComponent < ViewComponent::Base
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<%= link_to @message_thread, class:"flex justify-stretch overflow-clip items-center grow gap-2" do %>
<div class="flex flex-col truncate justify-start items-stretch grow gap-1">
<p title="<%= @message_thread.title%>"class="truncate text-lg text-gray-900 <%="font-semibold" unless @message_thread.read? %>"><%= @message_thread.title %></p>
<p title="<%= @message_thread.title%>" class="truncate text-lg text-gray-900 <%="font-semibold" unless @message_thread.read? %>"><%= @message_thread.title %></p>
<p class="text-base text-left text-gray-500"><%= @message_thread.with_whom %></p>
</div>
<div class="flex flex-wrap truncate justify-start items-start gap-1">
Expand Down
23 changes: 23 additions & 0 deletions app/components/settings/rules/action_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%= tag.turbo_frame id: "action-#{@index}", class:"flex justify-between self-stretch grow" do %>
<div class="flex justify-stretch gap-2">
<%= @form.select :type, @action_type_list, {}, class:"mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %>
<%= @form.text_field :value, class:"mt-2 block rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-400 ring-1 ring-inset ring-gray-400 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6", disabled: !@enabled %>
</div>
<% if @enabled %>
<div>
<% if @form.object.type %>
<%= button_tag type: "submit", formaction: settings_automation_action_path(id: @form.object.id, index: @index), formmethod: :delete, data: {turbo_frame: "condition-#{@index}"} do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<%= button_tag type: "submit", formaction: settings_automation_action_path(index: @index), formmethod: :patch do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
<% else %>
<%= button_tag type: "submit", formaction: settings_automation_actions_path(index: @index), formmethod: :post do %>
<%= render Common::AddButtonComponent.new %>
<% end %>
<% end %>
</div>
<% end %>
</div>
<% end %>
11 changes: 11 additions & 0 deletions app/components/settings/rules/action_form_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Settings::Rules::ActionFormComponent < ViewComponent::Base
def initialize(form:, index:, enabled: true)
@form = form
@index = index
@enabled = enabled
end

def before_render
@action_type_list = Automation::Action.subclasses.map { |subclass| [t(subclass.name), subclass.name] }
end
end
50 changes: 50 additions & 0 deletions app/components/settings/rules/actions_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<%= tag.turbo_frame(id: 'modal') do %>
<div class="fixed inset-0 z-50 p-2" role="dialog" aria-modal="true">
<div class="fixed inset-0 transition-opacity bg-gray-400 bg-opacity-75" aria-hidden="true"></div>
<div class="relative flex items-center justify-center h-full">
<div class="flex flex-col justify-start items-start w-[900] overflow-hidden rounded-lg bg-white border border-gray-300" role="dialog" style="box-shadow: 1px 1px 4px 0 rgba(0,0,0,0.1);">
<div class="flex flex-col justify-start items-start self-stretch flex-grow-0 flex-shrink-0">
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 overflow-hidden gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<div class="flex flex-col justify-start items-start flex-grow relative">
<p class="self-stretch flex-grow w-[788px] text-xl font-semibold text-left text-gray-900"> Úprava pravidla </p>
<p class="flex-grow-0 flex-shrink-0 text-xs text-left text-gray-500"> Krok 3 z 3 – Akcie pravidla </p>
</div>
<%= link_to settings_automation_rules_path, data: { turbo_frame: "_top" } do %>
<%= render Common::CloseButtonComponent.new %>
<% end %>
</div>
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 relative gap-4 p-6 bg-white border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<%= render Icons::InfoComponent.new %>
<p class="flex-grow w-[804px] text-base text-left text-gray-900"> Pravidlo spúšťa ľubovoľný počet akcií, pričom všetky budú vykonané ak sú splnené všetky podmienky pravidla.</p>
</div>
<%= form_with model: [:settings, @new_rule], class:"flex justify-start items-center self-stretch gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |new_rule_form| %>
<%= new_rule_form.fields_for :actions do |new_action_form| %>
<%= tag.turbo_frame id: "action-new", class:"flex justify-between grow" do %>
<%= render Settings::Rules::ActionFormComponent.new(form: new_action_form, index: @automation_rule.actions.size) %>
<% end %>
<% end %>
<% end %>
<%= form_with model: [:settings, @automation_rule], class:"flex flex-col self-stretch" do |rule_form| %>
<%= tag.turbo_frame id: 'actions', class:"flex flex-col justify-start items-start grow gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do %>
<%= rule_form.fields_for :actions do |action_form| %>
<% if action_form.object.delete_record %>
<%= action_form.hidden_field :delete_record, value:true %>
<% else %>
<%= render Settings::Rules::ActionsFormRowComponent.new(form: action_form, index: action_form.index) %>
<% end %>
<% end %>
<% end %>
<%= render Settings::Rules::HiddenRuleFormComponent.new(form: rule_form) %>
<%= rule_form.fields_for :conditions do |condition_form| %>
<%= render Settings::Rules::HiddenConditionRowComponent.new(form:condition_form) %>
<% end %>
<div class="flex justify-start items-start self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6">
<%= rule_form.button "Späť", formaction: conditions_step_settings_automation_rule_path, class:"flex justify-center items-center flex-grow relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md border border-gray-300 text-base font-medium text-left text-gray-900 bg-white" %>
<%= rule_form.button "Uložiť zmeny", class:"flex justify-center items-center flex-grow relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md text-base font-medium text-left text-white bg-blue-600" %>
</div>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/components/settings/rules/actions_form_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Settings::Rules::ActionsFormComponent < ViewComponent::Base
def initialize(automation_rule:)
@automation_rule = automation_rule
@new_rule = Automation::Rule.new(actions: [Automation::Action.new])
end
end
20 changes: 20 additions & 0 deletions app/components/settings/rules/actions_form_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%= tag.turbo_frame id: "condition-#{@index}", class:"flex justify-start self-stretch grow" do %>
<div class="flex justify-between items-center self-stretch flex-grow flex-shrink-0 relative">
<div class="flex gap-1">
<p class="text-base font-medium text-left text-gray-900"><%= t @form.object.type %></p>
<p class="text-base text-left text-gray-900"><%= @form.object.value %></p>
<%= @form.hidden_field :type %>
<%= @form.hidden_field :value %>
</div>
<% if @editable %>
<div class="flex">
<%= button_tag type: "submit", formaction: settings_automation_action_path(index: @index), formmethod: :post do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_tag type: "submit", formaction: settings_automation_action_path(id: @form.object.id, index: @index), formmethod: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
<% end %>
</div>
<% end %>
7 changes: 7 additions & 0 deletions app/components/settings/rules/actions_form_row_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Settings::Rules::ActionsFormRowComponent < ViewComponent::Base
def initialize(form:, index:, editable: true)
@form = form
@index = index
@editable = editable
end
end
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<div class="flex flex-col justify-start items-start rounded-md bg-white border border-gray-200">
<div class="flex justify-start items-center relative gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" >
<p class=" w-[1074px] text-xl font-semibold text-left text-gray-900">
Automatické pravidlá
</p>
<div
class="flex justify-center items-center relative gap-2.5 px-3.5 py-2.5 rounded-md bg-blue-600"
>
<p class=" text-base font-medium text-left text-white">
Vytvoriť pravidlo
</p>
</div>
</div>
<div class="flex flex-col justify-start items-start ">
<div
class="flex justify-start items-center gap-2 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200"
>
<% automation_rules.each do |automation_rule| %>
<%= automation_rule %>
<% end %>
<div class="flex justify-start items-start w-full">
<div class="flex flex-col justify-start items-start flex-grow gap-4 p-4">
<div class="flex flex-col justify-start items-start self-stretch flex-grow-0 flex-shrink-0 overflow-hidden rounded-md bg-white border border-gray-200">
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 relative overflow-hidden gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" >
<p class="flex-grow w-[1074px] text-xl font-semibold text-left text-gray-900">Automatické pravidlá</p>
<%= link_to new_settings_automation_rule_path, class:"flex justify-center items-center gap-2.5 px-3.5 py-2.5 rounded-md bg-blue-600" do %>
<p class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-white">Vytvoriť pravidlo</p>
<% end %>
</div>
<div class="flex flex-col justify-start items-start self-stretch flex-grow-0 flex-shrink-0">
<div class="flex flex-col justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<% automation_rules.each do |automation_rule| %>
<%= automation_rule %>
<% end %>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

class Settings::Rules::AutomationRulesListComponent < ViewComponent::Base
renders_many :automation_rules
end
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
<div class="flex flex-col justify-start items-start relative gap-1">
<p class=" text-lg text-left text-gray-900">
<span class=" text-lg text-left text-gray-900">Správy, kde</span>
<% @automation_rule.conditions.each_with_index do |condition, index| %>
<span class=" text-lg font-medium text-left text-gray-900"><%= condition.attr %></span>
<span class=" text-lg text-left text-gray-900"><%= condition.type_human_string %></span>
<% if index < @automation_rule.conditions.size - 1 %>
<% @suffix = ' a' %>
<% else %>
<% @suffix = '' %>
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<div class="flex flex-col justify-start items-start flex-grow relative gap-1">
<p class="flex-grow-0 flex-shrink-0 text-lg text-left text-gray-900">
<span class="flex-grow-0 flex-shrink-0 text-lg text-left text-gray-900">Správy, kde</span>
<% @automation_rule.conditions.each_with_index do |condition, index| %>
<span class="flex-grow-0 flex-shrink-0 text-lg font-medium text-left text-gray-900"><%= t condition.attr %></span>
<span class="flex-grow-0 flex-shrink-0 text-lg text-left text-gray-900"><%= t condition.type %></span>
<% if index < @automation_rule.conditions.size - 1 %>
<% @suffix = ' a' %>
<% else %>
<% @suffix = '' %>
<% end %>
<span class="flex-grow-0 flex-shrink-0 text-lg font-medium text-left text-gray-900"><%= "'#{condition.value}'#{@suffix}"%></span>
<% end %>
<span class=" text-lg font-medium text-left text-gray-900"><%= "'#{condition.value}'#{@suffix}"%></span>
</p>
<p class="flex-grow-0 flex-shrink-0 text-base text-left text-gray-500">
<% @automation_rule.actions.each_with_index do |action, index| %>
<span class="flex-grow-0 flex-shrink-0 text-base text-left text-gray-500"><%= t action.type %></span>
<span class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-gray-500"><%= action.value %></span>
<%if index < @automation_rule.actions.length - 1%><%= ', '%><% end %>
<% end %>
</p>
</div>
<div class="flex justify-start items-start flex-grow-0 flex-shrink-0 gap-2">
<%= link_to edit_settings_automation_rule_path(@automation_rule), data: { turbo_frame: :modal } do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
</p>
<p class=" text-base text-left text-gray-500">
<% @automation_rule.actions.each_with_index do |action, index| %>
<span class=" text-base text-left text-gray-500"><%= action.type_human_string %></span>
<span class=" text-base font-medium text-left text-gray-500"><%= action.params['tag_name'] %></span>
<%= button_to settings_automation_rule_path(@automation_rule), method: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</p>
</div>
<div class="flex justify-start items-start gap-2">
<a href=<%= edit_settings_automation_rule_path(@automation_rule) %>>
<div class="flex justify-center items-center relative gap-2.5 px-3.5 py-2.5 rounded-md bg-white border border-gray-300">
<svg width="20" height="20"viewBox="0 0 20 20"fill="none"xmlns="http://www.w3.org/2000/svg"class=" w-5 h-5 relative"preserveAspectRatio="xMidYMid meet">
<path d="M12.6933 4.36003L15.64 7.3067M13.9433 3.11003C14.3341 2.71928 14.8641 2.49976 15.4167 2.49976C15.9693 2.49976 16.4992 2.71928 16.89 3.11003C17.2808 3.50078 17.5003 4.03076 17.5003 4.58336C17.5003 5.13597 17.2808 5.66595 16.89 6.0567L5.41667 17.53H2.5V14.5534L13.9433 3.11003Z"stroke="#111827"stroke-width="2"stroke-linecap="round"stroke-linejoin="round"></path>
</svg>
</div>
<a href=<%= settings_automation_rule_path(@automation_rule) %>>
<div class="flex justify-center items-center relative gap-2.5 px-3.5 py-2.5 rounded-md bg-white border border-gray-300">
<svg width="20"height="20"viewBox="0 0 20 20"fill="none"xmlns="http://www.w3.org/2000/svg"class=" w-5 h-5 relative"preserveAspectRatio="xMidYMid meet">
<path d="M8.33301 9.16667V14.1667M11.6663 9.16667V14.1667M3.33301 5.83333H16.6663M15.833 5.83333L15.1105 15.9517C15.0806 16.3722 14.8924 16.7657 14.5839 17.053C14.2755 17.3403 13.8696 17.5 13.448 17.5H6.55134C6.12979 17.5 5.7239 17.3403 5.41541 17.053C5.10693 16.7657 4.91877 16.3722 4.88884 15.9517L4.16634 5.83333H15.833ZM12.4997 5.83333V3.33333C12.4997 3.11232 12.4119 2.90036 12.2556 2.74408C12.0993 2.5878 11.8874 2.5 11.6663 2.5H8.33301C8.11199 2.5 7.90003 2.5878 7.74375 2.74408C7.58747 2.90036 7.49967 3.11232 7.49967 3.33333V5.83333H12.4997Z"stroke="#DC2626"stroke-width="2"stroke-linecap="round"stroke-linejoin="round"></path>
</svg>
</div>
</a>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

class Settings::Rules::AutomationRulesTableRowComponent < ViewComponent::Base
def initialize(automation_rule)
@automation_rule = automation_rule
Expand Down
Loading

0 comments on commit a14d6f1

Please sign in to comment.