11module Admin
22 class IgnoreListsController < BaseController
3- before_action :set_ignore_list , only : [ : edit, : update, : destroy]
3+ before_action :set_ignore_list , only : %i[ edit update destroy ]
44
55 def index
66 @ignore_lists = IgnoreList . all
77
88 # Filter by list type
9- if params [ :list_type ] . present?
10- @ignore_lists = @ignore_lists . where ( list_type : params [ :list_type ] )
11- end
9+ @ignore_lists = @ignore_lists . where ( list_type : params [ :list_type ] ) if params [ :list_type ] . present?
1210
1311 # Search functionality
14- if params [ :search ] . present?
15- @ignore_lists = @ignore_lists . where ( 'value ILIKE ?' , "%#{ params [ :search ] } %" )
16- end
12+ @ignore_lists = @ignore_lists . where ( "value ILIKE ?" , "%#{ params [ :search ] } %" ) if params [ :search ] . present?
1713
1814 # Sorting
1915 @ignore_lists = @ignore_lists . order ( created_at : :desc )
@@ -31,43 +27,42 @@ def new
3127 @ignore_list = IgnoreList . new ( list_type : params [ :list_type ] )
3228 end
3329
30+ def edit ; end
31+
3432 def create
3533 @ignore_list = IgnoreList . new ( ignore_list_params )
3634
3735 if @ignore_list . save
38- redirect_to admin_ignore_lists_path , notice : ' Ignore list entry was successfully created.'
36+ redirect_to admin_ignore_lists_path , notice : " Ignore list entry was successfully created."
3937 else
40- render :new , status : :unprocessable_entity
38+ render :new , status : :unprocessable_content
4139 end
4240 end
4341
44- def edit
45- end
46-
4742 def update
4843 if @ignore_list . update ( ignore_list_params )
49- redirect_to admin_ignore_lists_path , notice : ' Ignore list entry was successfully updated.'
44+ redirect_to admin_ignore_lists_path , notice : " Ignore list entry was successfully updated."
5045 else
51- render :edit , status : :unprocessable_entity
46+ render :edit , status : :unprocessable_content
5247 end
5348 end
5449
5550 def destroy
5651 @ignore_list . destroy
57- redirect_to admin_ignore_lists_path , notice : ' Ignore list entry was successfully deleted.'
52+ redirect_to admin_ignore_lists_path , notice : " Ignore list entry was successfully deleted."
5853 end
5954
6055 # Bulk import action
6156 def bulk_import
62- if request . post?
63- results = process_bulk_import ( params [ :import_data ] , params [ :list_type ] )
64-
65- if results [ :errors ] . empty?
66- redirect_to admin_ignore_lists_path , notice : "Successfully imported #{ results [ :created ] . count } entries."
67- else
68- redirect_to admin_ignore_lists_path ,
69- alert : "Imported #{ results [ :created ] . count } entries. #{ results [ :errors ] . count } errors occurred."
70- end
57+ return unless request . post?
58+
59+ results = process_bulk_import ( params [ :import_data ] , params [ :list_type ] )
60+
61+ if results [ :errors ] . empty?
62+ redirect_to admin_ignore_lists_path , notice : "Successfully imported #{ results [ :created ] . count } entries."
63+ else
64+ redirect_to admin_ignore_lists_path ,
65+ alert : "Imported #{ results [ :created ] . count } entries. #{ results [ :errors ] . count } errors occurred."
7166 end
7267 end
7368
@@ -78,12 +73,12 @@ def set_ignore_list
7873 end
7974
8075 def ignore_list_params
81- params . require ( : ignore_list) . permit ( : list_type, : value, : notes)
76+ params . expect ( ignore_list : %i[ list_type value notes ] )
8277 end
8378
8479 def process_bulk_import ( import_data , list_type )
8580 results = { created : [ ] , errors : [ ] }
86-
81+
8782 return results if import_data . blank? || list_type . blank?
8883
8984 # Split by newlines and process each line
@@ -92,7 +87,7 @@ def process_bulk_import(import_data, list_type)
9287 next if value . blank?
9388
9489 ignore_list = IgnoreList . new ( list_type : list_type , value : value )
95-
90+
9691 if ignore_list . save
9792 results [ :created ] << ignore_list
9893 else
@@ -103,4 +98,4 @@ def process_bulk_import(import_data, list_type)
10398 results
10499 end
105100 end
106- end
101+ end
0 commit comments