diff --git a/app/assets/javascripts/content.js b/app/assets/javascripts/content.js index 6eac7528..8de06125 100644 --- a/app/assets/javascripts/content.js +++ b/app/assets/javascripts/content.js @@ -104,13 +104,35 @@ $(document).ready(function () { // Replace this element's content with the name of the page var tag = $(this); - $.get( - '/api/internal/' + tag.data('klass') + '/' + tag.data('id') + '/name' - ).done(function (response) { - tag.find('.name-container').text(response); - }).fail(function() { - tag.find('.name-conainer').text("Unknown " + tag.data('klass')); - }); + // Instantiate a cache for all page lookup queries (if not already created) + window.load_page_name_cache = window.load_page_name_cache || {}; + var page_name_key = tag.data('klass') + '/' + tag.data('id'); + + if (page_name_key in window.load_page_name_cache) { + // If we've already made a request for this klass+id, we can just insta-load the + // cached result instead of requesting it again. + tag.find('.name-container').text(window.load_page_name_cache[page_name_key]); + + } else { + // If we haven't made a request for this klass+id, look it up and cache it + $.get( + '/api/internal/' + page_name_key + '/name' + ).done(function (response) { + tag.find('.name-container').text(response); + window.load_page_name_cache[page_name_key] = response; + + // Go ahead and pre-fill all tags on the page for this klass+id, too + $('.js-load-page-name[data-klass=' + tag.data('klass') + '][data-id=' + tag.data('id') + ']') + .find('.name-container') + .text(response); + + }).fail(function() { + tag.find('.name-container').text("Unknown " + tag.data('klass')); + }); + } + + + }); }); diff --git a/app/assets/javascripts/page_tags.coffee b/app/assets/javascripts/page_tags.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/page_tags.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6e5b9a9f..cd3e10b2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -159,7 +159,7 @@ class ApplicationController < ActionController::Base cache_current_user_content @contributable_universe_ids ||= if user_signed_in? - current_user.contributable_universe_ids + @current_user_content.fetch('Universe', []).map(&:id) + current_user.contributable_universe_ids else [] end diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb index f42eef7e..b6897575 100644 --- a/app/controllers/data_controller.rb +++ b/app/controllers/data_controller.rb @@ -115,6 +115,10 @@ class DataController < ApplicationController @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) diff --git a/app/controllers/page_tags_controller.rb b/app/controllers/page_tags_controller.rb new file mode 100644 index 00000000..55653d39 --- /dev/null +++ b/app/controllers/page_tags_controller.rb @@ -0,0 +1,23 @@ +class PageTagsController < ApplicationController + # Remove a tag and all of its links to a page + def remove + # Params + # {"page_type"=>"Location", "slug"=>"mountains", "controller"=>"page_tags", "action"=>"remove" + return unless params.key?(:page_type) && params.key?(:slug) + + PageTag.where( + page_type: params[:page_type], + slug: params[:slug], + user_id: current_user.id + ).destroy_all + + return redirect_back fallback_location: root_path, notice: 'Tag(s) deleted successfully.' + end + + # Destroy a specific tag by ID + def destroy + PageTag.find_by(id: params[:id], user_id: current_user.id).destroy! + + return redirect_back fallback_location: root_path, notice: 'Tag(s) deleted successfully.' + end +end diff --git a/app/helpers/page_tags_helper.rb b/app/helpers/page_tags_helper.rb new file mode 100644 index 00000000..96c4808b --- /dev/null +++ b/app/helpers/page_tags_helper.rb @@ -0,0 +1,2 @@ +module PageTagsHelper +end diff --git a/app/views/content/display/_changelog.html.erb b/app/views/content/display/_changelog.html.erb index 396aa2b0..8f1aecee 100644 --- a/app/views/content/display/_changelog.html.erb +++ b/app/views/content/display/_changelog.html.erb @@ -5,7 +5,6 @@ changed_fields = AttributeField.where(id: changed_attributes.pluck(:attribute_field_id)).includes([:attribute_category]) %> -

@@ -72,10 +71,14 @@ <%= link_to(change_event.user.display_name, change_event.user, class: "#{User.text_color}") %> -
<%= time_ago_in_words change_event.created_at %> ago
+
+ <%= time_ago_in_words change_event.created_at %> ago + · + <%= change_event.created_at.strftime('%B %d, %H:%M %Z') %> +

-
+
<%= render partial: "content/changelog/field_change/#{related_field.field_type}", locals: { old_value: old_value, new_value: new_value } diff --git a/app/views/content/panels/_associations.html.erb b/app/views/content/panels/_associations.html.erb index d9b68636..3c2b17a6 100644 --- a/app/views/content/panels/_associations.html.erb +++ b/app/views/content/panels/_associations.html.erb @@ -2,10 +2,6 @@ TODO: everything here (probably) should move to the ContentSerializer so we don't have this heavy logic in a random partial %> -<% - relations = Rails.application.config.content_relations[content.class.name] - relations ||= [] -%>
<%= render partial: 'notice_dismissal/messages/07' %> @@ -29,37 +25,5 @@ locals: { value: link_codes, content: content } %> <% end %> - - <% if user_signed_in? %> -
- Notice: The newest Notebook.ai release is adding the ability to create your own link - fields, which includes a rather large migration of all existing link fields into a new linking system. - Links that haven't been migrated yet can be seen below this message; links on the new system appear above. -

- Thank you for your patience during this large rewrite! This notice will automatically disappear after the - migration has completed for everyone. -

- — Andrew -
- <% end %> - - <%# TODO: remove these after finishing link migration script %> - <% relations.each do |name, params| %> - <% - results = params[:related_class].where("#{params[:through_relation].downcase}_id": content.id) - .map { |content| content.send(params[:inverse_class].downcase) } - .select { |content| content && content.readable_by?(current_user || User.new) } - %> - <% next unless results.any? %> - -
- <%= params[:relation_text].to_s.titleize.downcase %> of -
- <%= - link_codes = results.map { |page| "#{page.page_type}-#{page.id}" } - render partial: "content/display/attribute_value/link", - locals: { value: link_codes, content: content } - %> - <% end %>
\ No newline at end of file diff --git a/app/views/data/index.html.erb b/app/views/data/index.html.erb index 5d291cce..88beecef 100644 --- a/app/views/data/index.html.erb +++ b/app/views/data/index.html.erb @@ -69,6 +69,20 @@ <% end %>
+
+ <%= link_to tags_path, class: 'black-text' do %> +
+
+ <%= PageTag.icon %> +
Tag management
+

+ Manage the tags you've used for your worldbuilding. +

+
+
+ <% end %> +
+
<%= link_to notebook_export_path, class: 'black-text' do %>
diff --git a/app/views/data/tags.html.erb b/app/views/data/tags.html.erb new file mode 100644 index 00000000..ee09258f --- /dev/null +++ b/app/views/data/tags.html.erb @@ -0,0 +1,82 @@ +<% + showed_any_tags = false +%> + +

Your Notebook.ai tags

+ + +<% if !showed_any_tags %> +
+ When you create tags for your pages, they'll appear here. Come back later when you've added some! +
+<% end %> \ No newline at end of file diff --git a/app/views/data/usage.html.erb b/app/views/data/usage.html.erb index 0082c62f..e76979cf 100644 --- a/app/views/data/usage.html.erb +++ b/app/views/data/usage.html.erb @@ -81,4 +81,4 @@
- \ No newline at end of file + diff --git a/app/views/layouts/_sidenav.html.erb b/app/views/layouts/_sidenav.html.erb index 6d07ff4a..9338dd49 100644 --- a/app/views/layouts/_sidenav.html.erb +++ b/app/views/layouts/_sidenav.html.erb @@ -17,8 +17,7 @@