Skip to content

Commit

Permalink
WIP UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Sep 20, 2024
1 parent a936d45 commit aabeedd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/controllers/projects/extracts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def show
return
end

@insights = Project::Insight.find_by(
project: @project, info_request: @info_request
)

@main_insight = @insights.output.find do |i|
i[:answers].values.any?(&:present?)
end

@value_set = Dataset::ValueSet.new
end

Expand Down
9 changes: 9 additions & 0 deletions app/views/projects/dataset/keys/_key.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<% value = f.object.values.find { |v| v.key.order == key.order } %>
<%= f.fields_for :values, value || Dataset::Value.new do |nested_form| %>
<%= render partial: "projects/dataset/keys/#{key.format}_key",
locals: { f: nested_form, key: key } %>
<%= nested_form.hidden_field :dataset_key_id, value: key.to_param %>
<% ai_value = @main_insight[:answers]["question#{nested_form.options[:child_index] + 1}"] %>
<%= content_tag :span, class: 'ai-insights', onclick: "fillAIValue(#{nested_form.options[:child_index]}, '#{ai_value}')" do %>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M12,22 C12,15.571428,15.571429,12,22,12 C15.571429,12,12,8.428571,12,2 C12,8.428571,8.428572,12,2,12 C8.428572,12,12,15.571428,12,22 Z" stroke-linejoin="round" style="stroke-width: 1.787002px;" stroke="currentColor" fill="none" />
<path d="M19.3,8 C19.3,5.878571,20.478572,4.7,22.6,4.7 C20.478572,4.7,19.3,3.521428,19.3,1.4 C19.3,3.521428,18.121429,4.7,16,4.7 C18.121429,4.7,19.3,5.878571,19.3,8 Z" stroke-linejoin="round" style="stroke-width: 0.958969px;" stroke="currentColor" fill="currentColor;" />
</svg>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/projects/dataset/keys/_numeric_key.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="dataset-key">
<%= f.label :value, key.title %>
<%= f.number_field :value %>
<%= f.text_field :value %>
</div>
20 changes: 20 additions & 0 deletions app/views/projects/extracts/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,25 @@
<%= render partial: 'form', locals: { project: project,
info_request: info_request,
value_set: value_set } %>

<details>
<summary>Debug: HUMAN</summary>
<%= debug Project::Export::InfoRequest.new(@project, @info_request).send(:extracted_values).pluck(:value) %>
</details>

<details>
<summary>Debug: AI</summary>
<%= debug @insights&.output %>
</details>

<script type="text/javascript">
function fillAIValue(index, value) {
const element = document.getElementById(`extract_values_attributes_${index}_value`);
if (element) {
element.value = value;
element.dispatchEvent(new Event('change', { bubbles: true }));
}
}
</script>
</div>
</div>

0 comments on commit aabeedd

Please sign in to comment.