Ruby constants are now automatically available in JS. Refactoring was needed.

This commit is contained in:
Matej Zrimšek 2016-10-05 17:45:20 +02:00
parent a3dfb59558
commit 0780bd2416
52 changed files with 439 additions and 394 deletions

View file

@ -182,7 +182,8 @@ 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_PX %>)});
top: (parentTopPos +
<%= Constants::DROPDOWN_TOP_OFFSET_PX %>)});
}
});
}
@ -208,7 +209,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_PX %>) });
.offset({ top: (offset + <%= Constants::DROPDOWN_TOP_OFFSET_PX %>) });
});
}

View file

@ -497,7 +497,7 @@ function importProtocolFromFile(
$.extend(data_json, params);
var rough_size = roughSizeOfObject(data_json);
if (rough_size > <%= FILE_MAX_SIZE.megabytes %>) {
if (rough_size > <%= Constants::FILE_MAX_SIZE_MB.megabytes %>) {
// Call the callback function
resultCallback({ name: protocolJson["name"], new_name: null, status: "size_too_large" });
return;

View file

@ -1,47 +1,4 @@
// All the constants from server-side available on client-side.
// All Ruby global constants are provided to JS
<%= Constants.output_to_js %>
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 %>;
// JS global constants

View file

@ -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: "<%= Constants::NAME_MIN_LENGTH %>",
NAME_MAX_LENGTH: "<%= Constants::NAME_MAX_LENGTH %>",
TEXT_MAX_LENGTH: "<%= Constants::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: "<%= Constants::FILE_MAX_SIZE_MB.megabytes %>",
AVATAR: "<%= Constants::AVATAR_MAX_SIZE_MB.megabytes %>"
});
function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) {
@ -139,9 +139,9 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
if (file.size > fileTypeEnum) {
switch (fileTypeEnum) {
case FileTypeSizeEnum.FILE:
return "<%= I18n.t 'general.file.size_exceeded', file_size: FILE_MAX_SIZE %>".strToErrorFormat();
return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>".strToErrorFormat();
case FileTypeSizeEnum.AVATAR:
return "<%= I18n.t 'general.file.size_exceeded', file_size: AVATAR_MAX_SIZE %>".strToErrorFormat();
return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::AVATAR_MAX_SIZE_MB %>".strToErrorFormat();
}
}
};

View file

