mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
WIP adding field options to attribute editor
This commit is contained in:
parent
dca034ca9f
commit
ecae4e7807
@ -2,7 +2,7 @@ $(document).ready(function() {
|
||||
$('.panel-field.autosave-field').click(function () {
|
||||
console.log('autosaving');
|
||||
var content_form = $(this).closest('form');
|
||||
content_form.submit();
|
||||
// content_form.submit();
|
||||
});
|
||||
|
||||
// To ensure all fields get unblurred (and therefore autosaved) upon navigation,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
# Controller for the Attribute model
|
||||
class AttributeFieldsController < ContentController
|
||||
def create
|
||||
initialize_object.save!
|
||||
@ -18,6 +17,50 @@ class AttributeFieldsController < ContentController
|
||||
related_category.destroy if related_category.attribute_fields.empty?
|
||||
end
|
||||
|
||||
def update
|
||||
content_type = AttributeField
|
||||
# todo rework from here
|
||||
|
||||
content_type = content_type_from_controller(self.class)
|
||||
@content = content_type.with_deleted.find(params[:id])
|
||||
|
||||
unless @content.updatable_by?(current_user)
|
||||
flash[:notice] = "You don't have permission to edit that!"
|
||||
return redirect_back fallback_location: @content
|
||||
end
|
||||
|
||||
Mixpanel::Tracker.new(Rails.application.config.mixpanel_token).track(current_user.id, 'updated content', {
|
||||
'content_type': content_type.name
|
||||
}) if Rails.env.production?
|
||||
|
||||
if params.key?('image_uploads')
|
||||
upload_files(params['image_uploads'], content_type.name, @content.id)
|
||||
end
|
||||
|
||||
if @content.is_a?(Universe) && params.key?('contributors') && @content.user == current_user
|
||||
params[:contributors][:email].reject(&:blank?).each do |email|
|
||||
ContributorService.invite_contributor_to_universe(universe: @content, email: email.downcase)
|
||||
end
|
||||
end
|
||||
|
||||
update_page_tags if @content.respond_to?(:page_tags)
|
||||
|
||||
if @content.user == current_user
|
||||
# todo this needs some extra validation probably to ensure each attribute is one associated with this page
|
||||
update_success = @content.reload.update(content_params)
|
||||
else
|
||||
# Exclude fields only the real owner can edit
|
||||
#todo move field list somewhere when it grows
|
||||
update_success = @content.update(content_params.except(:universe_id))
|
||||
end
|
||||
|
||||
if update_success
|
||||
successful_response(@content, t(:update_success, model_name: @content.try(:name).presence || humanized_model_name))
|
||||
else
|
||||
failed_response('edit', :unprocessable_entity, "Unable to save page. Error code: " + @content.errors.to_json)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def initialize_object
|
||||
@ -78,7 +121,8 @@ class AttributeFieldsController < ContentController
|
||||
:label, :description,
|
||||
:entity_type,
|
||||
:attribute_category_id,
|
||||
:hidden
|
||||
:hidden,
|
||||
:field_options
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@ -256,7 +256,7 @@ class ContentController < ApplicationController
|
||||
end
|
||||
|
||||
cache_params = {}
|
||||
cache_params[:name] = @content.name_field_value unless [AttributeCategory, AttributeField, Attribute].include?(@content.class)
|
||||
cache_params[:name] = @content.name_field_value unless [AttributeCategory, Attribute].include?(@content.class)
|
||||
cache_params[:universe] = @content.universe_field_value if self.respond_to?(:universe_id)
|
||||
@content.update(cache_params) if cache_params.any? && update_success
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<%= content_for :full_width_page_header do %>
|
||||
<%= render partial: 'content/components/parallax_header', locals: { content_type: @content_type, content_class: @content_type_class } %>
|
||||
<%# render partial: 'content/components/parallax_header', locals: { content_type: @content_type, content_class: @content_type_class } %>
|
||||
<% end %>
|
||||
|
||||
<!--
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="grey-text text-darken-1">
|
||||
<strong>New:</strong> Notebook.ai can now suggest additional fields for this category.
|
||||
Notebook.ai can suggest additional fields for this category.
|
||||
</div>
|
||||
<p class="suggest-fields-container">
|
||||
</p>
|
||||
|
||||
@ -18,6 +18,14 @@
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%=
|
||||
render(
|
||||
partial: 'content/attributes/fields/options/' + field.field_type,
|
||||
locals: { field: field }
|
||||
) if lookup_context.template_exists?(field.field_type, 'content/attributes/fields/options', true)
|
||||
%>
|
||||
|
||||
<% if false %>
|
||||
<div class="row">
|
||||
<div class="col s12 center grey-text uppercase">
|
||||
@ -53,6 +61,7 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="row">
|
||||
<div class="col s12 center grey-text uppercase">
|
||||
more actions
|
||||
|
||||
@ -1,22 +1 @@
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<% klass = @content_type_class.new.send(field.old_column_source).klass %>
|
||||
<% klass_name = klass.name %>
|
||||
|
||||
<div class="card-panel <%= klass.color %>">
|
||||
<div class="valign-wrapper white black-text">
|
||||
<i class="material-icons" style="margin: 0 10px;">link</i>
|
||||
Links to
|
||||
<%=
|
||||
link_to(
|
||||
klass_name,
|
||||
attribute_customization_path(content_type: klass_name.downcase),
|
||||
style: 'padding: 0.3em',
|
||||
class: "#{klass.color}-text"
|
||||
)
|
||||
%>
|
||||
pages
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- this partial intentionally left blank -->
|
||||
21
app/views/content/attributes/fields/options/_link.html.erb
Normal file
21
app/views/content/attributes/fields/options/_link.html.erb
Normal file
@ -0,0 +1,21 @@
|
||||
<div class="row">
|
||||
<div class="col s12 center grey-text uppercase">
|
||||
Field options
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<p>
|
||||
Customize which pages this field can link to with the dropdown below.
|
||||
</p>
|
||||
</div>
|
||||
<div class="input-field col s12">
|
||||
<%= form_for field do |f| %>
|
||||
<label>Linkable page types</label>
|
||||
<select multiple name="attribute_field[field_options][linkable_types]" prompt="Please select at least one page type for this field to link to">
|
||||
<%= options_for_select(Rails.application.config.content_types[:all].map { |klass| [klass.name.pluralize, klass.name] }) %>
|
||||
</select>
|
||||
<%= f.submit 'Save link changes' %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@ -1,5 +1,6 @@
|
||||
class AddFieldOptionsToAttributeFields < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :attribute_fields, :field_options, :json
|
||||
change_column :attribute_fields, :field_options, :type, default: "{}"
|
||||
end
|
||||
end
|
||||
|
||||
@ -121,7 +121,7 @@ ActiveRecord::Schema.define(version: 2021_03_20_230154) do
|
||||
end
|
||||
|
||||
# Could not dump table "attribute_fields" because of following StandardError
|
||||
# Unknown type 'type' for column 'migrated_from_legacy'
|
||||
# Unknown type '' for column 'field_options'
|
||||
|
||||
create_table "attributes", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user