Skip to content

CE-738: Refactor Tree Field Type #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/cells/plugins/core/checkbox/checkbox.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
%label.mdl-checkbox.mdl-js-checkbox.mdl-js-ripple-effect{ for: @options[:node]["id"] }
= @options[:form].check_box "data[values][#{@options[:node]['id']}]", { checked: value, class: 'mdl-checkbox__input', id: @options[:node]["id"] }, 1, nil
= @options[:form].label :data, display_lineage, class: 'mdl-checkbox__label'
%label.mdl-checkbox.mdl-js-checkbox.mdl-js-ripple-effect{ for: @options[:node_key], **checkbox_attributes }
= @options[:form].check_box checkbox_input_value, { checked: value, class: 'mdl-checkbox__input', id: @options[:node_key] }, 1, nil
= @options[:form].label :data, node['name'], class: 'mdl-checkbox__label'

- if @options[:node]["children"].any?
- @options[:node]["children"].each do |child|
= cell(Plugins::Core::CheckboxCell, nil, form: @options[:form], node: child, child: child_identifier, data: @options[:data]).(:checkbox)
- if @options[:tree_fields][@options[:node_key]]['children'].any?
.nested-checkbox-group{ id: "nested_#{@options[:node_key]}" }
- @options[:tree_fields][@options[:node_key]]['children'].each do |checkbox_key|
= @options[:form].hidden_field :field_id, value: @options[:field_id]
= cell(Plugins::Core::CheckboxCell, nil, field_id: @options[:field_id], form: @options[:form], node_key: checkbox_key, tree_fields: @options[:tree_fields], data: @options[:data]).(:checkbox)
18 changes: 11 additions & 7 deletions app/cells/plugins/core/checkbox_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ def value
if @options[:data].blank?
false
else
@options[:data]["values"].include?(node_id) ? true : false
@options[:data]["values"].include?(@options[:node_key])
end
end

def node_id
@options[:node]['id'].to_s
def checkbox_attributes
if @options[:tree_fields][@options[:node_key]]['children'].any?
{ onclick: "TreeBranchClicked(#{ '"#nested_' + @options[:node_key] + '"' }, this)" }
else
{}
end
end

def child_identifier
@options[:child].to_s + " " + "->"
def checkbox_input_value
"data[values][#{@options[:node_key]}]"
end

def display_lineage
@options[:child].to_s + " " + @options[:node]["node"]["name"]
def node
@node ||= @options[:tree_fields][@options[:node_key]]
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/cells/plugins/core/tree/checkboxes.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
= render_label
= render_tooltip unless @options[:tooltip].nil?

- @options[:metadata]["data"]["tree_array"].each do |node|
- @options[:metadata]['head'].each do |checkbox_key|
= render_field_id
= cell(Plugins::Core::CheckboxCell, nil, form: @options[:form], node: node, data: data).(:checkbox)
= cell(Plugins::Core::CheckboxCell, nil, field_id: field.id , form: @options[:form], node_key: checkbox_key, tree_fields: tree_fields, data: data).(:checkbox)
8 changes: 6 additions & 2 deletions app/cells/plugins/core/tree_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ def value
data&.[]('values') || @options[:default_value]
end

def tree_fields
@tree_fields ||= @options[:metadata]['tree_fields']
end

def render_select
@options[:form].select 'data[values]', metadata_values, {selected: value}
end

def metadata_values
values = [["-- Select an Option --", nil]]

@options[:metadata]["data"]["tree_array"].map do |value|
values << [value["node"]["name"], value["id"]]
@options[:metadata]['data'].keys.map do |field_key|
values << [@options[:metadata]['data'][field_key]['name'], field_key]
end

values
Expand Down
6 changes: 4 additions & 2 deletions app/transactions/get_field_tree_list_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def init(input)
end

def process(input)
tree_array = input[:field].metadata['allowed_values']['data']['tree_array']
tree_values = input[:content_item].field_items.find {|field_item| field_item.field_id == input[:field].id}.data['values']
tree_array = input[:field].metadata['allowed_values']

tree_values = input[:content_item].field_items.find {|field_item| field_item.field_id == input[:field].id}.data['values']
# This will break
tree_list = tree_values.map {|value| tree_array.find {|node| node['id'] == value.to_i}['node']['name']}.join(',')

Right(tree_list)
end
end