From ec55782873284f352b8b402ce24dea70a63b1892 Mon Sep 17 00:00:00 2001 From: drusepth Date: Wed, 7 Sep 2022 16:22:05 -0700 Subject: [PATCH] reuse new foldered index view across content pages and documents --- app/controllers/content_controller.rb | 1 + app/controllers/documents_controller.rb | 1 + app/helpers/application_helper.rb | 3 + .../display/_tailwind_foldered_index.html.erb | 693 +++++++++++ app/views/content/index.html.erb | 1014 +++++++++++------ app/views/documents/index.html.erb | 35 + 6 files changed, 1393 insertions(+), 354 deletions(-) create mode 100644 app/views/content/display/_tailwind_foldered_index.html.erb diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 25f18107..68d86aaa 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -55,6 +55,7 @@ class ContentController < ApplicationController end @content = @content.sort_by {|x| [x.favorite? ? 0 : 1, x.name] } + @folders = [] @questioned_content = @content.sample @attribute_field_to_question = SerendipitousService.question_for(@questioned_content) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 75aef647..cfedbf1c 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -57,6 +57,7 @@ class DocumentsController < ApplicationController page_id: @documents.map(&:id) ).order(:tag) + @filtered_page_tags = [] if params.key?(:tag) @filtered_page_tags = @page_tags.where(slug: params[:tag]) @documents = @documents.to_a.select { |document| @filtered_page_tags.pluck(:page_id).include?(document.id) } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d03680a8..3cfd6d19 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,6 +4,9 @@ module ApplicationHelper # If we pass in a class (e.g. Character instead of "Character") by mistake, just return it return class_name if class_name.is_a?(Class) + # Extra whitelisting for some other classes we don't necessarily want in the content_types array + return Folder if class_name == Folder.name + Rails.application.config.content_types_by_name[class_name] end diff --git a/app/views/content/display/_tailwind_foldered_index.html.erb b/app/views/content/display/_tailwind_foldered_index.html.erb new file mode 100644 index 00000000..7b3847fc --- /dev/null +++ b/app/views/content/display/_tailwind_foldered_index.html.erb @@ -0,0 +1,693 @@ +<% + if mixed_content_types + content_counts_per_type = { content_type_name: content.count } + else + content_counts_per_type = Hash.new(0) + content.each { |page| content_counts_per_type[page.is_a?(ContentPage) ? page['page_type'] : page.class.name] += 1 } + end + + if @folders.any? + content_counts_per_type[Folder.name] = @folders.count + end +%> + + +
+ +
+ +
+
+
+ Workflow +
+
+ +
+
+
+
+
+ + + + +
+
+ <%= image_tag asset_path(header_image), class: 'h-32 w-full object-cover lg:h-48' %> +
+ +
+
+
+ <% if @universe_scope %> + <%= link_to @universe_scope do %> + <%= image_tag @universe_scope.random_image_including_private(format: :hero), class: 'h-24 w-24 rounded-full ring-4 ring-purple-800 sm:h-32 sm:w-32' %> + <% end %> + <% else %> + <%= image_tag current_user.image_url, class: 'h-24 w-24 rounded-full ring-4 ring-green-800 sm:h-32 sm:w-32' %> + <% end %> +
+
+
+

+ Showing <%= pluralize content.count, content_type_name.downcase %> +

+ <% if @universe_scope %> +
+ in <%= link_to @universe_scope.name, @universe_scope, class: Universe.text_color %> +
+ <% end %> +
+
+ <%= link_to attribute_customization_path(content_type_name.downcase) do %> + + <% end %> + + <% if current_user.can_create?(content_type_class) || PermissionService.user_has_active_promotion_for_this_content_type(user: current_user, content_type: content_type_class.name) %> + <%= link_to new_polymorphic_path(content_type_class) do %> + + <% end %> + <% else %> + <%= link_to subscription_path do %> + + <% end %> + <% end %> +
+
+
+ +
+
+ + +
+ + + + +
+

