diff --git a/app/assets/javascripts/repositories/import/records_importer.js b/app/assets/javascripts/repositories/import/records_importer.js index ec02baf5f..d4d42a142 100644 --- a/app/assets/javascripts/repositories/import/records_importer.js +++ b/app/assets/javascripts/repositories/import/records_importer.js @@ -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(); diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 05d1c8cb6..80ad95773 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/models/repository.rb b/app/models/repository.rb index 40cc3ed6e..333f62282 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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' diff --git a/app/views/repositories/_import_repository_records.html.erb b/app/views/repositories/_import_repository_records_modal.html.erb similarity index 100% rename from app/views/repositories/_import_repository_records.html.erb rename to app/views/repositories/_import_repository_records_modal.html.erb diff --git a/app/views/repositories/_repository.html.erb b/app/views/repositories/_repository.html.erb index 6fa19e73e..9db4b0199 100644 --- a/app/views/repositories/_repository.html.erb +++ b/app/views/repositories/_repository.html.erb @@ -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 %>