Merge pull request #2732 from TracksApp/import_fixes

Error message fixes for CSV import. Add the necessary directory to Do…
This commit is contained in:
Jyri-Petteri Paloposki 2022-02-09 12:03:46 +02:00 committed by GitHub
commit 6c187bf1e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 3 deletions

View file

@ -17,10 +17,25 @@ RUN apt-get update && apt-get install -y yarn netcat
RUN mkdir /app/log RUN mkdir /app/log
COPY . /app/ COPY COPYING /app/
COPY config /app/config/
COPY config/database.docker.yml /app/config/database.yml COPY config/database.docker.yml /app/config/database.yml
COPY config/site.docker.yml /app/config/site.yml COPY config/site.docker.yml /app/config/site.yml
COPY bin /app/bin/
COPY script /app/script/
COPY public /app/public/
COPY vendor /app/vendor/
COPY .yardopts /app/
COPY Rakefile /app/
COPY config.ru /app/
COPY docker-entrypoint.sh /app/
COPY lib /app/lib/
COPY app /app/app/
COPY db /app/db/
RUN RAILS_ENV=production bundle exec rake assets:precompile RUN RAILS_ENV=production bundle exec rake assets:precompile
ENTRYPOINT ["/app/docker-entrypoint.sh"] ENTRYPOINT ["/app/docker-entrypoint.sh"]

View file

@ -62,12 +62,16 @@ class DataController < ApplicationController
flash[:notice] = t 'data.import.projects_count', count: count flash[:notice] = t 'data.import.projects_count', count: count
when 'todos' when 'todos'
count = Todo.import path_and_file, params, current_user count = Todo.import path_and_file, params, current_user
flash[:notice] = t 'data.import.todos.count', count: count if !count
flash[:error] = t('data.import.errors.no_context')
else
flash[:notice] = t 'data.import.todos_count', count: count
end
else else
flash[:error] = t('data.import.errors.invalid_destination') flash[:error] = t('data.import.errors.invalid_destination')
end end
rescue Exception => e rescue Exception => e
flash[:error] = t 'data.import.invalid_destination', e: e flash[:error] = t 'data.import.errors.invalid_destination', e: e
end end
File.delete(path_and_file) File.delete(path_and_file)
redirect_to import_data_path redirect_to import_data_path

View file

@ -353,6 +353,7 @@ class Todo < ApplicationRecord
def self.import(filename, params, user) def self.import(filename, params, user)
default_context = user.contexts.order('id').first default_context = user.contexts.order('id').first
return false if default_context.nil?
count = 0 count = 0
CSV.foreach(filename, headers: true) do |row| CSV.foreach(filename, headers: true) do |row|

View file

@ -207,6 +207,7 @@ en:
invalid_csv: "Invalid CSV: could not read headers: %{e}" invalid_csv: "Invalid CSV: could not read headers: %{e}"
save_error: "Could not save uploaded CSV (%{path_and_file}). Can Tracks write\ save_error: "Could not save uploaded CSV (%{path_and_file}). Can Tracks write\
\ to the upload directory? %{e}" \ to the upload directory? %{e}"
no_context: No default context could be found
map_title: Map fields to be imported map_title: Map fields to be imported
header: Importing data header: Importing data
submit: Import submit: Import

0
public/uploads/csv/.keep Normal file
View file