This commit is contained in:
zmagod 2017-06-21 17:39:20 +02:00
parent bad52ceff1
commit 28129ebb73
5 changed files with 16 additions and 23 deletions

View file

@ -2,8 +2,8 @@
'use strict';
global.repositoryRecordsImporter = function() {
var previousIndex, disabledOptions, loadingSamples;
loadingSamples = false;
var previousIndex, disabledOptions, loadingRecords;
loadingRecords = false;
$('select').focus(function() {
previousIndex = $(this)[0].selectedIndex;
}).change(function() {
@ -22,22 +22,22 @@
previousIndex = currIndex;
});
// Create import samples ajax
// Create import repository records ajax
$('form#form-import').submit(function(e) {
// Check if we already uploading samples
if (loadingSamples) {
// Check if we already uploading repository records
if (loadingRecords) {
return false;
}
disabledOptions = $("option[disabled='disabled']");
disabledOptions.removeAttr('disabled');
loadingSamples = true;
loadingRecords = true;
animateSpinner();
}).on('ajax:success', function(ev, data, status) {
// Simply reload page to show flash and updated samples list
loadingSamples = false;
// Simply reload page to show flash and updated repository records list
loadingRecords = false;
location.reload();
}).on('ajax:error', function(ev, data, status) {
loadingSamples = false;
loadingRecords = false;
if (_.isUndefined(data.responseJSON.html)) {
// Simply reload page to show flash
location.reload();

View file

@ -199,9 +199,10 @@ class RepositoriesController < ApplicationController
if parsed_file.too_large?
repository_response(t('general.file.size_exceeded',
file_size: Constants::FILE_MAX_SIZE_MB))
else
elsif parsed_file.empty?
flash[:notice] = t('teams.parse_sheet.errors.empty_file')
redirect_to back and return if parsed_file.empty?
redirect_to back and return
else
@import_data = parsed_file.data
if parsed_file.generated_temp_file?
format.json do

View file

@ -28,7 +28,7 @@ class Repository < ActiveRecord::Base
def available_repository_fields
fields = {}
# First and foremost add sample name
# First and foremost add record name
fields['-1'] = I18n.t('repositories.default_column')
# Add all other custom columns
repository_columns.order(:created_at).each do |rc|
@ -82,16 +82,16 @@ class Repository < ActiveRecord::Base
end
end
# Now we can iterate through sample data and save stuff into db
# Now we can iterate through record data and save stuff into db
(2..sheet.last_row).each do |i|
error = []
nr_of_added += 1
record_row = RepositoryRow.new(name: sheet.row(i)[name_index],
repository: self,
created_by: user,
last_modified_by: user)
next unless record_row.save
nr_of_added += 1
sheet.row(i).each.with_index do |value, index|
if custom_fields[index]
# we're working with CustomField
@ -120,14 +120,6 @@ class Repository < ActiveRecord::Base
private
# def generate_new_columns(header)
# rep_columns_names = self.repository_columns.pluck(:name).push('Name')
# header.each do |cname|
# next if rep_columns_names.include? cname
# RepositoryColumn.create(repository: self, name: cname, data_type: 0)
# end
# end
def generate_file(filename, file_path)
case File.extname(filename)
when '.csv'

View file

@ -134,6 +134,6 @@
repository_index_link: repository_table_index_path(repository)
}
%>
<%= render partial: 'repositories/import_repository_records.html.erb',
<%= render partial: 'repositories/import_repository_records_modal.html.erb',
locals: { repository: repository } %>
<%= javascript_include_tag 'repositories/edit', 'data-turbolinks-track' => true %>