Skip to content

Commit 80ba049

Browse files
authored
Merge pull request #1036 from indentlabs/2021-10-04
Oct 4 fixes
2 parents b1b41e6 + dd8b0bb commit 80ba049

File tree

15 files changed

+169
-50
lines changed

15 files changed

+169
-50
lines changed

app/assets/javascripts/content.js

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

107-
$.get(
108-
'/api/internal/' + tag.data('klass') + '/' + tag.data('id') + '/name'
109-
).done(function (response) {
110-
tag.find('.name-container').text(response);
111-
}).fail(function() {
112-
tag.find('.name-conainer').text("Unknown " + tag.data('klass'));
113-
});
107+
// Instantiate a cache for all page lookup queries (if not already created)
108+
window.load_page_name_cache ||= {};
109+
var page_name_key = tag.data('klass') + '/' + tag.data('id');
110+
111+
if (page_name_key in window.load_page_name_cache) {
112+
// If we've already made a request for this klass+id, we can just insta-load the
113+
// cached result instead of requesting it again.
114+
tag.find('.name-container').text(window.load_page_name_cache[page_name_key]);
115+
116+
} else {
117+
// If we haven't made a request for this klass+id, look it up and cache it
118+
$.get(
119+
'/api/internal/' + page_name_key + '/name'
120+
).done(function (response) {
121+
tag.find('.name-container').text(response);
122+
window.load_page_name_cache[page_name_key] = response;
123+
124+
// Go ahead and pre-fill all tags on the page for this klass+id, too
125+
$('.js-load-page-name[data-klass=' + tag.data('klass') + '][data-id=' + tag.data('id') + ']')
126+
.find('.name-container')
127+
.text(response);
128+
129+
}).fail(function() {
130+
tag.find('.name-container').text("Unknown " + tag.data('klass'));
131+
});
132+
}
133+
134+
135+
114136
});
115137

116138
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def cache_contributable_universe_ids
159159
cache_current_user_content
160160

161161
@contributable_universe_ids ||= if user_signed_in?
162-
current_user.contributable_universe_ids + @current_user_content.fetch('Universe', []).map(&:id)
162+
current_user.contributable_universe_ids
163163
else
164164
[]
165165
end

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)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class PageTagsController < ApplicationController
2+
def remove
3+
# Params
4+
# {"page_type"=>"Location", "slug"=>"mountains", "controller"=>"page_tags", "action"=>"remove"
5+
return unless params.key?(:page_type) && params.key?(:slug)
6+
7+
PageTag.where(
8+
page_type: params[:page_type],
9+
slug: params[:slug],
10+
user_id: current_user.id
11+
).destroy_all
12+
13+
return redirect_back fallback_location: root_path, notice: 'Tag deleted successfully.'
14+
end
15+
end

app/helpers/page_tags_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module PageTagsHelper
2+
end

app/views/content/display/_changelog.html.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
changed_fields = AttributeField.where(id: changed_attributes.pluck(:attribute_field_id)).includes([:attribute_category])
66
%>
77

8-
98
<div class="row">
109
<div class="col s12 m12 l10 offset-l1">
1110
<h1 class="flow-text grey-text">
@@ -72,10 +71,14 @@
7271
<span>
7372
<%= link_to(change_event.user.display_name, change_event.user, class: "#{User.text_color}") %>
7473
</span>
75-
<div class="grey-text right"><%= time_ago_in_words change_event.created_at %> ago</div>
74+
<div class="grey-text right">
75+
<%= time_ago_in_words change_event.created_at %> ago
76+
&middot;
77+
<%= change_event.created_at.strftime('%B %d, %H:%M %Z') %>
78+
</div>
7679
</div>
7780
</div>
78-
<div style="margin-bottom: 4em">
81+
<div style="margin-bottom: 4em" class="black-text">
7982
<%=
8083
render partial: "content/changelog/field_change/#{related_field.field_type}",
8184
locals: { old_value: old_value, new_value: new_value }

app/views/content/panels/_associations.html.erb

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
TODO: everything here (probably) should move to the ContentSerializer so we don't have this
33
heavy logic in a random partial
44
%>
5-
<%
6-
relations = Rails.application.config.content_relations[content.class.name]
7-
relations ||= []
8-
%>
95

106
<div id="associations_panel" class="panel">
117
<%= render partial: 'notice_dismissal/messages/07' %>
@@ -29,37 +25,5 @@
2925
locals: { value: link_codes, content: content }
3026
%>
3127
<% end %>
32-
33-
<% if user_signed_in? %>
34-
<div class="card-panel yellow lighten-5 black-text">
35-
Notice: The newest Notebook.ai release is adding the ability to create your own link
36-
fields, which includes a rather large migration of all existing link fields into a new linking system.
37-
Links that haven't been migrated yet can be seen below this message; links on the new system appear above.
38-
<br /><br />
39-
Thank you for your patience during this large rewrite! This notice will automatically disappear after the
40-
migration has completed for everyone.
41-
<br /><br />
42-
&mdash; Andrew
43-
</div>
44-
<% end %>
45-
46-
<%# TODO: remove these after finishing link migration script %>
47-
<% relations.each do |name, params| %>
48-
<%
49-
results = params[:related_class].where("#{params[:through_relation].downcase}_id": content.id)
50-
.map { |content| content.send(params[:inverse_class].downcase) }
51-
.select { |content| content && content.readable_by?(current_user || User.new) }
52-
%>
53-
<% next unless results.any? %>
54-
55-
<div class="uppercase grey-text">
56-
<%= params[:relation_text].to_s.titleize.downcase %> of
57-
</div>
58-
<%=
59-
link_codes = results.map { |page| "#{page.page_type}-#{page.id}" }
60-
render partial: "content/display/attribute_value/link",
61-
locals: { value: link_codes, content: content }
62-
%>
63-
<% end %>
6428
</div>
6529
</div>

app/views/data/index.html.erb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@
6969
<% end %>
7070
</div>
7171

72+
<div class="col s12 m12 l6">
73+
<%= link_to tags_path, class: 'black-text' do %>
74+
<div class="hoverable card purple lighten-5">
75+
<div class="card-content">
76+
<i class="material-icons right purple-text text-lighten-4"><%= PageTag.icon %></i>
77+
<div class="card-title">Tag management</div>
78+
<p>
79+
Manage the tags you've used for your worldbuilding.
80+
</p>
81+
</div>
82+
</div>
83+
<% end %>
84+
</div>
85+
7286
<div class="col s12 m12 l6">
7387
<%= link_to notebook_export_path, class: 'black-text' do %>
7488
<div class="hoverable card brown lighten-3">

app/views/data/tags.html.erb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<%
2+
showed_any_tags = false
3+
%>
4+
5+
<h2 class="grey-text" style="font-size: 2rem">Your Notebook.ai tags</h2>
6+
<ul class="collapsible">
7+
<% Rails.application.config.content_types[:all].each do |content_type| %>
8+
<%
9+
grouped_tags = PageTag.where(page_type: content_type.name, user_id: current_user).order('tag ASC').group_by(&:tag)
10+
11+
next if grouped_tags.values.length == 0
12+
13+
showed_any_tags = true
14+
%>
15+
16+
<li>
17+
<div class="collapsible-header">
18+
<i class="material-icons <%= content_type.text_color %>"><%= content_type.icon %></i>
19+
<%= content_type.name %> tags
20+
<span class="badge"><%= grouped_tags.values.length %></span>
21+
</div>
22+
<div class="collapsible-body">
23+
<% grouped_tags.each do |tag, page_list| %>
24+
<div class="row" style="border-bottom: 1px solid #ccc; padding-bottom: 2em; margin-bottom: 2em">
25+
<div class="col s12 m6 l4">
26+
<div>
27+
<%=
28+
link_to send(
29+
"#{content_type.name.downcase.pluralize}_path",
30+
slug: PageTagService.slug_for(tag)
31+
) do
32+
%>
33+
<span class="<%= content_type.color %> white-text" style="padding: 0.3em 0.4em; font-size: 1em">
34+
<%= tag %>
35+
</span>
36+
<% end %>
37+
</div>
38+
<div class="grey-text" style="padding-top: 1em">
39+
Used by <%= pluralize page_list.length, 'page' %>
40+
</div>
41+
<div>
42+
<%=
43+
link_to 'Delete this tag', tag_remove_path(
44+
page_type: content_type.name,
45+
slug: PageTagService.slug_for(tag)
46+
), data: {
47+
confirm: "Are you sure? This will delete this tag and remove it from all pages."
48+
}, class: 'red-text'
49+
%>
50+
</div>
51+
</div>
52+
<div class="col s12 m6 l8">
53+
<% page_list.each do |page_tag| %>
54+
<div class="chip js-load-page-name" data-klass="<%= page_tag.page_type %>" data-id="<%= page_tag.page_id %>">
55+
<%= link_to send("#{page_tag.page_type.downcase}_path", page_tag.page_id) do %>
56+
<span class="<%= content_type.text_color %>">
57+
<i class="material-icons left">
58+
<%= content_type.icon %>
59+
</i>
60+
</span>
61+
<span class="name-container">
62+
<em>Loading <%= content_type.name %> name...</em>
63+
</span>
64+
<% end %>
65+
</div>
66+
<% end %>
67+
</div>
68+
</div>
69+
<% end %>
70+
</div>
71+
</li>
72+
<% end %>
73+
</ul>
74+
75+
<% if !showed_any_tags %>
76+
<div class="card-panel">
77+
When you create tags for your pages, they'll appear here. Come back later when you've added some!
78+
</div>
79+
<% end %>

0 commit comments

Comments
 (0)