mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-19 05:47:53 +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
|
end
|
||||||
|
|
||||||
def parse_sheet
|
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'))
|
repository_response(t('teams.parse_sheet.errors.no_file_selected'))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
parsed_file = ImportRepository::ParseRepository.new(
|
parsed_file = ImportRepository::ParseRepository.new(
|
||||||
file: params[:file],
|
file: import_params[:file],
|
||||||
repository: repository,
|
repository: repository,
|
||||||
session: session
|
session: session
|
||||||
)
|
)
|
||||||
|
@ -229,7 +229,7 @@ class RepositoriesController < ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
# Check if there exist mapping for repository record (it's mandatory)
|
# 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
|
import_records = repostiory_import_actions
|
||||||
status = import_records.import!
|
status = import_records.import!
|
||||||
|
|
||||||
|
@ -272,9 +272,9 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
def repostiory_import_actions
|
def repostiory_import_actions
|
||||||
ImportRepository::ImportRecords.new(
|
ImportRepository::ImportRecords.new(
|
||||||
temp_file: TempFile.find_by_id(params[:file_id]),
|
temp_file: TempFile.find_by_id(import_params[:file_id]),
|
||||||
repository: current_team.repositories.find_by_id(params[:id]),
|
repository: current_team.repositories.find_by_id(import_params[:id]),
|
||||||
mappings: params[:mappings],
|
mappings: import_params[:mappings],
|
||||||
session: session,
|
session: session,
|
||||||
user: current_user
|
user: current_user
|
||||||
)
|
)
|
||||||
|
@ -317,6 +317,10 @@ class RepositoriesController < ApplicationController
|
||||||
params.require(:repository).permit(:name)
|
params.require(:repository).permit(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def import_params
|
||||||
|
params.permit(:id, :file, :file_id, mappings: {}).to_h
|
||||||
|
end
|
||||||
|
|
||||||
def repository_response(message)
|
def repository_response(message)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
|
|
@ -161,12 +161,7 @@ class Repository < ApplicationRecord
|
||||||
repository_column: columns[index]
|
repository_column: columns[index]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
cell = RepositoryCell.new(repository_row: record_row,
|
unless cell_value.valid?
|
||||||
repository_column: columns[index],
|
|
||||||
value: cell_value)
|
|
||||||
cell.skip_on_import = true
|
|
||||||
cell_value.repository_cell = cell
|
|
||||||
unless cell.valid? && cell_value.valid?
|
|
||||||
errors = true
|
errors = true
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal" onClick="pageReload()"><%= t('general.cancel')%></button>
|
<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>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal" onClick="pageReload()"><%= t('general.cancel')%></button>
|
<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>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue