mirror of
https://github.com/we-promise/sure.git
synced 2026-04-08 14:54:49 +00:00
* Implement API v1 Imports controller - Add Api::V1::ImportsController with index, show, and create actions - Add Jbuilder views for index and show - Add integration tests - Implement row generation logic in create action - Update routes * Validate import account belongs to family - Add validation to Import model to ensure account belongs to the same family - Add regression test case in Api::V1::ImportsControllerTest * updating docs to be more detailed * Rescue StandardError instead of bare rescue in ImportsController * Optimize Imports API and fix documentation - Implement rows_count counter cache for Imports - Preload rows in Api::V1::ImportsController#show - Update documentation to show correct OAuth scopes * Fix formatting in ImportsControllerTest * Permit all import parameters and fix unknown attribute error * Restore API routes for auth, chats, and messages * removing pr summary * Fix trailing whitespace and configured? test failure - Update Import#configured? to use rows_count for performance and consistency - Mock rows_count in TransactionImportTest - Fix trailing whitespace in migration * Harden security and fix mass assignment in ImportsController - Handle type and account_id explicitly in create action - Rename import_params to import_config_params for clarity - Validate type against Import::TYPES * Fix MintImport rows_count update and migration whitespace - Update MintImport#generate_rows_from_csv to update rows_count counter cache - Fix trailing whitespace and final newline in AddRowsCountToImports migration * Implement full-screen Drag and Drop CSV import on Transactions page - Add DragAndDropImport Stimulus controller listening on document - Add full-screen overlay with icon and text to Transactions index - Update ImportsController to handle direct file uploads via create action - Add system test for drag and drop functionality * Implement Drag and Drop CSV upload on Import Upload page - Add drag-and-drop-import controller to import/uploads/show - Add full-screen overlay to import/uploads/show - Annotate upload form and input with drag-and-drop targets - Add PR_SUMMARY.md * removing pr summary * Add file validation to ImportsController - Validate file size (max 10MB) and MIME type in create action - Prevent memory exhaustion and invalid file processing - Defined MAX_CSV_SIZE and ALLOWED_MIME_TYPES in Import model * Refactor dragLeave logic with counter pattern to prevent flickering * Extract shared drag-and-drop overlay partial - Create app/views/imports/_drag_drop_overlay.html.erb - Update transactions/index and import/uploads/show to use the partial - Reduce code duplication in views * Update Brakeman and harden ImportsController security - Update brakeman to 7.1.2 - Explicitly handle type assignment in ImportsController#create to avoid mass assignment - Remove :type from permitted import parameters * Fix trailing whitespace in DragAndDropImportTest * Don't commit LLM comments as file * FIX add api validation --------- Co-authored-by: Carlos Adames <cj@Carloss-MacBook-Air.local> Co-authored-by: Juan José Mata <jjmata@jjmata.com> Co-authored-by: sokie <sokysrm@gmail.com>
81 lines
4.0 KiB
Plaintext
81 lines
4.0 KiB
Plaintext
<%= content_for :header_nav do %>
|
|
<%= render "imports/nav", import: @import %>
|
|
<% end %>
|
|
|
|
<%= content_for :previous_path, imports_path %>
|
|
|
|
<div class="space-y-4" data-controller="drag-and-drop-import">
|
|
<!-- Overlay -->
|
|
<%= render "imports/drag_drop_overlay", title: "Drop CSV to upload", subtitle: "Your file will be uploaded automatically" %>
|
|
|
|
<div class="space-y-4 mx-auto max-w-md">
|
|
<div class="text-center space-y-2">
|
|
<h1 class="text-3xl text-primary font-medium"><%= t(".title") %></h1>
|
|
<p class="text-secondary text-sm"><%= t(".description") %></p>
|
|
</div>
|
|
|
|
<%= render DS::Tabs.new(active_tab: params[:tab] || "csv-upload", url_param_key: "tab", testid: "import-tabs") do |tabs| %>
|
|
<% tabs.with_nav do |nav| %>
|
|
<% nav.with_btn(id: "csv-upload", label: "Upload CSV") %>
|
|
<% nav.with_btn(id: "csv-paste", label: "Copy & Paste") %>
|
|
<% end %>
|
|
|
|
<% tabs.with_panel(tab_id: "csv-upload") do %>
|
|
<%= styled_form_with model: @import, scope: :import, url: import_upload_path(@import), multipart: true, class: "space-y-2", data: { drag_and_drop_import_target: "form" } do |form| %>
|
|
<%= form.select :col_sep, Import::SEPARATORS, label: true %>
|
|
|
|
<% if @import.type == "TransactionImport" || @import.type == "TradeImport" %>
|
|
<%= form.select :account_id, @import.family.accounts.visible.pluck(:name, :id), { label: "Account (optional)", include_blank: "Multi-account import", selected: @import.account_id } %>
|
|
<% end %>
|
|
|
|
<div class="flex flex-col items-center justify-center w-full h-64 border border-secondary border-dashed rounded-xl cursor-pointer" data-controller="file-upload" data-action="click->file-upload#triggerFileInput" data-file-upload-target="uploadArea">
|
|
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
|
<div data-file-upload-target="uploadText" class="flex flex-col items-center">
|
|
<%= icon("plus", size: "lg", class: "mb-4 mx-auto") %>
|
|
<p class="mb-2 text-md text-gray text-center">
|
|
<span class="font-medium text-primary">Browse</span> to add your CSV file here
|
|
</p>
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-4 items-center hidden mb-2" data-file-upload-target="fileName">
|
|
<span class="text-primary">
|
|
<%= icon("file-text", size: "lg", color: "current") %>
|
|
</span>
|
|
<p class="text-md font-medium text-primary"></p>
|
|
</div>
|
|
|
|
<%= form.file_field :csv_file, class: "hidden", "data-auto-submit-form-target": "auto", "data-file-upload-target": "input", "data-drag-and-drop-import-target": "input" %>
|
|
</div>
|
|
</div>
|
|
|
|
<%= form.submit "Upload CSV", disabled: @import.complete? %>
|
|
<% end %>
|
|
<% end %>
|
|
|
|
<% tabs.with_panel(tab_id: "csv-paste") do %>
|
|
<%= styled_form_with model: @import, scope: :import, url: import_upload_path(@import), multipart: true, class: "space-y-2" do |form| %>
|
|
<%= form.select :col_sep, Import::SEPARATORS, label: true %>
|
|
|
|
<% if @import.type == "TransactionImport" || @import.type == "TradeImport" %>
|
|
<%= form.select :account_id, @import.family.accounts.visible.pluck(:name, :id), { label: "Account (optional)", include_blank: "Multi-account import", selected: @import.account_id } %>
|
|
<% end %>
|
|
|
|
<%= form.text_area :raw_file_str,
|
|
rows: 10,
|
|
required: true,
|
|
placeholder: "Paste your CSV file contents here",
|
|
"data-auto-submit-form-target": "auto" %>
|
|
|
|
<%= form.submit "Upload CSV", disabled: @import.complete? %>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|
|
|
|
<div class="flex justify-center">
|
|
<span class="text-secondary text-sm">
|
|
<%= link_to "Download a sample CSV", "/imports/#{@import.id}/upload/sample_csv", class: "text-primary underline", data: { turbo: false } %> to see the required CSV format
|
|
</span>
|
|
</div>
|
|
</div>
|