From 58e2575c75a6ab787dc7c7618ffc41e0208b1d7a Mon Sep 17 00:00:00 2001 From: lenart Date: Fri, 7 Jul 2017 15:56:16 +0200 Subject: [PATCH 01/24] Truncate checklist items in activity modal [fixes SCI-1249] --- app/controllers/steps_controller.rb | 3 ++- app/helpers/activity_helper.rb | 16 ++++++++++++++-- .../my_modules/activities/_activity.html.erb | 2 +- .../_my_module_activity_element.html.erb | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index 20ee1b81b..741d613ed 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -290,10 +290,11 @@ class StepsController < ApplicationController "activities.uncheck_step_checklist_item" completed_items = chkItem.checklist.checklist_items.where(checked: true).count all_items = chkItem.checklist.checklist_items.count + text_activity = chkItem.text.gsub(/\s+/, ' ') message = t( str, user: current_user.full_name, - checkbox: smart_annotation_parser(simple_format(chkItem.text)), + checkbox: text_activity, step: chkItem.checklist.step.position + 1, step_name: chkItem.checklist.step.name, completed: completed_items, diff --git a/app/helpers/activity_helper.rb b/app/helpers/activity_helper.rb index 83cf57023..d400abdb9 100644 --- a/app/helpers/activity_helper.rb +++ b/app/helpers/activity_helper.rb @@ -3,7 +3,19 @@ module ActivityHelper activity_titles = message.scan(/(.*?)<\/strong>/) activity_titles.each do |activity_title| activity_title = activity_title[0] - if activity_title.length > Constants::NAME_TRUNCATION_LENGTH + unless activity_title.length == smart_annotation_parser(activity_title) + .length + temp = activity_title.index('[') + while !temp.nil? && temp < len + if activity_title[temp + 1] == '#' || activity_title[temp + 1] == '@' + last_sa = activity_title.index(']', temp) + end + temp = activity_title.index('[', last_sa) + len = last_sa if last_sa > len + end + len += 4 + end + if activity_title.length > len title = " - <%= hidden_field_tag 'file_id', @import_data.temp_file.id %> + <%= hidden_field_tag 'file_id', @temp_file.id %>
From 38bce08b5abf341a0af005dcd863d78602e3fc33 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Fri, 13 Oct 2017 09:27:18 +0200 Subject: [PATCH 15/24] Minor wording change. --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index cb1a4a473..402735557 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1311,7 +1311,7 @@ en: addons: head_title: "Settings | Add-ons" title: "Add-ons" - no_addons: "You have no add-ons." + no_addons: "You have no sciNote Add-ons." teams: head_title: "Settings | Teams" breadcrumbs: From d2660344068f890a31ab57884bcda5ec04caf037 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Fri, 13 Oct 2017 17:15:51 +0200 Subject: [PATCH 16/24] Use case insensitive sample types and groups in import [SCI-1689] --- app/models/team.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/team.rb b/app/models/team.rb index 04a45375a..88d29ffee 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -106,10 +106,12 @@ class Team < ActiveRecord::Base sheet.row(i).each.with_index do |value, index| if index == stype_index - stype = SampleType.where(name: value.strip, team: self).take + stype = SampleType.where(team: self) + .where('name ILIKE ?', value.strip) + .take unless stype - stype = SampleType.new(name: value, team: self) + stype = SampleType.new(name: value.strip, team: self) unless stype.save errors = true raise ActiveRecord::Rollback @@ -117,10 +119,12 @@ class Team < ActiveRecord::Base end sample.sample_type = stype elsif index == sgroup_index - sgroup = SampleGroup.where(name: value.strip, team: self).take + sgroup = SampleGroup.where(team: self) + .where('name ILIKE ?', value.strip) + .take unless sgroup - sgroup = SampleGroup.new(name: value, team: self) + sgroup = SampleGroup.new(name: value.strip, team: self) unless sgroup.save errors = true raise ActiveRecord::Rollback From 4d8f2665d340daf1ecf4bc67212060ad37963b47 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 17 Oct 2017 13:10:02 +0200 Subject: [PATCH 17/24] Revert "Add Add-ons page to User -> Settings -> Account [SCI-1675]" --- .../settings/account/addons_controller.rb | 8 ------- app/helpers/user_settings_helper.rb | 7 +----- .../settings/account/_navigation.html.erb | 3 --- .../settings/account/addons/index.html.erb | 22 ------------------- config/locales/en.yml | 5 ----- config/routes.rb | 3 --- 6 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 app/controllers/users/settings/account/addons_controller.rb delete mode 100644 app/views/users/settings/account/addons/index.html.erb diff --git a/app/controllers/users/settings/account/addons_controller.rb b/app/controllers/users/settings/account/addons_controller.rb deleted file mode 100644 index 9b18d556a..000000000 --- a/app/controllers/users/settings/account/addons_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -module Users - module Settings - module Account - class AddonsController < ApplicationController - end - end - end -end diff --git a/app/helpers/user_settings_helper.rb b/app/helpers/user_settings_helper.rb index 448ef9b63..ce06ccf60 100644 --- a/app/helpers/user_settings_helper.rb +++ b/app/helpers/user_settings_helper.rb @@ -1,8 +1,7 @@ module UserSettingsHelper def on_settings_account_page? controller_name == 'registrations' && action_name == 'edit' || - controller_name == 'preferences' && action_name == 'index' || - controller_name == 'addons' && action_name == 'index' + controller_name == 'preferences' && action_name == 'index' end def on_settings_account_profile_page? @@ -13,10 +12,6 @@ module UserSettingsHelper controller_name == 'preferences' end - def on_settings_account_addons_page? - controller_name == 'addons' - end - def on_settings_team_page? controller_name.in?(%w(teams audits)) && action_name.in?(%w(index new create show audits_index)) diff --git a/app/views/users/settings/account/_navigation.html.erb b/app/views/users/settings/account/_navigation.html.erb index 63993494d..f890b5a5f 100644 --- a/app/views/users/settings/account/_navigation.html.erb +++ b/app/views/users/settings/account/_navigation.html.erb @@ -5,7 +5,4 @@ - \ No newline at end of file diff --git a/app/views/users/settings/account/addons/index.html.erb b/app/views/users/settings/account/addons/index.html.erb deleted file mode 100644 index de7c58a21..000000000 --- a/app/views/users/settings/account/addons/index.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<% provide(:head_title, t('users.settings.account.addons.head_title')) %> - -<%= render partial: 'users/settings/navigation.html.erb' %> -
-
- -
-
- <%= render partial: 'users/settings/account/navigation.html.erb' %> -
-
-

<%= t('users.settings.account.addons.title') %>

-
- - <%= t('users.settings.account.addons.no_addons') %> - -
-
-
-
-
-
diff --git a/config/locales/en.yml b/config/locales/en.yml index 459367f3b..4241aba35 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1287,7 +1287,6 @@ en: navigation: profile: "Profile" preferences: "Preferences" - addons: "Add-ons" preferences: head_title: "Settings | My preferences" edit: @@ -1303,10 +1302,6 @@ en: select_team: "Select team" tutorial_reset_flash: "Tutorial can now be repeated." tutorial_reset_error: "Tutorial could not be repeated." - addons: - head_title: "Settings | Add-ons" - title: "Add-ons" - no_addons: "You have no sciNote Add-ons." teams: head_title: "Settings | Teams" breadcrumbs: diff --git a/config/routes.rb b/config/routes.rb index c6b412da4..7aed6b3f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,9 +28,6 @@ Rails.application.routes.draw do get 'users/settings/account/preferences', to: 'users/settings/account/preferences#index', as: 'preferences' - get 'users/settings/account/addons', - to: 'users/settings/account/addons#index', - as: 'addons' put 'users/settings/account/preferences', to: 'users/settings/account/preferences#update', as: 'update_preferences' From 30d091dc65ccd11291d97520263d1908cf7617d0 Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 17 Oct 2017 14:10:56 +0200 Subject: [PATCH 18/24] adds label under protocols keywords input [fixes SCI-1560] --- app/views/protocols/header/_edit_keywords_modal_body.html.erb | 3 ++- config/locales/en.yml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/protocols/header/_edit_keywords_modal_body.html.erb b/app/views/protocols/header/_edit_keywords_modal_body.html.erb index 51250f321..021e33ad1 100644 --- a/app/views/protocols/header/_edit_keywords_modal_body.html.erb +++ b/app/views/protocols/header/_edit_keywords_modal_body.html.erb @@ -4,4 +4,5 @@ <% end %> -<% end %> \ No newline at end of file + <%=t 'protocols.header.keywords_modal' %> +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 4241aba35..5361ba628 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1414,6 +1414,7 @@ en: no_authors: "No authors" description: "Description" no_description: "No description" + keywords_modal: "Input one or multiple keywords, confirm each keyword with ENTER key" edit_name_modal: title: "Edit name of protocol %{protocol}" label: "Name" From c8d2ae70fa40fb0fe1bbdf3dc2063015d5e9ef7e Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 17 Oct 2017 14:42:06 +0200 Subject: [PATCH 19/24] Move duplicated code to service [SCI-1665] --- Gemfile | 2 +- app/controllers/repositories_controller.rb | 3 +- app/controllers/teams_controller.rb | 28 ++-------- app/models/repository.rb | 40 +------------- app/models/team.rb | 35 +----------- .../import_repository/import_records.rb | 8 ++- .../import_repository/parse_repository.rb | 26 +-------- app/services/spreadsheet_parser.rb | 55 +++++++++++++++++++ 8 files changed, 70 insertions(+), 127 deletions(-) create mode 100644 app/services/spreadsheet_parser.rb diff --git a/Gemfile b/Gemfile index 65740b8d7..9a8576cd9 100644 --- a/Gemfile +++ b/Gemfile @@ -73,6 +73,7 @@ gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails gem 'tinymce-rails', '~> 4.5.7' # Rich text editor gem 'base62' # Used for smart annotations +gem 'newrelic_rpm' group :development, :test do gem 'byebug' @@ -85,7 +86,6 @@ group :development, :test do end group :production do - gem 'newrelic_rpm' gem 'puma' gem 'rails_12factor' end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6b638589c..7454f1b81 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -205,8 +205,7 @@ class RepositoriesController < ApplicationController return repository_response(t('teams.parse_sheet.errors.empty_file')) end - @temp_file = parsed_file.generate_temp_file - if @temp_file + if (@temp_file = parsed_file.generate_temp_file) respond_to do |format| format.json do render json: { diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 32bd3d1d8..c09e06389 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -17,30 +17,10 @@ class TeamsController < ApplicationController end begin - sheet = Team.open_spreadsheet(params[:file]) - # Get data (it will trigger any errors as well) - if sheet.is_a?(Roo::CSV) - @header = sheet.row(1) - @columns = sheet.row(2) - elsif sheet.is_a?(Roo::Excelx) - i = 1 - sheet.each_row_streaming do |row| - @header = row.map(&:cell_value) if i == 1 - @columns = row.map(&:cell_value) if i == 2 - i += 1 - break if i > 2 - end - else - i = 1 - sheet.rows.each do |row| - @header = row.values if i == 1 - @columns = row.values if i == 2 - i += 1 - break if i > 2 - end - end + sheet = SpreadsheetParser.open_spreadsheet(params[:file]) + @header, @columns = SpreadsheetParser.first_two_rows(sheet) - unless @header && @header.any? && @columns && @columns.any? + unless @header.any? && @columns.any? return parse_sheet_error(t('teams.parse_sheet.errors.empty_file')) end @@ -93,7 +73,7 @@ class TeamsController < ApplicationController if @temp_file.session_id == session.id # Check if mappings exists or else we don't have anything to parse if params[:mappings] - @sheet = Team.open_spreadsheet(@temp_file.file) + @sheet = SpreadsheetParser.open_spreadsheet(@temp_file.file) # Check for duplicated values h1 = params[:mappings].clone.delete_if { |k, v| v.empty? } diff --git a/app/models/repository.rb b/app/models/repository.rb index 93b5a30e4..349651882 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -58,17 +58,6 @@ class Repository < ActiveRecord::Base end end - def open_spreadsheet(file) - filename = file.original_filename - file_path = file.path - - if file.class == Paperclip::Attachment && file.is_stored_on_s3? - fa = file.fetch - file_path = fa.path - end - generate_file(filename, file_path) - end - def available_repository_fields fields = {} # First and foremost add record name @@ -131,13 +120,7 @@ class Repository < ActiveRecord::Base unless col_compact.map(&:id).uniq.length == col_compact.length return { status: :error, nr_of_added: nr_of_added, total_nr: total_nr } end - rows = if sheet.is_a?(Roo::CSV) - sheet - elsif sheet.is_a?(Roo::Excelx) - sheet.each_row_streaming - else - sheet.rows - end + rows = SpreadsheetParser.spreadsheet_enumerator(sheet) # Now we can iterate through record data and save stuff into db rows.each do |row| @@ -202,25 +185,4 @@ class Repository < ActiveRecord::Base end { status: :ok, nr_of_added: nr_of_added, total_nr: total_nr } end - - private - - def generate_file(filename, file_path) - case File.extname(filename) - when '.csv' - Roo::CSV.new(file_path, extension: :csv) - when '.tsv' - Roo::CSV.new(file_path, csv_options: { col_sep: "\t" }) - when '.txt' - # This assumption is based purely on biologist's habits - Roo::CSV.new(file_path, csv_options: { col_sep: "\t" }) - when '.xlsx' - # Roo Excel parcel was replaced with Creek, but it can be enabled back, - # just swap lines below. But only one can be enabled at the same time. - # Roo::Excelx.new(file_path) - Creek::Book.new(file_path).sheets[0] - else - raise TypeError - end - end end diff --git a/app/models/team.rb b/app/models/team.rb index 57284d2d1..ad22d7d42 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -26,33 +26,6 @@ class Team < ActiveRecord::Base has_many :protocol_keywords, inverse_of: :team, dependent: :destroy has_many :tiny_mce_assets, inverse_of: :team, dependent: :destroy has_many :repositories, dependent: :destroy - # Based on file's extension opens file (used for importing) - def self.open_spreadsheet(file) - filename = file.original_filename - file_path = file.path - - if file.class == Paperclip::Attachment and file.is_stored_on_s3? - fa = file.fetch - file_path = fa.path - end - - case File.extname(filename) - when '.csv' then - Roo::CSV.new(file_path, extension: :csv) - when '.tsv' then - Roo::CSV.new(file_path, csv_options: { col_sep: "\t" }) - when '.txt' then - # This assumption is based purely on biologist's habits - Roo::CSV.new(file_path, csv_options: { col_sep: "\t" }) - when '.xlsx' then - # Roo Excel parcel was replaced with Creek, but it can be enabled back, - # just swap lines below. But only one can be enabled at the same time. - # Roo::Excelx.new(file_path) - Creek::Book.new(file_path).sheets[0] - else - raise TypeError - end - end def search_users(query = nil) a_query = "%#{query}%" @@ -96,13 +69,7 @@ class Team < ActiveRecord::Base end end - rows = if sheet.is_a?(Roo::CSV) - sheet - elsif sheet.is_a?(Roo::Excelx) - sheet.each_row_streaming - else - sheet.rows - end + rows = SpreadsheetParser.spreadsheet_enumerator(sheet) # Now we can iterate through sample data and save stuff into db rows.each do |row| diff --git a/app/services/import_repository/import_records.rb b/app/services/import_repository/import_records.rb index e9deea8b4..ba80a4b0a 100644 --- a/app/services/import_repository/import_records.rb +++ b/app/services/import_repository/import_records.rb @@ -17,9 +17,11 @@ module ImportRepository private def run_import_actions - @repository.import_records(@repository.open_spreadsheet(@temp_file.file), - @mappings, - @user) + @repository.import_records( + SpreadsheetParser.open_spreadsheet(@temp_file.file), + @mappings, + @user + ) end def run_checks diff --git a/app/services/import_repository/parse_repository.rb b/app/services/import_repository/parse_repository.rb index 23fe97b67..222b71274 100644 --- a/app/services/import_repository/parse_repository.rb +++ b/app/services/import_repository/parse_repository.rb @@ -5,37 +5,15 @@ module ImportRepository @file = options.fetch(:file) @repository = options.fetch(:repository) @session = options.fetch(:session) - @sheet = @repository.open_spreadsheet(@file) + @sheet = SpreadsheetParser.open_spreadsheet(@file) end def data - # Get data (it will trigger any errors as well) - if @sheet.is_a?(Roo::CSV) - header = @sheet.row(1) - columns = @sheet.row(2) - elsif @sheet.is_a?(Roo::Excelx) - i = 1 - @sheet.each_row_streaming do |row| - header = row.map(&:cell_value) if i == 1 - columns = row.map(&:cell_value) if i == 2 - i += 1 - break if i > 2 - end - else - i = 1 - @sheet.rows.each do |row| - header = row.values if i == 1 - columns = row.values if i == 2 - i += 1 - break if i > 2 - end - end + header, columns = SpreadsheetParser.first_two_rows(@sheet) # Fill in fields for dropdown @repository.available_repository_fields.transform_values! do |name| truncate(name, length: Constants::NAME_TRUNCATION_LENGTH_DROPDOWN) end - header ||= [] - columns ||= [] Data.new(header, columns, @repository.available_repository_fields, diff --git a/app/services/spreadsheet_parser.rb b/app/services/spreadsheet_parser.rb new file mode 100644 index 000000000..3d5a64774 --- /dev/null +++ b/app/services/spreadsheet_parser.rb @@ -0,0 +1,55 @@ +class SpreadsheetParser + # Based on file's extension opens file (used for importing) + def self.open_spreadsheet(file) + filename = file.original_filename + file_path = file.path + + if file.class == Paperclip::Attachment && file.is_stored_on_s3? + fa = file.fetch + file_path = fa.path + end + + case File.extname(filename) + when '.csv' + Roo::CSV.new(file_path, extension: :csv) + when '.tsv' + Roo::CSV.new(file_path, csv_options: { col_sep: "\t" }) + when '.txt' + # This assumption is based purely on biologist's habits + Roo::CSV.new(file_path, csv_options: { col_sep: "\t" }) + when '.xlsx' + # Roo Excel parcel was replaced with Creek, but it can be enabled back, + # just swap lines below. But only one can be enabled at the same time. + # Roo::Excelx.new(file_path) + Creek::Book.new(file_path).sheets[0] + else + raise TypeError + end + end + + def self.spreadsheet_enumerator(sheet) + if sheet.is_a?(Roo::CSV) + sheet + elsif sheet.is_a?(Roo::Excelx) + sheet.each_row_streaming + else + sheet.rows + end + end + + def self.first_two_rows(sheet) + rows = spreadsheet_enumerator(sheet) + header = [] + columns = [] + i = 1 + rows.each do |row| + # Creek XLSX parser returns Hash of the row, Roo - Array + row = row.is_a?(Hash) ? row.values.map(&:to_s) : row.map(&:to_s) + header = row if i == 1 && row + columns = row if i == 2 && row + i += 1 + break if i > 2 + end + return header, columns + end +end From cd0aba1896f6d9b72246e09f03dbf94e1b003344 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 17 Oct 2017 15:23:54 +0200 Subject: [PATCH 20/24] Change any? to empty? [SCI-1665] --- app/controllers/repositories_controller.rb | 2 +- app/controllers/teams_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 7454f1b81..e356471e8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -201,7 +201,7 @@ class RepositoriesController < ApplicationController else @import_data = parsed_file.data - unless @import_data.header.any? && @import_data.columns.any? + if @import_data.header.empty? || @import_data.columns.empty? return repository_response(t('teams.parse_sheet.errors.empty_file')) end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index c09e06389..982b34d11 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -20,7 +20,7 @@ class TeamsController < ApplicationController sheet = SpreadsheetParser.open_spreadsheet(params[:file]) @header, @columns = SpreadsheetParser.first_two_rows(sheet) - unless @header.any? && @columns.any? + if @header.empty? || @columns.empty? return parse_sheet_error(t('teams.parse_sheet.errors.empty_file')) end From 631b41cdaaed7c9def70e6737b82b6e101a7119b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 19 Oct 2017 11:38:23 +0200 Subject: [PATCH 21/24] Improve error handling in file uploads [SCI-1609][SCI-1612][SCI-1551] --- .../javascripts/sitewide/drag_n_drop.js.erb | 144 ++++++++++++------ app/assets/stylesheets/themes/scinote.scss | 3 +- app/controllers/result_assets_controller.rb | 62 ++++---- app/views/result_assets/_new.html.erb | 2 +- 4 files changed, 126 insertions(+), 85 deletions(-) diff --git a/app/assets/javascripts/sitewide/drag_n_drop.js.erb b/app/assets/javascripts/sitewide/drag_n_drop.js.erb index 0f1c62068..f585c3aaa 100644 --- a/app/assets/javascripts/sitewide/drag_n_drop.js.erb +++ b/app/assets/javascripts/sitewide/drag_n_drop.js.erb @@ -21,12 +21,13 @@ // loops through a list of files and display each file in a separate panel function listItems() { - droppedFiles = droppedFiles.filter(Boolean); + totalSize = 0; + _enableSubmitButton(); $('.panel-step-attachment-new').remove(); _dragNdropAssetsOff(); for(var i = 0; i < droppedFiles.length; i++) { $('#new-step-assets') - .append(_uploadedAseetPreview(droppedFiles[i], i)) + .append(_uploadedAssetPreview(droppedFiles[i], i)) .promise() .done(function() { _removeItemHandler(i); @@ -42,7 +43,6 @@ var prevEls = $('input').filter(function() { return this.name.match(regex); }); - droppedFiles = droppedFiles.filter(Boolean); var fd = new FormData($(ev.target).closest('form').get(0)); for(var i = 0; i < droppedFiles.length; i++) { var index = i + prevEls.length; @@ -56,30 +56,55 @@ return fd; } - function _validateFilesSize(file) { - var maxSize = file.size/1048576; - if(maxSize > <%= Constants::FILE_MAX_SIZE_MB %> && filesValid) { - return "

<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>

"; + function _disableSubmitButton() { + $('.step-save').prop('disabled', true); + } + + function _enableSubmitButton() { + $('.step-save').prop('disabled', false); + } + + function _filerAndCheckFiles() { + for(var i = 0; i < droppedFiles.length; i++) { + if(droppedFiles[i].isValid == false) { + return false; + } + } + return (droppedFiles.length > 0); + } + + function _validateFilesSize(file) { + var fileSize = file.size; + totalSize += parseInt(fileSize); + if(fileSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) { + file.isValid = false; + _disableSubmitButton(); + return "

<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>

"; } - totalSize += parseInt(maxSize); return ''; } function _validateTotalSize() { - if(totalSize > <%= Constants::FILE_MAX_SIZE_MB %>) { + if(totalSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) { filesValid = false; + _disableSubmitButton(); $.each($('.panel-step-attachment-new'), function() { - $(this) - .find('.panel-body') - .append("

<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>

"); + if(!$(this).find('p').hasClass('dnd-total-error')) { + $(this) + .find('.panel-body') + .append("

<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>

"); + } }); } else { - $('.dnd-error').remove(); - filesValid = true; + $('.dnd-total-error').remove(); + if(_filerAndCheckFiles()) { + filesValid = true; + _enableSubmitButton(); + } } } - function _uploadedAseetPreview(asset, i) { + function _uploadedAssetPreview(asset, i) { var html = '
'; html += '
'; html += ''; @@ -104,10 +129,9 @@ e.stopPropagation(); var $el = $(this); var index = $el.data('item-id'); - totalSize -= parseInt(droppedFiles[index]/1048576); - droppedFiles[index] = null; - $el.closest('.panel-step-attachment-new').remove(); - _validateTotalSize(); + totalSize -= parseInt(droppedFiles[index].size); + droppedFiles.splice(index, 1); + listItems(); }); } @@ -131,11 +155,10 @@ var totalSize = 0; function init(files) { - var filesPresent = droppedFiles.length; for(var i = 0; i < files.length; i++) { droppedFiles.push(files[i]); } - listItems(filesPresent); + listItems(); } // return the status of files if they are ready to submit @@ -144,18 +167,24 @@ } // loops through a list of files and display each file in a separate panel - function listItems(index) { - _dragNdropAssetsOff(); - for(var i = index; i < droppedFiles.length; i++) { - $('#new-result-assets-select') - .after(_uploadedAseetPreview(droppedFiles[i], i)) - .promise() - .done(function() { - _removeItemHandler(i); - }); + function listItems() { + totalSize = 0; + $('.panel-result-attachment-new').remove(); + if(droppedFiles.length < 1) { + _disableSubmitButton(); + } else { + _dragNdropAssetsOff(); + for(var i = 0; i < droppedFiles.length; i++) { + $('#new-result-assets-select') + .after(_uploadedAssetPreview(droppedFiles[i], i)) + .promise() + .done(function() { + _removeItemHandler(i); + }); + } + _validateTotalSize(); + dragNdropAssetsInit('results'); } - _validateTotalSize(); - dragNdropAssetsInit('results'); } // appent the files to the form before submit @@ -181,31 +210,51 @@ return fd; } + function _disableSubmitButton() { + $('.save-result').prop('disabled', true); + } + + function _enableSubmitButton() { + $('.save-result').prop('disabled', false); + } + function _filerAndCheckFiles() { - droppedFiles = droppedFiles.filter(Boolean); + for(var i = 0; i < droppedFiles.length; i++) { + if(droppedFiles[i].isValid == false) { + return false; + } + } return (droppedFiles.length > 0); } function _validateFilesSize(file) { - var maxSize = file.size/1048576; - if(maxSize > <%= Constants::FILE_MAX_SIZE_MB %> && isValid) { - return "

<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>

"; + var fileSize = file.size; + totalSize += parseInt(fileSize); + if(fileSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) { + file.isValid = false; + _disableSubmitButton(); + return "

<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>

"; } - totalSize += parseInt(maxSize); return ''; } function _validateTotalSize() { - if(totalSize > <%= Constants::FILE_MAX_SIZE_MB %>) { + if(totalSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) { isValid = false; + _disableSubmitButton(); $.each($('.panel-result-attachment-new'), function() { - $(this) - .find('.panel-body') - .append("

<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>

"); + if(!$(this).find('p').hasClass('dnd-total-error')) { + $(this) + .find('.panel-body') + .append("

<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>

"); + } }); } else { - $('.dnd-error').remove(); - isValid = true; + $('.dnd-total-error').remove(); + if(_filerAndCheckFiles()) { + isValid = true; + _enableSubmitButton(); + } } } @@ -220,7 +269,7 @@ } } - function _uploadedAseetPreview(asset, i) { + function _uploadedAssetPreview(asset, i) { var html = '
'; html += '
'; html += ''; @@ -249,10 +298,9 @@ e.stopPropagation(); var $el = $(this); var index = $el.data('item-id'); - totalSize -= parseInt(droppedFiles[index]/1048576); - droppedFiles[index] = null; - $el.closest('.panel-result-attachment-new').remove(); - _validateTotalSize(); + totalSize -= parseInt(droppedFiles[index].size); + droppedFiles.splice(index, 1); + listItems(); }); } diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index e5a41a988..91a296e07 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1288,7 +1288,8 @@ ul.content-module-activities { padding-top: 30px; } -.dnd-error { +.dnd-error, +.dnd-total-error { color: $color-milano-red; } diff --git a/app/controllers/result_assets_controller.rb b/app/controllers/result_assets_controller.rb index faeb069e2..e966bd731 100644 --- a/app/controllers/result_assets_controller.rb +++ b/app/controllers/result_assets_controller.rb @@ -76,23 +76,23 @@ class ResultAssetsController < ApplicationController @result.last_modified_by = current_user @result.assign_attributes(update_params) - success_flash = t("result_assets.update.success_flash", - module: @my_module.name) + success_flash = t('result_assets.update.success_flash', + module: @my_module.name) if @result.archived_changed?(from: false, to: true) if previous_asset.locked? respond_to do |format| - format.html { + format.html do flash[:error] = t('result_assets.archive.error_flash') redirect_to results_my_module_path(@my_module) return - } + end end end saved = @result.archive(current_user) - success_flash = t("result_assets.archive.success_flash", - module: @my_module.name) + success_flash = t('result_assets.archive.success_flash', + module: @my_module.name) if saved Activity.create( type_of: :archive_result, @@ -126,7 +126,7 @@ class ResultAssetsController < ApplicationController # Asset (file) and/or name has been changed saved = @result.save - if saved then + if saved # Release team's space taken due to # previous asset being removed team = @result.my_module.experiment.project.team @@ -134,9 +134,7 @@ class ResultAssetsController < ApplicationController team.save # Post process new file if neccesary - if @result.asset.present? - @result.asset.post_process_file(team) - end + @result.asset.post_process_file(team) if @result.asset.present? Activity.create( type_of: :edit_result, @@ -144,32 +142,33 @@ class ResultAssetsController < ApplicationController project: @my_module.experiment.project, experiment: @my_module.experiment, my_module: @my_module, - message: t( - "activities.edit_asset_result", - user: current_user.full_name, - result: @result.name - ) + message: t('activities.edit_asset_result', + user: current_user.full_name, + result: @result.name) ) end end respond_to do |format| if saved - format.html { + format.html do flash[:success] = success_flash redirect_to results_my_module_path(@my_module) - } - format.json { + end + format.json do render json: { - html: render_to_string({ - partial: "my_modules/result.html.erb", locals: {result: @result} - }) + html: render_to_string( + partial: 'my_modules/result.html.erb', locals: { result: @result } + ) }, status: :ok - } + end else - format.json { - render json: @result.errors, status: :bad_request - } + format.json do + render json: { + status: :error, + errors: @result.errors + }, status: :bad_request + end end end end @@ -189,22 +188,15 @@ class ResultAssetsController < ApplicationController def load_vars_nested @my_module = MyModule.find_by_id(params[:my_module_id]) - - unless @my_module - render_404 - end + render_404 unless @my_module end def check_create_permissions - unless can_create_result_asset_in_module(@my_module) - render_403 - end + render_403 unless can_create_result_asset_in_module(@my_module) end def check_edit_permissions - unless can_edit_result_asset_in_module(@my_module) - render_403 - end + render_403 unless can_edit_result_asset_in_module(@my_module) end def check_archive_permissions diff --git a/app/views/result_assets/_new.html.erb b/app/views/result_assets/_new.html.erb index fe28d123d..275e40cd9 100644 --- a/app/views/result_assets/_new.html.erb +++ b/app/views/result_assets/_new.html.erb @@ -11,6 +11,7 @@
- <%# end %>
From fa4c787c6ba0b1cd19fbd5dfc9786127e2c72e06 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Fri, 20 Oct 2017 14:13:58 +0200 Subject: [PATCH 22/24] Bump version to 1.12.5 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 89c881bc9..e0a6b34fb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.12.4 +1.12.5 From 6c2c5aff17ff4ed88e715791f72fc6aca94c3762 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Mon, 23 Oct 2017 09:51:13 +0200 Subject: [PATCH 23/24] Additional fixes required by latest merge from master --- app/models/my_module.rb | 4 ++-- config/initializers/devise_async.rb | 3 --- ...20171003082333_add_connections_and_sample_tasks_indexes.rb | 2 +- db/migrate/20171005135350_update_my_module_groups.rb | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 4e01eee3a..e4677a97f 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -284,7 +284,7 @@ class MyModule < ApplicationRecord until modules.empty? my_module = modules.shift final << my_module unless final.include?(my_module) - modules.push(*my_module.my_modules.flatten) + modules.push(*my_module.my_modules) end final end @@ -296,7 +296,7 @@ class MyModule < ApplicationRecord until modules.empty? my_module = modules.shift final << my_module unless final.include?(my_module) - modules.push(*my_module.my_module_antecessors.flatten) + modules.push(*my_module.my_module_antecessors) end final end diff --git a/config/initializers/devise_async.rb b/config/initializers/devise_async.rb index ca94fa499..8f24c4a87 100644 --- a/config/initializers/devise_async.rb +++ b/config/initializers/devise_async.rb @@ -1,4 +1 @@ Devise::Async.enabled = true -Devise::Async.backend = :delayed_job -Devise::Async.queue = :devise_email -# Devise::Async.priority = 10 diff --git a/db/migrate/20171003082333_add_connections_and_sample_tasks_indexes.rb b/db/migrate/20171003082333_add_connections_and_sample_tasks_indexes.rb index 29f1fb9a0..78b40ca88 100644 --- a/db/migrate/20171003082333_add_connections_and_sample_tasks_indexes.rb +++ b/db/migrate/20171003082333_add_connections_and_sample_tasks_indexes.rb @@ -1,4 +1,4 @@ -class AddConnectionsAndSampleTasksIndexes < ActiveRecord::Migration +class AddConnectionsAndSampleTasksIndexes < ActiveRecord::Migration[4.2] def change add_index :connections, :input_id add_index :connections, :output_id diff --git a/db/migrate/20171005135350_update_my_module_groups.rb b/db/migrate/20171005135350_update_my_module_groups.rb index 99ad4de88..063ab784b 100644 --- a/db/migrate/20171005135350_update_my_module_groups.rb +++ b/db/migrate/20171005135350_update_my_module_groups.rb @@ -1,4 +1,4 @@ -class UpdateMyModuleGroups < ActiveRecord::Migration +class UpdateMyModuleGroups < ActiveRecord::Migration[4.2] def change remove_column :my_module_groups, :name, :string end From e740e586e8f4aa39b98989dd55e90fc217d5b622 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Mon, 23 Oct 2017 10:43:32 +0200 Subject: [PATCH 24/24] Additional fixes required by latest merge from master (nr. 2) --- Gemfile | 4 +++- Gemfile.lock | 13 +++++++++---- config/initializers/devise_async.rb | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index d4e9bd6a7..6937d6d89 100644 --- a/Gemfile +++ b/Gemfile @@ -71,7 +71,9 @@ gem 'aws-sdk', '~> 2' gem 'aws-sdk-v1' gem 'delayed_job_active_record' -gem 'devise-async' +gem 'devise-async', + git: 'https://github.com/mhfs/devise-async.git', + branch: 'devise-4.x' gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails gem 'tinymce-rails', '~> 4.6.4' # Rich text editor diff --git a/Gemfile.lock b/Gemfile.lock index 90aab3ac9..c793aa1e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,6 +21,14 @@ GIT activejob (>= 4.2) paperclip (>= 3.3) +GIT + remote: https://github.com/mhfs/devise-async.git + revision: 177f6363a002f7ff28f1d289c8cab7ad8d9cb8c5 + branch: devise-4.x + specs: + devise-async (0.10.2) + devise (>= 4.0) + GIT remote: https://github.com/phatworx/devise_security_extension.git revision: b2ee978af7d49f0fb0e7271c6ac074dfb4d39353 @@ -185,9 +193,6 @@ GEM railties (>= 4.1.0, < 5.2) responders warden (~> 1.2.3) - devise-async (1.0.0) - activejob (>= 5.0) - devise (>= 4.0) devise_invitable (1.7.2) actionmailer (>= 4.1.0) devise (>= 4.0.0) @@ -498,7 +503,7 @@ DEPENDENCIES delayed_job_active_record delayed_paperclip! devise (~> 4.3.0) - devise-async + devise-async! devise_invitable devise_security_extension! factory_girl_rails diff --git a/config/initializers/devise_async.rb b/config/initializers/devise_async.rb index 8f24c4a87..0255b5671 100644 --- a/config/initializers/devise_async.rb +++ b/config/initializers/devise_async.rb @@ -1 +1,4 @@ Devise::Async.enabled = true +Devise::Async.backend = :delayed_job +Devise::Async.queue = :devise_email +# Devise::Async.priority = 10 \ No newline at end of file