@ -106,7 +106,7 @@ class AssetsController < ApplicationController
success_action_status: '201',
acl: 'private',
storage_class: "STANDARD",
content_length_range: 1..FILE_MAX_SIZE.megabytes,
content_length_range: 1..Constants::FILE_MAX_SIZE_MB.megabytes,
content_type: asset.file_content_type
)
posts.push({
@ -121,7 +121,7 @@ class AssetsController < ApplicationController
success_action_status: '201',
acl: 'public-read',
storage_class: "REDUCED_REDUNDANCY",
content_length_range: 1..FILE_MAX_SIZE.megabytes,
content_length_range: 1..Constants::FILE_MAX_SIZE_MB.megabytes,
content_type: asset.file_content_type
)
posts.push({

View file

@ -162,7 +162,7 @@ class MyModuleCommentsController < ApplicationController
def load_vars
@last_comment_id = params[:from].to_i
@per_page = COMMENTS_SEARCH_LIMIT
@per_page = Constants::COMMENTS_SEARCH_LIMIT
@my_module = MyModule.find_by_id(params[:my_module_id])
unless @my_module

View file

@ -11,8 +11,9 @@ class OrganizationsController < ApplicationController
if params[:file]
begin
if params[:file].size > FILE_MAX_SIZE.megabytes
error = t 'general.file.size_exceeded', file_size: FILE_MAX_SIZE
if params[:file].size > Constants::FILE_MAX_SIZE_MB.megabytes
error = t 'general.file.size_exceeded',
file_size: Constants::FILE_MAX_SIZE_MB
format.html {
flash[:alert] = error

View file

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

View file

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

View file

@ -24,7 +24,7 @@ class SearchController < ApplicationController
search_tables if @search_category == :tables
search_comments if @search_category == :comments
@search_pages = (@search_count.to_f / SEARCH_LIMIT.to_f).ceil
@search_pages = (@search_count.to_f / Constants::SEARCH_LIMIT.to_f).ceil
@start_page = @search_page - 2
@start_page = 1 if @start_page < 1
@end_page = @start_page + 4
@ -48,27 +48,29 @@ class SearchController < ApplicationController
@search_page = params[:page].to_i || 1
@display_query = @search_query
if @search_query.length < NAME_MIN_LENGTH
if @search_query.length < Constants::NAME_MIN_LENGTH
flash[:error] = t 'general.query.length_too_short',
min_length: NAME_MIN_LENGTH
min_length: Constants::NAME_MIN_LENGTH
return redirect_to :back
end
# splits the search query to validate all entries
@splited_query = @search_query.split
if @splited_query.first.length < NAME_MIN_LENGTH
if @splited_query.first.length < Constants::NAME_MIN_LENGTH
flash[:error] = t 'general.query.length_too_short',
min_length: NAME_MIN_LENGTH
min_length: Constants::NAME_MIN_LENGTH
redirect_to :back
elsif @splited_query.first.length > TEXT_MAX_LENGTH
elsif @splited_query.first.length > Constants::TEXT_MAX_LENGTH
flash[:error] = t 'general.query.length_too_long',
max_length: TEXT_MAX_LENGTH
max_length: Constants::TEXT_MAX_LENGTH
redirect_to :back
elsif @splited_query.length > 1
@search_query = ''
@splited_query.each_with_index do |w, i|
@search_query += "#{@splited_query[i]} " if w.length >= NAME_MIN_LENGTH
if w.length >= Constants::NAME_MIN_LENGTH
@search_query += "#{@splited_query[i]} "
end
end
else
@search_query = @splited_query.join(' ')

View file

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

View file

@ -229,7 +229,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
success_action_status: '201',
acl: 'public-read',
storage_class: "REDUCED_REDUNDANCY",
content_length_range: 1..FILE_MAX_SIZE.megabytes,
content_length_range: 1..Constants::FILE_MAX_SIZE_MB.megabytes,
content_type: content_type
)
posts.push({

View file

@ -121,17 +121,19 @@ class Users::SettingsController < ApplicationController
format.json {
if params.include? :existing_query and
query = params[:existing_query].strip()
if query.length < NAME_MIN_LENGTH
if query.length < Constants::NAME_MIN_LENGTH
render json: {
"existing_query": [
t('general.query.length_too_short', min_length: NAME_MIN_LENGTH)
t('general.query.length_too_short',
min_length: Constants::NAME_MIN_LENGTH)
]
},
status: :unprocessable_entity
elsif query.length > NAME_MAX_LENGTH
elsif query.length > Constants::NAME_MAX_LENGTH
render json: {
"existing_query": [
t('general.query.length_too_long', max_length: NAME_MAX_LENGTH)
t('general.query.length_too_long',
max_length: Constants::NAME_MAX_LENGTH)
]
},
status: :unprocessable_entity
@ -140,7 +142,8 @@ class Users::SettingsController < ApplicationController
nr_of_results = User.search(true, query, @org).count
users = User.search(false, query, @org).limit(MODAL_SEARCH_LIMIT)
users = User.search(false, query, @org)
.limit(Constants::MODAL_SEARCH_LIMIT)
nr_of_members = User.organization_search(false, query, @org).count

View file

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

View file

@ -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: URL_LONG_EXPIRE_TIME)
url = prefix + asset.url(:medium, timeout: Constants::URL_LONG_EXPIRE_TIME)
image_tag(url)
end

View file

@ -6,11 +6,11 @@ class Asset < ActiveRecord::Base
require 'tempfile'
# Paperclip validation
has_attached_file :file, styles: { medium: MEDIUM_PIC_FORMAT }
has_attached_file :file, styles: { medium: Constants::MEDIUM_PIC_FORMAT }
validates_attachment :file,
presence: true,
size: { less_than: FILE_MAX_SIZE.megabytes }
size: { less_than: Constants::FILE_MAX_SIZE_MB.megabytes }
validates :estimated_size, presence: true
validates :file_present, inclusion: { in: [true, false] }
@ -71,14 +71,14 @@ class Asset < ActiveRecord::Base
)
step_ids =
Step
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.joins(:step_assets)
.select("step_assets.id")
.distinct
result_ids =
Result
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.joins(:result_asset)
.select("result_assets.id")
.distinct
@ -121,10 +121,10 @@ class Asset < ActiveRecord::Base
)
# Show all results if needed
if page != SEARCH_NO_LIMIT
if page != Constants::SEARCH_NO_LIMIT
ids = ids
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
Asset
@ -140,7 +140,9 @@ class Asset < ActiveRecord::Base
end
def text?
TEXT_EXTRACT_FILE_TYPES.any? { |v| file_content_type.start_with? v }
Constants::TEXT_EXTRACT_FILE_TYPES.any? do |v|
file_content_type.start_with? v
end
end
# TODO: get the current_user
@ -235,7 +237,7 @@ class Asset < ActiveRecord::Base
es += get_octet_length_record(asset_text_datum, :data)
es += get_octet_length_record(asset_text_datum, :data_vector)
end
es = es * ASSET_ESTIMATED_SIZE_FACTOR
es = es * Constants::ASSET_ESTIMATED_SIZE_FACTOR
update(estimated_size: es)
Rails.logger.info "Asset #{id}: Estimated size successfully calculated"
@ -246,7 +248,7 @@ class Asset < ActiveRecord::Base
end
end
def url(style = :original, timeout: URL_SHORT_EXPIRE_TIME)
def url(style = :original, timeout: Constants::URL_SHORT_EXPIRE_TIME)
if file.is_stored_on_s3?
presigned_url(style, timeout: timeout)
else
@ -255,7 +257,9 @@ 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: URL_SHORT_EXPIRE_TIME)
def presigned_url(style = :original,
download: false,
timeout: Constants::URL_SHORT_EXPIRE_TIME)
if file.is_stored_on_s3?
if download
download_arg = 'attachment; filename=' + URI.escape(file_file_name)

View file

@ -2,7 +2,9 @@ class Checklist < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :name, nullify: false
validates :name, presence: true, length: { maximum: TEXT_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :step, presence: true
belongs_to :step, inverse_of: :checklists
@ -23,7 +25,7 @@ class Checklist < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1)
step_ids =
Step
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -43,12 +45,12 @@ class Checklist < ActiveRecord::Base
.where_attributes_like(["checklists.name", "checklist_items.text"], a_query)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -1,6 +1,8 @@
class ChecklistItem < ActiveRecord::Base
auto_strip_attributes :text, nullify: false
validates :text, presence: true, length: { maximum: TEXT_MAX_LENGTH }
validates :text,
presence: true,
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :checklist, presence: true
validates :checked, inclusion: { in: [true, false] }

View file

@ -2,7 +2,9 @@ class Comment < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :message, nullify: false
validates :message, presence: true, length: { maximum: TEXT_MAX_LENGTH }
validates :message,
presence: true,
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :user, presence: true
validate :belongs_to_only_one_object
@ -24,19 +26,19 @@ class Comment < ActiveRecord::Base
)
project_ids =
Project
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
my_module_ids =
MyModule
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
step_ids =
Step
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
result_ids =
Result
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
@ -73,12 +75,12 @@ class Comment < ActiveRecord::Base
)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -2,7 +2,7 @@ class CustomField < ActiveRecord::Base
auto_strip_attributes :name, nullify: false
validates :name,
presence: true,
length: { maximum: NAME_MAX_LENGTH },
length: { maximum: Constants::NAME_MAX_LENGTH },
uniqueness: { scope: :organization, case_sensitive: true },
exclusion: { in: ['Assigned', 'Sample name', 'Sample type',
'Sample group', 'Added on', 'Added by'] }

