Skip to content

Commit

Permalink
Add gem rails admin
Browse files Browse the repository at this point in the history
  • Loading branch information
binhpt-1239 committed Mar 12, 2024
1 parent 9d21f94 commit 5cbf5b1
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem "pagy"
gem "puma", "~> 4.1"
gem "rails", "~> 6.0.4", ">= 6.0.4.6"
gem "rails-i18n"
gem "rails_admin"
gem "ransack"
gem "sass-rails", ">= 6"
gem "turbolinks", "~> 5"
Expand Down
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ GEM
globalid (>= 0.3.6)
activemodel (6.0.4.7)
activesupport (= 6.0.4.7)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (6.0.4.7)
activemodel (= 6.0.4.7)
activesupport (= 6.0.4.7)
Expand Down Expand Up @@ -141,6 +145,18 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
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)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand All @@ -157,6 +173,7 @@ GEM
minitest (5.15.0)
msgpack (1.5.1)
mysql2 (0.5.3)
nested_form (0.3.2)
nio4r (2.5.8)
nokogiri (1.13.4)
mini_portile2 (~> 2.8.0)
Expand Down Expand Up @@ -203,6 +220,12 @@ GEM
rails-i18n (7.0.3)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
rails_admin (3.0.0)
activemodel-serializers-xml (>= 1.0)
kaminari (>= 0.14, < 2.0)
nested_form (~> 0.3)
rails (>= 6.0, < 8)
turbo-rails (~> 1.0)
railties (6.0.4.7)
actionpack (= 6.0.4.7)
activesupport (= 6.0.4.7)
Expand Down Expand Up @@ -292,6 +315,9 @@ GEM
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.0.10)
turbo-rails (1.0.1)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
Expand Down Expand Up @@ -342,6 +368,7 @@ DEPENDENCIES
rails (~> 6.0.4, >= 6.0.4.6)
rails-controller-testing
rails-i18n
rails_admin
ransack
rspec-rails (~> 4.0.1)
rubocop (~> 0.74.0)
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/packs/rails_admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "rails_admin/src/rails_admin/base";
import "../stylesheets/rails_admin.scss";
1 change: 1 addition & 0 deletions app/javascript/stylesheets/rails_admin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "~rails_admin/src/rails_admin/styles/base";
1 change: 0 additions & 1 deletion app/models/currency.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Currency < ApplicationRecord
belongs_to :user, optional: true
belongs_to :currency_type

enum currency_type_id: {payment: 1, withdrawal: 2, win: 3, lose: 4}

Expand Down
2 changes: 2 additions & 0 deletions app/models/goal_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class GoalResult < ApplicationRecord
belongs_to :soccer_match
belongs_to :team

scope :newest, ->{order created_at: :desc}

scope :score, (lambda do |team_id, soccer_match_id|
where(soccer_match_id: soccer_match_id, team_id: team_id)
end)
Expand Down
1 change: 1 addition & 0 deletions app/models/news.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class News < ApplicationRecord
belongs_to :user
has_many :comments, dependent: :nullify
end
3 changes: 3 additions & 0 deletions app/views/shared/_asider_admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<li class="nav-item">
<%= link_to t("shared.asider_user.home"), admin_root_path, class: "nav-link py-3 px-2 bi-house fs-6" %>
</li>
<li class="nav-item">
<%= link_to t("actions.Dashboard.menu"), Settings.dashboard_path, class: "nav-link py-3 px-2 bi-house fs-6" %>
</li>
<li class="nav-item">
<%= link_to t(".create_soccer_match"), new_admin_soccer_match_path, class: "nav-link py-3 px-2 bi bi-chevron-double-right fs-6" %>
</li>
Expand Down
34 changes: 34 additions & 0 deletions config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
RailsAdmin.config do |config|
config.asset_source = :webpacker

config.main_app_name = Settings.admin_app_name

config.included_models = %w(SoccerMatch News Comment User Currency UserBet Bet)

config.authenticate_with do
warden.authenticate! scope: :user
end

config.current_user_method(&:current_user)

config.authorize_with do
I18n.locale = params[:locale] || default_locale
redirect_to main_app.root_path unless current_user.admin?
end

