diff --git a/app/dashboards/category_dashboard.rb b/app/dashboards/category_dashboard.rb index 2afd8fb..d96da41 100644 --- a/app/dashboards/category_dashboard.rb +++ b/app/dashboards/category_dashboard.rb @@ -1,4 +1,5 @@ require "administrate/base_dashboard" +require "administrate/fields/colour" class CategoryDashboard < Administrate::BaseDashboard READ_ONLY_ATTRIBUTES = [ @@ -14,16 +15,16 @@ class CategoryDashboard < Administrate::BaseDashboard # which determines how the attribute is displayed # on pages throughout the dashboard. ATTRIBUTE_TYPES = { - photos: Field::HasMany, id: Field::Number, name: Field::String, + slug: Field::String, description: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, - photo_id: Field::Number, - base_colour: Field::String, + # photo_id: Field::Number, + base_colour: Field::Colour, sort: Field::Number, - slug: Field::String, + photos: Field::HasMany, } # TABLE_ATTRIBUTES @@ -31,7 +32,7 @@ class CategoryDashboard < Administrate::BaseDashboard # # 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) + TABLE_ATTRIBUTES = %i(base_colour name description photos) # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. diff --git a/app/dashboards/page_dashboard.rb b/app/dashboards/page_dashboard.rb index 4064a54..1fb0faa 100644 --- a/app/dashboards/page_dashboard.rb +++ b/app/dashboards/page_dashboard.rb @@ -1,4 +1,5 @@ require "administrate/base_dashboard" +require "administrate/fields/markdown" class PageDashboard < Administrate::BaseDashboard READ_ONLY_ATTRIBUTES = [ @@ -17,7 +18,7 @@ class PageDashboard < Administrate::BaseDashboard id: Field::Number, name: Field::String, title: Field::String, - content: Field::String, + content: Field::Markdown, created_at: Field::DateTime, updated_at: Field::DateTime, } diff --git a/app/dashboards/photo_dashboard.rb b/app/dashboards/photo_dashboard.rb index 6f9eecb..52a8754 100644 --- a/app/dashboards/photo_dashboard.rb +++ b/app/dashboards/photo_dashboard.rb @@ -14,20 +14,19 @@ class PhotoDashboard < Administrate::BaseDashboard # which determines how the attribute is displayed # on pages throughout the dashboard. ATTRIBUTE_TYPES = { - categories: Field::HasMany, + title: Field::String, + image: Field::Image, + description: Field::String, + taken_at: Field::DateTime, id: Field::Number, flickr_url: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, - title: Field::String, - description: Field::String, sort: Field::Number, featured: Field::Boolean, enabled: Field::Boolean, - taken_at: Field::DateTime, views: Field::Number, - image_uid: Field::String, - image_name: Field::String, + categories: Field::HasMany, } # TABLE_ATTRIBUTES @@ -35,7 +34,7 @@ class PhotoDashboard < Administrate::BaseDashboard # # 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) + TABLE_ATTRIBUTES = %i(image title taken_at views) # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. diff --git a/app/views/admin/photos/_form.html.erb b/app/views/admin/photos/_form.html.erb new file mode 100644 index 0000000..893abb4 --- /dev/null +++ b/app/views/admin/photos/_form.html.erb @@ -0,0 +1,28 @@ +<%= form_for([Administrate::NAMESPACE, @page.resource], class: "form") do |f| %> + <% if @page.resource.errors.any? %> +
+

+ <%= pluralize(@page.resource.errors.count, "error") %> + prohibited this <%= @page.resource_name %> from being saved: +

+ + +
+ <% end %> + +
+ <% @page.attributes.each do |attribute| -%> +
+ <%= render_field attribute, f: f %> +
+ <% end -%> +
+ +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/admin/photos/_table.html.erb b/app/views/admin/photos/_table.html.erb new file mode 100644 index 0000000..3d0663c --- /dev/null +++ b/app/views/admin/photos/_table.html.erb @@ -0,0 +1,54 @@ + + + + <% table_presenter.attribute_types.each do |attr_name, attr_type| %> + + <% end %> + + + + + + <% resources.each do |resource| %> + + <% table_presenter.attributes_for(resource).each do |attribute| %> + + <% end %> + + + + + + <% end %> + +
+ <%= link_to(params.merge( + table_presenter.order_params_for(attr_name) + )) do %> + <%= attr_name.to_s.titleize %> + + <% if table_presenter.ordered_by?(attr_name) %> + + <%= inline_svg("administrate/sort_arrow.svg") %> + + <% end %> + <% end %> +
+ <%= render_field attribute %> + <%= link_to( + t("administrate.actions.edit"), + [:edit, Administrate::NAMESPACE, resource], + class: "action-edit", + ) %><%= link_to( + t("administrate.actions.destroy"), + [Administrate::NAMESPACE, resource], + class: "table__action--destroy", + method: :delete, + data: { confirm: t("administrate.actions.confirm") } + ) %>
diff --git a/app/views/admin/photos/edit.html.erb b/app/views/admin/photos/edit.html.erb new file mode 100644 index 0000000..38ba4d7 --- /dev/null +++ b/app/views/admin/photos/edit.html.erb @@ -0,0 +1,8 @@ +<% content_for(:title) { "Edit #{@page.page_title}" } %> + +
+

<%= content_for(:title) %>

+ <%= link_to "Show #{@page.resource}", [Administrate::NAMESPACE, @page.resource], class: "button" %> +
+ +<%= render "form" %> diff --git a/app/views/admin/photos/index.html.erb b/app/views/admin/photos/index.html.erb new file mode 100644 index 0000000..a123a91 --- /dev/null +++ b/app/views/admin/photos/index.html.erb @@ -0,0 +1,32 @@ +<% content_for(:title) { @page.resource_name.pluralize.titleize } %> + +<% content_for(:search) do %> + +<% end %> + +
+

<%= content_for(:title) %>

+ <%= link_to( + "New #{@page.resource_name.titleize.downcase}", + [:new, Administrate::NAMESPACE, @page.resource_name], + class: "button", + ) %> +
+ +<%= render "table", table_presenter: @page, resources: @resources %> + +<%= paginate @resources %> diff --git a/app/views/admin/photos/new.html.erb b/app/views/admin/photos/new.html.erb new file mode 100644 index 0000000..0074b10 --- /dev/null +++ b/app/views/admin/photos/new.html.erb @@ -0,0 +1,8 @@ +<% content_for(:title) { "New #{@page.resource_name.titleize}" } %> + +
+

<%= content_for(:title) %>

+ <%= link_to 'Back', @page.resource_name.pluralize, class: "button" %> +
+ +<%= render 'form' %> diff --git a/app/views/admin/photos/show.html.erb b/app/views/admin/photos/show.html.erb new file mode 100644 index 0000000..38c1c37 --- /dev/null +++ b/app/views/admin/photos/show.html.erb @@ -0,0 +1,19 @@ +<% content_for(:title) { @page.page_title } %> + +
+

<%= content_for(:title) %>

+ <%= link_to( + "Edit", + [:edit, Administrate::NAMESPACE, @page.resource], + class: "button", + ) %> +
+ +
+ <% @page.attributes.each do |attribute| %> +
<%= attribute.name.titleize %>
+ +
<%= render_field attribute %>
+ <% end %> +
diff --git a/app/views/fields/colour/_form.html.erb b/app/views/fields/colour/_form.html.erb new file mode 100644 index 0000000..c333065 --- /dev/null +++ b/app/views/fields/colour/_form.html.erb @@ -0,0 +1,2 @@ +<%= f.label field.attribute %> +<%= f.color_field field.attribute, style: 'height: 2.35em; width: 5em;' %> diff --git a/app/views/fields/colour/_index.html.erb b/app/views/fields/colour/_index.html.erb new file mode 100644 index 0000000..391309d --- /dev/null +++ b/app/views/fields/colour/_index.html.erb @@ -0,0 +1,2 @@ +<%= content_tag :div, nil, + style: "height: 1.5em; width: 1.5em; background-color: #{field.data}" %> diff --git a/app/views/fields/colour/_show.html.erb b/app/views/fields/colour/_show.html.erb new file mode 100644 index 0000000..fbf2ae3 --- /dev/null +++ b/app/views/fields/colour/_show.html.erb @@ -0,0 +1,2 @@ +<%= content_tag :span, field.data, + style: "color: white; padding: 0.2em 0.5em; background-color: #{field.data}" %> diff --git a/app/views/fields/image/_form.html.erb b/app/views/fields/image/_form.html.erb new file mode 100644 index 0000000..15844d9 --- /dev/null +++ b/app/views/fields/image/_form.html.erb @@ -0,0 +1,3 @@ +<%= f.label field.attribute %> +<%= image_tag field.data.thumb('32x32#').url, alt: nil if field.data.present? %> +<%= f.file_field field.attribute %> diff --git a/app/views/fields/image/_index.html.erb b/app/views/fields/image/_index.html.erb new file mode 100644 index 0000000..52e1062 --- /dev/null +++ b/app/views/fields/image/_index.html.erb @@ -0,0 +1 @@ +<%= image_tag field.data.thumb('50x50#').url, alt: nil %> diff --git a/app/views/fields/image/_show.html.erb b/app/views/fields/image/_show.html.erb new file mode 100644 index 0000000..d1bbc97 --- /dev/null +++ b/app/views/fields/image/_show.html.erb @@ -0,0 +1 @@ +<%= image_tag field.data.thumb('400x400').url %> diff --git a/app/views/fields/markdown/_form.html.erb b/app/views/fields/markdown/_form.html.erb new file mode 100644 index 0000000..60b9685 --- /dev/null +++ b/app/views/fields/markdown/_form.html.erb @@ -0,0 +1,2 @@ +<%= f.label field.attribute %> +<%= f.text_area field.attribute %> diff --git a/app/views/fields/markdown/_index.html.erb b/app/views/fields/markdown/_index.html.erb new file mode 100644 index 0000000..d683ccc --- /dev/null +++ b/app/views/fields/markdown/_index.html.erb @@ -0,0 +1 @@ +<%= field.truncate %> diff --git a/app/views/fields/markdown/_show.html.erb b/app/views/fields/markdown/_show.html.erb new file mode 100644 index 0000000..19ee2dd --- /dev/null +++ b/app/views/fields/markdown/_show.html.erb @@ -0,0 +1 @@ +<%= field.rendered %> diff --git a/app/views/fields/text/_form.html.erb b/app/views/fields/text/_form.html.erb new file mode 100644 index 0000000..60b9685 --- /dev/null +++ b/app/views/fields/text/_form.html.erb @@ -0,0 +1,2 @@ +<%= f.label field.attribute %> +<%= f.text_area field.attribute %> diff --git a/app/views/fields/text/_index.html.erb b/app/views/fields/text/_index.html.erb new file mode 100644 index 0000000..d683ccc --- /dev/null +++ b/app/views/fields/text/_index.html.erb @@ -0,0 +1 @@ +<%= field.truncate %> diff --git a/app/views/fields/text/_show.html.erb b/app/views/fields/text/_show.html.erb new file mode 100644 index 0000000..5177ca4 --- /dev/null +++ b/app/views/fields/text/_show.html.erb @@ -0,0 +1 @@ +<%= field.data %> diff --git a/lib/administrate/fields/colour.rb b/lib/administrate/fields/colour.rb new file mode 100644 index 0000000..9a4dfbd --- /dev/null +++ b/lib/administrate/fields/colour.rb @@ -0,0 +1,6 @@ +module Administrate + module Field + class Colour < Administrate::Field::Base + end + end +end diff --git a/lib/administrate/fields/markdown.rb b/lib/administrate/fields/markdown.rb new file mode 100644 index 0000000..74d0377 --- /dev/null +++ b/lib/administrate/fields/markdown.rb @@ -0,0 +1,15 @@ +module Administrate + module Field + class Markdown < Administrate::Field::Base + def rendered + renderer.render(data).html_safe + end + + private + + def renderer + Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions: {}) + end + end + end +end diff --git a/lib/administrate/fields/text.rb b/lib/administrate/fields/text.rb new file mode 100644 index 0000000..b60d25f --- /dev/null +++ b/lib/administrate/fields/text.rb @@ -0,0 +1,6 @@ +module Administrate + module Field + class Text < Administrate::Field::Base + end + end +end