View file

@ -19,9 +19,10 @@ class Experiment < ActiveRecord::Base
auto_strip_attributes :name, :description, nullify: false
validates :name,
length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH },
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH },
uniqueness: { scope: :project, case_sensitive: false }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :project, presence: true
validates :created_by, presence: true
validates :last_modified_by, presence: true
@ -35,7 +36,7 @@ class Experiment < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1)
project_ids =
Project
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -62,12 +63,12 @@ class Experiment < ActiveRecord::Base
end
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -5,8 +5,9 @@ class MyModule < ActiveRecord::Base
auto_strip_attributes :name, :description, nullify: false
validates :name,
length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH }
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :x, :y, :workflow_order, presence: true
validates :experiment, presence: true
validates :my_module_group, presence: true, if: "!my_module_group_id.nil?"
@ -43,7 +44,7 @@ class MyModule < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1)
exp_ids =
Experiment
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -70,12 +71,12 @@ class MyModule < ActiveRecord::Base
end
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end
@ -145,13 +146,13 @@ class MyModule < ActiveRecord::Base
)
end
def last_activities(count = ACTIVITY_SEARCH_LIMIT)
def last_activities(count = Constants::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 = COMMENTS_SEARCH_LIMIT)
def last_comments(last_id = 1, per_page = Constants::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 +162,7 @@ class MyModule < ActiveRecord::Base
comments.reverse
end
def last_activities(last_id = 1, count = ACTIVITY_SEARCH_LIMIT)
def last_activities(last_id = 1, count = Constants::ACTIVITY_SEARCH_LIMIT)
last_id = 9999999999999 if last_id <= 1
Activity.joins(:my_module)
.where(my_module_id: id)

View file

@ -2,7 +2,9 @@ class MyModuleGroup < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :name, nullify: false
validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :experiment, presence: true
belongs_to :experiment, inverse_of: :my_module_groups
@ -12,7 +14,7 @@ class MyModuleGroup < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1)
exp_ids =
Experiment
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
@ -32,12 +34,12 @@ class MyModuleGroup < ActiveRecord::Base
.where_attributes_like("my_module_groups.name", a_query)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -5,8 +5,9 @@ class Organization < ActiveRecord::Base
auto_strip_attributes :name, :description, nullify: false
validates :name,
length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH }
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :space_taken, presence: true
belongs_to :created_by, :foreign_key => 'created_by_id', :class_name => 'User'
@ -274,7 +275,7 @@ class Organization < ActiveRecord::Base
end
end
# project.experiments.each |experiment|
self.space_taken = [st, MINIMAL_ORGANIZATION_SPACE_TAKEN].max
self.space_taken = [st, Constants::MINIMAL_ORGANIZATION_SPACE_TAKEN].max
Rails::logger.info "Organization #{self.id}: " +
"space (re)calculated to: " +
"#{self.space_taken}B (#{number_to_human_size(self.space_taken)})"
@ -293,7 +294,8 @@ class Organization < ActiveRecord::Base
# Release specified amount of bytes
def release_space(space)
orig_space = self.space_taken
self.space_taken = [space_taken - space, MINIMAL_ORGANIZATION_SPACE_TAKEN].max
self.space_taken = [space_taken - space,
Constants::MINIMAL_ORGANIZATION_SPACE_TAKEN].max
Rails::logger.info "Organization #{self.id}: " +
"space released: " +
"#{orig_space}B - #{space}B = " +

