mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 11:45:18 +08:00
Fix repository records import [SCI-1939]
This commit is contained in:
parent
ebd354e4d5
commit
a64012237e
4 changed files with 14 additions and 15 deletions
|
@ -181,15 +181,15 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def parse_sheet
|
||||
repository = current_team.repositories.find_by_id(params[:id])
|
||||
repository = current_team.repositories.find_by_id(import_params[:id])
|
||||
|
||||
unless params[:file]
|
||||
unless import_params[:file]
|
||||
repository_response(t('teams.parse_sheet.errors.no_file_selected'))
|
||||
return
|
||||
end
|
||||
begin
|
||||
parsed_file = ImportRepository::ParseRepository.new(
|
||||
file: params[:file],
|
||||
file: import_params[:file],
|
||||
repository: repository,
|
||||
session: session
|
||||
)
|
||||
|
@ -229,7 +229,7 @@ class RepositoriesController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.json do
|
||||
# Check if there exist mapping for repository record (it's mandatory)
|
||||
if params[:mappings].value?('-1')
|
||||
if import_params[:mappings].value?('-1')
|
||||
import_records = repostiory_import_actions
|
||||
status = import_records.import!
|
||||
|
||||
|
@ -272,9 +272,9 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
def repostiory_import_actions
|
||||
ImportRepository::ImportRecords.new(
|
||||
temp_file: TempFile.find_by_id(params[:file_id]),
|
||||
repository: current_team.repositories.find_by_id(params[:id]),
|
||||
mappings: params[:mappings],
|
||||
temp_file: TempFile.find_by_id(import_params[:file_id]),
|
||||
repository: current_team.repositories.find_by_id(import_params[:id]),
|
||||
mappings: import_params[:mappings],
|
||||
session: session,
|
||||
user: current_user
|
||||
)
|
||||
|
@ -317,6 +317,10 @@ class RepositoriesController < ApplicationController
|
|||
params.require(:repository).permit(:name)
|
||||
end
|
||||
|
||||
def import_params
|
||||
params.permit(:id, :file, :file_id, mappings: {}).to_h
|
||||
end
|
||||
|
||||
def repository_response(message)
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
|
|
|
@ -161,12 +161,7 @@ class Repository < ApplicationRecord
|
|||
repository_column: columns[index]
|
||||
}
|
||||
)
|
||||
cell = RepositoryCell.new(repository_row: record_row,
|
||||
repository_column: columns[index],
|
||||
value: cell_value)
|
||||
cell.skip_on_import = true
|
||||
cell_value.repository_cell = cell
|
||||
unless cell.valid? && cell_value.valid?
|
||||
unless cell_value.valid?
|
||||
errors = true
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal" onClick="pageReload()"><%= t('general.cancel')%></button>
|
||||
<input type="submit" class="btn btn-primary" value="<%= t("repositories.modal_import.upload") %>"</input>
|
||||
<input type="submit" class="btn btn-primary" value="<%= t("repositories.modal_import.upload") %>">
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal" onClick="pageReload()"><%= t('general.cancel')%></button>
|
||||
<input type="submit" class="btn btn-primary" value="<%= t('repositories.modal_parse.title') %>"</input>
|
||||
<input type="submit" class="btn btn-primary" value="<%= t('repositories.modal_parse.title') %>">
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue