-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a basic CSV import module for bulk-importing account transactions. Changes include: - User can load a CSV - User can configure the column mappings for a CSV - Imported CSV shows invalid cells - User can clean up their data directly in the UI - User can see a preview of the import rows and confirm import - Layout refactor + Import nav stepper - System test stability improvements
- Loading branch information
Showing
71 changed files
with
1,653 additions
and
113 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,102 @@ | ||
require "ostruct" | ||
|
||
class ImportsController < ApplicationController | ||
before_action :set_import, except: %i[ index new create ] | ||
|
||
def index | ||
@imports = Current.family.imports | ||
render layout: "with_sidebar" | ||
end | ||
|
||
def new | ||
@import = Import.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
account = Current.family.accounts.find(params[:import][:account_id]) | ||
|
||
@import.update! account: account | ||
redirect_to load_import_path(@import), notice: t(".import_updated") | ||
end | ||
|
||
def create | ||
account = Current.family.accounts.find(params[:import][:account_id]) | ||
@import = Import.create!(account: account) | ||
|
||
redirect_to load_import_path(@import), notice: t(".import_created") | ||
end | ||
|
||
def destroy | ||
@import.destroy! | ||
redirect_to imports_url, notice: t(".import_destroyed"), status: :see_other | ||
end | ||
|
||
def load | ||
end | ||
|
||
def load_csv | ||
if @import.update(import_params) | ||
redirect_to configure_import_path(@import), notice: t(".import_loaded") | ||
else | ||
flash.now[:error] = @import.errors.full_messages.to_sentence | ||
render :load, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def configure | ||
unless @import.loaded? | ||
redirect_to load_import_path(@import), alert: t(".invalid_csv") | ||
end | ||
end | ||
|
||
def update_mappings | ||
@import.update! import_params(@import.expected_fields.map(&:key)) | ||
redirect_to clean_import_path(@import), notice: t(".column_mappings_saved") | ||
end | ||
|
||
def clean | ||
unless @import.loaded? | ||
redirect_to load_import_path(@import), alert: t(".invalid_csv") | ||
end | ||
end | ||
|
||
def update_csv | ||
update_params = import_params[:csv_update] | ||
|
||
@import.update_csv! \ | ||
row_idx: update_params[:row_idx], | ||
col_idx: update_params[:col_idx], | ||
value: update_params[:value] | ||
|
||
render :clean | ||
end | ||
|
||
def confirm | ||
unless @import.cleaned? | ||
redirect_to clean_import_path(@import), alert: t(".invalid_data") | ||
end | ||
end | ||
|
||
def publish | ||
if @import.valid? | ||
@import.publish_later | ||
redirect_to imports_path, notice: t(".import_published") | ||
else | ||
flash.now[:error] = t(".invalid_data") | ||
render :confirm, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_import | ||
@import = Current.family.imports.find(params[:id]) | ||
end | ||
|
||
def import_params(permitted_mappings = nil) | ||
params.require(:import).permit(:raw_csv_str, column_mappings: permitted_mappings, csv_update: [ :row_idx, :col_idx, :value ]) | ||
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class PagesController < ApplicationController | ||
layout "with_sidebar" | ||
|
||
include Filterable | ||
|
||
def dashboard | ||
|
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
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,3 @@ | ||
class SettingsController < ApplicationController | ||
layout "with_sidebar" | ||
end |
2 changes: 2 additions & 0 deletions
2
app/controllers/transactions/categories/deletions_controller.rb
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class Transactions::RulesController < ApplicationController | ||
layout "with_sidebar" | ||
|
||
def index | ||
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
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,19 @@ | ||
module ImportsHelper | ||
def table_corner_class(row_idx, col_idx, rows, cols) | ||
return "rounded-tl-xl" if row_idx == 0 && col_idx == 0 | ||
return "rounded-tr-xl" if row_idx == 0 && col_idx == cols.size - 1 | ||
return "rounded-bl-xl" if row_idx == rows.size - 1 && col_idx == 0 | ||
return "rounded-br-xl" if row_idx == rows.size - 1 && col_idx == cols.size - 1 | ||
"" | ||
end | ||
|
||
def nav_steps(import = Import.new) | ||
[ | ||
{ name: "Select", complete: import.persisted?, path: import.persisted? ? edit_import_path(import) : new_import_path }, | ||
{ name: "Import", complete: import.loaded?, path: import.persisted? ? load_import_path(import) : nil }, | ||
{ name: "Setup", complete: import.configured?, path: import.persisted? ? configure_import_path(import) : nil }, | ||
{ name: "Clean", complete: import.cleaned?, path: import.persisted? ? clean_import_path(import) : nil }, | ||
{ name: "Confirm", complete: import.complete?, path: import.persisted? ? confirm_import_path(import) : nil } | ||
] | ||
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,7 @@ | ||
class ImportJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(import) | ||
import.publish | ||
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
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
Oops, something went wrong.