View file

@ -5,7 +5,8 @@ class Project < ActiveRecord::Base
auto_strip_attributes :name, nullify: false
validates :name,
length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH },
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH },
uniqueness: { scope: :organization, case_sensitive: false }
validates :visibility, presence: true
validates :organization, presence: true
@ -64,22 +65,22 @@ class Project < ActiveRecord::Base
end
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end
def last_activities(count = ACTIVITY_SEARCH_LIMIT)
def last_activities(count = Constants::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 = COMMENTS_SEARCH_LIMIT)
def last_comments(last_id = 1, per_page = Constants::COMMENTS_SEARCH_LIMIT)
last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:project_comment)
.where(project_comments: { project_id: id })

View file

@ -15,8 +15,8 @@ class Protocol < ActiveRecord::Base
auto_strip_attributes :name, :description, nullify: false
# Name is required when its actually specified (i.e. :in_repository? is true)
validates :name, length: { maximum: NAME_MAX_LENGTH }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :organization, presence: true
validates :protocol_type, presence: true
@ -76,7 +76,7 @@ class Protocol < ActiveRecord::Base
module_ids =
MyModule
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
where_str =
@ -140,12 +140,12 @@ class Protocol < ActiveRecord::Base
)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -1,11 +1,12 @@
class ProtocolKeyword < ActiveRecord::Base
auto_strip_attributes :name, nullify: false
validates :name,
length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH }
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH }
validates :organization, presence: true
belongs_to :organization, inverse_of: :protocol_keywords
has_many :protocol_protocol_keywords, inverse_of: :protocol_keyword, dependent: :destroy
has_many :protocols, through: :protocol_protocol_keywords
end
end

View file

@ -3,9 +3,10 @@ class Report < ActiveRecord::Base
auto_strip_attributes :name, :description, nullify: false
validates :name,
length: { minimum: NAME_MIN_LENGTH, maximum: NAME_MAX_LENGTH },
length: { minimum: Constants::NAME_MIN_LENGTH,
maximum: Constants::NAME_MAX_LENGTH },
uniqueness: { scope: [:user, :project], case_sensitive: false }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :project, presence: true
validates :user, presence: true
@ -26,7 +27,7 @@ class Report < ActiveRecord::Base
project_ids =
Project
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -53,12 +54,12 @@ class Report < ActiveRecord::Base
)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -3,7 +3,7 @@ class Result < ActiveRecord::Base
auto_strip_attributes :name, nullify: false
validates :user, :my_module, presence: true
validates :name, length: { maximum: NAME_MAX_LENGTH }
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
validate :text_or_asset_or_table
belongs_to :user, inverse_of: :results
@ -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, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -59,12 +59,12 @@ class Result < ActiveRecord::Base
end
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end
@ -72,7 +72,7 @@ class Result < ActiveRecord::Base
is_asset ? result_asset.space_taken : 0
end
def last_comments(last_id = 1, per_page = COMMENTS_SEARCH_LIMIT)
def last_comments(last_id = 1, per_page = Constants::COMMENTS_SEARCH_LIMIT)
last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:result_comment)
.where(result_comments: { result_id: id })

View file

@ -1,6 +1,8 @@
class ResultText < ActiveRecord::Base
auto_strip_attributes :text, nullify: false
validates :text, presence: true, length: { maximum: TEXT_MAX_LENGTH }
validates :text,
presence: true,
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :result, presence: true
belongs_to :result, inverse_of: :result_text

View file

@ -2,7 +2,9 @@ class Sample < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :name, nullify: false
validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :user, :organization, presence: true
belongs_to :user, inverse_of: :samples
@ -59,12 +61,12 @@ class Sample < ActiveRecord::Base
)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -1,6 +1,8 @@
class SampleCustomField < ActiveRecord::Base
auto_strip_attributes :value, nullify: false
validates :value, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :value,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :custom_field, :sample, presence: true
belongs_to :custom_field, inverse_of: :sample_custom_fields

View file

@ -1,7 +1,11 @@
class SampleGroup < ActiveRecord::Base
auto_strip_attributes :name, :color, nullify: false
validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :color, presence: true, length: { maximum: COLOR_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :color,
presence: true,
length: { maximum: Constants::COLOR_MAX_LENGTH }
validates :organization, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'

View file

@ -1,6 +1,8 @@
class SampleType < ActiveRecord::Base
auto_strip_attributes :name, nullify: false
validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :organization, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'

View file

@ -2,8 +2,10 @@ class Step < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :name, :description, nullify: false
validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :description, length: { maximum: TEXT_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :position, presence: true
validates :completed, inclusion: { in: [true, false] }
validates :user, :protocol, presence: true
@ -42,7 +44,7 @@ class Step < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1)
protocol_ids =
Protocol
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -61,12 +63,12 @@ class Step < ActiveRecord::Base
.where_attributes_like([:name, :description], a_query)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end
@ -86,7 +88,7 @@ class Step < ActiveRecord::Base
protocol.present? ? protocol.my_module : nil
end
def last_comments(last_id = 1, per_page = COMMENTS_SEARCH_LIMIT)
def last_comments(last_id = 1, per_page = Constants::COMMENTS_SEARCH_LIMIT)
last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:step_comment)
.where(step_comments: { step_id: id })

