From de8ef224d40798d29b8bc64249f4db61a7279d69 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 2 Jun 2018 13:28:09 +0900 Subject: [PATCH] [phase-10]add radio_button to select terms view with grouping by categories or without grouping. --- app/controllers/glossary_terms_controller.rb | 1 + ...ategory.html.erb => _index_terms.html.erb} | 0 app/views/glossary_terms/_sidebar.html.erb | 11 ++++++++++ app/views/glossary_terms/index.html.erb | 20 +++++++++++-------- config/locales/en.yml | 2 ++ config/locales/ja.yml | 2 ++ 6 files changed, 28 insertions(+), 8 deletions(-) rename app/views/glossary_terms/{_index_in_category.html.erb => _index_terms.html.erb} (100%) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index 6292367..12aa62b 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -6,6 +6,7 @@ class GlossaryTermsController < ApplicationController def index @glossary_terms = GlossaryTerm.where(project_id: @project.id) @glossary_terms = @glossary_terms.search_by_name(params[:index]) unless params[:index].nil? + @grouping = params[:grouping] end def new diff --git a/app/views/glossary_terms/_index_in_category.html.erb b/app/views/glossary_terms/_index_terms.html.erb similarity index 100% rename from app/views/glossary_terms/_index_in_category.html.erb rename to app/views/glossary_terms/_index_terms.html.erb diff --git a/app/views/glossary_terms/_sidebar.html.erb b/app/views/glossary_terms/_sidebar.html.erb index dda5e16..4232024 100644 --- a/app/views/glossary_terms/_sidebar.html.erb +++ b/app/views/glossary_terms/_sidebar.html.erb @@ -1,6 +1,17 @@ <% content_for :sidebar do %>

<%=l :label_view %>

+ <%= form_with url: project_glossary_terms_path, method: :get, local: true do |form| %> +
+ <%=l :label_grouping %> + <%= form.radio_button :grouping, 1, checked: @grouping == '1' ? 'checked' : nil %> + <%= form.label :grouping, l(:label_categorized), vaule: 1 %> + <%= form.radio_button :grouping, 0, checked: @grouping == '0' ? 'checked' : nil %> + <%= form.label :grouping, l(:label_not_categorized), value: 0 %> +
+ <%= form.submit l(:label_view) %> + <% end %> +

<%=l :label_glossary_term %>

<%= link_to_if_authorized l(:label_glossary_term_new), { controller: :glossary_terms, action: :new, project_id: @project }, diff --git a/app/views/glossary_terms/index.html.erb b/app/views/glossary_terms/index.html.erb index 3e237a8..5d5a996 100644 --- a/app/views/glossary_terms/index.html.erb +++ b/app/views/glossary_terms/index.html.erb @@ -8,15 +8,19 @@ <%= render partial: 'sidebar' %> -<% categorized_terms = @glossary_terms.reject { |t| t.category_id.nil? } %> -<% uncategorized_terms = @glossary_terms.where(category_id: nil) %> +<% if @grouping == '1' %> + <% categorized_terms = @glossary_terms.reject { |t| t.category_id.nil? } %> + <% uncategorized_terms = @glossary_terms.where(category_id: nil) %> -<% categorized_terms.group_by(&:category).each do |category, terms| %> -

<%= category.name %>

- <%= render partial: 'index_in_category', locals: {terms: terms} %> + <% categorized_terms.group_by(&:category).each do |category, terms| %> +

<%= category.name %>

+ <%= render partial: 'index_terms', locals: {terms: terms} %> + <% end %> + +

<%=l :label_not_categorized %>

+ <%= render 'index_terms', terms: uncategorized_terms %> +<% else %> + <%= render 'index_terms', terms: @glossary_terms %> <% end %> -

<%=l :label_not_categorized %>

-<%= render 'index_in_category', terms: uncategorized_terms %> - diff --git a/config/locales/en.yml b/config/locales/en.yml index 238ea40..c4a8839 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,6 +13,8 @@ en: label_view: View label_glossary_index: index label_not_categorized: Not categorized + label_grouping: Grouping + label_categorized: Categorized index_en: | A B C D E F diff --git a/config/locales/ja.yml b/config/locales/ja.yml index d997de3..2034a95 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -12,6 +12,8 @@ ja: label_view: 表示 label_glossary_index: 索引 label_not_categorized: 未分類 + label_grouping: グループ化 + label_categorized: カテゴリで分類 permission_view_glossary: 用語集の閲覧 permission_manage_glossary: 用語集の管理