This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #519 from churchio/import
CSV Import Redesign
- Loading branch information
Showing
84 changed files
with
2,884 additions
and
576 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
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,17 @@ | ||
.spaced-table td, .spaced-table th { | ||
padding-right: 10px; | ||
} | ||
|
||
td.strong { | ||
font-weight: bold; | ||
} | ||
|
||
tr.row-with-actions, tr.row-with-controls { | ||
@extend tr.row-with-avatar; | ||
} | ||
|
||
.table-no-top-border tr:first-child { | ||
th, td { | ||
border-top: none; | ||
} | ||
} |
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,93 @@ | ||
class Administration::ImportsController < ApplicationController | ||
before_filter :only_admins | ||
|
||
def index | ||
@imports = Import.order(created_at: :desc).page(params[:page]) | ||
end | ||
|
||
def show | ||
@import = Import.find(params[:id]) | ||
respond_to do |format| | ||
format.html do | ||
@rows = @import.rows.includes(:import_attributes).paginate(page: params[:page], per_page: 100) | ||
redirect_to(action: :edit) if @import.parsed? | ||
render :errored if @import.errored? | ||
end | ||
format.json do | ||
render json: @import | ||
end | ||
end | ||
end | ||
|
||
def new | ||
end | ||
|
||
def create | ||
return redirect_to(action: 'new') unless params[:file] | ||
@import = Import.create( | ||
person: @logged_in, | ||
filename: params[:file].original_filename, | ||
importable_type: 'Person', | ||
status: 'pending', | ||
mappings: previous_import.try(:mappings) || {}, | ||
match_strategy: previous_import.try(:match_strategy), | ||
create_as_active: previous_import.create_as_active? | ||
) | ||
@import.parse_async( | ||
file: params[:file], | ||
strategy_name: 'csv' | ||
) | ||
redirect_to administration_import_path(@import) | ||
end | ||
|
||
def edit | ||
@import = Import.find(params[:id]) | ||
@import.update_attributes(status: 'parsed') | ||
@example = build_example | ||
end | ||
|
||
def update | ||
@import = Import.find(params[:id]) | ||
@import.attributes = import_params | ||
@import.mappings = params[:import][:mappings] | ||
@import.status = 'matched' if params[:status] == 'matched' | ||
if @import.save | ||
redirect_to administration_import_path(@import) | ||
else | ||
@example = build_example | ||
render action :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@import = Import.find(params[:id]) | ||
@import.destroy if @import.destroyable? | ||
redirect_to administration_imports_path | ||
end | ||
|
||
def execute | ||
@import = Import.find(params[:id]) | ||
@import.execute_async | ||
redirect_to administration_import_path(@import) | ||
end | ||
|
||
private | ||
|
||
def import_params | ||
params.require(:import).permit(:match_strategy, :create_as_active) | ||
end | ||
|
||
def build_example | ||
@import.rows.first.try(:import_attributes_as_hash, keep_invalid: true) || {} | ||
end | ||
|
||
def only_admins | ||
return if @logged_in.admin?(:import_data) | ||
render text: t('only_admins'), layout: true, status: 401 | ||
false | ||
end | ||
|
||
def previous_import | ||
Import.order(:created_at).last | ||
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
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
Oops, something went wrong.