View file

@ -3,7 +3,7 @@ class Table < ActiveRecord::Base
validates :contents,
presence: true,
length: { maximum: TABLE_JSON_MAX_SIZE.megabytes }
length: { maximum: Constants::TABLE_JSON_MAX_SIZE_MB.megabytes }
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
@ -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, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.joins(:step_tables)
.select("step_tables.id")
.distinct
result_ids =
Result
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.joins(:result_table)
.select("result_tables.id")
.distinct
@ -55,12 +55,12 @@ class Table < ActiveRecord::Base
new_query = table_query
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end
@ -78,4 +78,3 @@ class Table < ActiveRecord::Base
end
end
end

View file

@ -2,8 +2,12 @@ class Tag < ActiveRecord::Base
include SearchableModel
auto_strip_attributes :name, :color, nullify: false
validates :name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :color, presence: true, length: { maximum: COLOR_MAX_LENGTH }
validates :name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :color,
presence: true,
length: { maximum: Constants::COLOR_MAX_LENGTH }
validates :project, presence: true
belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User'
@ -15,7 +19,7 @@ class Tag < ActiveRecord::Base
def self.search(user, include_archived, query = nil, page = 1)
project_ids =
Project
.search(user, include_archived, nil, SEARCH_NO_LIMIT)
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
.select("id")
if query
@ -34,12 +38,12 @@ class Tag < ActiveRecord::Base
.where_attributes_like(:name, a_query)
# Show all results if needed
if page == SEARCH_NO_LIMIT
if page == Constants::SEARCH_NO_LIMIT
new_query
else
new_query
.limit(SEARCH_LIMIT)
.offset((page - 1) * SEARCH_LIMIT)
.limit(Constants::SEARCH_LIMIT)
.offset((page - 1) * Constants::SEARCH_LIMIT)
end
end

View file

@ -5,12 +5,12 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable, stretches: 10
has_attached_file :avatar,
styles: {
medium: MEDIUM_PIC_FORMAT,
thumb: THUMB_PIC_FORMAT,
icon: ICON_PIC_FORMAT,
icon_small: ICON_SMALL_PIC_FORMAT
medium: Constants::MEDIUM_PIC_FORMAT,
thumb: Constants::THUMB_PIC_FORMAT,
icon: Constants::ICON_PIC_FORMAT,
icon_small: Constants::ICON_SMALL_PIC_FORMAT
},
default_url: DEFAULT_AVATAR_URL
default_url: Constants::DEFAULT_AVATAR_URL
enum tutorial_status: {
no_tutorial_done: 0,
@ -18,15 +18,19 @@ class User < ActiveRecord::Base
}
auto_strip_attributes :full_name, :initials, nullify: false
validates :full_name, presence: true, length: { maximum: NAME_MAX_LENGTH }
validates :full_name,
presence: true,
length: { maximum: Constants::NAME_MAX_LENGTH }
validates :initials,
presence: true,
length: { maximum: USER_INITIALS_MAX_LENGTH }
validates :email, presence: true, length: { maximum: EMAIL_MAX_LENGTH }
length: { maximum: Constants::USER_INITIALS_MAX_LENGTH }
validates :email,
presence: true,
length: { maximum: Constants::EMAIL_MAX_LENGTH }
validates_attachment :avatar,
:content_type => { :content_type => ["image/jpeg", "image/png"] },
size: { less_than: AVATAR_MAX_SIZE.megabytes }
size: { less_than: Constants::AVATAR_MAX_SIZE_MB.megabytes }
validates :time_zone, presence: true
validate :time_zone_check
@ -234,7 +238,8 @@ 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 = ACTIVITY_SEARCH_LIMIT)
def last_activities(last_activity_id = nil,
per_page = Constants::ACTIVITY_SEARCH_LIMIT)
# TODO replace with some kind of Infinity value
last_activity_id = 999999999999999999999999 if last_activity_id < 1
Activity

View file

