diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0400f1689..e0dc620ee 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -194,9 +194,9 @@ function notificationAlertClose(){ $(document).ready(function(){ $('.tree-link a').each( function(){ - truncateLongString( $(this), 30); + truncateLongString( $(this), NAME_TRUNCATION_LENGTH); }); $(".tree-link span").each( function(){ - truncateLongString( $(this), 30); + truncateLongString( $(this), NAME_TRUNCATION_LENGTH); }); }); diff --git a/app/assets/javascripts/comments.js.erb b/app/assets/javascripts/comments.js.erb index b0fe8f0cd..2497bffb9 100644 --- a/app/assets/javascripts/comments.js.erb +++ b/app/assets/javascripts/comments.js.erb @@ -182,7 +182,7 @@ var Comments = (function() { var parentTopPos = $el.offset().top; if (leftPos + menu.width() > $(window).width()) { menu.offset({ left: leftPos - menu.width(), - top: (parentTopPos + <%= DROPDOWN_TOP_OFFSET %>)}); + top: (parentTopPos + <%= DROPDOWN_TOP_OFFSET_PX %>)}); } }); } @@ -208,7 +208,7 @@ var Comments = (function() { var $el = $(el); var offset = useParentOffset ? $el.offset().top : $el.position().top; $el.find('.dropdown-menu-fixed') - .offset({ top: (offset + <%= DROPDOWN_TOP_OFFSET %>) }); + .offset({ top: (offset + <%= DROPDOWN_TOP_OFFSET_PX %>) }); }); } diff --git a/app/assets/javascripts/protocols/header.js b/app/assets/javascripts/protocols/header.js index 9937ed9ba..2686bdc3c 100644 --- a/app/assets/javascripts/protocols/header.js +++ b/app/assets/javascripts/protocols/header.js @@ -88,11 +88,11 @@ function initEditKeywords() { // Init tagsinput & typeahead input.tagsinput({ - maxChars: 50, + maxChars: NAME_MAX_LENGTH, trimValue: true, typeaheadjs: { highlight: true, - minLength: 3, + minLength: NAME_MIN_LENGTH, name: "keywords", source: keywordsEngine } diff --git a/app/assets/javascripts/reports/new.js b/app/assets/javascripts/reports/new.js index acffe5b96..6b6ad4dc7 100644 --- a/app/assets/javascripts/reports/new.js +++ b/app/assets/javascripts/reports/new.js @@ -1124,7 +1124,7 @@ function initializeReportSidebartruncation() { function() { $.each($("a.report-nav-link"), function(){ - truncateLongString($(this), 30); + truncateLongString($(this), NAME_TRUNCATION_LENGTH); }); } ); @@ -1214,8 +1214,8 @@ $(document).ready(function() { initializeUnsavedWorkDialog(); initializeTutorial(); - $(".report-nav-link").each( function(){ - truncateLongString( $(this), 30); + $('.report-nav-link').each(function() { + truncateLongString($(this), NAME_TRUNCATION_LENGTH); }); } }) @@ -1223,7 +1223,7 @@ $(document).ready(function() { $(document).change(function(){ setTimeout(function(){ $(".report-nav-link").each( function(){ - truncateLongString( $(this), 30); + truncateLongString( $(this), NAME_TRUNCATION_LENGTH); }); }, 1000); }); diff --git a/app/assets/javascripts/sitewide/constants.js.erb b/app/assets/javascripts/sitewide/constants.js.erb new file mode 100644 index 000000000..a395ceef4 --- /dev/null +++ b/app/assets/javascripts/sitewide/constants.js.erb @@ -0,0 +1,47 @@ +// All the constants from server-side available on client-side. + +var APP_VERSION = "<%= APP_VERSION %>"; +var TAG_COLORS = <%= TAG_COLORS %>; +var TEXT_EXTRACT_FILE_TYPES = <%= TEXT_EXTRACT_FILE_TYPES %>; +var DEFAULT_PRIVATE_ORG_NAME = "<%= DEFAULT_PRIVATE_ORG_NAME %>"; + +var NAME_MIN_LENGTH = <%= NAME_MIN_LENGTH %>; +var NAME_MAX_LENGTH = <%= NAME_MAX_LENGTH %>; +var NAME_TRUNCATION_LENGTH = <%= NAME_TRUNCATION_LENGTH %>; +var TEXT_MAX_LENGTH = <%= TEXT_MAX_LENGTH %>; +var COLOR_MAX_LENGTH = <%= TEXT_MAX_LENGTH %>; +var DROPDOWN_TEXT_MAX_LENGTH = <%= DROPDOWN_TEXT_MAX_LENGTH %>; +var FILENAME_TRUNCATION_LENGTH = <%= FILENAME_TRUNCATION_LENGTH %>; +var USER_INITIALS_MAX_LENGTH = <%= USER_INITIALS_MAX_LENGTH %>; +var EMAIL_MAX_LENGTH = <%= EMAIL_MAX_LENGTH %>; + +var SEARCH_LIMIT = <%= SEARCH_LIMIT %>; +var SEARCH_NO_LIMIT = <%= SEARCH_NO_LIMIT %>; +var MODAL_SEARCH_LIMIT = <%= MODAL_SEARCH_LIMIT %>; +var COMMENTS_SEARCH_LIMIT = <%= COMMENTS_SEARCH_LIMIT %>; +var ACTIVITY_SEARCH_LIMIT = <%= ACTIVITY_SEARCH_LIMIT %>; + +var TABLE_JSON_MAX_SIZE = <%= TABLE_JSON_MAX_SIZE %>; +var FILE_MAX_SIZE = <%= FILE_MAX_SIZE %>; +var AVATAR_MAX_SIZE = <%= AVATAR_MAX_SIZE %>; + +var MEDIUM_PIC_FORMAT = "<%= MEDIUM_PIC_FORMAT %>"; +var THUMB_PIC_FORMAT = "<%= THUMB_PIC_FORMAT %>"; +var ICON_PIC_FORMAT = "<%= ICON_PIC_FORMAT %>"; +var ICON_SMALL_PIC_FORMAT = "<%= ICON_SMALL_PIC_FORMAT %>"; + +var URL_SHORT_EXPIRE_TIME = <%= URL_SHORT_EXPIRE_TIME %>; +var URL_LONG_EXPIRE_TIME = <%= URL_LONG_EXPIRE_TIME %>; + +var MINIMAL_ORGANIZATION_SPACE_TAKEN = + <%= MINIMAL_ORGANIZATION_SPACE_TAKEN %>; +var ASSET_ESTIMATED_SIZE_FACTOR = <%= ASSET_ESTIMATED_SIZE_FACTOR %>; + +var TUTORIALS_URL = "<%= TUTORIALS_URL %>"; +var FAQ_URL = "<%= FAQ_URL %>"; +var SUPPORT_URL = "<%= SUPPORT_URL %>"; +var PLANS_URL = "<%= PLANS_URL %>"; +var CONTACT_URL = "<%= CONTACT_URL %>"; +var DEFAULT_AVATAR_URL = "<%= DEFAULT_AVATAR_URL %>"; + +var KICKSTARTER_SUPPORTERS = <%= KICKSTARTER_SUPPORTERS %>; diff --git a/app/assets/javascripts/sitewide/form_validators.js.erb b/app/assets/javascripts/sitewide/form_validators.js.erb index 327162821..bcb261f0f 100644 --- a/app/assets/javascripts/sitewide/form_validators.js.erb +++ b/app/assets/javascripts/sitewide/form_validators.js.erb @@ -21,9 +21,9 @@ $.fn.onSubmitValidator = function(validatorCb) { var TextLimitEnum = Object.freeze({ OPTIONAL: 0, REQUIRED: 1, - NAME_MIN_LENGTH: '<%= NAME_MIN_LENGTH %>', - NAME_MAX_LENGTH: '<%= NAME_MAX_LENGTH %>', - TEXT_MAX_LENGTH: '<%= TEXT_MAX_LENGTH %>' + NAME_MIN_LENGTH: "<%= NAME_MIN_LENGTH %>", + NAME_MAX_LENGTH: "<%= NAME_MAX_LENGTH %>", + TEXT_MAX_LENGTH: "<%= TEXT_MAX_LENGTH %>" }); /* @@ -102,8 +102,8 @@ function checklistsValidator(ev, checklists, editMode) { } var FileTypeSizeEnum = Object.freeze({ - FILE: '<%= FILE_MAX_SIZE.megabytes %>', - AVATAR: '<%= AVATAR_MAX_SIZE.megabytes %>' + FILE: "<%= FILE_MAX_SIZE.megabytes %>", + AVATAR: "<%= AVATAR_MAX_SIZE.megabytes %>" }); function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) { diff --git a/app/assets/javascripts/sitewide/string_utils.js b/app/assets/javascripts/sitewide/string_utils.js index 3f47285ef..ff59943e8 100644 --- a/app/assets/javascripts/sitewide/string_utils.js +++ b/app/assets/javascripts/sitewide/string_utils.js @@ -9,7 +9,7 @@ function truncateLongString( el, chars ) { html = el.children()[0]; } - if( input.length >= chars){ + if( input.length >= chars ){ var newText = el.text().slice(0, chars); for( var i = newText.length; i > 0; i--){ if(newText[i] === ' ' && i > 10){ diff --git a/app/controllers/my_module_comments_controller.rb b/app/controllers/my_module_comments_controller.rb index 5138c8126..bac0316f1 100644 --- a/app/controllers/my_module_comments_controller.rb +++ b/app/controllers/my_module_comments_controller.rb @@ -162,7 +162,7 @@ class MyModuleCommentsController < ApplicationController def load_vars @last_comment_id = params[:from].to_i - @per_page = 10 + @per_page = COMMENTS_SEARCH_LIMIT @my_module = MyModule.find_by_id(params[:my_module_id]) unless @my_module diff --git a/app/controllers/project_comments_controller.rb b/app/controllers/project_comments_controller.rb index a6b06fe7b..0e58634a0 100644 --- a/app/controllers/project_comments_controller.rb +++ b/app/controllers/project_comments_controller.rb @@ -158,7 +158,7 @@ class ProjectCommentsController < ApplicationController def load_vars @last_comment_id = params[:from].to_i - @per_page = 10 + @per_page = COMMENTS_SEARCH_LIMIT @project = Project.find_by_id(params[:project_id]) unless @project diff --git a/app/controllers/result_comments_controller.rb b/app/controllers/result_comments_controller.rb index 77083ec6a..ae187161a 100644 --- a/app/controllers/result_comments_controller.rb +++ b/app/controllers/result_comments_controller.rb @@ -159,7 +159,7 @@ class ResultCommentsController < ApplicationController def load_vars @last_comment_id = params[:from].to_i - @per_page = 10 + @per_page = COMMENTS_SEARCH_LIMIT @result = Result.find_by_id(params[:result_id]) @my_module = @result.my_module diff --git a/app/controllers/step_comments_controller.rb b/app/controllers/step_comments_controller.rb index 1f6502da5..acd7fd966 100644 --- a/app/controllers/step_comments_controller.rb +++ b/app/controllers/step_comments_controller.rb @@ -168,7 +168,7 @@ class StepCommentsController < ApplicationController def load_vars @last_comment_id = params[:from].to_i - @per_page = 10 + @per_page = COMMENTS_SEARCH_LIMIT @step = Step.find_by_id(params[:step_id]) @protocol = @step.protocol diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 50596bb53..a168e347a 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -140,7 +140,7 @@ class Users::SettingsController < ApplicationController nr_of_results = User.search(true, query, @org).count - users = User.search(false, query, @org).limit(EXISTING_USERS_SEARCH_LIMIT) + users = User.search(false, query, @org).limit(MODAL_SEARCH_LIMIT) nr_of_members = User.organization_search(false, query, @org).count diff --git a/app/helpers/activity_helper.rb b/app/helpers/activity_helper.rb index 9e81721a2..62bec3fd1 100644 --- a/app/helpers/activity_helper.rb +++ b/app/helpers/activity_helper.rb @@ -1,7 +1,7 @@ module ActivityHelper - def activity_truncate(message, len = 20) + def activity_truncate(message, len = NAME_TRUNCATION_LENGTH) activity_title = message.match(/(.*?)<\/strong>/)[1] - if activity_title.length > 20 + if activity_title.length > NAME_TRUNCATION_LENGTH title = "" else diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 51b90e7a1..62dc42570 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -81,7 +81,7 @@ end def report_image_asset_url(asset) prefix = (ENV["PAPERCLIP_STORAGE"].present? && ENV["MAIL_SERVER_URL"].present? && ENV["PAPERCLIP_STORAGE"] == "filesystem") ? ENV["MAIL_SERVER_URL"] : "" prefix = (!prefix.empty? && !prefix.include?("http://") && !prefix.include?("https://")) ? "http://#{prefix}" : prefix - url = prefix + asset.url(:medium, timeout: 86_400) + url = prefix + asset.url(:medium, timeout: URL_LONG_EXPIRE_TIME) image_tag(url) end diff --git a/app/models/asset.rb b/app/models/asset.rb index d7436ed69..5ba874643 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -6,11 +6,7 @@ class Asset < ActiveRecord::Base require 'tempfile' # Paperclip validation - has_attached_file :file, { - styles: { - medium: '300x300>' - } - } + has_attached_file :file, styles: { medium: MEDIUM_PIC_FORMAT } validates_attachment :file, presence: true, @@ -75,14 +71,14 @@ class Asset < ActiveRecord::Base ) step_ids = Step - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .joins(:step_assets) .select("step_assets.id") .distinct result_ids = Result - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .joins(:result_asset) .select("result_assets.id") .distinct @@ -125,7 +121,7 @@ class Asset < ActiveRecord::Base ) # Show all results if needed - if page != SHOW_ALL_RESULTS + if page != SEARCH_NO_LIMIT ids = ids .limit(SEARCH_LIMIT) .offset((page - 1) * SEARCH_LIMIT) @@ -250,7 +246,7 @@ class Asset < ActiveRecord::Base end end - def url(style = :original, timeout: 30) + def url(style = :original, timeout: URL_SHORT_EXPIRE_TIME) if file.is_stored_on_s3? presigned_url(style, timeout: timeout) else @@ -259,7 +255,7 @@ class Asset < ActiveRecord::Base end # When using S3 file upload, we can limit file accessibility with url signing - def presigned_url(style = :original, download: false, timeout: 30) + def presigned_url(style = :original, download: false, timeout: URL_SHORT_EXPIRE_TIME) if file.is_stored_on_s3? if download download_arg = 'attachment; filename=' + URI.escape(file_file_name) diff --git a/app/models/checklist.rb b/app/models/checklist.rb index 481cf2959..afa52d656 100644 --- a/app/models/checklist.rb +++ b/app/models/checklist.rb @@ -23,7 +23,7 @@ class Checklist < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) step_ids = Step - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -43,7 +43,7 @@ class Checklist < ActiveRecord::Base .where_attributes_like(["checklists.name", "checklist_items.text"], a_query) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/comment.rb b/app/models/comment.rb index ac5e37eab..0b13eb517 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -24,19 +24,19 @@ class Comment < ActiveRecord::Base ) project_ids = Project - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") my_module_ids = MyModule - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") step_ids = Step - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") result_ids = Result - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") @@ -73,7 +73,7 @@ class Comment < ActiveRecord::Base ) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 052d13a6e..59abc74ba 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -35,7 +35,7 @@ class Experiment < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) project_ids = Project - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -62,7 +62,7 @@ class Experiment < ActiveRecord::Base end # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query @@ -335,10 +335,10 @@ class Experiment < ActiveRecord::Base format = 'Clone %d - %s' i = 1 - i += 1 while experiment_names.include?(format(format, i, name)[0, 50]) + i += 1 while experiment_names.include?(format(format, i, name)) clone = Experiment.new( - name: format(format, i, name)[0, 50], + name: format(format, i, name), description: description, created_by: current_user, last_modified_by: current_user, diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 137f7c664..06fb4070e 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -43,7 +43,7 @@ class MyModule < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) exp_ids = Experiment - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -70,7 +70,7 @@ class MyModule < ActiveRecord::Base end # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query @@ -145,13 +145,13 @@ class MyModule < ActiveRecord::Base ) end - def last_activities(count = 20) + def last_activities(count = ACTIVITY_SEARCH_LIMIT) Activity.where(my_module_id: id).order(:created_at).last(count) end # Get module comments ordered by created_at time. Results are paginated # using last comment id and per_page parameters. - def last_comments(last_id = 1, per_page = 20) + def last_comments(last_id = 1, per_page = COMMENTS_SEARCH_LIMIT) last_id = 9999999999999 if last_id <= 1 comments = Comment.joins(:my_module_comment) .where(my_module_comments: { my_module_id: id }) @@ -161,7 +161,7 @@ class MyModule < ActiveRecord::Base comments.reverse end - def last_activities(last_id = 1, count = 20) + def last_activities(last_id = 1, count = ACTIVITY_SEARCH_LIMIT) last_id = 9999999999999 if last_id <= 1 Activity.joins(:my_module) .where(my_module_id: id) @@ -177,7 +177,7 @@ class MyModule < ActiveRecord::Base protocols.count > 0 ? protocols.first : nil end - def first_n_samples(count = 20) + def first_n_samples(count) samples.order(name: :asc).limit(count) end diff --git a/app/models/my_module_group.rb b/app/models/my_module_group.rb index d221cc559..3fe60a2bf 100644 --- a/app/models/my_module_group.rb +++ b/app/models/my_module_group.rb @@ -12,7 +12,7 @@ class MyModuleGroup < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) exp_ids = Experiment - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") @@ -32,7 +32,7 @@ class MyModuleGroup < ActiveRecord::Base .where_attributes_like("my_module_groups.name", a_query) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/project.rb b/app/models/project.rb index e924ebec2..a4409fec7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -64,7 +64,7 @@ class Project < ActiveRecord::Base end # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query @@ -73,13 +73,13 @@ class Project < ActiveRecord::Base end end - def last_activities(count = 20) + def last_activities(count = ACTIVITY_SEARCH_LIMIT) activities.order(created_at: :desc).first(count) end # Get project comments order by created_at time. Results are paginated # using last comment id and per_page parameters. - def last_comments(last_id = 1, per_page = 20) + def last_comments(last_id = 1, per_page = COMMENTS_SEARCH_LIMIT) last_id = 9999999999999 if last_id <= 1 comments = Comment.joins(:project_comment) .where(project_comments: { project_id: id }) diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 9fc7230a3..0e0fa5036 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -76,7 +76,7 @@ class Protocol < ActiveRecord::Base module_ids = MyModule - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") where_str = @@ -140,7 +140,7 @@ class Protocol < ActiveRecord::Base ) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/protocol_keyword.rb b/app/models/protocol_keyword.rb index 6035db9af..25eea9ed9 100644 --- a/app/models/protocol_keyword.rb +++ b/app/models/protocol_keyword.rb @@ -1,6 +1,7 @@ class ProtocolKeyword < ActiveRecord::Base auto_strip_attributes :name, nullify: false - validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH } + validates :name, + length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH } validates :organization, presence: true belongs_to :organization, inverse_of: :protocol_keywords diff --git a/app/models/report.rb b/app/models/report.rb index 0d4aee9f7..e44be0a57 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -26,7 +26,7 @@ class Report < ActiveRecord::Base project_ids = Project - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -53,7 +53,7 @@ class Report < ActiveRecord::Base ) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/result.rb b/app/models/result.rb index 17254e496..554c2f30f 100644 --- a/app/models/result.rb +++ b/app/models/result.rb @@ -35,7 +35,7 @@ class Result < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) module_ids = MyModule - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -59,7 +59,7 @@ class Result < ActiveRecord::Base end # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query @@ -72,7 +72,7 @@ class Result < ActiveRecord::Base is_asset ? result_asset.space_taken : 0 end - def last_comments(last_id = 1, per_page = 20) + def last_comments(last_id = 1, per_page = COMMENTS_SEARCH_LIMIT) last_id = 9999999999999 if last_id <= 1 comments = Comment.joins(:result_comment) .where(result_comments: { result_id: id }) diff --git a/app/models/sample.rb b/app/models/sample.rb index 441547684..f18f259d8 100644 --- a/app/models/sample.rb +++ b/app/models/sample.rb @@ -59,7 +59,7 @@ class Sample < ActiveRecord::Base ) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/step.rb b/app/models/step.rb index 21323b6df..4dc7dba74 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -42,7 +42,7 @@ class Step < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) protocol_ids = Protocol - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -61,7 +61,7 @@ class Step < ActiveRecord::Base .where_attributes_like([:name, :description], a_query) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query @@ -86,7 +86,7 @@ class Step < ActiveRecord::Base protocol.present? ? protocol.my_module : nil end - def last_comments(last_id = 1, per_page = 20) + def last_comments(last_id = 1, per_page = COMMENTS_SEARCH_LIMIT) last_id = 9999999999999 if last_id <= 1 comments = Comment.joins(:step_comment) .where(step_comments: { step_id: id }) diff --git a/app/models/table.rb b/app/models/table.rb index 0484f0064..a0087fae6 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -20,14 +20,14 @@ class Table < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) step_ids = Step - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .joins(:step_tables) .select("step_tables.id") .distinct result_ids = Result - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .joins(:result_table) .select("result_tables.id") .distinct @@ -55,7 +55,7 @@ class Table < ActiveRecord::Base new_query = table_query # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/tag.rb b/app/models/tag.rb index e1d9549b3..028fc5aa1 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -15,7 +15,7 @@ class Tag < ActiveRecord::Base def self.search(user, include_archived, query = nil, page = 1) project_ids = Project - .search(user, include_archived, nil, SHOW_ALL_RESULTS) + .search(user, include_archived, nil, SEARCH_NO_LIMIT) .select("id") if query @@ -34,7 +34,7 @@ class Tag < ActiveRecord::Base .where_attributes_like(:name, a_query) # Show all results if needed - if page == SHOW_ALL_RESULTS + if page == SEARCH_NO_LIMIT new_query else new_query diff --git a/app/models/user.rb b/app/models/user.rb index b8ca5edfd..b9e6f9021 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,13 +3,14 @@ class User < ActiveRecord::Base devise :invitable, :confirmable, :database_authenticatable, :registerable, :async, :recoverable, :rememberable, :trackable, :validatable, stretches: 10 - has_attached_file :avatar, :styles => { - :medium => "300x300>", - :thumb => "100x100>", - :icon => "40x40>", - :icon_small => "30x30>" - }, - :default_url => "/images/:style/missing.png" + has_attached_file :avatar, + styles: { + medium: MEDIUM_PIC_FORMAT, + thumb: THUMB_PIC_FORMAT, + icon: ICON_PIC_FORMAT, + icon_small: ICON_SMALL_PIC_FORMAT + }, + default_url: DEFAULT_AVATAR_URL enum tutorial_status: { no_tutorial_done: 0, @@ -233,7 +234,7 @@ class User < ActiveRecord::Base # Finds all activities of user that is assigned to project. If user # is not an owner of the project, user must be also assigned to # module. - def last_activities(last_activity_id = nil, per_page = 10) + def last_activities(last_activity_id = nil, per_page = ACTIVITY_SEARCH_LIMIT) # TODO replace with some kind of Infinity value last_activity_id = 999999999999999999999999 if last_activity_id < 1 Activity diff --git a/app/views/activities/_activity.html.erb b/app/views/activities/_activity.html.erb index 8d0136188..8fb5f5ae1 100644 --- a/app/views/activities/_activity.html.erb +++ b/app/views/activities/_activity.html.erb @@ -3,19 +3,19 @@ <%= l activity.created_at, format: '%H:%M' %> - <%= activity_truncate( activity.message ) %> + <%= activity_truncate(activity.message) %> <% if activity.my_module %> [<%=t 'Project' %>: - <% if activity.my_module.experiment.project.name.length > 20 %> + <% if activity.my_module.experiment.project.name.length > NAME_TRUNCATION_LENGTH %> <% else %> <%= activity.my_module.experiment.project.name %> <% end %>, <%=t 'Module' %>: - <% if activity.my_module.name.length > 20 %> -