mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
start implementing stopgap field type between new and old link types
This commit is contained in:
parent
c0b39cf004
commit
dca034ca9f
@ -66,7 +66,8 @@ class ContentSerializer
|
||||
hidden: !!field.hidden,
|
||||
position: field.position,
|
||||
old_column_source: field.old_column_source,
|
||||
value: value_for(field, content)
|
||||
value: value_for(field, content),
|
||||
options: field.field_options
|
||||
}
|
||||
}.sort do |a, b|
|
||||
if a[:position] && b[:position]
|
||||
@ -111,6 +112,7 @@ class ContentSerializer
|
||||
def value_for(attribute_field, content)
|
||||
case attribute_field.field_type
|
||||
when 'link'
|
||||
# TODO: use attribute_values but fall back on sending old_column if blank / not migrated
|
||||
self.raw_model.send(attribute_field.old_column_source)
|
||||
|
||||
when 'tags'
|
||||
|
||||
@ -10,11 +10,15 @@
|
||||
|
||||
<div class="card-content">
|
||||
<% if category[:name] == 'gallery' %>
|
||||
<%= render partial: 'content/form/gallery/panel', locals: { f: f, content: content } %>
|
||||
<%= form_for raw_model do |f| %>
|
||||
<%= render partial: 'content/form/gallery/panel', locals: { f: f, content: content } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if category[:name] == 'contributors' %>
|
||||
<%= render partial: 'content/form/contributors', locals: { f: f, content: content } %>
|
||||
<%= form_for raw_model do |f| %>
|
||||
<%= render partial: 'content/form/contributors', locals: { f: f, content: content } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% category[:fields].each do |field| %>
|
||||
@ -24,7 +28,7 @@
|
||||
<div class="panel-field autosave-field">
|
||||
<% if field[:type] == 'link' %>
|
||||
<%=
|
||||
render partial: 'content/form/field_types/legacy_link', locals: {
|
||||
render partial: 'content/form/field_types/migration_link', locals: {
|
||||
f: f,
|
||||
attribute: field[:old_column_source],
|
||||
field: field,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
<%= raise field.inspect %>
|
||||
<div class="content-field link">
|
||||
<div class="hoverable">
|
||||
<div>
|
||||
|
||||
44
app/views/content/form/field_types/_migration_link.html.erb
Normal file
44
app/views/content/form/field_types/_migration_link.html.erb
Normal file
@ -0,0 +1,44 @@
|
||||
<%
|
||||
# Fall back on legacy link klass if we don't have any linkable types set on this link field
|
||||
linkable_types = field.dig(:options, :linkable_types) || [page.send(attribute).klass]
|
||||
%>
|
||||
|
||||
<div class="content-field link">
|
||||
<div>
|
||||
<i class="material-icons left grey-text">link</i>
|
||||
<%= f.label attribute, I18n.translate(
|
||||
"attributes.#{page.class.name.downcase}.#{attribute}",
|
||||
scope: :activerecord,
|
||||
default: label.humanize.capitalize
|
||||
) %>
|
||||
</div>
|
||||
|
||||
<div class="input-field">
|
||||
<select multiple>
|
||||
<% linkable_types.each do |page_type| %>
|
||||
<optgroup label="<%= page_type.name.pluralize %>">
|
||||
<% @current_user_content.fetch(page_type.name, []).each do |page| %>
|
||||
<option value="<%= page.id %>"
|
||||
data-icon="<%= asset_path page.random_image_including_private(format: :thumb) %>"
|
||||
<%= 'selected' if field[:value].include?(page) %>
|
||||
>
|
||||
<%= page.name %>
|
||||
</option>
|
||||
<% end %>
|
||||
</optgroup>
|
||||
<% end %>
|
||||
</select>
|
||||
<div>
|
||||
<small>
|
||||
<i class="material-icons left">link</i>
|
||||
<% linkable_types.each do |page_type| %>
|
||||
<i class="material-icons <%= page_type.color %>-text tooltipped" data-tooltip="Link <%= page_type.name.pluralize.downcase %>">
|
||||
<%= page_type.icon %>
|
||||
</i>
|
||||
<% end %>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
(<%= relation %>)
|
||||
</div>
|
||||
@ -0,0 +1,5 @@
|
||||
class AddFieldOptionsToAttributeFields < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :attribute_fields, :field_options, :json
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,6 @@
|
||||
class AddLinkMigrationFlagToAttributeFields < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :attribute_fields, :migrated_from_legacy, :boolean
|
||||
change_column :attribute_fields, :migrated_from_legacy, :type, default: false
|
||||
end
|
||||
end
|
||||
36
db/schema.rb
36
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_03_08_200757) do
|
||||
ActiveRecord::Schema.define(version: 2021_03_20_230154) do
|
||||
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
@ -120,38 +120,8 @@ ActiveRecord::Schema.define(version: 2021_03_08_200757) do
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "attribute_fields", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "attribute_category_id", null: false
|
||||
t.string "name", null: false
|
||||
t.string "label", null: false
|
||||
t.string "field_type", null: false
|
||||
t.text "description"
|
||||
t.string "privacy", default: "public", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "hidden", default: false
|
||||
t.datetime "deleted_at"
|
||||
t.string "old_column_source"
|
||||
t.integer "position"
|
||||
t.index ["attribute_category_id", "deleted_at"], name: "index_attribute_fields_on_attribute_category_id_and_deleted_at"
|
||||
t.index ["attribute_category_id", "label", "old_column_source", "field_type"], name: "attribute_fields_aci_label_ocs_ft"
|
||||
t.index ["attribute_category_id", "label", "old_column_source", "user_id", "field_type"], name: "attribute_fields_aci_label_ocs_ui_ft"
|
||||
t.index ["attribute_category_id", "old_column_source", "user_id", "field_type"], name: "attribute_fields_aci_ocs_ui_ft"
|
||||
t.index ["deleted_at", "attribute_category_id"], name: "deleted_at__attribute_category_id"
|
||||
t.index ["deleted_at", "name"], name: "index_attribute_fields_on_deleted_at_and_name"
|
||||
t.index ["deleted_at", "position"], name: "index_attribute_fields_on_deleted_at_and_position"
|
||||
t.index ["deleted_at", "user_id", "attribute_category_id", "label", "hidden"], name: "attribute_fields_da_ui_aci_l_h"
|
||||
t.index ["user_id", "attribute_category_id", "field_type", "deleted_at"], name: "special_field_type_index"
|
||||
t.index ["user_id", "attribute_category_id", "label", "hidden", "deleted_at"], name: "field_lookup_by_label_index"
|
||||
t.index ["user_id", "attribute_category_id", "label", "old_column_source", "field_type", "deleted_at"], name: "temporary_migration_lookup_with_deleted_index"
|
||||
t.index ["user_id", "attribute_category_id", "label", "old_column_source", "field_type"], name: "temporary_migration_lookup_index"
|
||||
t.index ["user_id", "attribute_category_id"], name: "index_attribute_fields_on_user_id_and_attribute_category_id"
|
||||
t.index ["user_id", "field_type"], name: "index_attribute_fields_on_user_id_and_field_type"
|
||||
t.index ["user_id", "name"], name: "index_attribute_fields_on_user_id_and_name"
|
||||
t.index ["user_id", "old_column_source"], name: "index_attribute_fields_on_user_id_and_old_column_source"
|
||||
t.index ["user_id"], name: "index_attribute_fields_on_user_id"
|
||||
end
|
||||
# Could not dump table "attribute_fields" because of following StandardError
|
||||
# Unknown type 'type' for column 'migrated_from_legacy'
|
||||
|
||||
create_table "attributes", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user