From 960e5d4ae09a979e2efe9ca2fe622f7a08951557 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 28 Sep 2019 17:05:18 -0500 Subject: [PATCH] views: factor out sidebar layout template. * Factor out common sidebar layout template. * Convert wiki pages and posts to use this template. * Add data-layout attribute to element indicating the current layout. --- app/controllers/posts_controller.rb | 1 + .../wiki_page_versions_controller.rb | 1 + app/controllers/wiki_pages_controller.rb | 4 +- app/helpers/application_helper.rb | 1 + app/views/layouts/sidebar.html.erb | 15 + app/views/posts/index.html.erb | 81 +++--- app/views/posts/show.html.erb | 270 +++++++++--------- app/views/wiki_page_versions/diff.html.erb | 26 +- app/views/wiki_page_versions/index.html.erb | 24 +- app/views/wiki_page_versions/show.html.erb | 32 +-- app/views/wiki_pages/_sidebar.html.erb | 4 +- app/views/wiki_pages/edit.html.erb | 22 +- app/views/wiki_pages/index.html.erb | 46 ++- app/views/wiki_pages/new.html.erb | 33 +-- app/views/wiki_pages/show.html.erb | 59 ++-- app/views/wiki_pages/show_or_new.html.erb | 36 ++- 16 files changed, 316 insertions(+), 339 deletions(-) create mode 100644 app/views/layouts/sidebar.html.erb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d9a8cfb2b..e97503696 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,6 +1,7 @@ class PostsController < ApplicationController before_action :member_only, :except => [:show, :show_seq, :index, :home, :random] respond_to :html, :xml, :json + layout "sidebar" def index if params[:md5].present? diff --git a/app/controllers/wiki_page_versions_controller.rb b/app/controllers/wiki_page_versions_controller.rb index 3eaa72fda..bfdfced06 100644 --- a/app/controllers/wiki_page_versions_controller.rb +++ b/app/controllers/wiki_page_versions_controller.rb @@ -1,5 +1,6 @@ class WikiPageVersionsController < ApplicationController respond_to :html, :xml, :json + layout "sidebar" def index @wiki_page_versions = WikiPageVersion.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 75f12d004..999fcf253 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -3,7 +3,8 @@ class WikiPagesController < ApplicationController before_action :member_only, :except => [:index, :search, :show, :show_or_new] before_action :builder_only, :only => [:destroy] before_action :normalize_search_params, :only => [:index] - + layout "sidebar" + def new @wiki_page = WikiPage.new(wiki_page_params(:create)) respond_with(@wiki_page) @@ -30,6 +31,7 @@ class WikiPagesController < ApplicationController end def search + render layout: "default" end def show diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index daa46ce9c..0904ba41e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -187,6 +187,7 @@ module ApplicationHelper data: { controller: controller_param, action: action_param, + layout: controller.class.send(:_layout), **data_attributes_for(user, "user", attributes) } } diff --git a/app/views/layouts/sidebar.html.erb b/app/views/layouts/sidebar.html.erb new file mode 100644 index 000000000..51398787a --- /dev/null +++ b/app/views/layouts/sidebar.html.erb @@ -0,0 +1,15 @@ +<% content_for(:layout) do %> +
+
+ + +
+ <%= yield :content %> +
+
+
+<% end %> + +<%= render template: "layouts/default" %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 1fe9a2dec..8c6f940d5 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,58 +1,53 @@ -
-
- + <%= render "posts/partials/index/related" %> +<% end %> -
- -
  • Posts
  • +<% content_for(:content) do %> + +
  • Posts
  • - <% if @post_set.artist.present? %> -
  • <%= link_to "Artist", artist_path(@post_set.artist), :id => "show-excerpt-link" %>
  • - <% elsif @post_set.wiki_page.present? %> -
  • <%= link_to "Wiki", wiki_page_path(@post_set.wiki_page), :id => "show-excerpt-link" %>
  • - <% elsif @post_set.has_pool? %> -
  • <%= link_to "Pool", pool_path(@post_set.pool), :id => "show-excerpt-link" %>
  • - <% elsif @post_set.has_favgroup? %> -
  • <%= link_to "Favorite Group", favorite_group_path(@post_set.favgroup), :id => "show-excerpt-link" %>
  • - <% elsif @post_set.has_blank_wiki? %> -
  • <%= link_to "Wiki", new_wiki_page_path(wiki_page: { title: @post_set.tag_string }), id: "show-excerpt-link" %>
  • - <% end %> + <% if @post_set.artist.present? %> +
  • <%= link_to "Artist", artist_path(@post_set.artist), :id => "show-excerpt-link" %>
  • + <% elsif @post_set.wiki_page.present? %> +
  • <%= link_to "Wiki", wiki_page_path(@post_set.wiki_page), :id => "show-excerpt-link" %>
  • + <% elsif @post_set.has_pool? %> +
  • <%= link_to "Pool", pool_path(@post_set.pool), :id => "show-excerpt-link" %>
  • + <% elsif @post_set.has_favgroup? %> +
  • <%= link_to "Favorite Group", favorite_group_path(@post_set.favgroup), :id => "show-excerpt-link" %>
  • + <% elsif @post_set.has_blank_wiki? %> +
  • <%= link_to "Wiki", new_wiki_page_path(wiki_page: { title: @post_set.tag_string }), id: "show-excerpt-link" %>
  • + <% end %> - -
    + +
    - <%= render "posts/partials/index/edit" %> - <%= render "posts/partials/index/excerpt", :post_set => @post_set %> - <%= render "posts/partials/index/posts", :post_set => @post_set %> -
    - + <%= render "posts/partials/index/edit" %> + <%= render "posts/partials/index/excerpt", :post_set => @post_set %> + <%= render "posts/partials/index/posts", :post_set => @post_set %> +<% end %> - <%= post_search_count_js %> +<%= post_search_count_js %> -
    - <%= render "saved_searches/interface" %> -
    -
    +
    + <%= render "saved_searches/interface" %>
    <% if params[:tags] =~ /search:/ %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 423021def..c66adda2b 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -1,155 +1,151 @@ -
    -
    - +
    +

    History

    +
      +
    • <%= link_to "Tags", post_versions_path(search: { post_id: @post.id }) %>
    • +
    • <%= link_to "Pools", pool_versions_path(search: { post_id: @post.id }) %>
    • +
    • <%= link_to "Notes", note_versions_path(search: { post_id: @post.id }) %>
    • +
    • <%= link_to "Moderation", post_events_path(@post.id) %>
    • +
    • <%= link_to "Commentary", artist_commentary_versions_path(search: { post_id: @post.id }) %>
    • +
    • <%= link_to "Replacements", post_replacements_path(search: {post_id: @post.id }) %>
    • +
    +
    +<% end %> -
    - <% if @post.presenter.has_nav_links?(self) %> - <%= render "posts/partials/show/nav_links", :post => @post, :position => "top" %> - <% end %> +<% content_for(:content) do %> + <% if @post.presenter.has_nav_links?(self) %> + <%= render "posts/partials/show/nav_links", :post => @post, :position => "top" %> + <% end %> - <%= render "posts/partials/show/notices", :post => @post %> + <%= render "posts/partials/show/notices", :post => @post %> - <%= content_tag(:section, { id: "image-container" }.merge(PostPresenter.data_attributes(@post))) do -%> -
    -
    - <%= render "posts/partials/show/embedded", post: @post %> - <% end -%> - - <% if CurrentUser.is_member? %> - <%= content_tag(:div, class: "fav-buttons fav-buttons-#{@post.is_favorited?}") do %> - <%= form_tag(favorites_path(post_id: @post.id), method: "post", id: "add-fav-button", "data-remote": true) do %> - <%= button_tag tag.i(class: "far fa-heart"), class: "ui-button ui-widget ui-corner-all", "data-disable-with": tag.i(class: "fas fa-spinner fa-spin") %> - <% end %> - - <%= form_tag(favorite_path(@post.id), method: "delete", id: "remove-fav-button", "data-remote": true) do %> - <%= button_tag tag.i(class: "fas fa-heart"), class: "ui-button ui-widget ui-corner-all", "data-disable-with": tag.i(class: "fas fa-spinner fa-spin") %> - <% end %> - <% end %> - <% end %> - - - - <% if @post.artist_commentary && @post.artist_commentary.any_field_present? %> -
    - <%= render "artist_commentaries/show", :artist_commentary => @post.artist_commentary %> -
    - <% end %> - - <% if @post.presenter.has_nav_links?(self) %> - <%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %> - <% end %> - - -
  • Comments
  • - - <% if RecommenderService.available_for_post?(@post) %> -
  • Recommended
  • - <% end %> - - <% if CurrentUser.is_member? && @post.visible? %> -
  • Edit
  • - <% end %> -
    - - <% if RecommenderService.available_for_post?(@post) %> - - <% end %> - -
    - <% if !CurrentUser.user.is_builder? %> -

    Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.

    - <% end %> - <%= render "comments/partials/index/list", comments: @comments, post: @post, page: :post %> -
    - - - - <% if CurrentUser.is_member? && @post.visible? %> - - <% end %> -
    -
    + <%= content_tag(:section, { id: "image-container" }.merge(PostPresenter.data_attributes(@post))) do -%> +
    +
    + <%= render "posts/partials/show/embedded", post: @post %> + <% end -%> <% if CurrentUser.is_member? %> - + <%= content_tag(:div, class: "fav-buttons fav-buttons-#{@post.is_favorited?}") do %> + <%= form_tag(favorites_path(post_id: @post.id), method: "post", id: "add-fav-button", "data-remote": true) do %> + <%= button_tag tag.i(class: "far fa-heart"), class: "ui-button ui-widget ui-corner-all", "data-disable-with": tag.i(class: "fas fa-spinner fa-spin") %> + <% end %> - + <%= form_tag(favorite_path(@post.id), method: "delete", id: "remove-fav-button", "data-remote": true) do %> + <%= button_tag tag.i(class: "fas fa-heart"), class: "ui-button ui-widget ui-corner-all", "data-disable-with": tag.i(class: "fas fa-spinner fa-spin") %> + <% end %> + <% end %> + <% end %> - + + <% if @post.presenter.has_nav_links?(self) %> + <%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %> + <% end %> + + +
  • Comments
  • + + <% if RecommenderService.available_for_post?(@post) %> +
  • Recommended
  • + <% end %> + + <% if CurrentUser.is_member? && @post.visible? %> +
  • Edit
  • + <% end %> +
    + + <% if RecommenderService.available_for_post?(@post) %> + + <% end %> + +
    + <% if !CurrentUser.user.is_builder? %> +

    Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.

    + <% end %> + <%= render "comments/partials/index/list", comments: @comments, post: @post, page: :post %> +
    + + + + <% if CurrentUser.is_member? && @post.visible? %> + + <% end %> +<% end %> + +<% if CurrentUser.is_member? %> + + + + + +<% end %> <%= post_view_count_js %> diff --git a/app/views/wiki_page_versions/diff.html.erb b/app/views/wiki_page_versions/diff.html.erb index bb5f9b5eb..b60410d8c 100644 --- a/app/views/wiki_page_versions/diff.html.erb +++ b/app/views/wiki_page_versions/diff.html.erb @@ -1,18 +1,18 @@ -
    -
    -

    Wiki Page: <%= @thispage.title %>

    +<%= render "wiki_pages/sidebar" %> - <% if @thispage.visible? %> -

    Showing differences between <%= compact_time @thispage.updated_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.updated_at %> (<%= link_to_user @otherpage.updater %>)

    +<% content_for(:content) do %> +

    Wiki Page: <%= @thispage.title %>

    -
    - <%= wiki_page_diff(@thispage, @otherpage) %> -
    - <% else %> -

    The artist requested removal of this page.

    - <% end %> -
    -
    + <% if @thispage.visible? %> +

    Showing differences between <%= compact_time @thispage.updated_at %> (<%= link_to_user @thispage.updater %>) and <%= compact_time @otherpage.updated_at %> (<%= link_to_user @otherpage.updater %>)

    + +
    + <%= wiki_page_diff(@thispage, @otherpage) %> +
    + <% else %> +

    The artist requested removal of this page.

    + <% end %> +<% end %> <%= render "wiki_pages/secondary_links" %> diff --git a/app/views/wiki_page_versions/index.html.erb b/app/views/wiki_page_versions/index.html.erb index d0e595c34..57dc219d1 100644 --- a/app/views/wiki_page_versions/index.html.erb +++ b/app/views/wiki_page_versions/index.html.erb @@ -1,19 +1,15 @@ -
    -
    - <%= render "wiki_pages/sidebar" %> +<%= render "wiki_pages/sidebar" %> -
    -

    Wiki Page History

    +<% content_for(:content) do %> +

    Wiki Page History

    - <% if params.dig(:search, :wiki_page_id).present? %> - <%= render "page_listing" %> - <% else %> - <%= render "global_listing" %> - <% end %> + <% if params.dig(:search, :wiki_page_id).present? %> + <%= render "page_listing" %> + <% else %> + <%= render "global_listing" %> + <% end %> - <%= numbered_paginator(@wiki_page_versions) %> -
    -
    -
    + <%= numbered_paginator(@wiki_page_versions) %> +<% end %> <%= render "wiki_pages/secondary_links" %> diff --git a/app/views/wiki_page_versions/show.html.erb b/app/views/wiki_page_versions/show.html.erb index 3db899bf7..a4872aa71 100644 --- a/app/views/wiki_page_versions/show.html.erb +++ b/app/views/wiki_page_versions/show.html.erb @@ -1,24 +1,20 @@ -
    -
    - <%= render "wiki_pages/sidebar" %> +<%= render "wiki_pages/sidebar" %> -
    -

    <%= @wiki_page_version.pretty_title %>

    -

    <%= time_ago_in_words_tagged(@wiki_page_version.updated_at) %>

    +<% content_for(:content) do %> +

    <%= @wiki_page_version.pretty_title %>

    +

    <%= time_ago_in_words_tagged(@wiki_page_version.updated_at) %>

    -
    - <% if @wiki_page_version.visible? %> - <% if @wiki_page_version.other_names.present? %> -

    <%= wiki_page_other_names_list(@wiki_page_version) %>

    - <% end %> +
    + <% if @wiki_page_version.visible? %> + <% if @wiki_page_version.other_names.present? %> +

    <%= wiki_page_other_names_list(@wiki_page_version) %>

    + <% end %> - <%= format_text(@wiki_page_version.body) %> - <% else %> -

    The artist has requested removal of this page.

    - <% end %> -
    -
    + <%= format_text(@wiki_page_version.body) %> + <% else %> +

    The artist has requested removal of this page.

    + <% end %>
    -
    +<% end %> <%= render "wiki_pages/secondary_links" %> diff --git a/app/views/wiki_pages/_sidebar.html.erb b/app/views/wiki_pages/_sidebar.html.erb index 461e3bccf..c86163280 100644 --- a/app/views/wiki_pages/_sidebar.html.erb +++ b/app/views/wiki_pages/_sidebar.html.erb @@ -1,4 +1,4 @@ - +<% end %> diff --git a/app/views/wiki_pages/edit.html.erb b/app/views/wiki_pages/edit.html.erb index 5d3eb65eb..93f133402 100644 --- a/app/views/wiki_pages/edit.html.erb +++ b/app/views/wiki_pages/edit.html.erb @@ -1,17 +1,13 @@ -
    -
    - <%= render "sidebar" %> +<%= render "sidebar" %> -
    -

    Edit Wiki

    +<% content_for(:content) do %> +

    Edit Wiki

    - <% if @wiki_page.visible? %> - <%= render "form" %> - <% else %> -

    The artist requested removal of this page.

    - <% end %> -
    -
    -
    + <% if @wiki_page.visible? %> + <%= render "form" %> + <% else %> +

    The artist requested removal of this page.

    + <% end %> +<% end %> <%= render "secondary_links" %> diff --git a/app/views/wiki_pages/index.html.erb b/app/views/wiki_pages/index.html.erb index 661fa5791..1dac46316 100644 --- a/app/views/wiki_pages/index.html.erb +++ b/app/views/wiki_pages/index.html.erb @@ -1,30 +1,26 @@ -
    -
    - <%= render "sidebar" %> +<%= render "sidebar" %> -
    -

    Wiki

    +<% content_for(:content) do %> +

    Wiki

    - - - - - - - - - <% @wiki_pages.each do |wiki_page| %> - - - - - <% end %> - -
    TitleLast edited
    <%= link_to wiki_page.pretty_title, wiki_page_path(wiki_page, :noredirect => 1) %><%= wiki_page.updated_at.strftime("%Y-%m-%d %H:%M") %> by <%= h link_to_user wiki_page.updater %>
    + + + + + + + + + <% @wiki_pages.each do |wiki_page| %> + + + + + <% end %> + +
    TitleLast edited
    <%= link_to wiki_page.pretty_title, wiki_page_path(wiki_page, :noredirect => 1) %><%= wiki_page.updated_at.strftime("%Y-%m-%d %H:%M") %> by <%= h link_to_user wiki_page.updater %>
    - <%= numbered_paginator(@wiki_pages) %> -
    -
    -
    + <%= numbered_paginator(@wiki_pages) %> +<% end %> <%= render "secondary_links" %> diff --git a/app/views/wiki_pages/new.html.erb b/app/views/wiki_pages/new.html.erb index a8723554d..2434d0011 100644 --- a/app/views/wiki_pages/new.html.erb +++ b/app/views/wiki_pages/new.html.erb @@ -1,26 +1,17 @@ -
    -
    - <%= render "sidebar" %> +<%= render "sidebar" %> -
    -

    New Wiki Page

    +<% content_for(:content) do %> +

    New Wiki Page

    - <% if @wiki_page.title.present? %> -
    - This wiki page does not yet exist. The form below will allow you to create a new page for <%= @wiki_page.title %>. It will act as an explanation on how to use the tag for other users on the site. -
    - <% end %> + <% if @wiki_page.title.present? %> +
    + This wiki page does not yet exist. The form below will allow you to create a new page for <%= @wiki_page.title %>. It will act as an explanation on how to use the tag for other users on the site. +
    + <% end %> - <%= render "form" %> - - <%= wiki_page_alias_and_implication_list(@wiki_page)%> - - <%= wiki_page_post_previews(@wiki_page) %> - -
    - -
    -
    -
    + <%= render "form" %> + <%= wiki_page_alias_and_implication_list(@wiki_page)%> + <%= wiki_page_post_previews(@wiki_page) %> +<% end %> <%= render "secondary_links" %> diff --git a/app/views/wiki_pages/show.html.erb b/app/views/wiki_pages/show.html.erb index 113ba7515..593bc8964 100644 --- a/app/views/wiki_pages/show.html.erb +++ b/app/views/wiki_pages/show.html.erb @@ -1,43 +1,38 @@ -
    -
    - <%= render "sidebar" %> +<%= render "sidebar" %> -
    -

    +<% content_for(:content) do %> +

    + <%= link_to @wiki_page.pretty_title, posts_path(:tags => @wiki_page.title), :class => "tag-type-#{@wiki_page.category_name}" %> - <%= link_to @wiki_page.pretty_title, posts_path(:tags => @wiki_page.title), :class => "tag-type-#{@wiki_page.category_name}" %> + <% if @wiki_page.is_locked? %> + (locked) + <% end %> - <% if @wiki_page.is_locked? %> - (locked) - <% end %> + <% if @wiki_page.is_deleted? %> + (deleted) + <% end %> +

    - <% if @wiki_page.is_deleted? %> - (deleted) - <% end %> - +
    + <% if @wiki_page.visible? %> + <% if @wiki_page.other_names.present? %> +

    <%= wiki_page_other_names_list(@wiki_page) %>

    + <% end %> -
    - <% if @wiki_page.visible? %> - <% if @wiki_page.other_names.present? %> -

    <%= wiki_page_other_names_list(@wiki_page) %>

    - <% end %> + <%= format_text(@wiki_page.body) %> - <%= format_text(@wiki_page.body) %> + <% if @wiki_page.artist %> +

    <%= link_to "View artist", @wiki_page.artist %>

    + <% end %> - <% if @wiki_page.artist %> -

    <%= link_to "View artist", @wiki_page.artist %>

    - <% end %> - - <%= wiki_page_alias_and_implication_list(@wiki_page) %> - <% else %> -

    This artist has requested removal of their information.

    - <% end %> -
    - - <%= wiki_page_post_previews(@wiki_page) %> -
    + <%= wiki_page_alias_and_implication_list(@wiki_page) %> + <% else %> +

    This artist has requested removal of their information.

    + <% end %>
    -
    + + <%= wiki_page_post_previews(@wiki_page) %> +<% end %> <% content_for(:page_title) do %> Wiki - <%= @wiki_page.pretty_title %> - <%= Danbooru.config.app_name %> diff --git a/app/views/wiki_pages/show_or_new.html.erb b/app/views/wiki_pages/show_or_new.html.erb index fd4bdb6d1..904fd7195 100644 --- a/app/views/wiki_pages/show_or_new.html.erb +++ b/app/views/wiki_pages/show_or_new.html.erb @@ -1,25 +1,21 @@ -
    -
    - <%= render "sidebar" %> +<%= render "sidebar" %> -
    -

    - <%= link_to @wiki_page.pretty_title, posts_path(:tags => @wiki_page.title), :class => "tag-type-#{@wiki_page.category_name}" %> -

    -
    -

    This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(:wiki_page => {:title => params[:title]}) %>.

    -
    - - <% if @wiki_page.artist.present? %> -

    <%= link_to "View artist", @wiki_page.artist %>

    - <% end %> - - <%= wiki_page_alias_and_implication_list(@wiki_page)%> - - <%= wiki_page_post_previews(@wiki_page) %> -
    +<% content_for(:content) do %> +

    + <%= link_to @wiki_page.pretty_title, posts_path(:tags => @wiki_page.title), :class => "tag-type-#{@wiki_page.category_name}" %> +

    +
    +

    This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(:wiki_page => {:title => params[:title]}) %>.

    -
    + + <% if @wiki_page.artist.present? %> +

    <%= link_to "View artist", @wiki_page.artist %>

    + <% end %> + + <%= wiki_page_alias_and_implication_list(@wiki_page)%> + + <%= wiki_page_post_previews(@wiki_page) %> +<% end %> <%= render "secondary_links" %>