@ -6,16 +6,21 @@
<%= activity_truncate(activity.message) %>
<% if activity.my_module %>
[<%=t 'Project' %>:
<% if activity.my_module.experiment.project.name.length > NAME_TRUNCATION_LENGTH %>
<% if activity.my_module.experiment.project.name.length >
Constants::NAME_TRUNCATION_LENGTH %>
<div class="modal-tooltip">
<%= truncate(activity.my_module.experiment.project.name, lenght: NAME_TRUNCATION_LENGTH).strip %>
<%= truncate(activity.my_module.experiment.project.name,
lenght: Constants::NAME_TRUNCATION_LENGTH).strip %>
<span class="modal-tooltiptext"><%= activity.my_module.experiment.project.name %></span>
</div>
<% else %>
<%= activity.my_module.experiment.project.name %>
<% end %>, <%=t 'Module' %>:
<% if activity.my_module.name.length > NAME_TRUNCATION_LENGTH %>
<div class="modal-tooltip"><%= truncate(activity.my_module.name, lenght: NAME_TRUNCATION_LENGTH) %>
<% if activity.my_module.name.length >
Constants::NAME_TRUNCATION_LENGTH %>
<div class="modal-tooltip"><%= truncate(
activity.my_module.name,
lenght: Constants::NAME_TRUNCATION_LENGTH) %>
<span class="modal-tooltiptext"><%= activity.my_module.name %></span>
</div>
<% else %>

View file

@ -63,7 +63,13 @@
<%= bootstrap_form_for [@my_module, @new_mmt], remote: true, format: :json, html: { class: 'add-tag-form' } do |f| %>
<div class="col-xs-6">
<div class="well well-sm">
<%= collection_select(:my_module_tag, :tag_id, @unassigned_tags.collect{ |t| t.name = t.name.truncate(DROPDOWN_TEXT_MAX_LENGTH, omission: '...'); t }, :id, :name, {}, { class: 'selectpicker' }) %>
<%= collection_select(:my_module_tag,
:tag_id,
@unassigned_tags.collect{ |t| t.name = t.name.truncate(Constants::DROPDOWN_TEXT_MAX_LENGTH, omission: '...'); t },
:id,
:name,
{},
{ class: 'selectpicker' }) %>
<%= f.button class: 'btn btn-primary' do %>
<span class="glyphicon glyphicon-plus"></span>
<span class="hidden-xs"><%= t("experiments.canvas.modal_manage_tags.create") %></span>

View file

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

View file

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

View file

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

View file

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

View file

@ -15,7 +15,7 @@
<% else %>
<img src="/images/logo.png" class="with-version" id="logo">
<span class="version">
<%= APP_VERSION %>
<%= Constants::APP_VERSION %>
</span>
<% end %>
</a>
@ -55,6 +55,7 @@
<!-- profile info -->
<ul class="nav navbar-nav navbar-right">
<!-- notifications -->
<li class="dropdown">
<a href="#"
id="notifications-dropdown"
@ -74,21 +75,27 @@
<li class="notifications-dropdown-footer"><%= link_to t('notifications.show_all'), notifications_path %></li>
</ul>
</li>
<!-- help -->
<li class="dropdown">
<a href="#" id="help-link" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-info-sign"></span>
</a>
<ul class="dropdown-menu">
<li><%= link_to t('nav.help.tutorials'), TUTORIALS_URL, target: "_blank" %></li>
<li><%= link_to t('nav.help.faq'), FAQ_URL, target: "_blank" %></li>
<li><%= link_to t('nav.help.release_notes'), RELEASE_NOTES_URL, target: "_blank" %></li>
<li><%= link_to t('nav.help.support'), SUPPORT_URL, target: "_blank" %></li>
<li><%= link_to t('nav.help.plans'), PLANS_URL, target: "_blank" %></li>
<li><%= link_to t('nav.help.contact'), CONTACT_URL, target: "_blank" %></li>
<li><%= link_to t('nav.help.tutorials'),
Constants::TUTORIALS_URL %></li>
<li><%= link_to t('nav.help.faq'),
Constants::FAQ_URL %></li>
<li><%= link_to t('nav.help.support'),
Constants::SUPPORT_URL %></li>
<li><%= link_to t('nav.help.plans'),
Constants::PLANS_URL %></li>
<li><%= link_to t('nav.help.contact'),
Constants::CONTACT_URL %></li>
</ul>
</li>
<!-- greetings -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span><%= t('nav.user_greeting', full_name: current_user.full_name) %></span>

View file

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

View file

@ -1,181 +1,184 @@
#===============================================================================
# Defaults
#===============================================================================
class Constants
#=============================================================================
# Defaults
#=============================================================================
# Application version
APP_VERSION = '1.3.1'.freeze
# Application version
APP_VERSION = '1.3.1'.freeze
TAG_COLORS = [
'#6C159E',
'#159B5E',
'#FF4500',
'#008B8B',
'#757575',
'#32CD32',
'#FFD700',
'#48D1CC',
'#15369E',
'#FF69B4',
'#CD5C5C',
'#C9C9C9',
'#6495ED',
'#DC143C',
'#FF8C00',
'#C71585',
'#000000'
].freeze
TAG_COLORS = [
'#6C159E',
'#159B5E',
'#FF4500',
'#008B8B',
'#757575',
'#32CD32',
'#FFD700',
'#48D1CC',
'#15369E',
'#FF69B4',
'#CD5C5C',
'#C9C9C9',
'#6495ED',
'#DC143C',
'#FF8C00',
'#C71585',
'#000000'
].freeze
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
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
# Organization name for default admin user
DEFAULT_PRIVATE_ORG_NAME = 'My projects'.freeze
#===============================================================================
# String length
#===============================================================================
#=============================================================================
# String length
#=============================================================================
# Min characters for short text fields
NAME_MIN_LENGTH = 2
# Max characters for short text fields
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
TEXT_MAX_LENGTH = 10000
# Max characters for color field (given in HEX format)
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
# Min characters for short text fields
NAME_MIN_LENGTH = 2
# Max characters for short text fields
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
TEXT_MAX_LENGTH = 10000
# Max characters for color field (given in HEX format)
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
# Standard max length for email
EMAIL_MAX_LENGTH = 254
USER_INITIALS_MAX_LENGTH = 4
# Standard max length for email
EMAIL_MAX_LENGTH = 254
#===============================================================================
# Query/display limits
#===============================================================================
#=============================================================================
# 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
# 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
#===============================================================================
#=============================================================================
# File and data memory size
#=============================================================================
# Max table JSON size in MB
TABLE_JSON_MAX_SIZE = 20
# Max uploaded file size in MB
FILE_MAX_SIZE = 50
# Max uploaded user picture avatar size in MB
AVATAR_MAX_SIZE = 0.2
# Max table JSON size in MB
TABLE_JSON_MAX_SIZE_MB = 20
# Max uploaded file size in MB
FILE_MAX_SIZE_MB = 50
# Max uploaded user picture avatar size in MB
AVATAR_MAX_SIZE_MB = 0.2
#===============================================================================
# Picture size format
#===============================================================================
#=============================================================================
# Picture size format
#=============================================================================
MEDIUM_PIC_FORMAT = '300x300>'.freeze
THUMB_PIC_FORMAT = '100x100>'.freeze
ICON_PIC_FORMAT = '40x40>'.freeze
ICON_SMALL_PIC_FORMAT = '30x30>'.freeze
MEDIUM_PIC_FORMAT = '300x300>'.freeze
THUMB_PIC_FORMAT = '100x100>'.freeze
ICON_PIC_FORMAT = '40x40>'.freeze
ICON_SMALL_PIC_FORMAT = '30x30>'.freeze
#===============================================================================
# Styling
#===============================================================================
#=============================================================================
# Styling
#=============================================================================
# Dropdown top offset from the parent
DROPDOWN_TOP_OFFSET_PX = 20
# Dropdown top offset from the parent
DROPDOWN_TOP_OFFSET_PX = 20
#===============================================================================
# Time
#===============================================================================
#=============================================================================
# Time
#=============================================================================
# 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
# 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
#===============================================================================
# Space
#===============================================================================
#=============================================================================
# Space
#=============================================================================
# 1 MB of space is minimal for organizations (in B)
MINIMAL_ORGANIZATION_SPACE_TAKEN = 1.megabyte
# additional space of each file is added to its estimated
# size to account for DB indexes size etc.
ASSET_ESTIMATED_SIZE_FACTOR = 1.1
# 1 MB of space is minimal for organizations (in B)
MINIMAL_ORGANIZATION_SPACE_TAKEN = 1.megabyte
# additional space of each file is added to its estimated
# size to account for DB indexes size etc.
ASSET_ESTIMATED_SIZE_FACTOR = 1.1
#===============================================================================
# External URL
#===============================================================================
#=============================================================================
# External URL
#=============================================================================
HTTP = 'http://'.freeze
TUTORIALS_URL = (HTTP + 'scinote.net/product/tutorials/').freeze
FAQ_URL = (HTTP + 'scinote.net/product/faq/').freeze
SUPPORT_URL = (HTTP + 'scinote.net/plans/#prof-support').freeze
PLANS_URL = (HTTP + 'scinote.net/plans/').freeze
CONTACT_URL = (HTTP + 'scinote.net/about-us/').freeze
RELEASE_NOTES_URL = (HTTP + 'scinote.net/docs/release-notes/').freeze
# Default user picture avatar
DEFAULT_AVATAR_URL = '/images/:style/missing.png'.freeze
HTTP = 'http://'.freeze
TUTORIALS_URL = (HTTP + 'scinote.net/product/tutorials/').freeze
FAQ_URL = (HTTP + 'scinote.net/product/faq/').freeze
SUPPORT_URL = (HTTP + 'scinote.net/plans/#prof-support').freeze
PLANS_URL = (HTTP + 'scinote.net/plans/').freeze
CONTACT_URL = (HTTP + 'scinote.net/about-us/').freeze
RELEASE_NOTES_URL = (HTTP + 'scinote.net/docs/release-notes/').freeze
# Default user picture avatar
DEFAULT_AVATAR_URL = '/images/:style/missing.png'.freeze
#===============================================================================
# Other
#===============================================================================
#=============================================================================
# Other
#=============================================================================
# ) \ / (
# /|\ )\_/( /|\
# * / | \ (/\|/\) / | \ *
# |`.____________________/__|__o____\`|'/___o__|__\___________________.'|
# | '^` \|/ '^` |
# | V |
# | _____ _ _ __ |
# | |_ _| |__ __ _ _ __ | | __ _ _ ___ _ _ ( | |
# | | | | '_ \ / _` | '_ \| |/ / | | | |/ _ \| | | | | ) |
# | | | | | | | (_| | | | | < | |_| | ( | | |_| | \_/ |
# | |_| |_| |_|\__,_|_| |_|_|\_\ \__, |\___/ \_,|_| _ |
# | |___/ (_) |
# | |
# | Special Thank You for supporting sciNote on Kicstarter goes |
# | to the following supporters |
# | ._________________________________________________________________. |
# |' l /\ / \\ \ /\ l `|
# * l / V )) V \ l *
# l/ // \I
KICKSTARTER_SUPPORTERS = [
'Manuela Lanzafame',
'Fluckiger Rudolf',
'Emily Gleason',
'Benjamin E Doremus',
'Chord Pet Wearable',
'Chris Taylor',
'Abraham White',
'Ryotaro Eguchi',
'Simon Waldherr',
'Isaac Sandaljian',
'Markus Rademacher'
].freeze
# ) \ / (
# /|\ )\_/( /|\
# * / | \ (/\|/\) / | \ *
# |`.____________________/__|__o____\`|'/___o__|__\___________________.'|
# | '^` \|/ '^` |
# | V |
# | _____ _ _ __ |
# | |_ _| |__ __ _ _ __ | | __ _ _ ___ _ _ ( | |
# | | | | '_ \ / _` | '_ \| |/ / | | | |/ _ \| | | | | ) |
# | | | | | | | (_| | | | | < | |_| | ( | | |_| | \_/ |
# | |_| |_| |_|\__,_|_| |_|_|\_\ \__, |\___/ \_,|_| _ |
# | |___/ (_) |
# | |
# | Special Thank You for supporting sciNote on Kicstarter goes |
# | to the following supporters |
# | ._________________________________________________________________. |
# |' l /\ / \\ \ /\ l `|
# * l / V )) V \ l *
# l/ // \I
KICKSTARTER_SUPPORTERS = [
'Manuela Lanzafame',
'Fluckiger Rudolf',
'Emily Gleason',
'Benjamin E Doremus',
'Chord Pet Wearable',
'Chris Taylor',
'Abraham White',
'Ryotaro Eguchi',
'Simon Waldherr',
'Isaac Sandaljian',
'Markus Rademacher'
].freeze
end

View file

@ -7,6 +7,6 @@ create_user(
"admin@scinote.net",
admin_password,
true,
DEFAULT_PRIVATE_ORG_NAME,
Constants::DEFAULT_PRIVATE_ORG_NAME,
[]
)
)

