use table view for documents#index

This commit is contained in:
Andrew Brown 2021-06-17 22:06:35 -07:00
parent e9383af20c
commit 57e422ae9c
4 changed files with 91 additions and 15 deletions

View File

@ -16,7 +16,7 @@ class DocumentsController < ApplicationController
def index
@page_title = "My documents"
@documents = @current_user_content.fetch('Document', [])
@documents = current_user.linkable_documents.order('favorite DESC, title ASC')
@recent_documents = current_user.linkable_documents.order('updated_at DESC')
end

View File

@ -0,0 +1,71 @@
<%# Usage: render partial: 'content/list/document_table', locals: { content_list: @content, content_type: @content_type_class } %>
<table class="highlight z-depth-1">
<thead>
<tr>
<th>Title</th>
<th>Length</th>
<th>Last edited</th>
</tr>
</thead>
<% content_list.each do |document| %>
<tr class="white">
<td>
<div>
<i class="material-icons left <%= Document.color %>-text"><%= Document.icon %></i>
<%
if document.favorite?
icon = 'star'
action = 'Unfavorite'
else
icon = 'star_border'
action = 'Favorite'
end
%>
<% if document.persisted? && user_signed_in? && document.user == current_user %>
<i class="material-icons right orange-text favorite-button tooltipped"
data-tooltip="<%= action %> this page"
data-content-id="<%= document.id %>"
data-content-class="<%= document.class.name.downcase.pluralize %>">
<%= icon %>
</i>
<% end %>
<strong style="font-size: 1.2em"><%= document.title %></strong>
</div>
<div style="padding-left: 2.6em">
<% if current_user.can_update?(document) %>
<%= link_to edit_polymorphic_path(document), class: 'green white-text btn-flat', target: document.is_a?(Document) ? '_new' : '_self' do %>
<i class="material-icons left"><%= content_type.icon %></i>
Edit
<% end %>
<% end %>
<% if current_user.can_read?(document) %>
<%= link_to polymorphic_path(document), class: 'blue white-text text-lighten-1 btn-flat' do %>
<i class="material-icons left"><%= content_type.icon %></i>
View
<% end %>
<% end %>
<%= link_to '#', class: 'btn-flat orange white-text' do %>
<i class="material-icons left">bar_chart</i>
Analyze
<% end %>
</div>
</td>
<td>
<%= document.reading_estimate %>
<%# pluralize 0, 'word' %>
</td>
<td>
<span class="tooltipped" data-tooltip="Last edited at <%= document.updated_at.strftime("%m/%d/%Y %H:%M UTC") %>">
<%= document.updated_at == document.created_at ? 'created' : 'updated' %>
<%= time_ago_in_words document.updated_at %> ago
</span>
</td>
</tr>
<% end %>
</table>

View File

@ -54,25 +54,27 @@
<% end %>
</span>
<p class="tags-container">
<% content.page_tags.each do |tag| %>
<% if user_signed_in? && content.user == current_user %>
<%=
link_to send(
"page_tag_#{content.class.name.downcase.pluralize}_path",
slug: PageTagService.slug_for(tag.tag)
) do
%>
<% if content.respond_to?(:page_tags) %>
<% content.page_tags.each do |tag| %>
<% if user_signed_in? && content.user == current_user %>
<%=
link_to send(
"page_tag_#{content.class.name.downcase.pluralize}_path",
slug: PageTagService.slug_for(tag.tag)
) do
%>
<span class="new badge <%= params[:slug] == tag.slug ? @content_type_class.color : 'grey' %> left" data-badge-caption="<%= tag.tag %>"></span>
<% end %>
<% else %>
<span class="new badge <%= params[:slug] == tag.slug ? @content_type_class.color : 'grey' %> left" data-badge-caption="<%= tag.tag %>"></span>
<% end %>
<% else %>
<span class="new badge <%= params[:slug] == tag.slug ? @content_type_class.color : 'grey' %> left" data-badge-caption="<%= tag.tag %>"></span>
<% end %>
<% end %>
</p>
<p class='grey-text' style="clear: both">
<% if user_signed_in? %>
<span class="timestamp tooltipped" data-position="bottom" data-delay="500" data-tooltip="<%= content.updated_at.strftime("%m/%d/%Y %H:%M") %>" style="font-size: 80%">
<i class="material-icons">mode_edit</i>
<i class="material-icons tiny left">mode_edit</i>
<%
if content.updated_at == content.created_at

View File

@ -17,17 +17,20 @@
<h5>Recently-edited documents</h5>
<%= render partial: 'content/list/cards', locals: { content_list: @documents.first(3), content_type: Document, show_new_button: false } %>
</div>
<!-- recent documents -->
<br />
<div class="row">
<%= render partial: 'content/components/list_filter_bar', locals: { content_type: Document } %>
<h5>All documents</h5>
<%= render partial: 'content/components/list_filter_bar', locals: { content_type: Document } %>
<%= render partial: 'notice_dismissal/messages/02' %>
<%= render partial: 'content/list/cards', locals: { content_list: @documents, content_type: Document } %>
<%= render partial: 'content/list/document_table', locals: { content_list: @documents, content_type: Document } %>
</div>
</div>
<% end %>
<% end %>
<!-- recent analysis -->
<% if @documents.empty? %>
<div class="row">
<div class="col s12 m8 offset-m2">