Skip to content

Commit 0046af6

Browse files
committed
add basic tags view in data vault
1 parent 73fed6c commit 0046af6

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed

app/assets/javascripts/content.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ $(document).ready(function () {
104104
// Replace this element's content with the name of the page
105105
var tag = $(this);
106106

107+
// TODO: we should be caching this to reduce duplicate requests on the same page
108+
107109
$.get(
108110
'/api/internal/' + tag.data('klass') + '/' + tag.data('id') + '/name'
109111
).done(function (response) {

app/controllers/data_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def usage
115115
@content = current_user.content
116116
end
117117

118+
def tags
119+
@tags = current_user.page_tags
120+
end
121+
118122
def discussions
119123
@topics = Thredded::Topic.where(user_id: current_user.id)
120124
@posts = Thredded::Post.where(user_id: current_user.id)

app/views/data/tags.html.erb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<% Rails.application.config.content_types[:all].each do |content_type| %>
2+
<%
3+
grouped_tags = PageTag.where(page_type: content_type.name, user_id: current_user).group_by(&:tag)
4+
5+
next if grouped_tags.values.length == 0
6+
%>
7+
8+
<h2 class="grey-text" style="font-size: 2rem"><%= content_type.name %> tags</h2>
9+
<% grouped_tags.each do |tag, page_list| %>
10+
<div class="row">
11+
<div class="col s12">
12+
<div class="card">
13+
<div class="card-content">
14+
<div class="row">
15+
<div class="col s12 m6 l4">
16+
<%=
17+
link_to send(
18+
"#{content_type.name.downcase.pluralize}_path",
19+
slug: PageTagService.slug_for(tag)
20+
) do
21+
%>
22+
<span class="new badge <%= content_type.color %> left" data-badge-caption="<%= tag %>" style="margin: 0.2em; font-size: 1em"></span>
23+
<% end %>
24+
</div>
25+
<div class="col s12 m6 l8">
26+
<% page_list.each do |page_tag| %>
27+
<div class="chip js-load-page-name" data-klass="<%= page_tag.page_type %>" data-id="<%= page_tag.page_id %>">
28+
<%= link_to send("#{page_tag.page_type.downcase}_path", page_tag.page_id) do %>
29+
<span class="<%= content_type.text_color %>">
30+
<i class="material-icons left">
31+
<%= content_type.icon %>
32+
</i>
33+
</span>
34+
<span class="name-container">
35+
<%= "<em>Loading #{content_type.name} name...</em>".html_safe %>
36+
</span>
37+
<% end %>
38+
</div>
39+
<% end %>
40+
</div>
41+
</div>
42+
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
<% end %>
48+
<% end %>
49+
50+
51+
<% @tags.group_by(&:page_type).each do |page_type, tags| %>
52+
<div class="row">
53+
<div class="col s12">
54+
<div class="card">
55+
<div class="card-content">
56+
<div class="card-title"><%= page_type %> tags</div>
57+
58+
<% tags.each do |tag| %>
59+
<div class="row">
60+
<div class="col s12 m6 l4">
61+
<%=
62+
link_to send(
63+
"#{tag.page_type.downcase.pluralize}_path",
64+
slug: tag.slug
65+
) do
66+
%>
67+
<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>
68+
<% end %>
69+
70+
</div>
71+
<div class="col s12 m6 l8">
72+
73+
</div>
74+
</div>
75+
<% end %>
76+
77+
</div>
78+
</div>
79+
</div>
80+
</div>
81+
<% end %>
82+
83+
84+
<div class="row">
85+
<div class="col s12">
86+
<div class="card">
87+
<div class="card-content">
88+
<div class="card-title">Tags</div>
89+
<div class="row clearfix">
90+
<% @tags.group_by(&:page_type).each do |page_type, tags| %>
91+
<div class="col s12 m6 l4">
92+
<div class="card-title grey-text">
93+
<%= page_type %> Tags
94+
</div>
95+
</div>
96+
97+
<div class="col s12 m6 l8">
98+
<% tags.each do |tag| %>
99+
<div class="row">
100+
<div class="col s12 m6 l4">
101+
<%=
102+
link_to send(
103+
"#{tag.page_type.downcase.pluralize}_path",
104+
slug: tag.slug
105+
) do
106+
%>
107+
<span class="new badge <%= content_class_from_name(tag.page_type).color %> left" data-badge-caption="<%= tag.tag %>" style="margin: 0.2em"></span>
108+
<% end %>
109+
</div>
110+
<div class="col s12 m6 l8">
111+
112+
</div>
113+
</div>
114+
<% end %>
115+
</div>
116+
<% end %>
117+
</div>
118+
</div>
119+
</div>
120+
</div>
121+
</div>

app/views/data/usage.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@
8181
</div>
8282
</div>
8383
</div>
84-
</div>
84+
</div>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
scope '/data' do
134134
get '/', to: 'data#index', as: :data_vault
135135
get '/usage', to: 'data#usage'
136+
get '/tags', to: 'data#tags'
136137
get '/recyclebin', to: 'data#recyclebin'
137138
get '/archive', to: 'data#archive'
138139
get '/documents', to: 'data#documents', as: :data_documents

0 commit comments

Comments
 (0)