Filters

+ +
+
+
+
+ +
+ + +
+ + + + + +
+
+ + + <% if filtered_page_tags.any? %> +
+
+

+ Showing only <%= content_type_name.pluralize %> with <%= 'tag'.pluralize(filtered_page_tags.count) %> + , active +

+ + + +
+
+ <% filtered_page_tags.each do |page_tag| %> + + <%= page_tag.tag %> + <%= link_to(polymorphic_path(content_type_class, { slug: params.fetch(:slug, []) - [page_tag.slug] })) do %> + + <% end %> + + <% end %> +
+
+
+
+ <% end %> +
+
+ + <%# render partial: 'content/components/list_filter_bar', locals: { content_type: content_type_class } %> + + <%# to be made into new card list partial? %> + <% if content.any? %> +
+ <% content.each do |content| %> +
+ <%= link_to content.is_a?(ContentPage) ? content.view_path : content do %> +
+ <%= image_tag content.random_image_including_private(format: :small), class: 'h-64 rounded-t w-full object-cover object-center mb-6' %> +
+ star_outline +

+ <%= content.page_type %> +

+

+ <%= content.name %> +

+
+
+ <% end %> +
+ <% end %> +
+ <% end %> + + <% if content.empty? %> +
+
+ +
+
+ +
+
+ <% end %> + + + + + +
+ + + +
+
+
+ + + + + + + + + + + + +
+

+ Folders + <%= folders.count %> + + <%= link_to '#', class: "float-right text-xs #{Folder.color} hover:bg-teal-500 text-white rounded-lg px-2 py-1" do %> + Create folder + <% end %> +

+ +
+ +
+

+ Documents + <%= folders.count %> + + <%= link_to '#', class: "float-right text-xs #{Document.color} hover:bg-teal-600 text-white rounded-lg px-2 py-1" do %> + Create document + <% end %> +

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
NameTitleStatusRole + Edit +
+
+
+ +
+
+
Jane Cooper
+
jane.cooper@example.com
+
+
+
+
Regional Paradigm Technician
+
Optimization
+
+ Active + Admin + Edit +
+
+
+
+
+
+ + + + + + + + + diff --git a/app/views/content/index.html.erb b/app/views/content/index.html.erb index 7b15e033..d27deec2 100644 --- a/app/views/content/index.html.erb +++ b/app/views/content/index.html.erb @@ -1,381 +1,687 @@ - -
-
- <%= image_tag asset_path("card-headers/#{@content_type_name.downcase.pluralize}.webp"), class: 'h-32 w-full object-cover lg:h-48' %> -
+<%= render partial: 'content/display/tailwind_foldered_index', locals: { + header_image: "card-headers/#{@content_type_name.downcase.pluralize}.webp", + content: @content, + mixed_content_types: false, + folders: @folders, + content_type_class: @content_type_class, + content_type_name: @content_type_name, + filtered_page_tags: @filtered_page_tags, + page_tags: @page_tags +} %> -
-
-
- <% if @universe_scope %> - <%= link_to @universe_scope do %> - <%= image_tag @universe_scope.random_image_including_private(format: :hero), class: 'h-24 w-24 rounded-full ring-4 ring-purple-800 sm:h-32 sm:w-32' %> - <% end %> - <% else %> - <%= image_tag current_user.image_url, class: 'h-24 w-24 rounded-full ring-4 ring-green-800 sm:h-32 sm:w-32' %> - <% end %> -
-
-
-

- Showing <%= pluralize @content.count, @content_type_name.downcase %> -

- <% if @universe_scope %> -
- in <%= link_to @universe_scope.name, @universe_scope, class: Universe.text_color %> -
- <% end %> + + + + + + + + + + + + +
+ +
+
+
+
+ Workflow
-
- <%= link_to attribute_customization_path(@content_type_name.downcase) do %> - - <% end %> - - <% if current_user.can_create?(@content_type_class) || PermissionService.user_has_active_promotion_for_this_content_type(user: current_user, content_type: @content_type_class.name) %> - <%= link_to new_polymorphic_path(@content_type_class) do %> - - <% end %> - <% else %> - <%= link_to subscription_path do %> - - <% end %> - <% end %> +
+
- -
-
+
+
- -
- - - - -
-

