enable/disable des conditions et filtres

This commit is contained in:
Jérémy Lecour 2021-03-05 00:18:43 +01:00 committed by Jérémy Lecour
parent 6296c7cd05
commit 62f5500f0b
7 changed files with 99 additions and 27 deletions

View file

@ -1,6 +1,6 @@
class ConditionsController < ApplicationController
before_action :set_filter
before_action :set_condition, only: [:show, :edit, :update, :destroy]
before_action :set_condition, only: [:show, :edit, :update, :destroy, :enable, :disable]
# GET /conditions
def index
@ -40,6 +40,22 @@ class ConditionsController < ApplicationController
end
end
def enable
if @condition.update(enabled: true)
redirect_to @filter, notice: 'Condition was successfully enabled.'
else
render :edit
end
end
def disable
if @condition.update(enabled: false)
redirect_to @filter, notice: 'Condition was successfully disabled.'
else
render :edit
end
end
# DELETE /conditions/1
def destroy
@condition.destroy

View file

@ -1,6 +1,6 @@
class OperationsController < ApplicationController
before_action :set_filter
before_action :set_operation, only: [:show, :edit, :update, :destroy]
before_action :set_operation, only: [:show, :edit, :update, :destroy, :enable, :disable]
# GET /operations
def index
@ -40,6 +40,22 @@ class OperationsController < ApplicationController
end
end
def enable
if @operation.update(enabled: true)
redirect_to @filter, notice: 'Operation was successfully enabled.'
else
render :edit
end
end
def disable
if @operation.update(enabled: false)
redirect_to @filter, notice: 'Operation was successfully disabled.'
else
render :edit
end
end
# DELETE /operations/1
def destroy
@operation.destroy

View file

@ -1,8 +1,20 @@
<div id="<%= dom_id condition %>" class="flex flex-cols">
<div class="flex-auto text-left">
<strong>Enabled:</strong>
<%= condition.enabled %>
<% if condition.enabled? %>
<!-- Enabled: "bg-indigo-600", Not Enabled: "bg-gray-200" -->
<%= link_to disable_filter_condition_path(condition.filter, condition), data: { method: :patch, confirm: 'Are you sure you want to disable this condition?' }, class: "bg-green-400 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500", "aria-pressed":"false" do %>
<span class="sr-only">Disable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-5 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% else %>
<%= link_to enable_filter_condition_path(condition.filter, condition), data: { method: :patch, confirm: 'Are you sure you want to disable this condition?' }, class: "bg-gray-200 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500", "aria-pressed":"false" do %>
<span class="sr-only">Enable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-0 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% end %>
</div>
<div class="flex-auto text-left">

View file

@ -1,8 +1,25 @@
<div id="<%= dom_id filter %>" class="<%= filter.enabled? ? 'filter--enabled' : 'filter--disabled' %> flex space-x-2">
<div class="flex-auto">
<% if filter.enabled? %>
<!-- Enabled: "bg-indigo-600", Not Enabled: "bg-gray-200" -->
<%= link_to disable_filter_path(filter), data: { method: :patch, confirm: 'Are you sure you want to disable this filter?' }, class: "bg-green-400 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500", "aria-pressed":"false" do %>
<span class="sr-only">Disable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-5 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% else %>
<%= link_to enable_filter_path(filter), data: { method: :patch, confirm: 'Are you sure you want to disable this filter?' }, class: "bg-gray-200 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500", "aria-pressed":"false" do %>
<span class="sr-only">Enable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-0 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% end %>
</div>
<div class="flex-auto">
<strong class="pr-1">Description:</strong>
<%= filter.description || "<i>No description</i>" %>
<%= filter.description || "<i>No description</i>".html_safe %>
</div>
<div class="flex-auto">
@ -19,15 +36,5 @@
<div class="">
<%= link_to 'Edit', edit_filter_path(@filter) %>
</div>
<div class="">
<%= link_to 'Delete', @filter, method: :delete, data: { confirm: 'Are you sure you want to delete this filter?' } %>
</div>
<div class="">
<% if filter.enabled? %>
<%= link_to 'Disable', disable_filter_path(@filter), data: { method: :patch, confirm: 'Are you sure you want to disable this filter?' } %>
<% else %>
<%= link_to 'Enable', enable_filter_path(@filter), data: { method: :patch, confirm: 'Are you sure you want to enable this filter?' } %>
<% end %>
</div>
</div>
</div>

View file

@ -24,13 +24,18 @@
</td>
<td class="px-6 py-4 whitespace-nowrap">
<% if filter.enabled? %>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
<%= filter.enabled %>
</span>
<!-- Enabled: "bg-indigo-600", Not Enabled: "bg-gray-200" -->
<%= link_to disable_filter_path(filter), data: { method: :patch, confirm: 'Are you sure you want to disable this filter?' }, class: "bg-green-400 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500", "aria-pressed":"false" do %>
<span class="sr-only">Disable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-5 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% else %>
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
<%= filter.enabled %>
</span>
<%= link_to enable_filter_path(filter), data: { method: :patch, confirm: 'Are you sure you want to disable this filter?' }, class: "bg-gray-200 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500", "aria-pressed":"false" do %>
<span class="sr-only">Enable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-0 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% end %>
</td>
<td class="px-6 py-4 whitespace-nowrap">
@ -41,8 +46,6 @@
</td>
<td>
<%= link_to 'Show', filter %>
<%= link_to 'Edit', edit_filter_path(filter) %>
<%= link_to 'Destroy', filter, method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>

View file

@ -1,8 +1,20 @@
<div id="<%= dom_id operation %>" class="flex flex-cols">
<div class="flex-auto text-left">
<strong class="pr-1">Enabled:</strong>
<%= operation.enabled %>
<% if operation.enabled? %>
<!-- Enabled: "bg-indigo-600", Not Enabled: "bg-gray-200" -->
<%= link_to disable_filter_operation_path(operation.filter, operation), data: { method: :patch, confirm: 'Are you sure you want to disable this operation?' }, class: "bg-green-400 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500", "aria-pressed":"false" do %>
<span class="sr-only">Disable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-5 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% else %>
<%= link_to enable_filter_operation_path(operation.filter, operation), data: { method: :patch, confirm: 'Are you sure you want to disable this operation?' }, class: "bg-gray-200 relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500", "aria-pressed":"false" do %>
<span class="sr-only">Enable</span>
<!-- Enabled: "translate-x-5", Not Enabled: "translate-x-0" -->
<span aria-hidden="true" class="translate-x-0 pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow transform ring-0 transition ease-in-out duration-200"></span>
<% end %>
<% end %>
</div>
<div class="flex-auto text-left">

View file

@ -8,8 +8,14 @@ Rails.application.routes.draw do
resources :filters do
patch :enable, on: :member
patch :disable, on: :member
resources :conditions
resources :operations
resources :conditions do
patch :enable, on: :member
patch :disable, on: :member
end
resources :operations do
patch :enable, on: :member
patch :disable, on: :member
end
end
root to: "emails#index"