config.actions do
dashboard # mandatory
index # mandatory
new do
except %w(Bet UserBet SoccerMatch)
end
export do
except %w(SoccerMatch)
end
bulk_delete
show
edit
delete
show_in_app
end
end
157 changes: 157 additions & 0 deletions config/locales/rails_admin.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
en:
admin:
js:
true: True
false: False
is_present: Is present
is_blank: Is blank
date: Date ...
between_and_: Between ... and ...
today: Today
yesterday: Yesterday
this_week: This week
last_week: Last week
time: Time ...
number: Number ...
contains: Contains
does_not_contain: Does not contain
is_exactly: Is exactly
starts_with: Starts with
ends_with: Ends with
too_many_objects: "Too many objects, use search box above"
no_objects: "No objects found"
clear: Clear
toggle_navigation: Toggle navigation
home:
name: "Home"
pagination:
previous: "&laquo; Prev"
next: "Next &raquo;"
truncate: ""
misc:
search: "Search"
filter: "Filter"
reset_filters: "Reset filters"
refresh: "Refresh"
show_all: "Show all"
add_filter: "Add filter"
bulk_menu_title: "Selected items"
remove: "Remove"
add_new: "Add new"
chose_all: "Choose all"
clear_all: "Clear all"
up: "Up"
down: "Down"
navigation: "Navigation"
root_navigation: "Actions"
navigation_static_label: "Links"
log_out: "Log out"
time_ago: "%{time} ago"
ago: "ago"
more: "Plus %{count} more %{models_name}"
flash:
successful: "%{name} successfully %{action}"
error: "%{name} failed to be %{action}"
noaction: "No actions were taken"
model_not_found: "Model '%{model}' could not be found"
object_not_found: "%{model} with id '%{id}' could not be found"
table_headers:
model_name: "Model name"
last_created: "Last created"
records: "Records"
username: "User"
changes: "Changes"
created_at: "Date/Time"
item: "Item"
message: "Message"
actions:
dashboard:
title: "Site Administration"
menu: "Dashboard"
breadcrumb: "Dashboard"
index:
title: "List of %{model_label_plural}"
menu: "List"
breadcrumb: "%{model_label_plural}"
no_records: "No records found"
show:
title: "Details for %{model_label} '%{object_label}'"
menu: "Show"
breadcrumb: "%{object_label}"
show_in_app:
menu: "Show in app"
new:
title: "New %{model_label}"
menu: "Add new"
breadcrumb: "New"
link: "Add a new %{model_label}"
done: "created"
edit:
title: "Edit %{model_label} '%{object_label}'"
menu: "Edit"
breadcrumb: "Edit"
link: "Edit this %{model_label}"
done: "updated"
delete:
title: "Delete %{model_label} '%{object_label}'"
menu: "Delete"
breadcrumb: "Delete"
link: "Delete '%{object_label}'"
done: "deleted"
bulk_delete:
title: "Delete %{model_label_plural}"
menu: "Multiple delete"
breadcrumb: "Multiple delete"
bulk_link: "Delete selected %{model_label_plural}"
export:
title: "Export %{model_label_plural}"
menu: "Export"
breadcrumb: "Export"
link: "Export found %{model_label_plural}"
bulk_link: "Export selected %{model_label_plural}"
done: "exported"
history_index:
title: "History for %{model_label_plural}"
menu: "History"
breadcrumb: "History"
history_show:
title: "History for %{model_label} '%{object_label}'"
menu: "History"
breadcrumb: "History"
form:
cancel: "Cancel"
basic_info: "Basic info"
required: "Required"
optional: "Optional"
one_char: "character"
char_length_up_to: "length up to"
char_length_of: "length of"
save: "Save"
save_and_add_another: "Save and add another"
save_and_edit: "Save and edit"
delete_file: "Delete '%{field_label}' #%{number}"
all_of_the_following_related_items_will_be_deleted: "? The following related items may be deleted or orphaned:"
are_you_sure_you_want_to_delete_the_object: "Are you sure you want to delete this %{model_name}"
confirmation: "Yes, I'm sure"
bulk_delete: "The following objects will be deleted, which may delete or orphan some of their related dependencies:"
new_model: "%{name} (new)"
export:
confirmation: "Export to %{name}"
select: "Select fields to export"
select_all_fields: "Select All Fields"
fields_from: "Fields from %{name}"
fields_from_associated: "Fields from associated %{name}"
display: "Display %{name}: %{type}"
options_for: "Options for %{name}"
empty_value_for_associated_objects: "<empty>"
click_to_reverse_selection: "Click to reverse selection"
csv:
header_for_root_methods: "%{name}" # 'model' is available
header_for_association_methods: "%{name} [%{association}]"
encoding_to: "Encode to"
encoding_to_help: "Choose output encoding. Leave empty to let current input encoding untouched: (%{name})"
skip_header: "No header"
skip_header_help: "Do not output a header (no fields description)"
default_col_sep: ","
col_sep: "Column separator"
col_sep_help: "Leave blank for default ('%{value}')" # value is default_col_sep
Loading

0 comments on commit 5cbf5b1

Please sign in to comment.