Added remaining constants.

This commit is contained in:
Matej Zrimšek 2016-09-29 14:12:52 +02:00
parent 21ec05d541
commit a3dfb59558
40 changed files with 271 additions and 161 deletions

View file

@ -194,9 +194,9 @@ function notificationAlertClose(){
$(document).ready(function(){ $(document).ready(function(){
$('.tree-link a').each( function(){ $('.tree-link a').each( function(){
truncateLongString( $(this), 30); truncateLongString( $(this), NAME_TRUNCATION_LENGTH);
}); });
$(".tree-link span").each( function(){ $(".tree-link span").each( function(){
truncateLongString( $(this), 30); truncateLongString( $(this), NAME_TRUNCATION_LENGTH);
}); });
}); });

View file

@ -182,7 +182,7 @@ var Comments = (function() {
var parentTopPos = $el.offset().top; var parentTopPos = $el.offset().top;
if (leftPos + menu.width() > $(window).width()) { if (leftPos + menu.width() > $(window).width()) {
menu.offset({ left: leftPos - menu.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 $el = $(el);
var offset = useParentOffset ? $el.offset().top : $el.position().top; var offset = useParentOffset ? $el.offset().top : $el.position().top;
$el.find('.dropdown-menu-fixed') $el.find('.dropdown-menu-fixed')
.offset({ top: (offset + <%= DROPDOWN_TOP_OFFSET %>) }); .offset({ top: (offset + <%= DROPDOWN_TOP_OFFSET_PX %>) });
}); });
} }

View file

@ -88,11 +88,11 @@ function initEditKeywords() {
// Init tagsinput & typeahead // Init tagsinput & typeahead
input.tagsinput({ input.tagsinput({
maxChars: 50, maxChars: NAME_MAX_LENGTH,
trimValue: true, trimValue: true,
typeaheadjs: { typeaheadjs: {
highlight: true, highlight: true,
minLength: 3, minLength: NAME_MIN_LENGTH,
name: "keywords", name: "keywords",
source: keywordsEngine source: keywordsEngine
} }

View file

@ -1124,7 +1124,7 @@ function initializeReportSidebartruncation() {
function() { function() {
$.each($("a.report-nav-link"), $.each($("a.report-nav-link"),
function(){ function(){
truncateLongString($(this), 30); truncateLongString($(this), NAME_TRUNCATION_LENGTH);
}); });
} }
); );
@ -1214,8 +1214,8 @@ $(document).ready(function() {
initializeUnsavedWorkDialog(); initializeUnsavedWorkDialog();
initializeTutorial(); initializeTutorial();
$(".report-nav-link").each( function(){ $('.report-nav-link').each(function() {
truncateLongString( $(this), 30); truncateLongString($(this), NAME_TRUNCATION_LENGTH);
}); });
} }
}) })
@ -1223,7 +1223,7 @@ $(document).ready(function() {
$(document).change(function(){ $(document).change(function(){
setTimeout(function(){ setTimeout(function(){
$(".report-nav-link").each( function(){ $(".report-nav-link").each( function(){
truncateLongString( $(this), 30); truncateLongString( $(this), NAME_TRUNCATION_LENGTH);
}); });
}, 1000); }, 1000);
}); });

View file

@ -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 %>;

View file

@ -21,9 +21,9 @@ $.fn.onSubmitValidator = function(validatorCb) {
var TextLimitEnum = Object.freeze({ var TextLimitEnum = Object.freeze({
OPTIONAL: 0, OPTIONAL: 0,
REQUIRED: 1, REQUIRED: 1,
NAME_MIN_LENGTH: '<%= NAME_MIN_LENGTH %>', NAME_MIN_LENGTH: "<%= NAME_MIN_LENGTH %>",
NAME_MAX_LENGTH: '<%= NAME_MAX_LENGTH %>', NAME_MAX_LENGTH: "<%= NAME_MAX_LENGTH %>",
TEXT_MAX_LENGTH: '<%= TEXT_MAX_LENGTH %>' TEXT_MAX_LENGTH: "<%= TEXT_MAX_LENGTH %>"
}); });
/* /*
@ -102,8 +102,8 @@ function checklistsValidator(ev, checklists, editMode) {
} }
var FileTypeSizeEnum = Object.freeze({ var FileTypeSizeEnum = Object.freeze({
FILE: '<%= FILE_MAX_SIZE.megabytes %>', FILE: "<%= FILE_MAX_SIZE.megabytes %>",
AVATAR: '<%= AVATAR_MAX_SIZE.megabytes %>' AVATAR: "<%= AVATAR_MAX_SIZE.megabytes %>"
}); });
function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) { function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) {

View file

@ -9,7 +9,7 @@ function truncateLongString( el, chars ) {
html = el.children()[0]; html = el.children()[0];
} }
if( input.length >= chars){ if( input.length >= chars ){
var newText = el.text().slice(0, chars); var newText = el.text().slice(0, chars);
for( var i = newText.length; i > 0; i--){ for( var i = newText.length; i > 0; i--){
if(newText[i] === ' ' && i > 10){ if(newText[i] === ' ' && i > 10){

View file

@ -162,7 +162,7 @@ class MyModuleCommentsController < ApplicationController
def load_vars def load_vars
@last_comment_id = params[:from].to_i @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]) @my_module = MyModule.find_by_id(params[:my_module_id])
unless @my_module unless @my_module

View file

@ -158,7 +158,7 @@ class ProjectCommentsController < ApplicationController
def load_vars def load_vars
@last_comment_id = params[:from].to_i @last_comment_id = params[:from].to_i
@per_page = 10 @per_page = COMMENTS_SEARCH_LIMIT
@project = Project.find_by_id(params[:project_id]) @project = Project.find_by_id(params[:project_id])
unless @project unless @project

View file

@ -159,7 +159,7 @@ class ResultCommentsController < ApplicationController
def load_vars def load_vars
@last_comment_id = params[:from].to_i @last_comment_id = params[:from].to_i
@per_page = 10 @per_page = COMMENTS_SEARCH_LIMIT
@result = Result.find_by_id(params[:result_id]) @result = Result.find_by_id(params[:result_id])
@my_module = @result.my_module @my_module = @result.my_module

View file

@ -168,7 +168,7 @@ class StepCommentsController < ApplicationController
def load_vars def load_vars
@last_comment_id = params[:from].to_i @last_comment_id = params[:from].to_i
@per_page = 10 @per_page = COMMENTS_SEARCH_LIMIT
@step = Step.find_by_id(params[:step_id]) @step = Step.find_by_id(params[:step_id])
@protocol = @step.protocol @protocol = @step.protocol

View file

@ -140,7 +140,7 @@ class Users::SettingsController < ApplicationController
nr_of_results = User.search(true, query, @org).count 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 nr_of_members = User.organization_search(false, query, @org).count

View file

@ -1,7 +1,7 @@
module ActivityHelper module ActivityHelper
def activity_truncate(message, len = 20) def activity_truncate(message, len = NAME_TRUNCATION_LENGTH)
activity_title = message.match(/<strong>(.*?)<\/strong>/)[1] activity_title = message.match(/<strong>(.*?)<\/strong>/)[1]
if activity_title.length > 20 if activity_title.length > NAME_TRUNCATION_LENGTH
title = "<div class='modal-tooltip'>#{truncate(activity_title, length: len)} title = "<div class='modal-tooltip'>#{truncate(activity_title, length: len)}
<span class='modal-tooltiptext'>#{activity_title}</span></div>" <span class='modal-tooltiptext'>#{activity_title}</span></div>"
else else

View file

@ -81,7 +81,7 @@ end
def report_image_asset_url(asset) 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 = (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 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) image_tag(url)
end end

View file

@ -6,11 +6,7 @@ class Asset < ActiveRecord::Base
require 'tempfile' require 'tempfile'
# Paperclip validation # Paperclip validation
has_attached_file :file, { has_attached_file :file, styles: { medium: MEDIUM_PIC_FORMAT }
styles: {
medium: '300x300>'
}
}
validates_attachment :file, validates_attachment :file,
presence: true, presence: true,
@ -75,14 +71,14 @@ class Asset < ActiveRecord::Base
) )
step_ids = step_ids =
Step Step
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.joins(:step_assets) .joins(:step_assets)
.select("step_assets.id") .select("step_assets.id")
.distinct .distinct
result_ids = result_ids =
Result Result
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.joins(:result_asset) .joins(:result_asset)
.select("result_assets.id") .select("result_assets.id")
.distinct .distinct
@ -125,7 +121,7 @@ class Asset < ActiveRecord::Base
) )
# Show all results if needed # Show all results if needed
if page != SHOW_ALL_RESULTS if page != SEARCH_NO_LIMIT
ids = ids ids = ids
.limit(SEARCH_LIMIT) .limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT) .offset((page - 1) * SEARCH_LIMIT)
@ -250,7 +246,7 @@ class Asset < ActiveRecord::Base
end end
end end
def url(style = :original, timeout: 30) def url(style = :original, timeout: URL_SHORT_EXPIRE_TIME)
if file.is_stored_on_s3? if file.is_stored_on_s3?
presigned_url(style, timeout: timeout) presigned_url(style, timeout: timeout)
else else
@ -259,7 +255,7 @@ class Asset < ActiveRecord::Base
end end
# When using S3 file upload, we can limit file accessibility with url signing # 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 file.is_stored_on_s3?
if download if download
download_arg = 'attachment; filename=' + URI.escape(file_file_name) download_arg = 'attachment; filename=' + URI.escape(file_file_name)

View file

@ -23,7 +23,7 @@ class Checklist < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
step_ids = step_ids =
Step Step
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -43,7 +43,7 @@ class Checklist < ActiveRecord::Base
.where_attributes_like(["checklists.name", "checklist_items.text"], a_query) .where_attributes_like(["checklists.name", "checklist_items.text"], a_query)
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -24,19 +24,19 @@ class Comment < ActiveRecord::Base
) )
project_ids = project_ids =
Project Project
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
my_module_ids = my_module_ids =
MyModule MyModule
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
step_ids = step_ids =
Step Step
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
result_ids = result_ids =
Result Result
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
@ -73,7 +73,7 @@ class Comment < ActiveRecord::Base
) )
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -35,7 +35,7 @@ class Experiment < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
project_ids = project_ids =
Project Project
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -62,7 +62,7 @@ class Experiment < ActiveRecord::Base
end end
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query
@ -335,10 +335,10 @@ class Experiment < ActiveRecord::Base
format = 'Clone %d - %s' format = 'Clone %d - %s'
i = 1 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( clone = Experiment.new(
name: format(format, i, name)[0, 50], name: format(format, i, name),
description: description, description: description,
created_by: current_user, created_by: current_user,
last_modified_by: current_user, last_modified_by: current_user,

View file

@ -43,7 +43,7 @@ class MyModule < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
exp_ids = exp_ids =
Experiment Experiment
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -70,7 +70,7 @@ class MyModule < ActiveRecord::Base
end end
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query
@ -145,13 +145,13 @@ class MyModule < ActiveRecord::Base
) )
end end
def last_activities(count = 20) def last_activities(count = ACTIVITY_SEARCH_LIMIT)
Activity.where(my_module_id: id).order(:created_at).last(count) Activity.where(my_module_id: id).order(:created_at).last(count)
end end
# Get module comments ordered by created_at time. Results are paginated # Get module comments ordered by created_at time. Results are paginated
# using last comment id and per_page parameters. # 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 last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:my_module_comment) comments = Comment.joins(:my_module_comment)
.where(my_module_comments: { my_module_id: id }) .where(my_module_comments: { my_module_id: id })
@ -161,7 +161,7 @@ class MyModule < ActiveRecord::Base
comments.reverse comments.reverse
end 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 last_id = 9999999999999 if last_id <= 1
Activity.joins(:my_module) Activity.joins(:my_module)
.where(my_module_id: id) .where(my_module_id: id)
@ -177,7 +177,7 @@ class MyModule < ActiveRecord::Base
protocols.count > 0 ? protocols.first : nil protocols.count > 0 ? protocols.first : nil
end end
def first_n_samples(count = 20) def first_n_samples(count)
samples.order(name: :asc).limit(count) samples.order(name: :asc).limit(count)
end end

View file

@ -12,7 +12,7 @@ class MyModuleGroup < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
exp_ids = exp_ids =
Experiment Experiment
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
@ -32,7 +32,7 @@ class MyModuleGroup < ActiveRecord::Base
.where_attributes_like("my_module_groups.name", a_query) .where_attributes_like("my_module_groups.name", a_query)
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -64,7 +64,7 @@ class Project < ActiveRecord::Base
end end
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query
@ -73,13 +73,13 @@ class Project < ActiveRecord::Base
end end
end end
def last_activities(count = 20) def last_activities(count = ACTIVITY_SEARCH_LIMIT)
activities.order(created_at: :desc).first(count) activities.order(created_at: :desc).first(count)
end end
# Get project comments order by created_at time. Results are paginated # Get project comments order by created_at time. Results are paginated
# using last comment id and per_page parameters. # 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 last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:project_comment) comments = Comment.joins(:project_comment)
.where(project_comments: { project_id: id }) .where(project_comments: { project_id: id })

View file

@ -76,7 +76,7 @@ class Protocol < ActiveRecord::Base
module_ids = module_ids =
MyModule MyModule
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
where_str = where_str =
@ -140,7 +140,7 @@ class Protocol < ActiveRecord::Base
) )
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -1,6 +1,7 @@
class ProtocolKeyword < ActiveRecord::Base class ProtocolKeyword < ActiveRecord::Base
auto_strip_attributes :name, nullify: false 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 validates :organization, presence: true
belongs_to :organization, inverse_of: :protocol_keywords belongs_to :organization, inverse_of: :protocol_keywords

View file

@ -26,7 +26,7 @@ class Report < ActiveRecord::Base
project_ids = project_ids =
Project Project
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -53,7 +53,7 @@ class Report < ActiveRecord::Base
) )
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -35,7 +35,7 @@ class Result < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
module_ids = module_ids =
MyModule MyModule
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -59,7 +59,7 @@ class Result < ActiveRecord::Base
end end
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query
@ -72,7 +72,7 @@ class Result < ActiveRecord::Base
is_asset ? result_asset.space_taken : 0 is_asset ? result_asset.space_taken : 0
end 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 last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:result_comment) comments = Comment.joins(:result_comment)
.where(result_comments: { result_id: id }) .where(result_comments: { result_id: id })

View file

@ -59,7 +59,7 @@ class Sample < ActiveRecord::Base
) )
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -42,7 +42,7 @@ class Step < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
protocol_ids = protocol_ids =
Protocol Protocol
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -61,7 +61,7 @@ class Step < ActiveRecord::Base
.where_attributes_like([:name, :description], a_query) .where_attributes_like([:name, :description], a_query)
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query
@ -86,7 +86,7 @@ class Step < ActiveRecord::Base
protocol.present? ? protocol.my_module : nil protocol.present? ? protocol.my_module : nil
end 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 last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:step_comment) comments = Comment.joins(:step_comment)
.where(step_comments: { step_id: id }) .where(step_comments: { step_id: id })

View file

@ -20,14 +20,14 @@ class Table < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
step_ids = step_ids =
Step Step
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.joins(:step_tables) .joins(:step_tables)
.select("step_tables.id") .select("step_tables.id")
.distinct .distinct
result_ids = result_ids =
Result Result
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.joins(:result_table) .joins(:result_table)
.select("result_tables.id") .select("result_tables.id")
.distinct .distinct
@ -55,7 +55,7 @@ class Table < ActiveRecord::Base
new_query = table_query new_query = table_query
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -15,7 +15,7 @@ class Tag < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1) def self.search(user, include_archived, query = nil, page = 1)
project_ids = project_ids =
Project Project
.search(user, include_archived, nil, SHOW_ALL_RESULTS) .search(user, include_archived, nil, SEARCH_NO_LIMIT)
.select("id") .select("id")
if query if query
@ -34,7 +34,7 @@ class Tag < ActiveRecord::Base
.where_attributes_like(:name, a_query) .where_attributes_like(:name, a_query)
# Show all results if needed # Show all results if needed
if page == SHOW_ALL_RESULTS if page == SEARCH_NO_LIMIT
new_query new_query
else else
new_query new_query

View file

@ -3,13 +3,14 @@ class User < ActiveRecord::Base
devise :invitable, :confirmable, :database_authenticatable, :registerable, :async, devise :invitable, :confirmable, :database_authenticatable, :registerable, :async,
:recoverable, :rememberable, :trackable, :validatable, stretches: 10 :recoverable, :rememberable, :trackable, :validatable, stretches: 10
has_attached_file :avatar, :styles => { has_attached_file :avatar,
:medium => "300x300>", styles: {
:thumb => "100x100>", medium: MEDIUM_PIC_FORMAT,
:icon => "40x40>", thumb: THUMB_PIC_FORMAT,
:icon_small => "30x30>" icon: ICON_PIC_FORMAT,
}, icon_small: ICON_SMALL_PIC_FORMAT
:default_url => "/images/:style/missing.png" },
default_url: DEFAULT_AVATAR_URL
enum tutorial_status: { enum tutorial_status: {
no_tutorial_done: 0, no_tutorial_done: 0,
@ -233,7 +234,7 @@ class User < ActiveRecord::Base
# Finds all activities of user that is assigned to project. If user # 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 # is not an owner of the project, user must be also assigned to
# module. # 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 # TODO replace with some kind of Infinity value
last_activity_id = 999999999999999999999999 if last_activity_id < 1 last_activity_id = 999999999999999999999999 if last_activity_id < 1
Activity Activity

View file

@ -3,19 +3,19 @@
<%= l activity.created_at, format: '%H:%M' %> <%= l activity.created_at, format: '%H:%M' %>
</span> </span>
<span class="activity-item-text"> <span class="activity-item-text">
<%= activity_truncate( activity.message ) %> <%= activity_truncate(activity.message) %>
<% if activity.my_module %> <% if activity.my_module %>
[<%=t 'Project' %>: [<%=t 'Project' %>:
<% if activity.my_module.experiment.project.name.length > 20 %> <% if activity.my_module.experiment.project.name.length > NAME_TRUNCATION_LENGTH %>
<div class="modal-tooltip"> <div class="modal-tooltip">
<%= truncate(activity.my_module.experiment.project.name, lenght: 20).strip %> <%= truncate(activity.my_module.experiment.project.name, lenght: NAME_TRUNCATION_LENGTH).strip %>
<span class="modal-tooltiptext"><%= activity.my_module.experiment.project.name %></span> <span class="modal-tooltiptext"><%= activity.my_module.experiment.project.name %></span>
</div> </div>
<% else %> <% else %>
<%= activity.my_module.experiment.project.name %> <%= activity.my_module.experiment.project.name %>
<% end %>, <%=t 'Module' %>: <% end %>, <%=t 'Module' %>:
<% if activity.my_module.name.length > 20 %> <% if activity.my_module.name.length > NAME_TRUNCATION_LENGTH %>
<div class="modal-tooltip"><%= truncate(activity.my_module.name, lenght: 20) %> <div class="modal-tooltip"><%= truncate(activity.my_module.name, lenght: NAME_TRUNCATION_LENGTH) %>
<span class="modal-tooltiptext"><%= activity.my_module.name %></span> <span class="modal-tooltiptext"><%= activity.my_module.name %></span>
</div> </div>
<% else %> <% else %>

View file

@ -5,8 +5,8 @@
<li><em><%= t 'experiments.canvas.popups.no_activities' %></em></li> <li><em><%= t 'experiments.canvas.popups.no_activities' %></em></li>
<% else %> <% else %>
<% @activities.each do |activity| %> <% @activities.each do |activity| %>
<li><span class="text-muted"><%=l activity.created_at, format: :full %></span> <li><span class="text-muted"><%= l activity.created_at, format: :full %></span>
<br><span><%= activity_truncate( activity.message ) %></span> <br><span><%= activity_truncate(activity.message) %></span>
</li> </li>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -6,7 +6,7 @@
<% else %> <% else %>
<% @activities.each do |activity| %> <% @activities.each do |activity| %>
<li><span class="text-muted"><%= l activity.created_at, format: :full %></span> <li><span class="text-muted"><%= l activity.created_at, format: :full %></span>
<br><span><%= activity_truncate( activity.message, 30 ) %></span> <br><span><%= activity_truncate(activity.message) %></span>
</li> </li>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -25,7 +25,7 @@
<div class="panel-body"> <div class="panel-body">
<% if experiment.workflowimg? %> <% if experiment.workflowimg? %>
<div class="workflowimg-container"> <div class="workflowimg-container">
<%= image_tag(experiment.workflowimg.expiring_url(30), <%= image_tag(experiment.workflowimg.expiring_url(URL_SHORT_EXPIRE_TIME),
class: 'img-responsive center-block') %> class: 'img-responsive center-block') %>
</div> </div>
<% end %> <% end %>

View file

@ -1,3 +1,3 @@
<%= link_to image_tag( @experiment.workflowimg.expiring_url(30), <%= link_to image_tag( @experiment.workflowimg.expiring_url(URL_SHORT_EXPIRE_TIME),
class: 'img-responsive center-block'), class: 'img-responsive center-block'),
canvas_experiment_path(@experiment) %> canvas_experiment_path(@experiment) %>

View file

@ -15,7 +15,7 @@
<%= name %> <%= name %>
</div> </div>
<div class="pull-left file-name"> <div class="pull-left file-name">
<em><%=t "projects.reports.elements.result_asset.file_name", file: truncate( asset.file_file_name, length: 50 ) %></em> <em><%=t "projects.reports.elements.result_asset.file_name", file: truncate( asset.file_file_name, length: FILENAME_TRUNCATION_LENGTH ) %></em>
</div> </div>
<div class="pull-left user-time"> <div class="pull-left user-time">
<%=t "projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full) %> <%=t "projects.reports.elements.result_asset.user_time", user: result.user.full_name, timestamp: l(timestamp, format: :full) %>

View file

@ -1,7 +1,7 @@
<% if can_view_or_download_result_assets(result.my_module) %> <% if can_view_or_download_result_assets(result.my_module) %>
<%= link_to download_asset_path(result.asset), data: {no_turbolink: true} do %> <%= link_to download_asset_path(result.asset), data: {no_turbolink: true} do %>
<%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %> <%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %>
<p><%= truncate(result.asset.file_file_name, length: 50) %></p> <p><%= truncate(result.asset.file_file_name, length: FILENAME_TRUNCATION_LENGTH) %></p>
<% end %> <% end %>
<% else %> <% else %>
<%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %> <%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %>

View file

@ -186,21 +186,21 @@
<% if can_view_projects(@project.organization) %> <% if can_view_projects(@project.organization) %>
<a href="<%= projects_path :organization => @project.organization.id %>"> <a href="<%= projects_path :organization => @project.organization.id %>">
<% end %> <% end %>
<%= truncate( @project.organization.name, length: 20 ) %> <%= truncate( @project.organization.name, length: NAME_TRUNCATION_LENGTH ) %>
<% if can_view_projects(@project.organization) %> <% if can_view_projects(@project.organization) %>
</a> </a>
<% end %> <% end %>
</li> </li>
<% if project_page? %> <% if project_page? %>
<li class="active"> <li class="active">
<%= truncate( @project.name, length: 20 ) %> <%= truncate( @project.name, length: NAME_TRUNCATION_LENGTH ) %>
</li> </li>
<% else %> <% else %>
<li> <li>
<% if can_view_project(@project) %> <% if can_view_project(@project) %>
<a href="<%= project_url(@project) %>"> <a href="<%= project_url(@project) %>">
<% end %> <% end %>
<%= truncate( @project.name, length: 20 ) %> <%= truncate( @project.name, length: NAME_TRUNCATION_LENGTH ) %>
<% if can_view_project(@project) %> <% if can_view_project(@project) %>
</a> </a>
<% end %> <% end %>
@ -209,21 +209,21 @@
<% if experiment_page? || module_page? %> <% if experiment_page? || module_page? %>
<% if !module_page? %> <% if !module_page? %>
<li class="active"> <li class="active">
<%= truncate(@experiment.name, length: 20) %> <%= truncate(@experiment.name, length: NAME_TRUNCATION_LENGTH) %>
</li> </li>
<% else %> <% else %>
<li> <li>
<% if can_view_experiment(@experiment) %> <% if can_view_experiment(@experiment) %>
<%= link_to truncate(@experiment.name, length: 20), canvas_experiment_path(@experiment) %> <%= link_to truncate(@experiment.name, length: NAME_TRUNCATION_LENGTH), canvas_experiment_path(@experiment) %>
<% else %> <% else %>
<%= truncate(@experiment.name, length: 20) %> <%= truncate(@experiment.name, length: NAME_TRUNCATION_LENGTH) %>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>
<% end %> <% end %>
<% if module_page? %> <% if module_page? %>
<li class="active"> <li class="active">
<%= truncate( @my_module.name, length: 20 ) %> <%= truncate( @my_module.name, length: NAME_TRUNCATION_LENGTH ) %>
</li> </li>
<% end %> <% end %>
</ul> </ul>

View file

@ -61,14 +61,16 @@
<% if asset.file_present %> <% if asset.file_present %>
<%= link_to download_asset_path(asset), data: {no_turbolink: true, id: true, status: "asset-present"} do %> <%= link_to download_asset_path(asset), data: {no_turbolink: true, id: true, status: "asset-present"} do %>
<%= image_tag preview_asset_path(asset) if asset.is_image? %> <%= image_tag preview_asset_path(asset) if asset.is_image? %>
<p><%= truncate(asset.file_file_name, length: 50) %></p> <p><%= truncate(asset.file_file_name,
length: FILENAME_TRUNCATION_LENGTH) %></p>
<% end %> <% end %>
<% else %> <% else %>
<%= asset_loading_span(asset) %> <%= asset_loading_span(asset) %>
<% end %> <% end %>
<% else %> <% else %>
<%= image_tag preview_asset_path(asset) if asset.is_image? %> <%= image_tag preview_asset_path(asset) if asset.is_image? %>
<p><%= truncate(asset.file_file_name, length: 50) %></p> <p><%= truncate(asset.file_file_name,
length: FILENAME_TRUNCATION_LENGTH) %></p>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>

View file

@ -1,81 +1,138 @@
#===============================================================================
# Defaults
#===============================================================================
# Application version # Application version
APP_VERSION = '1.3.1'.freeze APP_VERSION = '1.3.1'.freeze
TAG_COLORS = [ TAG_COLORS = [
"#6C159E", '#6C159E',
"#159B5E", '#159B5E',
"#FF4500", '#FF4500',
"#008B8B", '#008B8B',
"#757575", '#757575',
"#32CD32", '#32CD32',
"#FFD700", '#FFD700',
"#48D1CC", '#48D1CC',
"#15369E", '#15369E',
"#FF69B4", '#FF69B4',
"#CD5C5C", '#CD5C5C',
"#C9C9C9", '#C9C9C9',
"#6495ED", '#6495ED',
"#DC143C", '#DC143C',
"#FF8C00", '#FF8C00',
"#C71585", '#C71585',
"#000000" '#000000'
] ].freeze
# Min/max characters for short text fields TEXT_EXTRACT_FILE_TYPES = [
'application/pdf',
'application/rtf',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.text',
'application/vnd.ms-excel',
'application/vnd.ms-powerpoint',
'application/vnd.ms-word',
'text/plain'
].freeze
DEFAULT_PRIVATE_ORG_NAME = 'My projects'.freeze
#===============================================================================
# String length
#===============================================================================
# Min characters for short text fields
NAME_MIN_LENGTH = 2 NAME_MIN_LENGTH = 2
# Max characters for short text fields
NAME_MAX_LENGTH = 255 NAME_MAX_LENGTH = 255
# Max characters for short text fields, after which they get truncated
NAME_TRUNCATION_LENGTH = 25
# Max characters for long text fields # Max characters for long text fields
TEXT_MAX_LENGTH = 10000 TEXT_MAX_LENGTH = 10000
# Max characters for color field (given in HEX format) # Max characters for color field (given in HEX format)
COLOR_MAX_LENGTH = 7 COLOR_MAX_LENGTH = 7
# Max characters for text in dropdown list element
DROPDOWN_TEXT_MAX_LENGTH = 15
# Max characters for filenames, after which they get truncated
FILENAME_TRUNCATION_LENGTH = 50
USER_INITIALS_MAX_LENGTH = 4 USER_INITIALS_MAX_LENGTH = 4
# Standard length limit for email # Standard max length for email
EMAIL_MAX_LENGTH = 254 EMAIL_MAX_LENGTH = 254
#===============================================================================
# Query/display limits
#===============================================================================
# General limited/unlimited query/display elements for pages
SEARCH_LIMIT = 20
SEARCH_NO_LIMIT = -1
# General limited query/display elements for popup modals
MODAL_SEARCH_LIMIT = 5
# Comments limited query/display elements for pages
COMMENTS_SEARCH_LIMIT = 10
# Activity limited query/display elements for pages
ACTIVITY_SEARCH_LIMIT = 20
#===============================================================================
# File and data memory size
#===============================================================================
# Max table JSON size in MB # Max table JSON size in MB
TABLE_JSON_MAX_SIZE = 20 TABLE_JSON_MAX_SIZE = 20
# Max uploaded file size in MB # Max uploaded file size in MB
FILE_MAX_SIZE = 50 FILE_MAX_SIZE = 50
# Max uploaded user avatar size in MB # Max uploaded user picture avatar size in MB
AVATAR_MAX_SIZE = 0.2 AVATAR_MAX_SIZE = 0.2
# Max characters for text in dropdown list
DROPDOWN_TEXT_MAX_LENGTH = 15 #===============================================================================
# Picture size format
#===============================================================================
MEDIUM_PIC_FORMAT = '300x300>'.freeze
THUMB_PIC_FORMAT = '100x100>'.freeze
ICON_PIC_FORMAT = '40x40>'.freeze
ICON_SMALL_PIC_FORMAT = '30x30>'.freeze
#===============================================================================
# Styling
#===============================================================================
# Dropdown top offset from the parent # Dropdown top offset from the parent
DROPDOWN_TOP_OFFSET = 20 DROPDOWN_TOP_OFFSET_PX = 20
SEARCH_LIMIT = 20 #===============================================================================
# Time
#===============================================================================
EXISTING_USERS_SEARCH_LIMIT = 5 # URL expire time, used for presigned file URLs, because outsiders shouldn't
# have access to them, but some buffer time is needed for file to be loaded
URL_SHORT_EXPIRE_TIME = 30
# Same as URL_EXPIRE_TIME, except for cases where the URL migth be used in
# another page, and hence the URL mustn't expire by then (e.g. when generating
# report and than using same HTML code in PDF, and consequently same file URL);
# it expires in exactly one day
URL_LONG_EXPIRE_TIME = 86_400
SHOW_ALL_RESULTS = -1 #===============================================================================
# Space
QUERY_MIN_LENGTH = 2 #===============================================================================
TEXT_EXTRACT_FILE_TYPES = [
"application/pdf",
"application/rtf",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.oasis.opendocument.presentation",
"application/vnd.oasis.opendocument.spreadsheet",
"application/vnd.oasis.opendocument.text",
"application/vnd.ms-excel",
"application/vnd.ms-powerpoint",
"application/vnd.ms-word",
"text/plain"
]
# 1 MB of space is minimal for organizations (in B) # 1 MB of space is minimal for organizations (in B)
MINIMAL_ORGANIZATION_SPACE_TAKEN = 1.megabyte MINIMAL_ORGANIZATION_SPACE_TAKEN = 1.megabyte
# additional space of each file is added to its estimated # additional space of each file is added to its estimated
# size to account for DB indexes size etc. # size to account for DB indexes size etc.
ASSET_ESTIMATED_SIZE_FACTOR = 1.1 ASSET_ESTIMATED_SIZE_FACTOR = 1.1
DEFAULT_PRIVATE_ORG_NAME = "My projects" #===============================================================================
# External URL
#===============================================================================
# External URLs
HTTP = 'http://'.freeze HTTP = 'http://'.freeze
TUTORIALS_URL = (HTTP + 'scinote.net/product/tutorials/').freeze TUTORIALS_URL = (HTTP + 'scinote.net/product/tutorials/').freeze
FAQ_URL = (HTTP + 'scinote.net/product/faq/').freeze FAQ_URL = (HTTP + 'scinote.net/product/faq/').freeze
@ -83,6 +140,12 @@ SUPPORT_URL = (HTTP + 'scinote.net/plans/#prof-support').freeze
PLANS_URL = (HTTP + 'scinote.net/plans/').freeze PLANS_URL = (HTTP + 'scinote.net/plans/').freeze
CONTACT_URL = (HTTP + 'scinote.net/about-us/').freeze CONTACT_URL = (HTTP + 'scinote.net/about-us/').freeze
RELEASE_NOTES_URL = (HTTP + 'scinote.net/docs/release-notes/').freeze RELEASE_NOTES_URL = (HTTP + 'scinote.net/docs/release-notes/').freeze
# Default user picture avatar
DEFAULT_AVATAR_URL = '/images/:style/missing.png'.freeze
#===============================================================================
# Other
#===============================================================================
# ) \ / ( # ) \ / (
# /|\ )\_/( /|\ # /|\ )\_/( /|\
@ -104,15 +167,15 @@ RELEASE_NOTES_URL = (HTTP + 'scinote.net/docs/release-notes/').freeze
# * l / V )) V \ l * # * l / V )) V \ l *
# l/ // \I # l/ // \I
KICKSTARTER_SUPPORTERS = [ KICKSTARTER_SUPPORTERS = [
"Manuela Lanzafame", 'Manuela Lanzafame',
"Fluckiger Rudolf", 'Fluckiger Rudolf',
"Emily Gleason", 'Emily Gleason',
"Benjamin E Doremus", 'Benjamin E Doremus',
"Chord Pet Wearable", 'Chord Pet Wearable',
"Chris Taylor", 'Chris Taylor',
"Abraham White", 'Abraham White',
"Ryotaro Eguchi", 'Ryotaro Eguchi',
"Simon Waldherr", 'Simon Waldherr',
"Isaac Sandaljian", 'Isaac Sandaljian',
"Markus Rademacher" 'Markus Rademacher'
] ].freeze