diff --git a/Gemfile b/Gemfile index ae9a2e29..7a46838f 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,8 @@ gem "stimulus-rails" gem "rollbar" +gem "kaminari" + # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem "jbuilder", "~> 2.12" diff --git a/Gemfile.lock b/Gemfile.lock index bfe39ce6..2dc41061 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -170,6 +170,18 @@ GEM jsbundling-rails (1.3.1) railties (>= 6.0.0) json (2.7.2) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) kramdown (2.4.0) rexml language_server-protocol (3.17.0.3) @@ -403,6 +415,7 @@ DEPENDENCIES image_processing (~> 1.13) jbuilder (~> 2.12) jsbundling-rails + kaminari listen (>= 3.0.5, < 3.10) mysql2 (~> 0.5.6) puma (~> 6.4) diff --git a/app/controllers/admin/admins_controller.rb b/app/controllers/admin/admins_controller.rb new file mode 100644 index 00000000..f2d40af4 --- /dev/null +++ b/app/controllers/admin/admins_controller.rb @@ -0,0 +1,61 @@ +class Admin::AdminsController < Comfy::Admin::BaseController + before_action :build_admin, only: [:new, :create] + before_action :load_admin, only: [:show, :edit, :update, :destroy] + + def index + @admins = Admin.page(params[:page]) + end + + def show + render + end + + def new + render + end + + def edit + render + end + + def create + @admin.save! + flash[:success] = "Admin created" + redirect_to action: :show, id: @admin + rescue ActiveRecord::RecordInvalid + flash.now[:danger] = "Failed to create Admin" + render action: :new + end + + def update + @admin.update!(admin_params) + flash[:success] = "Admin updated" + redirect_to action: :show, id: @admin + rescue ActiveRecord::RecordInvalid + flash.now[:danger] = "Failed to update Admin" + render action: :edit + end + + def destroy + @admin.destroy + flash[:success] = "Admin deleted" + redirect_to action: :index + end + + protected + + def build_admin + @admin = Admin.new(admin_params) + end + + def load_admin + @admin = Admin.find(params[:id]) + rescue ActiveRecord::RecordNotFound + flash[:danger] = "Admin not found" + redirect_to action: :index + end + + def admin_params + params.fetch(:admin, {}).permit(:email, :password) + end +end diff --git a/app/views/admin/admins/_form.html.erb b/app/views/admin/admins/_form.html.erb new file mode 100644 index 00000000..113d55ef --- /dev/null +++ b/app/views/admin/admins/_form.html.erb @@ -0,0 +1,7 @@ +<%= form.text_field :email %> +<%= form.password_field :password %> + +<%= form.form_actions do %> + <%= form.submit class: "btn btn-primary ml-sm-1" %> + <%= link_to 'Cancel', admin_admins_path, class: "btn btn-link" %> +<% end %> diff --git a/app/views/admin/admins/edit.html.erb b/app/views/admin/admins/edit.html.erb new file mode 100644 index 00000000..bab45d13 --- /dev/null +++ b/app/views/admin/admins/edit.html.erb @@ -0,0 +1,7 @@ +