-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TOP-251 add keys to custom fields and service meta
- Loading branch information
Showing
15 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,7 @@ def service_params | |
], | ||
meta_attributes: [ | ||
:id, | ||
:label, | ||
:key, | ||
:value | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class API::V1::CustomFieldsController < ApplicationController | ||
skip_before_action :authenticate_user! | ||
|
||
def index | ||
render json: json_tree(CustomFieldSection.api_public.includes(:custom_fields)).to_json | ||
end | ||
|
||
private | ||
|
||
def json_tree(custom_field_sections) | ||
custom_field_sections.map do |section| | ||
{ | ||
id: section.id, | ||
name: section.name, | ||
hint: section.hint, | ||
custom_fields: section.custom_fields.map do |field| | ||
field_hash = { | ||
id: field.id, | ||
label: field.label, | ||
key: field.key, | ||
hint: field.hint, | ||
field_type: field.field_type | ||
} | ||
field_hash[:options] = process_options(field.options) if field.field_type == 'select' | ||
field_hash | ||
end | ||
} | ||
end | ||
end | ||
|
||
def process_options(options_string) | ||
options_string.split(',').map.with_index(1) do |option, index| | ||
{ | ||
value: option.strip, | ||
# key: option.strip.parameterize | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,7 @@ def service_params | |
meta_attributes: [ | ||
:id, | ||
:key, | ||
:label, | ||
:value | ||
] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
class ServiceMetaSerializer < ActiveModel::Serializer | ||
attribute :label | ||
attribute :key | ||
attribute :value | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class AddCustomFieldLabel < ActiveRecord::Migration[6.0] | ||
def change | ||
# Add new label column | ||
add_column :custom_fields, :label, :string | ||
|
||
# Copy data from key to label (only on up migration) | ||
reversible do |dir| | ||
dir.up do | ||
CustomField.reset_column_information | ||
CustomField.update_all('label = key') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters