mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
hook up content#show again, add internal api for fetching page names on pageload
This commit is contained in:
parent
838e8acb49
commit
55affe50c3
@ -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'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
26
app/controllers/api/internal/api_controller.rb
Normal file
26
app/controllers/api/internal/api_controller.rb
Normal file
@ -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
|
||||
@ -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', {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<div id="<%= category[:name].gsub("'", '') %>_panel" class="row panel">
|
||||
<div class="row">
|
||||
<% category[:fields].select { |field| !field[:hidden] }.each do |serialized_field| %>
|
||||
<% category[:fields].reject { |field| field[:hidden] }.each do |serialized_field| %>
|
||||
<% if serialized_field[:label].start_with?("Private") %>
|
||||
<% next unless user_signed_in? && (
|
||||
(content.raw_model.is_a?(Universe) && content.user == current_user) ||
|
||||
@ -21,14 +21,6 @@
|
||||
when 'link'
|
||||
serialized_field[:value]
|
||||
|
||||
# Leaving this old code in just in case there's an issue with links after release; good to delete after a successful deploy + time
|
||||
# if serialized_field[:old_column_source].present? && content.raw_model.respond_to?(serialized_field[:old_column_source].to_sym)
|
||||
# serialized_field[:value]
|
||||
# else
|
||||
# # todo uhhhh is this just a safety guard or are there actual cases of bad data triggering here?
|
||||
# nil
|
||||
# end
|
||||
|
||||
when 'tags'
|
||||
content.page_tags
|
||||
|
||||
@ -36,7 +28,10 @@
|
||||
raise "unknown field type = " + serialized_field[:type].inspect
|
||||
end
|
||||
%>
|
||||
<% next if value.blank? %>
|
||||
<%
|
||||
# Don't show fields with a blank value
|
||||
next if value.blank?
|
||||
%>
|
||||
|
||||
<div class="col s12 m10 offset-m1 field-value">
|
||||
<div class="grey-text uppercase">
|
||||
@ -51,7 +46,7 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<%=
|
||||
<%=
|
||||
render partial: "content/display/attribute_value/#{serialized_field[:type]}",
|
||||
locals: { value: value, content: content }
|
||||
%>
|
||||
|
||||
@ -1,13 +1,27 @@
|
||||
<% value.each do |li| %>
|
||||
<div class="chip">
|
||||
<%= link_to li do %>
|
||||
<span class="<%= li.class.color %>-text">
|
||||
|
||||
|
||||
<% value.each do |link_code| %>
|
||||
<%
|
||||
klass, id = link_code.split('-')
|
||||
%>
|
||||
<div class="chip js-load-page-name" data-klass="<%= klass %>" data-id="<%= id %>">
|
||||
<%= link_to content_class_from_name(klass) do %>
|
||||
<span class="<%= content_class_from_name(klass).color %>-text">
|
||||
<i class="material-icons left">
|
||||
<%= li.class.icon %>
|
||||
<%= content_class_from_name(klass).icon %>
|
||||
</i>
|
||||
</span>
|
||||
<%= li.name_field_value %>
|
||||
<span class="name-container">
|
||||
<%= id %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<br/><br/>
|
||||
<br/><br/>
|
||||
|
||||
<%#
|
||||
simple_format ContentFormatterService.show(
|
||||
text: value.map { |link_code| "[[#{link_code}]]"}.join("\n"),
|
||||
viewing_user: current_user
|
||||
)
|
||||
%>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<%# Treat universe values as if they're just link fields %>
|
||||
<%=
|
||||
render partial: "content/display/attribute_value/link",
|
||||
locals: { value: value, content: content }
|
||||
locals: { value: value.map { |universe| "Universe-#{universe.id}" }, content: content }
|
||||
%>
|
||||
@ -38,7 +38,7 @@
|
||||
<li class="collection-item">
|
||||
<%= link_to send("#{raw_model.class.name.downcase.pluralize}_user_path", { id: raw_model.user_id }) do %>
|
||||
<i class="material-icons left"><%= raw_model.class.icon %></i>
|
||||
<%= raw_model.class.name.pluralize %> by <%= editing ? current_user.display_name : @user.display_name %>
|
||||
<%= raw_model.class.name.pluralize %> by <%= editing ? current_user.display_name : raw_model.user.display_name %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
@ -303,6 +303,11 @@ Rails.application.routes.draw do
|
||||
get '/references', to: 'api_docs#references'
|
||||
end
|
||||
|
||||
# API requests we don't want to officially make public -- free to break!
|
||||
namespace :internal do
|
||||
get '/:page_type/:page_id/name', to: 'api#name_lookup'
|
||||
end
|
||||
|
||||
namespace :v1 do
|
||||
scope '/categories' do
|
||||
get '/suggest/:entity_type', to: 'attribute_categories#suggest'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user