diff --git a/app/controllers/admin/services_controller.rb b/app/controllers/admin/services_controller.rb index c220a16e..194089b6 100644 --- a/app/controllers/admin/services_controller.rb +++ b/app/controllers/admin/services_controller.rb @@ -192,6 +192,7 @@ def service_params ], meta_attributes: [ :id, + :label, :key, :value ] diff --git a/app/controllers/api/v1/custom_fields_controller.rb b/app/controllers/api/v1/custom_fields_controller.rb index cef1a259..11c83a0f 100644 --- a/app/controllers/api/v1/custom_fields_controller.rb +++ b/app/controllers/api/v1/custom_fields_controller.rb @@ -16,7 +16,7 @@ def json_tree(custom_field_sections) custom_fields: section.custom_fields.map do |field| field_hash = { id: field.id, - current_reference: "#{section.name.parameterize}--#{field.key.parameterize}", + label: field.label, key: field.key, hint: field.hint, field_type: field.field_type diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 74c4cfc4..bd71b817 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -158,6 +158,7 @@ def service_params meta_attributes: [ :id, :key, + :label, :value ] ) diff --git a/app/models/service_meta.rb b/app/models/service_meta.rb index ec884597..96175f36 100644 --- a/app/models/service_meta.rb +++ b/app/models/service_meta.rb @@ -1,5 +1,5 @@ class ServiceMeta < ApplicationRecord belongs_to :service - validates :key, presence: true - validates_uniqueness_of :key, scope: :service_id + validates :label, presence: true + validates_uniqueness_of :label, scope: :service_id end diff --git a/app/serializers/service_meta_serializer.rb b/app/serializers/service_meta_serializer.rb index c6f03512..b70b20a0 100644 --- a/app/serializers/service_meta_serializer.rb +++ b/app/serializers/service_meta_serializer.rb @@ -1,5 +1,6 @@ class ServiceMetaSerializer < ActiveModel::Serializer + attribute :label attribute :key attribute :value end \ No newline at end of file diff --git a/app/views/admin/services/editors/_custom-fields.html.erb b/app/views/admin/services/editors/_custom-fields.html.erb index e7a12746..d1367a83 100644 --- a/app/views/admin/services/editors/_custom-fields.html.erb +++ b/app/views/admin/services/editors/_custom-fields.html.erb @@ -8,20 +8,21 @@ <% end %> <% section.custom_fields.each do |field| %> - <% meta = s.object.meta.find_or_initialize_by(key: field.key) %> + <% meta = s.object.meta.find_or_initialize_by(label: field.label, key: field.key) %> <%= s.fields_for :meta, meta do |c| %> + <%= c.hidden_field :label %> <%= c.hidden_field :key %> <% if field.field_type === "checkbox" %>
<%= field.hint %>
<% end %> diff --git a/db/migrate/20241111181710_add_service_meta_label.rb b/db/migrate/20241111181710_add_service_meta_label.rb new file mode 100644 index 00000000..7eab7033 --- /dev/null +++ b/db/migrate/20241111181710_add_service_meta_label.rb @@ -0,0 +1,14 @@ +class AddServiceMetaLabel < ActiveRecord::Migration[6.0] + def change + # Add new label column + add_column :service_meta, :label, :string + + # Copy data from key to label (only on up migration) + reversible do |dir| + dir.up do + ServiceMeta.reset_column_information + ServiceMeta.update_all('label = key') + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7d94b76b..49336f1a 100644 --- a/db/schema.rb +++ b/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: 2024_11_11_163850) do +ActiveRecord::Schema.define(version: 2024_11_11_181710) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -319,6 +319,7 @@ t.string "value" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "label" t.index ["service_id"], name: "index_service_meta_on_service_id" end