Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add basic tags view in data vault
  • Loading branch information
drusepth committed Oct 5, 2021
commit 0046af6880ccbb0ead8077e3d3e94fedbadb0323
2 changes: 2 additions & 0 deletions app/assets/javascripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ $(document).ready(function () {
// Replace this element's content with the name of the page
var tag = $(this);

// TODO: we should be caching this to reduce duplicate requests on the same page

$.get(
'/api/internal/' + tag.data('klass') + '/' + tag.data('id') + '/name'
).done(function (response) {
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def usage
@content = current_user.content
end

def tags
@tags = current_user.page_tags
end

def discussions
@topics = Thredded::Topic.where(user_id: current_user.id)
@posts = Thredded::Post.where(user_id: current_user.id)
Expand Down
121 changes: 121 additions & 0 deletions app/views/data/tags.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<% Rails.application.config.content_types[:all].each do |content_type| %>
<%
grouped_tags = PageTag.where(page_type: content_type.name, user_id: current_user).group_by(&:tag)

next if grouped_tags.values.length == 0
%>

<h2 class="grey-text" style="font-size: 2rem"><%= content_type.name %> tags</h2>
<% grouped_tags.each do |tag, page_list| %>
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<div class="row">
<div class="col s12 m6 l4">
<%=
link_to send(
"#{content_type.name.downcase.pluralize}_path",
slug: PageTagService.slug_for(tag)
) do
%>
<span class="new badge <%= content_type.color %> left" data-badge-caption="<%= tag %>" style="margin: 0.2em; font-size: 1em"></span>
<% end %>
</div>
<div class="col s12 m6 l8">
<% page_list.each do |page_tag| %>
<div class="chip js-load-page-name" data-klass="<%= page_tag.page_type %>" data-id="<%= page_tag.page_id %>">
<%= link_to send("#{page_tag.page_type.downcase}_path", page_tag.page_id) do %>
<span class="<%= content_type.text_color %>">
<i class="material-icons left">
<%= content_type.icon %>
</i>
</span>
<span class="name-container">
<%= "<em>Loading #{content_type.name} name...</em>".html_safe %>
</span>
<% end %>
</div>
<% end %>
</div>
</div>

</div>
</div>
</div>
</div>
<% end %>
<% end %>


<% @tags.group_by(&:page_type).each do |page_type, tags| %>
<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<div class="card-title"><%= page_type %> tags</div>

<% tags.each do |tag| %>
<div class="row">
<div class="col s12 m6 l4">
<%=
link_to send(
"#{tag.page_type.downcase.pluralize}_path",
slug: tag.slug
) do
%>
<span class="new badge <%= content_class_from_name(tag.page_type).color %> left" data-badge-caption="<%= tag.tag %>" style="margin: 0.2em; font-size: 1em"></span>
<% end %>

</div>
<div class="col s12 m6 l8">

</div>
</div>
<% end %>

</div>
</div>
</div>
</div>
<% end %>


<div class="row">
<div class="col s12">
<div class="card">
<div class="card-content">
<div class="card-title">Tags</div>
<div class="row clearfix">
<% @tags.group_by(&:page_type).each do |page_type, tags| %>
<div class="col s12 m6 l4">
<div class="card-title grey-text">
<%= page_type %> Tags
</div>
</div>

<div class="col s12 m6 l8">
<% tags.each do |tag| %>
<div class="row">
<div class="col s12 m6 l4">
<%=
link_to send(
"#{tag.page_type.downcase.pluralize}_path",
slug: tag.slug
) do
%>
<span class="new badge <%= content_class_from_name(tag.page_type).color %> left" data-badge-caption="<%= tag.tag %>" style="margin: 0.2em"></span>
<% end %>
</div>
<div class="col s12 m6 l8">

</div>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/data/usage.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@
</div>
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
scope '/data' do
get '/', to: 'data#index', as: :data_vault
get '/usage', to: 'data#usage'
get '/tags', to: 'data#tags'
get '/recyclebin', to: 'data#recyclebin'
get '/archive', to: 'data#archive'
get '/documents', to: 'data#documents', as: :data_documents
Expand Down