diff options
| -rw-r--r-- | app/helpers/content_helper.rb | 3 | ||||
| -rw-r--r-- | app/helpers/link_helper.rb | 5 | ||||
| -rw-r--r-- | app/models/page.rb | 5 | ||||
| -rw-r--r-- | app/views/custom/partials/_chapter.html.erb | 38 | ||||
| -rw-r--r-- | public/stylesheets/ccc.css | 23 | ||||
| -rw-r--r-- | test/controllers/users_controller_test.rb | 4 | ||||
| -rw-r--r-- | test/models/page_test.rb | 13 |
7 files changed, 58 insertions, 33 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 9d52c110..b2603481 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -98,6 +98,9 @@ module ContentHelper | |||
| 98 | # order_by="published_at" | 98 | # order_by="published_at" |
| 99 | # order_direction="DESC" | 99 | # order_direction="DESC" |
| 100 | # ] | 100 | # ] |
| 101 | # | ||
| 102 | # order_by currently takes id, published_at, created_at, updated_at, title | ||
| 103 | # and slug | ||
| 101 | 104 | ||
| 102 | 105 | ||
| 103 | def aggregate? content | 106 | def aggregate? content |
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 2121133e..21e4da59 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb | |||
| @@ -21,8 +21,9 @@ module LinkHelper | |||
| 21 | active = (page_path == path.sub(/^\//, "")) | 21 | active = (page_path == path.sub(/^\//, "")) |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | active_class = active ? {:class => 'active'} : {:class => 'inactive'} | 24 | html_options = html_options.merge( |
| 25 | html_options = html_options.merge(active_class) | 25 | :class => [html_options[:class], active ? "active" : "inactive"].compact.join(" ") |
| 26 | ) | ||
| 26 | locale = (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale) | 27 | locale = (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale) |
| 27 | 28 | ||
| 28 | link_to( | 29 | link_to( |
diff --git a/app/models/page.rb b/app/models/page.rb index a66527da..8313b1d4 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -92,6 +92,11 @@ class Page < ApplicationRecord | |||
| 92 | .paginate(:page => page, :per_page => options[:limit]) | 92 | .paginate(:page => page, :per_page => options[:limit]) |
| 93 | end | 93 | end |
| 94 | 94 | ||
| 95 | if options[:order_by] == "slug" | ||
| 96 | return scope.order(Arel.sql("MIN(LOWER(nodes.slug)) #{direction}")) | ||
| 97 | .paginate(:page => page, :per_page => options[:limit]) | ||
| 98 | end | ||
| 99 | |||
| 95 | column = options[:order_by].to_s.sub(/\Apages\./, "") | 100 | column = options[:order_by].to_s.sub(/\Apages\./, "") |
| 96 | column = "id" unless %w[id published_at created_at updated_at].include?(column) | 101 | column = "id" unless %w[id published_at created_at updated_at].include?(column) |
| 97 | 102 | ||
diff --git a/app/views/custom/partials/_chapter.html.erb b/app/views/custom/partials/_chapter.html.erb index 5d47679e..8a92b46f 100644 --- a/app/views/custom/partials/_chapter.html.erb +++ b/app/views/custom/partials/_chapter.html.erb | |||
| @@ -1,26 +1,24 @@ | |||
| 1 | <div class="article_partial chapter_partial" lang="<%= page.effective_lang %>"> | 1 | <div class="article_partial chapter_partial" lang="<%= page.effective_lang %>"> |
| 2 | <div class="chapter_partial_layout"> | 2 | <div class="chapter_partial_layout"> |
| 3 | <% if page.headline_asset %> | 3 | <% if page.headline_asset %> |
| 4 | <%= link_to_path image_tag(page.headline_asset.upload.url(:thumb), :alt => ""), page.node.unique_name, class: "chapter_thumbnail" %> | 4 | <%= link_to_path image_tag(page.headline_asset.upload.url(:medium), :alt => ""), page.node.unique_name, class: "chapter_thumbnail" %> |
| 5 | <% end %> | 5 | <% end %> |
| 6 | <div class="chapter_partial_content"> | 6 | <h2 class="headline"><%= link_to_path page.title, page.node.unique_name %></h2> |
| 7 | <h2 class="headline"><%= link_to_path page.title, page.node.unique_name %></h2> | 7 | <% if page.abstract.present? %> |
| 8 | <% if page.abstract.present? %> | 8 | <div class="chapter_location"><%= page.abstract %></div> |
| 9 | <div class="chapter_location"><%= page.abstract %></div> | 9 | <% end %> |
| 10 | <% end %> | 10 | <% if page.node.external_url.present? %> |
| 11 | <% if page.node.external_url.present? %> | 11 | <div class="chapter_url"><%= link_to page.node.external_url, page.node.external_url, target: '_blank', rel: 'noopener' %></div> |
| 12 | <div class="chapter_url"><%= link_to page.node.external_url, page.node.external_url, target: '_blank', rel: 'noopener' %></div> | 12 | <% end %> |
| 13 | <% end %> | 13 | <% open_days = page.node.events.tagged_with('open-day').order(:start_time) %> |
| 14 | <% open_days = page.node.events.tagged_with('open-day').order(:start_time) %> | 14 | <% if open_days.any? %> |
| 15 | <% if open_days.any? %> | 15 | <div class="chapter_open_days"> |
| 16 | <div class="chapter_open_days"> | 16 | <span class="open_days_label"><%= t(:open_days_label) %>: </span> |
| 17 | <span class="open_days_label"><%= t(:open_days_label) %>: </span> | 17 | <% open_days.each do |event| %> |
| 18 | <% open_days.each do |event| %> | 18 | <span class="event_schedule"><%= event_schedule_text(event) %></span> |
| 19 | <span class="event_schedule"><%= event_schedule_text(event) %></span> | 19 | <% end %> |
| 20 | <% end %> | 20 | </div> |
| 21 | </div> | 21 | <% end %> |
| 22 | <% end %> | 22 | <p class="excerpt"><%= sanitize page.body %></p> |
| 23 | <p class="excerpt"><%= sanitize page.body %></p> | ||
| 24 | </div> | ||
| 25 | </div> | 23 | </div> |
| 26 | </div> | 24 | </div> |
diff --git a/public/stylesheets/ccc.css b/public/stylesheets/ccc.css index f018d2b2..9bd9f965 100644 --- a/public/stylesheets/ccc.css +++ b/public/stylesheets/ccc.css | |||
| @@ -752,25 +752,30 @@ div.author_and_date { | |||
| 752 | } | 752 | } |
| 753 | 753 | ||
| 754 | .chapter_partial_layout { | 754 | .chapter_partial_layout { |
| 755 | display: flex; | 755 | display: flow-root; |
| 756 | gap: 12px; | ||
| 757 | align-items: flex-start; | ||
| 758 | } | 756 | } |
| 759 | 757 | ||
| 760 | .chapter_thumbnail { | 758 | .chapter_thumbnail { |
| 761 | flex-shrink: 0; | 759 | float: right; |
| 760 | margin: 0.5rem 0 8px 12px; | ||
| 762 | } | 761 | } |
| 763 | 762 | ||
| 764 | .chapter_thumbnail img { | 763 | .chapter_thumbnail img { |
| 765 | width: 64px; | 764 | max-width: 150px; |
| 766 | height: 64px; | 765 | height: auto; |
| 767 | object-fit: cover; | ||
| 768 | border-radius: 4px; | 766 | border-radius: 4px; |
| 769 | display: block; | 767 | display: block; |
| 770 | } | 768 | } |
| 771 | 769 | ||
| 772 | .chapter_partial_content { | 770 | div#center_column .chapter_partial h2.headline { |
| 773 | min-width: 0; | 771 | border-top: none; |
| 772 | padding-top: 0; | ||
| 773 | } | ||
| 774 | |||
| 775 | div#center_column .chapter_partial + .chapter_partial { | ||
| 776 | border-top: 1px solid color-mix(in srgb, CanvasText, Canvas 70%); | ||
| 777 | margin-top: 1.5rem; | ||
| 778 | padding-top: 1.5rem; | ||
| 774 | } | 779 | } |
| 775 | 780 | ||
| 776 | .article_partial_layout { | 781 | .article_partial_layout { |
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index d7d8b9a6..2dd0759a 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb | |||
| @@ -13,8 +13,8 @@ class UsersControllerTest < ActionController::TestCase | |||
| 13 | login_as :aaron | 13 | login_as :aaron |
| 14 | get :index | 14 | get :index |
| 15 | assert_response :success | 15 | assert_response :success |
| 16 | assert_select "button[type=submit]", I18n.t("users.user.deactivate") | 16 | assert_select "button[type=submit][aria-label=?]", I18n.t("users.user.deactivate") |
| 17 | assert_select "a", I18n.t("admin.common.show") | 17 | assert_select "a[aria-label=?]", I18n.t("admin.common.show") |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | test "get new when logged in as admin" do | 20 | test "get new when logged in as admin" do |
diff --git a/test/models/page_test.rb b/test/models/page_test.rb index 395b6315..b737e8b0 100644 --- a/test/models/page_test.rb +++ b/test/models/page_test.rb | |||
| @@ -425,4 +425,17 @@ class PageTest < ActiveSupport::TestCase | |||
| 425 | assert_includes names, "updates/inside-post" | 425 | assert_includes names, "updates/inside-post" |
| 426 | assert_not_includes names, "outside-post" | 426 | assert_not_includes names, "outside-post" |
| 427 | end | 427 | end |
| 428 | |||
| 429 | test "an aggregate can order by node slug" do | ||
| 430 | parent = Node.root.children.create!(:slug => "slug_order_parent") | ||
| 431 | %w[zulu alpha Mike].each do |slug| | ||
| 432 | node = parent.children.create!(:slug => slug) | ||
| 433 | node.reload.draft.update!(:title => "T-#{slug}", :tag_list => "slug-order-test") | ||
| 434 | node.publish_draft! | ||
| 435 | end | ||
| 436 | |||
| 437 | names = Page.aggregate({ :tags => "slug-order-test", | ||
| 438 | :order_by => "slug" }).map { |p| p.node.slug } | ||
| 439 | assert_equal %w[alpha Mike zulu], names | ||
| 440 | end | ||
| 428 | end | 441 | end |