Filters

- -
-
-
+ +
- + <%= image_tag asset_path("card-headers/#{@content_type_name.downcase.pluralize}.webp"), class: 'h-32 w-full object-cover lg:h-48' %>
- -
- - - - - -
- <% end %> -
-
-<%# render partial: 'content/components/list_filter_bar', locals: { content_type: @content_type_class } %> + +
+ + + + +
+

Filters

+ +
+
+
+
+ +
+ + +
+ + + + + +
+
+ + + <% if @filtered_page_tags.any? %> +
+
+

+ Showing only <%= @content_type_name.pluralize %> with <%= 'tag'.pluralize(@filtered_page_tags.count) %> + , active +

+ + + +
+
+ <% @filtered_page_tags.each do |page_tag| %> + + <%= page_tag.tag %> + <%= link_to(polymorphic_path(@content_type_class, { slug: params.fetch(:slug, []) - [page_tag.slug] })) do %> + + <% end %> + + <% end %> +
+
+
+
+ <% end %> +
+
+ + <%# render partial: 'content/components/list_filter_bar', locals: { content_type: @content_type_class } %> + + <%# to be made into new card list partial? %> + <% if @content.any? %> +
+ <% @content.each do |content| %> +
+ <%= link_to content.view_path do %> +
+ <%= image_tag content.random_image_including_private(format: :small), class: 'h-64 rounded-t w-full object-cover object-center mb-6' %> +
+ star_outline +

+ <%= content.page_type %> +

+

+ <%= content.name %> +

+
+
+ <% end %> +
+ <% end %> +
+ <% end %> + + <% if @content.empty? %> +
+
+ +
+
+
<% end %> -
- <% end %> -
-<% end %> -<% if @content.empty? %> -
-
- + +
- - recommended before creating your first <%= @content_type_name.downcase %> - - -
-
- + + +
-<% end %> +
+ + + + + + + + + + + + +
+

+ Folders + <%= @folders.count %> + + <%= link_to '#', class: "float-right text-xs #{Folder.color} hover:bg-teal-500 text-white rounded-lg px-2 py-1" do %> + Create folder + <% end %> +

+
    + <% @folders.each do |folder| %> + <%= link_to folder, class: 'group' do %> +
  • +
    + <%= Folder.icon %> +
    +
    +
    +

    <%= folder.title %>

    +

    16 documents

    +
    +
    + +
    +
    +
  • + <% end %> + <% end %> +
+
+ +
+

+ Documents + <%= @folders.count %> + + <%= link_to '#', class: "float-right text-xs #{Document.color} hover:bg-teal-600 text-white rounded-lg px-2 py-1" do %> + Create document + <% end %> +

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
NameTitleStatusRole + Edit +
+
+
+ +
+
+
Jane Cooper
+
jane.cooper@example.com
+
+
+
+
Regional Paradigm Technician
+
Optimization
+
+ Active + Admin + Edit +
+
+
+
+
+
+ + + + + + + + -<%= render partial: 'javascripts/content_linking' %> \ No newline at end of file diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index b6406c95..83a2b9ba 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -1,3 +1,26 @@ +<%= render partial: 'content/display/tailwind_foldered_index', locals: { + header_image: "card-headers/documents.webp", + content: @documents, + mixed_content_types: false, + folders: @folders, + content_type_class: Document, + content_type_name: Document.name, + filtered_page_tags: @filtered_page_tags, + page_tags: @page_tags +} %> + + + + + + + + + + + + +
@@ -30,6 +53,11 @@ + + + + +
@@ -197,6 +225,12 @@
+ + + + + +