diff --git a/app/assets/javascripts/content.js b/app/assets/javascripts/content.js index 0fbf7f38..1cec4a92 100644 --- a/app/assets/javascripts/content.js +++ b/app/assets/javascripts/content.js @@ -100,5 +100,22 @@ $(document).ready(function () { }); }); + $('.js-load-page-name').each(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() { + console.log("OMG couldn't load that page: " + [tag.data('klass'), tag.data('id')]); + // set "unknown page" + }); + + console.log('loading page name'); + console.log(tag.data('klass') + '-' + tag.data('id')); + }); + }); diff --git a/app/controllers/api/internal/api_controller.rb b/app/controllers/api/internal/api_controller.rb new file mode 100644 index 00000000..3cb6c428 --- /dev/null +++ b/app/controllers/api/internal/api_controller.rb @@ -0,0 +1,26 @@ +module Api + module Internal + class ApiController < ApplicationController + before_action :sanitize_content_type + before_action :set_content + + def name_lookup + render body: @content.name, content_type: 'text/plain' + end + + private + + def sanitize_content_type + unless Rails.application.config.content_types[:all].map(&:name).include?(params[:page_type]) + raise "Invalid page type: #{params[:page_type]}" + end + + @sanitized_content_type = params[:page_type].constantize + end + + def set_content + @content = @sanitized_content_type.find_by(id: params[:page_id]) + end + end + end +end \ No newline at end of file diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index fe60723c..e486cf81 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -82,13 +82,6 @@ class ContentController < ApplicationController @serialized_content = ContentSerializer.new(@content) if (current_user || User.new).can_read?(@content) - if user_signed_in? - @navbar_actions.insert(1, { - label: @content.name, - href: main_app.polymorphic_path(@content) - }) - end - if user_signed_in? if @content.updated_at > 30.minutes.ago Mixpanel::Tracker.new(Rails.application.config.mixpanel_token).track(current_user.id, 'viewed content', { diff --git a/app/views/content/display/_category_panel.html.erb b/app/views/content/display/_category_panel.html.erb index 33a03657..0bbb7cf3 100644 --- a/app/views/content/display/_category_panel.html.erb +++ b/app/views/content/display/_category_panel.html.erb @@ -1,6 +1,6 @@