From 62f5500f0bad57e0580b84e4e7a8e867653b9b92 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Fri, 5 Mar 2021 00:18:43 +0100 Subject: [PATCH] enable/disable des conditions et filtres --- app/controllers/conditions_controller.rb | 18 ++++++++++++++- app/controllers/operations_controller.rb | 18 ++++++++++++++- app/views/conditions/_condition.html.erb | 16 +++++++++++-- app/views/filters/_filter.html.erb | 29 +++++++++++++++--------- app/views/filters/index.html.erb | 19 +++++++++------- app/views/operations/_operation.html.erb | 16 +++++++++++-- config/routes.rb | 10 ++++++-- 7 files changed, 99 insertions(+), 27 deletions(-) diff --git a/app/controllers/conditions_controller.rb b/app/controllers/conditions_controller.rb index 85f39bb..e537f64 100644 --- a/app/controllers/conditions_controller.rb +++ b/app/controllers/conditions_controller.rb @@ -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 diff --git a/app/controllers/operations_controller.rb b/app/controllers/operations_controller.rb index 0c7254a..501c0c0 100644 --- a/app/controllers/operations_controller.rb +++ b/app/controllers/operations_controller.rb @@ -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 diff --git a/app/views/conditions/_condition.html.erb b/app/views/conditions/_condition.html.erb index b987ac2..2033281 100644 --- a/app/views/conditions/_condition.html.erb +++ b/app/views/conditions/_condition.html.erb @@ -1,8 +1,20 @@
- Enabled: - <%= condition.enabled %> + <% if condition.enabled? %> + + <%= 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 %> + Disable + + + <% 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 %> + Enable + + + <% end %> + <% end %>
diff --git a/app/views/filters/_filter.html.erb b/app/views/filters/_filter.html.erb index d06fc13..8e37ac1 100644 --- a/app/views/filters/_filter.html.erb +++ b/app/views/filters/_filter.html.erb @@ -1,8 +1,25 @@
+
+ <% if filter.enabled? %> + + <%= 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 %> + Disable + + + <% 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 %> + Enable + + + <% end %> + <% end %> +
+
Description: - <%= filter.description || "No description" %> + <%= filter.description || "No description".html_safe %>
@@ -19,15 +36,5 @@
<%= link_to 'Edit', edit_filter_path(@filter) %>
-
- <%= link_to 'Delete', @filter, method: :delete, data: { confirm: 'Are you sure you want to delete this filter?' } %> -
-
- <% 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 %> -
diff --git a/app/views/filters/index.html.erb b/app/views/filters/index.html.erb index aec9233..53873ab 100644 --- a/app/views/filters/index.html.erb +++ b/app/views/filters/index.html.erb @@ -24,13 +24,18 @@ <% if filter.enabled? %> - - <%= filter.enabled %> - + + <%= 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 %> + Disable + + + <% end %> <% else %> - - <%= filter.enabled %> - + <%= 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 %> + Enable + + + <% end %> <% end %> @@ -41,8 +46,6 @@ <%= link_to 'Show', filter %> - <%= link_to 'Edit', edit_filter_path(filter) %> - <%= link_to 'Destroy', filter, method: :delete, data: { confirm: 'Are you sure?' } %> <% end %> diff --git a/app/views/operations/_operation.html.erb b/app/views/operations/_operation.html.erb index ef014f9..3319ce3 100644 --- a/app/views/operations/_operation.html.erb +++ b/app/views/operations/_operation.html.erb @@ -1,8 +1,20 @@
- Enabled: - <%= operation.enabled %> + <% if operation.enabled? %> + + <%= 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 %> + Disable + + + <% 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 %> + Enable + + + <% end %> + <% end %>
diff --git a/config/routes.rb b/config/routes.rb index cfef8b4..4d33326 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"