View file

@ -939,7 +939,8 @@ namespace :db do
# Now, at the end, add additional "private" organization
# to each user
User.find_each do |user|
create_private_user_organization(user, DEFAULT_PRIVATE_ORG_NAME)
create_private_user_organization(user,
Constants::DEFAULT_PRIVATE_ORG_NAME)
end
# Generate thumbnails of all experiments

View file

@ -61,7 +61,7 @@ namespace :db do
user_hash["email"],
password,
true,
create_orgs ? DEFAULT_PRIVATE_ORG_NAME : nil,
create_orgs ? Constants::DEFAULT_PRIVATE_ORG_NAME : nil,
org_ids
)
@ -117,7 +117,7 @@ namespace :db do
email,
password,
true,
create_org ? DEFAULT_PRIVATE_ORG_NAME : nil,
create_org ? Constants::DEFAULT_PRIVATE_ORG_NAME : nil,
org_ids
)
@ -135,4 +135,4 @@ namespace :db do
puts "Error creating user, transaction reverted: #{$!}"
end
end
end
end

View file

@ -2,7 +2,7 @@ one:
file_file_name: file1.pdf
file_content_type: application/pdf
file_file_size: 15
estimated_size: <%= (15 * ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
estimated_size: <%= (15 * Constants::ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
created_by: steve
last_modified_by: steve
@ -10,7 +10,7 @@ two:
file_file_name: file2.zip
file_content_type: application/zip
file_file_size: 32
estimated_size: <%= (32 * ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
estimated_size: <%= (32 * Constants::ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
created_by: mark
last_modified_by: mark
@ -19,7 +19,7 @@ three:
file_file_name: file3.jpg
file_content_type: image/jpg
file_file_size: 64
estimated_size: <%= (64 * ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
estimated_size: <%= (64 * Constants::ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
created_by: mark
last_modified_by: jlaw
@ -27,7 +27,7 @@ four:
file_file_name: file4.png
file_content_type: image/png
file_file_size: 128
estimated_size: <%= (128 * ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
estimated_size: <%= (128 * Constants::ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
created_by: steve
last_modified_by: jlaw
@ -35,7 +35,7 @@ test:
file_file_name: file7.png
file_content_type: image/png
file_file_size: 578
estimated_size: <%= (578 * ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
estimated_size: <%= (578 * Constants::ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
created_by: steve
last_modified_by: jlaw
@ -43,6 +43,6 @@ test_result:
file_file_name: file8.png
file_content_type: image/png
file_file_size: 631
estimated_size: <%= (631 * ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
estimated_size: <%= (631 * Constants::ASSET_ESTIMATED_SIZE_FACTOR).to_i %>
created_by: steve
last_modified_by: steve

View file

@ -28,7 +28,7 @@ class OrganizationTest < ActiveSupport::TestCase
test "space_taken_defaults_to_value" do
org = Organization.new
assert_equal MINIMAL_ORGANIZATION_SPACE_TAKEN, org.space_taken
assert_equal Constants::MINIMAL_ORGANIZATION_SPACE_TAKEN, org.space_taken
end
test "should save log message" do