diff --git a/Gemfile.lock b/Gemfile.lock index e856e32..310ce3a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,66 +7,67 @@ GIT GEM remote: http://rubygems.org/ specs: - actionmailer (4.2.4) - actionpack (= 4.2.4) - actionview (= 4.2.4) - activejob (= 4.2.4) + actionmailer (4.2.5) + actionpack (= 4.2.5) + actionview (= 4.2.5) + activejob (= 4.2.5) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.4) - actionview (= 4.2.4) - activesupport (= 4.2.4) + actionpack (4.2.5) + actionview (= 4.2.5) + activesupport (= 4.2.5) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.4) - activesupport (= 4.2.4) + actionview (4.2.5) + activesupport (= 4.2.5) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.4) - activesupport (= 4.2.4) + activejob (4.2.5) + activesupport (= 4.2.5) globalid (>= 0.3.0) - activemodel (4.2.4) - activesupport (= 4.2.4) + activemodel (4.2.5) + activesupport (= 4.2.5) builder (~> 3.1) - activerecord (4.2.4) - activemodel (= 4.2.4) - activesupport (= 4.2.4) + activerecord (4.2.5) + activemodel (= 4.2.5) + activesupport (= 4.2.5) arel (~> 6.0) - activesupport (4.2.4) + activesupport (4.2.5) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.3.8) - administrate (0.0.12) - autoprefixer-rails - datetime_picker_rails (~> 0.0.4) + administrate (0.1.1) + autoprefixer-rails (~> 6.0) + datetime_picker_rails (~> 0.0.5) inline_svg (~> 0.6) + jquery-rails (~> 4.0) kaminari (~> 0.16) - momentjs-rails (>= 2.9.0) + momentjs-rails (~> 2.8) neat (~> 1.1) normalize-rails (~> 3.0) rails (~> 4.2) - sass (~> 3.4) + sass-rails (~> 5.0) selectize-rails (~> 0.6) arel (6.0.3) ast (2.1.0) astrolabe (1.3.1) parser (~> 2.2) - autoprefixer-rails (6.0.3) + autoprefixer-rails (6.1.1) execjs json - aws-sdk (2.1.29) - aws-sdk-resources (= 2.1.29) - aws-sdk-core (2.1.29) + aws-sdk (2.2.1) + aws-sdk-resources (= 2.2.1) + aws-sdk-core (2.2.1) jmespath (~> 1.0) - aws-sdk-resources (2.1.29) - aws-sdk-core (= 2.1.29) + aws-sdk-resources (2.2.1) + aws-sdk-core (= 2.2.1) bcrypt (3.1.10) better_errors (2.1.1) coderay (>= 1.0.0) @@ -95,9 +96,9 @@ GEM coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.9.1.1) - database_cleaner (1.5.0) - datetime_picker_rails (0.0.4) + coffee-script-source (1.10.0) + database_cleaner (1.5.1) + datetime_picker_rails (0.0.5) momentjs-rails (>= 2.8.1) debug_inspector (0.0.2) diff-lcs (1.2.5) @@ -121,19 +122,17 @@ GEM factory_girl_rails (4.5.0) factory_girl (~> 4.5.0) railties (>= 3.0.0) - fivemat (1.3.1) + fivemat (1.3.2) fog-aws (0.7.6) fog-core (~> 1.27) fog-json (~> 1.0) fog-xml (~> 0.1) ipaddress (~> 0.8) - fog-core (1.32.1) + fog-core (1.34.0) builder excon (~> 0.45) formatador (~> 0.2) mime-types - net-scp (~> 1.1) - net-ssh (>= 2.1.3) fog-json (1.0.2) fog-core (~> 1.0) multi_json (~> 1.10) @@ -152,8 +151,9 @@ GEM nokogiri (~> 1.6) ipaddress (0.8.0) jmespath (1.1.3) - jquery-rails (3.1.4) - railties (>= 3.0, < 5.0) + jquery-rails (4.0.5) + rails-dom-testing (~> 1.0) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) kaminari (0.16.3) @@ -168,9 +168,9 @@ GEM mail (2.6.3) mime-types (>= 1.16, < 3) method_source (0.8.2) - mime-types (2.6.2) + mime-types (2.99) mini_portile (0.6.2) - minitest (5.8.1) + minitest (5.8.3) momentjs-rails (2.10.6) railties (>= 3.1) monban (0.2.1) @@ -183,16 +183,13 @@ GEM neat (1.7.2) bourbon (>= 4.0) sass (>= 3.3) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (3.0.1) - nokogiri (1.6.6.2) + nokogiri (1.6.6.4) mini_portile (~> 0.6.0) normalize-rails (3.0.3) parser (2.2.3.0) ast (>= 1.1, < 3.0) - pg (0.18.3) - poltergeist (1.7.0) + pg (0.18.4) + poltergeist (1.8.0) capybara (~> 2.1) cliver (~> 0.3.1) multi_json (~> 1.0) @@ -202,24 +199,24 @@ GEM powder (0.3.0) thor (>= 0.11.5) powerpack (0.1.1) - pry (0.10.2) + pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - puma (2.14.0) + puma (2.15.3) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) - rails (4.2.4) - actionmailer (= 4.2.4) - actionpack (= 4.2.4) - actionview (= 4.2.4) - activejob (= 4.2.4) - activemodel (= 4.2.4) - activerecord (= 4.2.4) - activesupport (= 4.2.4) + rails (4.2.5) + actionmailer (= 4.2.5) + actionpack (= 4.2.5) + actionview (= 4.2.5) + activejob (= 4.2.5) + activemodel (= 4.2.5) + activerecord (= 4.2.5) + activesupport (= 4.2.5) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.4) + railties (= 4.2.5) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -234,39 +231,40 @@ GEM rails_stdout_logging rails_serve_static_assets (0.0.4) rails_stdout_logging (0.0.4) - railties (4.2.4) - actionpack (= 4.2.4) - activesupport (= 4.2.4) + railties (4.2.5) + actionpack (= 4.2.5) + activesupport (= 4.2.5) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.0.0) rake (10.4.2) redcarpet (3.3.3) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-rails (3.3.3) + rspec-support (~> 3.4.0) + rspec-rails (3.4.0) actionpack (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3) railties (>= 3.0, < 4.3) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) - rubocop (0.34.2) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) + rubocop (0.35.1) astrolabe (~> 1.3) - parser (>= 2.2.2.5, < 3.0) + parser (>= 2.2.3.0, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) - ruby-progressbar (~> 1.4) + ruby-progressbar (~> 1.7) + tins (<= 1.6.0) ruby-progressbar (1.7.5) - ruby_parser (3.7.1) + ruby_parser (3.7.2) sexp_processor (~> 4.1) sass (3.4.19) sass-rails (5.0.4) @@ -291,7 +289,7 @@ GEM json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - skylight (0.8.1) + skylight (0.9.3) activesupport (>= 3.0.0) slop (3.6.0) slugtastic (1.2.1) @@ -308,6 +306,7 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (2.0.1) + tins (1.6.0) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.2) @@ -318,7 +317,7 @@ GEM unf_ext (0.0.7.1) warden (1.2.3) rack (>= 1.0) - websocket-driver (0.6.2) + websocket-driver (0.6.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) xpath (2.0.0) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb new file mode 100644 index 0000000..43795c3 --- /dev/null +++ b/app/controllers/admin/users_controller.rb @@ -0,0 +1,19 @@ +module Admin + class UsersController < Admin::ApplicationController + # To customize the behavior of this controller, + # simply overwrite any of the RESTful actions. For example: + # + # def index + # super + # @resources = User.all.paginate(10, params[:page]) + # end + + # Define a custom finder by overriding the `find_resource` method: + # def find_resource(param) + # User.find_by!(slug: param) + # end + + # See https://administrate-docs.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 d96da41..454dc49 100644 --- a/app/dashboards/category_dashboard.rb +++ b/app/dashboards/category_dashboard.rb @@ -1,13 +1,6 @@ require "administrate/base_dashboard" -require "administrate/fields/colour" class CategoryDashboard < Administrate::BaseDashboard - READ_ONLY_ATTRIBUTES = [ - :id, - :created_at, - :updated_at, - ] - # ATTRIBUTE_TYPES # a hash that describes the type of each of the model's fields. # @@ -18,21 +11,25 @@ class CategoryDashboard < Administrate::BaseDashboard id: Field::Number, name: Field::String, slug: Field::String, - description: Field::String, + description: Field::Text, created_at: Field::DateTime, updated_at: Field::DateTime, - # photo_id: Field::Number, - base_colour: Field::Colour, + base_colour: Field::ColourField, sort: Field::Number, photos: Field::HasMany, } - # TABLE_ATTRIBUTES + # 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 remove the limit or customize the returned array. - TABLE_ATTRIBUTES = %i(base_colour name description photos) + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = [ + :base_colour, + :name, + :description, + :photos, + ] # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. @@ -41,5 +38,12 @@ class CategoryDashboard < Administrate::BaseDashboard # FORM_ATTRIBUTES # an array of attributes that will be displayed # on the model's form (`new` and `edit`) pages. - FORM_ATTRIBUTES = ATTRIBUTE_TYPES.keys - READ_ONLY_ATTRIBUTES + FORM_ATTRIBUTES = [ + :name, + :slug, + :description, + :base_colour, + :sort, + :photos, + ] end diff --git a/app/dashboards/dashboard_manifest.rb b/app/dashboards/dashboard_manifest.rb index 4951b28..b735497 100644 --- a/app/dashboards/dashboard_manifest.rb +++ b/app/dashboards/dashboard_manifest.rb @@ -13,6 +13,7 @@ class DashboardManifest :photos, :categories, :pages, + :users, ] # `ROOT_DASHBOARD` diff --git a/app/dashboards/page_dashboard.rb b/app/dashboards/page_dashboard.rb index da82c75..fd7a849 100644 --- a/app/dashboards/page_dashboard.rb +++ b/app/dashboards/page_dashboard.rb @@ -1,13 +1,6 @@ require "administrate/base_dashboard" -require "administrate/fields/markdown" class PageDashboard < Administrate::BaseDashboard - READ_ONLY_ATTRIBUTES = [ - :id, - :created_at, - :updated_at, - ] - # ATTRIBUTE_TYPES # a hash that describes the type of each of the model's fields. # @@ -16,19 +9,23 @@ class PageDashboard < Administrate::BaseDashboard # on pages throughout the dashboard. ATTRIBUTE_TYPES = { title: Field::String, - content: Field::Markdown, + content: Field::MarkdownField, id: Field::Number, name: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, } - # TABLE_ATTRIBUTES + # 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 remove the limit or customize the returned array. - TABLE_ATTRIBUTES = ATTRIBUTE_TYPES.keys.first(4) + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = [ + :name, + :title, + :content, + ] # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. @@ -37,5 +34,9 @@ class PageDashboard < Administrate::BaseDashboard # FORM_ATTRIBUTES # an array of attributes that will be displayed # on the model's form (`new` and `edit`) pages. - FORM_ATTRIBUTES = ATTRIBUTE_TYPES.keys - READ_ONLY_ATTRIBUTES + FORM_ATTRIBUTES = [ + :name, + :title, + :content, + ] end diff --git a/app/dashboards/photo_dashboard.rb b/app/dashboards/photo_dashboard.rb index 52a8754..855f48f 100644 --- a/app/dashboards/photo_dashboard.rb +++ b/app/dashboards/photo_dashboard.rb @@ -1,12 +1,6 @@ require "administrate/base_dashboard" class PhotoDashboard < Administrate::BaseDashboard - READ_ONLY_ATTRIBUTES = [ - :id, - :created_at, - :updated_at, - ] - # ATTRIBUTE_TYPES # a hash that describes the type of each of the model's fields. # @@ -16,25 +10,30 @@ class PhotoDashboard < Administrate::BaseDashboard ATTRIBUTE_TYPES = { title: Field::String, image: Field::Image, - description: Field::String, - taken_at: Field::DateTime, - id: Field::Number, + description: Field::Text, flickr_url: Field::String, + taken_at: Field::DateTime, created_at: Field::DateTime, updated_at: Field::DateTime, - sort: Field::Number, featured: Field::Boolean, enabled: Field::Boolean, + id: Field::Number, + sort: Field::Number, views: Field::Number, categories: Field::HasMany, } - # TABLE_ATTRIBUTES + # 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 remove the limit or customize the returned array. - TABLE_ATTRIBUTES = %i(image title taken_at views) + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = [ + :image, + :title, + :taken_at, + :views, + ] # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. @@ -43,5 +42,15 @@ class PhotoDashboard < Administrate::BaseDashboard # FORM_ATTRIBUTES # an array of attributes that will be displayed # on the model's form (`new` and `edit`) pages. - FORM_ATTRIBUTES = ATTRIBUTE_TYPES.keys - READ_ONLY_ATTRIBUTES + FORM_ATTRIBUTES = [ + :title, + :image, + :description, + :flickr_url, + :taken_at, + :sort, + :featured, + :enabled, + :categories, + ] end diff --git a/app/dashboards/user_dashboard.rb b/app/dashboards/user_dashboard.rb new file mode 100644 index 0000000..a387992 --- /dev/null +++ b/app/dashboards/user_dashboard.rb @@ -0,0 +1,41 @@ +require "administrate/base_dashboard" + +class UserDashboard < 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 = { + id: Field::Number, + email: Field::String, + password_digest: Field::String, + created_at: Field::DateTime, + updated_at: Field::DateTime, + } + + # 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 = [ + :id, + :email, + :password_digest, + :created_at, + ] + + # SHOW_PAGE_ATTRIBUTES + # an array of attributes that will be displayed on the model's show page. + SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys + + # FORM_ATTRIBUTES + # an array of attributes that will be displayed + # on the model's form (`new` and `edit`) pages. + FORM_ATTRIBUTES = [ + :email, + :password_digest, + ] +end diff --git a/app/fields/colour_field.rb b/app/fields/colour_field.rb new file mode 100644 index 0000000..9e74533 --- /dev/null +++ b/app/fields/colour_field.rb @@ -0,0 +1,4 @@ +require "administrate/fields/base" + +class ColourField < Administrate::Field::Base +end diff --git a/app/fields/markdown_field.rb b/app/fields/markdown_field.rb new file mode 100644 index 0000000..67f9a0a --- /dev/null +++ b/app/fields/markdown_field.rb @@ -0,0 +1,21 @@ +require "administrate/fields/base" + +class MarkdownField < Administrate::Field::Base + def rendered + renderer.render(data).html_safe + end + + def truncate + data.to_s[0...truncation_length] + end + + private + + def renderer + Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions: {}) + end + + def truncation_length + options.fetch(:truncate, 50) + end +end diff --git a/app/views/admin/photos/_table.html.erb b/app/views/admin/applications/_collection.html.erb similarity index 55% rename from app/views/admin/photos/_table.html.erb rename to app/views/admin/applications/_collection.html.erb index 3d0663c..a11e8fd 100644 --- a/app/views/admin/photos/_table.html.erb +++ b/app/views/admin/applications/_collection.html.erb @@ -1,17 +1,37 @@ +<%# +# Table + +This partial is used on the `index` and `show` pages +to display a collection of resources in an HTML table. + +## Local variables: + +- `table_presenter`: + An instance of [Administrate::Page::Table][1]. + The table presenter uses `ResourceDashboard::TABLE_ATTRIBUTES` to determine + the columns displayed in the table +- `resources`: + An ActiveModel::Relation collection of resources to be displayed in the table. + By default, the number of resources is limited by pagination + or by a hard limit to prevent excessive page load times + +[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Table +%> +
| <%= link_to(params.merge( - table_presenter.order_params_for(attr_name) + collection_presenter.order_params_for(attr_name) )) do %> <%= attr_name.to_s.titleize %> - <% if table_presenter.ordered_by?(attr_name) %> - + <% if collection_presenter.ordered_by?(attr_name) %> + <%= inline_svg("administrate/sort_arrow.svg") %> <% end %> @@ -29,7 +49,7 @@ tabindex="0" data-url="<%= polymorphic_path([Administrate::NAMESPACE, resource]) -%>" > - <% table_presenter.attributes_for(resource).each do |attribute| %> + <% collection_presenter.attributes_for(resource).each do |attribute| %> | <%= render_field attribute %> | diff --git a/app/views/admin/applications/_form.html.erb b/app/views/admin/applications/_form.html.erb new file mode 100644 index 0000000..2cea728 --- /dev/null +++ b/app/views/admin/applications/_form.html.erb @@ -0,0 +1,44 @@ +<%# +# Form Partial + +This partial is rendered on a resource's `new` and `edit` pages, +and renders all form fields for a resource's editable attributes. + +## Local variables: + +- `page`: + An instance of [Administrate::Page::Form][1]. + Contains helper methods to display a form, + and knows which attributes should be displayed in the resource's form. + +[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form +%> + +<%= form_for([Administrate::NAMESPACE, page.resource], class: "form") do |f| %> + <% if page.resource.errors.any? %> +
|---|