Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Jul 26, 2019
1 parent 44bf6aa commit 1fad9cc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/admin/documents.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ActiveAdmin.register Document do
menu priority: 3, parent: 'Administration'
menu priority: 6

decorate_with DocumentDecorator

Expand Down
16 changes: 9 additions & 7 deletions app/javascript/controllers/litigation_side_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ export default class extends Controller {
}

_setDefaults() {
const selectedOption = this.connectedWithSelect.selectedOptions &&
this.connectedWithSelect.selectedOptions.length &&
this.connectedWithSelect.selectedOptions[0];

if (selectedOption) {
const entityType = selectedOption.value.split('-')[0];
if (this.connectedWithSelectedOption) {
const entityType = this.connectedWithSelectedOption.value.split('-')[0];
const partyType = ENTITY_TYPE_PARTY_TYPE_MAP[entityType];

if (partyType) {
$(this.partyTypeSelect).val(partyType);
$(this.partyTypeSelect).trigger('change');
}

this.nameInput.value = selectedOption.text;
this.nameInput.value = this.connectedWithSelectedOption.text;
}
}

get connectedWithSelect () {
return this.element.querySelector('select[id*="_connected_with"');
}

get connectedWithSelectedOption () {
return this.connectedWithSelect.selectedOptions &&
this.connectedWithSelect.selectedOptions.length &&
this.connectedWithSelect.selectedOptions[0];
}

get nameInput() {
return this.element.querySelector('input[id*="_name"');
}
Expand Down
3 changes: 2 additions & 1 deletion app/models/litigation_side.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def connected_with=(connected_with_string)
end

def self.available_connections
(Company.all + Location.all).map { |c| [c.name, "#{c.class}-#{c.id}"] }
(Company.all.select(:id, :name) + Location.all.select(:id, :name))
.map { |c| [c.name, "#{c.class}-#{c.id}"] }
end
end
7 changes: 3 additions & 4 deletions app/services/import_litigations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ def call

def import
import_each_with_logging(csv, FILEPATH) do |row|
l = Litigation.find_or_initialize_by(title: row[:title])
l.update!(litigation_attributes(row))
litigation = Litigation.find_or_initialize_by(title: row[:title])
litigation.update!(litigation_attributes(row))
get_litigation_sides(row).each do |side|
side.litigation_id = l.id
side.save!
side.update!(litigation_id: litigation.id)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/litigations/_side_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<% is_new_record = form.object.new_record? %>
<%= content_tag :div, class: "litigation-sides-fields nested-fields inline-fields", data: { controller: 'litigation-side', new_record: is_new_record } do %>
<%= content_tag :div, class: 'litigation-sides-fields nested-fields inline-fields', data: { controller: 'litigation-side', new_record: is_new_record } do %>
<%= form.input :side_type, as: :select, collection: array_to_select_collection(LitigationSide::SIDE_TYPES) %>
<%= form.input :connected_with, as: :select, collection: LitigationSide.available_connections %>
<%= form.input :name %>
<%= form.input :party_type, as: :select, collection: array_to_select_collection(LitigationSide::PARTY_TYPES) %>

<li class="input">
<%= button_tag "Remove", type: 'button', class: 'button button--raised button--red', data: { action: "click->nested-list#removeRecord" } %>
<%= button_tag 'Remove', type: 'button', class: 'button button--raised button--red', data: { action: 'click->nested-list#removeRecord' } %>
</li>
<%= form.hidden_field :_destroy %>
<% end %>
2 changes: 1 addition & 1 deletion config/initializers/active_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
menu.add label: 'Laws', priority: 2
menu.add label: 'TPI', priority: 3
menu.add label: 'Tags', priority: 4
menu.add label: 'Administration', priority: 6
menu.add label: 'Administration', priority: 7
end
end
#
Expand Down

0 comments on commit 1fad9cc

Please sign in to comment.