-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# All Administrate controllers inherit from this `Admin::ApplicationController`, | ||
# making it the ideal place to put authentication logic or other | ||
# before_actions. | ||
# | ||
# If you want to add pagination or other controller-level concerns, | ||
# you're free to overwrite the RESTful controller actions. | ||
module Admin | ||
class ApplicationController < Administrate::ApplicationController | ||
http_basic_authenticate_with( | ||
name: ENV.fetch('ADMIN_NAME', 'admin'), | ||
password: ENV.fetch('ADMIN_PASSWORD', 'admin') | ||
) | ||
|
||
# Override this value to specify the number of elements to display at a time | ||
# on index pages. Defaults to 20. | ||
# def records_per_page | ||
# params[:per_page] || 20 | ||
# end | ||
def index | ||
page = Administrate::Page::Collection.new(dashboard, order: order) | ||
|
||
render locals: { | ||
resources: resources, | ||
search_term: search_term, | ||
page: page, | ||
show_search_bar: show_search_bar?, | ||
} | ||
end | ||
|
||
private | ||
|
||
def resources | ||
r = Administrate::Search.new(resource_resolver, search_term).run | ||
r = order.apply(r) | ||
r.page(params[:page]).per(records_per_page) | ||
end | ||
|
||
def search_term | ||
params[:search].to_s.strip | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Admin | ||
class GamesController < Admin::ApplicationController | ||
# To customize the behavior of this controller, | ||
# you can overwrite any of the RESTful actions. For example: | ||
# | ||
# def index | ||
# super | ||
# @resources = Game. | ||
# page(params[:page]). | ||
# per(10) | ||
# end | ||
|
||
# Define a custom finder by overriding the `find_resource` method: | ||
# def find_resource(param) | ||
# Game.find_by!(slug: param) | ||
# end | ||
|
||
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions | ||
# for more information | ||
|
||
private | ||
|
||
def resources | ||
r = Administrate::Search.new(resource_resolver, search_term).run | ||
r.order_by_title.order_by_region.page(params[:page]).per(records_per_page) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Admin | ||
class PricesController < Admin::ApplicationController | ||
# To customize the behavior of this controller, | ||
# you can overwrite any of the RESTful actions. For example: | ||
# | ||
# def index | ||
# super | ||
# @resources = Price. | ||
# page(params[:page]). | ||
# per(10) | ||
# end | ||
|
||
# Define a custom finder by overriding the `find_resource` method: | ||
# def find_resource(param) | ||
# Price.find_by!(slug: param) | ||
# end | ||
|
||
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions | ||
# for more information | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'administrate/base_dashboard' | ||
|
||
class GameDashboard < Administrate::BaseDashboard | ||
# ATTRIBUTE_TYPES | ||
# a hash that describes the type of each of the model's fields. | ||
# | ||
# Each different type represents an Administrate::Field object, | ||
# which determines how the attribute is displayed | ||
# on pages throughout the dashboard. | ||
ATTRIBUTE_TYPES = { | ||
prices: Field::HasMany.with_options( | ||
limit: 50 | ||
), | ||
id: Field::Number, | ||
raw_game_code: Field::String, | ||
game_code: Field::String, | ||
nsuid: Field::String, | ||
region: Field::Select.with_options( | ||
collection: %w[americas asia europe] | ||
), | ||
title: Field::String, | ||
release_date: Field::DateTime, | ||
cover_url: Field::String, | ||
created_at: Field::DateTime, | ||
updated_at: Field::DateTime, | ||
}.freeze | ||
|
||
# COLLECTION_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's index page. | ||
# | ||
# By default, it's limited to four items to reduce clutter on index pages. | ||
# Feel free to add, remove, or rearrange items. | ||
COLLECTION_ATTRIBUTES = %i[ | ||
title | ||
game_code | ||
region | ||
nsuid | ||
].freeze | ||
|
||
# SHOW_PAGE_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's show page. | ||
SHOW_PAGE_ATTRIBUTES = %i[ | ||
raw_game_code | ||
game_code | ||
nsuid | ||
region | ||
title | ||
release_date | ||
cover_url | ||
prices | ||
created_at | ||
updated_at | ||
].freeze | ||
|
||
# FORM_ATTRIBUTES | ||
# an array of attributes that will be displayed | ||
# on the model's form (`new` and `edit`) pages. | ||
FORM_ATTRIBUTES = %i[ | ||
raw_game_code | ||
game_code | ||
nsuid | ||
region | ||
title | ||
release_date | ||
cover_url | ||
].freeze | ||
|
||
# Overwrite this method to customize how games are displayed | ||
# across all pages of the admin dashboard. | ||
|
||
def display_resource(game) | ||
game.title | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "administrate/base_dashboard" | ||
|
||
class PriceDashboard < Administrate::BaseDashboard | ||
# ATTRIBUTE_TYPES | ||
# a hash that describes the type of each of the model's fields. | ||
# | ||
# Each different type represents an Administrate::Field object, | ||
# which determines how the attribute is displayed | ||
# on pages throughout the dashboard. | ||
ATTRIBUTE_TYPES = { | ||
game: Field::BelongsTo, | ||
id: Field::Number, | ||
nsuid: Field::String, | ||
country: CountryField, | ||
status: Field::String, | ||
value: MoneyField, | ||
currency: Field::String, | ||
value_in_cents: Field::Number, | ||
created_at: Field::DateTime, | ||
updated_at: Field::DateTime, | ||
}.freeze | ||
|
||
# COLLECTION_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's index page. | ||
# | ||
# By default, it's limited to four items to reduce clutter on index pages. | ||
# Feel free to add, remove, or rearrange items. | ||
COLLECTION_ATTRIBUTES = %i[ | ||
game | ||
nsuid | ||
country | ||
value | ||
].freeze | ||
|
||
# SHOW_PAGE_ATTRIBUTES | ||
# an array of attributes that will be displayed on the model's show page. | ||
SHOW_PAGE_ATTRIBUTES = %i[ | ||
game | ||
nsuid | ||
country | ||
status | ||
value | ||
].freeze | ||
|
||
# FORM_ATTRIBUTES | ||
# an array of attributes that will be displayed | ||
# on the model's form (`new` and `edit`) pages. | ||
FORM_ATTRIBUTES = %i[ | ||
game | ||
nsuid | ||
country | ||
status | ||
currency | ||
value_in_cents | ||
].freeze | ||
|
||
# Overwrite this method to customize how prices are displayed | ||
# across all pages of the admin dashboard. | ||
# | ||
# def display_resource(price) | ||
# "Price ##{price.id}" | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'administrate/field/base' | ||
|
||
class CountryField < Administrate::Field::Base | ||
def to_s | ||
ISO3166::Country[data].unofficial_names.first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'administrate/field/base' | ||
|
||
class MoneyField < Administrate::Field::Base | ||
def format | ||
data.format | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="field-unit__label"> | ||
<%= f.label field.attribute %> | ||
</div> | ||
<div class="field-unit__field"> | ||
<%= f.text_field field.attribute %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= field.to_s %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= field.to_s %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= field.format %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= field.format %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters