decf82962d
Remove complex modal implementation and replace with simple page navigation: - Convert get_user view from modal partial to full edit page - Add proper form with Bootstrap 5 styling - Link directly from users list to edit page - Update controller actions to redirect instead of returning JSON - Add flash messages for success/error feedback - Remove all modal JavaScript and markup - Remove modal CSS and backdrop handling Benefits: - Much simpler and more maintainable - No JavaScript errors or complexity - Standard Rails CRUD pattern - Better user experience with proper navigation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
1.8 KiB
Ruby
Executable File
73 lines
1.8 KiB
Ruby
Executable File
# frozen_string_literal: true
|
|
class AdminController < ApplicationController
|
|
before_action :administrative, if: :admin_param, except: [:get_user]
|
|
skip_before_action :has_info
|
|
layout false, only: [:get_all_users]
|
|
|
|
def dashboard
|
|
end
|
|
|
|
def analytics
|
|
if params[:field].nil?
|
|
fields = "*"
|
|
else
|
|
fields = custom_fields.join(",")
|
|
end
|
|
|
|
if params[:ip]
|
|
@analytics = Analytics.hits_by_ip(params[:ip], fields)
|
|
else
|
|
@analytics = Analytics.all
|
|
end
|
|
end
|
|
|
|
def get_all_users
|
|
@users = User.all
|
|
end
|
|
|
|
def get_user
|
|
@user = User.find_by_id(params[:admin_id].to_s)
|
|
arr = ["true", "false"]
|
|
@admin_select = @user.admin ? arr : arr.reverse
|
|
end
|
|
|
|
def update_user
|
|
user = User.find_by_id(params[:admin_id])
|
|
if user
|
|
user.update(params[:user].reject { |k| k == ("password" || "password_confirmation") })
|
|
pass = params[:user][:password]
|
|
user.password = pass if !(pass.blank?)
|
|
user.save!
|
|
flash[:success] = "User updated successfully"
|
|
redirect_to admin_get_all_users_path(current_user.id)
|
|
else
|
|
flash[:error] = "User not found"
|
|
redirect_to admin_get_all_users_path(current_user.id)
|
|
end
|
|
end
|
|
|
|
def delete_user
|
|
user = User.find_by(id: params[:admin_id])
|
|
if user && !(current_user.id == user.id)
|
|
# Call destroy here so that all association records w/ id are destroyed as well
|
|
# Example user.retirement records would be destroyed
|
|
user.destroy
|
|
flash[:success] = "User deleted successfully"
|
|
else
|
|
flash[:error] = "Cannot delete this user"
|
|
end
|
|
redirect_to admin_get_all_users_path(current_user.id)
|
|
end
|
|
|
|
private
|
|
|
|
def custom_fields
|
|
params.require(:field).keys
|
|
end
|
|
helper_method :custom_fields
|
|
|
|
def admin_param
|
|
params[:admin_id] != "1"
|
|
end
|
|
end
|