diff --git a/Gemfile b/Gemfile index 0189349..0e8b30c 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,7 @@ group :production do end gem 'administrate' +gem 'administrate-field-image' gem 'dragonfly' gem 'dragonfly-s3_data_store' gem 'kaminari' diff --git a/Gemfile.lock b/Gemfile.lock index 5c20020..9bdd65e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,6 +48,8 @@ GEM momentjs-rails (~> 2.8) sass-rails (~> 5.0) selectize-rails (~> 0.6) + administrate-field-image (1.1.0) + administrate (>= 0.2.0.rc1) arel (6.0.4) ast (2.3.0) autoprefixer-rails (7.1.2.3) @@ -330,6 +332,7 @@ PLATFORMS DEPENDENCIES administrate + administrate-field-image aws-sdk better_errors binding_of_caller diff --git a/app/assets/stylesheets/administrate/overrides.css.scss b/app/assets/stylesheets/administrate/overrides.css.scss index 13d5ecb..b2729dc 100644 --- a/app/assets/stylesheets/administrate/overrides.css.scss +++ b/app/assets/stylesheets/administrate/overrides.css.scss @@ -1,9 +1,9 @@ -.logout { +.navigation__link--logout { position: absolute; - bottom: 1.5em; + bottom: 3em; } -.login { +.main-content--login { margin-left: auto; margin-right: auto; max-width: 50em; diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 4fc94ca..273ff84 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -1,6 +1,6 @@ # All Administrate controllers inherit from this `Admin::ApplicationController`, # making it the ideal place to put authentication logic or other -# before_filters. +# before_actions. # # If you want to add pagination or other controller-level concerns, # you're free to overwrite the RESTful controller actions. @@ -8,7 +8,7 @@ module Admin class ApplicationController < Administrate::ApplicationController include Monban::ControllerHelpers - before_filter :require_login + before_action :require_login # Override this value to specify the number of elements to display at a time # on index pages. Defaults to 20. diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb index 2ed78b7..4f88995 100644 --- a/app/controllers/admin/categories_controller.rb +++ b/app/controllers/admin/categories_controller.rb @@ -1,11 +1,13 @@ module Admin class CategoriesController < Admin::ApplicationController # To customize the behavior of this controller, - # simply overwrite any of the RESTful actions. For example: + # you can overwrite any of the RESTful actions. For example: # # def index # super - # @resources = Category.all.paginate(10, params[:page]) + # @resources = Category. + # page(params[:page]). + # per(10) # end # Define a custom finder by overriding the `find_resource` method: @@ -13,7 +15,7 @@ module Admin # Category.find_by!(slug: param) # end - # See https://administrate-docs.herokuapp.com/customizing_controller_actions + # See https://administrate-prototype.herokuapp.com/customizing_controller_actions # for more information end end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 126f048..f058900 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -1,11 +1,13 @@ module Admin class PagesController < Admin::ApplicationController # To customize the behavior of this controller, - # simply overwrite any of the RESTful actions. For example: + # you can overwrite any of the RESTful actions. For example: # # def index # super - # @resources = Page.all.paginate(10, params[:page]) + # @resources = Page. + # page(params[:page]). + # per(10) # end # Define a custom finder by overriding the `find_resource` method: @@ -13,7 +15,7 @@ module Admin # Page.find_by!(slug: param) # end - # See https://administrate-docs.herokuapp.com/customizing_controller_actions + # See https://administrate-prototype.herokuapp.com/customizing_controller_actions # for more information end end diff --git a/app/controllers/admin/photos_controller.rb b/app/controllers/admin/photos_controller.rb index 1b181ad..bad8773 100644 --- a/app/controllers/admin/photos_controller.rb +++ b/app/controllers/admin/photos_controller.rb @@ -1,11 +1,13 @@ module Admin class PhotosController < Admin::ApplicationController # To customize the behavior of this controller, - # simply overwrite any of the RESTful actions. For example: + # you can overwrite any of the RESTful actions. For example: # # def index # super - # @resources = Photo.all.paginate(10, params[:page]) + # @resources = Photo. + # page(params[:page]). + # per(10) # end # Define a custom finder by overriding the `find_resource` method: @@ -13,7 +15,7 @@ module Admin # Photo.find_by!(slug: param) # end - # See https://administrate-docs.herokuapp.com/customizing_controller_actions + # See https://administrate-prototype.herokuapp.com/customizing_controller_actions # for more information end end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 43795c3..70251c0 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,11 +1,13 @@ module Admin class UsersController < Admin::ApplicationController # To customize the behavior of this controller, - # simply overwrite any of the RESTful actions. For example: + # you can overwrite any of the RESTful actions. For example: # # def index # super - # @resources = User.all.paginate(10, params[:page]) + # @resources = User. + # page(params[:page]). + # per(10) # end # Define a custom finder by overriding the `find_resource` method: @@ -13,7 +15,7 @@ module Admin # User.find_by!(slug: param) # end - # See https://administrate-docs.herokuapp.com/customizing_controller_actions + # See https://administrate-prototype.herokuapp.com/customizing_controller_actions # for more information end end diff --git a/app/dashboards/category_dashboard.rb b/app/dashboards/category_dashboard.rb index dac6abc..7e090ea 100644 --- a/app/dashboards/category_dashboard.rb +++ b/app/dashboards/category_dashboard.rb @@ -18,7 +18,7 @@ class CategoryDashboard < Administrate::BaseDashboard base_colour: ColourField, sort: Field::Number, slug: Field::String, - } + }.freeze # COLLECTION_ATTRIBUTES # an array of attributes that will be displayed on the model's index page. @@ -29,7 +29,7 @@ class CategoryDashboard < Administrate::BaseDashboard :name, :base_colour, :photos, - ] + ].freeze # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. @@ -44,25 +44,24 @@ class CategoryDashboard < Administrate::BaseDashboard :photo_id, :sort, :photos, - ] + ].freeze # FORM_ATTRIBUTES # an array of attributes that will be displayed # on the model's form (`new` and `edit`) pages. FORM_ATTRIBUTES = [ - :photos, :name, + :slug, + :base_colour, :description, :photo_id, - :base_colour, :sort, - :slug, - ] + ].freeze # Overwrite this method to customize how categories are displayed # across all pages of the admin dashboard. # - def display_resource(category) - category.name - end + # def display_resource(category) + # "Category ##{category.id}" + # end end diff --git a/app/dashboards/page_dashboard.rb b/app/dashboards/page_dashboard.rb index aae4e06..ec6fe42 100644 --- a/app/dashboards/page_dashboard.rb +++ b/app/dashboards/page_dashboard.rb @@ -14,7 +14,7 @@ class PageDashboard < Administrate::BaseDashboard content: MarkdownField, 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. @@ -22,9 +22,9 @@ class PageDashboard < Administrate::BaseDashboard # By default, it's limited to four items to reduce clutter on index pages. # Feel free to add, remove, or rearrange items. COLLECTION_ATTRIBUTES = [ - :title, :name, - ] + :title, + ].freeze # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. @@ -35,7 +35,7 @@ class PageDashboard < Administrate::BaseDashboard :content, :created_at, :updated_at, - ] + ].freeze # FORM_ATTRIBUTES # an array of attributes that will be displayed @@ -44,12 +44,12 @@ class PageDashboard < Administrate::BaseDashboard :name, :title, :content, - ] + ].freeze # Overwrite this method to customize how pages are displayed # across all pages of the admin dashboard. # - def display_resource(page) - page.title - end + # def display_resource(page) + # "Page ##{page.id}" + # end end diff --git a/app/dashboards/photo_dashboard.rb b/app/dashboards/photo_dashboard.rb index 985beed..6573d2b 100644 --- a/app/dashboards/photo_dashboard.rb +++ b/app/dashboards/photo_dashboard.rb @@ -21,7 +21,7 @@ class PhotoDashboard < Administrate::BaseDashboard taken_at: Field::DateTime, views: Field::Number, image: Field::Image, - } + }.freeze # COLLECTION_ATTRIBUTES # an array of attributes that will be displayed on the model's index page. @@ -34,7 +34,7 @@ class PhotoDashboard < Administrate::BaseDashboard :taken_at, :featured, :categories, - ] + ].freeze # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. @@ -52,7 +52,7 @@ class PhotoDashboard < Administrate::BaseDashboard :enabled, :views, :categories, - ] + ].freeze # FORM_ATTRIBUTES # an array of attributes that will be displayed @@ -70,9 +70,12 @@ class PhotoDashboard < Administrate::BaseDashboard :enabled, :views, :categories, - ] + ].freeze - def display_resource(photo) - photo.title - end + # Overwrite this method to customize how photos are displayed + # across all pages of the admin dashboard. + # + # def display_resource(photo) + # "Photo ##{photo.id}" + # end end diff --git a/app/dashboards/user_dashboard.rb b/app/dashboards/user_dashboard.rb index b5dcefb..4a686af 100644 --- a/app/dashboards/user_dashboard.rb +++ b/app/dashboards/user_dashboard.rb @@ -13,7 +13,7 @@ class UserDashboard < Administrate::BaseDashboard password_digest: 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. @@ -22,25 +22,24 @@ class UserDashboard < Administrate::BaseDashboard # Feel free to add, remove, or rearrange items. COLLECTION_ATTRIBUTES = [ :email, - ] + :created_at, + ].freeze # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. SHOW_PAGE_ATTRIBUTES = [ :id, :email, - :password_digest, :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 = [ :email, - :password_digest, - ] + ].freeze # Overwrite this method to customize how users are displayed # across all pages of the admin dashboard. diff --git a/app/views/admin/application/_flashes.html.erb b/app/views/admin/application/_flashes.html.erb index ff3a9f5..07d4265 100644 --- a/app/views/admin/application/_flashes.html.erb +++ b/app/views/admin/application/_flashes.html.erb @@ -14,7 +14,7 @@ This partial renders flash messages on every page. <% if flash.any? %>
<% flash.each do |key, value| -%> -
<%= value %>
+
<%= value %>
<% end -%>
<% end %> diff --git a/app/views/admin/application/_javascript.html.erb b/app/views/admin/application/_javascript.html.erb index 499323b..5197fe6 100644 --- a/app/views/admin/application/_javascript.html.erb +++ b/app/views/admin/application/_javascript.html.erb @@ -7,7 +7,9 @@ but each page can define additional JS sources by providing a `content_for(:javascript)` block. %> -<%= javascript_include_tag "administrate/application" %> +<% Administrate::Engine.javascripts.each do |js_path| %> + <%= javascript_include_tag js_path %> +<% end %> <%= yield :javascript %> diff --git a/app/views/admin/application/_navigation.html.erb b/app/views/admin/application/_navigation.html.erb new file mode 100644 index 0000000..67c8525 --- /dev/null +++ b/app/views/admin/application/_navigation.html.erb @@ -0,0 +1,25 @@ +<%# +# Navigation + +This partial is used to display the navigation in Administrate. +By default, the navigation contains navigation links +for all resources in the admin dashboard, +as defined by the routes in the `admin/` namespace +%> + + diff --git a/app/views/admin/application/_sidebar.html.erb b/app/views/admin/application/_sidebar.html.erb deleted file mode 100644 index aa2a5fd..0000000 --- a/app/views/admin/application/_sidebar.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -<%# -# Sidebar - -This partial is used to display the sidebar in Administrate. -By default, the sidebar contains navigation links -for all resources in the admin dashboard, -as defined by the routes in the `admin/` namespace -%> - - diff --git a/app/views/admin/application/_stylesheet.html.erb b/app/views/admin/application/_stylesheet.html.erb new file mode 100644 index 0000000..90c3858 --- /dev/null +++ b/app/views/admin/application/_stylesheet.html.erb @@ -0,0 +1,16 @@ +<%# +# Stylesheet Partial + +This partial imports the necessary stylesheets on each page. +By default, it includes the application CSS, +but each page can define additional CSS sources +by providing a `content_for(:stylesheet)` block. +%> + +<% Administrate::Engine.stylesheets.each do |css_path| %> + <%= stylesheet_link_tag css_path %> +<% end %> + +<%= stylesheet_link_tag "administrate/overrides", media: "all" %> + +<%= yield :stylesheet %> diff --git a/app/views/layouts/admin/application.html.erb b/app/views/layouts/admin/application.html.erb index 07ef1bb..4951671 100644 --- a/app/views/layouts/admin/application.html.erb +++ b/app/views/layouts/admin/application.html.erb @@ -5,42 +5,35 @@ This view template is used as the layout for every page that Administrate generates. By default, it renders: -- Sidebar for navigation +- Navigation - Content for a search bar (if provided by a `content_for` block in a nested page) - Flashes -- Links to stylesheets and Javascripts +- Links to stylesheets and JavaScripts %> - - - - <%= content_for(:title) %> | <%= Rails.application.class.parent_name.titlecase %> - <%= stylesheet_link_tag "administrate/application", media: "all" %> - <%= stylesheet_link_tag "administrate/overrides", media: "all" %> + + + + + <%= content_for(:title) %> - <%= Rails.application.class.parent_name.titlecase %> + + <%= render "stylesheet" %> <%= csrf_meta_tags %> - + <%= render "icons" %>
- - + <%= render "navigation" -%>
- <%= content_for(:search) %> <%= render "flashes" -%> <%= yield %>
-
<%= render "javascript" %> diff --git a/app/views/layouts/admin/login.html.erb b/app/views/layouts/admin/login.html.erb index 48a875b..fb09f35 100644 --- a/app/views/layouts/admin/login.html.erb +++ b/app/views/layouts/admin/login.html.erb @@ -18,21 +18,19 @@ By default, it renders: - <%= Rails.application.class.parent_name.titlecase %> - <%= stylesheet_link_tag "administrate/application", media: "all" %> - <%= stylesheet_link_tag "administrate/overrides", media: "all" %> + + <%= content_for(:title) %> - <%= Rails.application.class.parent_name.titlecase %> + + <%= render "admin/application/stylesheet" %> <%= csrf_meta_tags %> -
- -
+
<%= render "admin/application/flashes" -%> <%= yield %>
-
<%= render "admin/application/javascript" %> diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 1088c1a..2da7640 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,29 +1,31 @@ -
-

Sign In

+ -<%= form_for :session, url: session_path do |form| %> -
-
-
- <%= form.label :email %> +
+ <%= form_for :session, url: session_path do |form| %> +
+
+
+ <%= form.label :email %> +
+
+ <%= form.email_field :email %> +
-
- <%= form.email_field :email %> + +
+
+ <%= form.label :password %> +
+
+ <%= form.password_field :password %> +
-
-
- <%= form.label :password %> -
-
- <%= form.password_field :password %> -
+
+ <%= form.submit "Sign in" %>
-
- -
- <%= form.submit "Sign in" %> -
-<% end %> + <% end %> +