From f2cd9890ddbb3f1a69838449b1d5905cd5743e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Thu, 13 Oct 2016 11:05:11 +0200 Subject: [PATCH] Replaced hardcoded infinity values with constants. Added quotation marks to Ruby string constants in JS. --- app/assets/javascripts/projects/canvas.js.erb | 4 ++-- app/assets/javascripts/projects/index.js.erb | 8 ++++---- app/assets/stylesheets/application.scss | 2 +- .../stylesheets/{colors.scss => constants.scss} | 11 +++++++++++ app/assets/stylesheets/extend/bootstrap.scss | 2 +- app/assets/stylesheets/notifications.scss | 4 ++-- app/assets/stylesheets/partials/_sidebar.scss | 2 +- app/assets/stylesheets/partials/_tree_view.scss | 2 +- app/assets/stylesheets/projects.scss | 2 +- app/assets/stylesheets/reports.scss | 2 +- app/assets/stylesheets/reports_print.scss | 2 +- app/assets/stylesheets/search.scss | 2 +- app/assets/stylesheets/themes/scinote.scss | 10 +++++----- app/models/my_module.rb | 4 ++-- app/models/project.rb | 2 +- app/models/result.rb | 2 +- app/models/step.rb | 2 +- app/models/user.rb | 3 +-- app/models/user_notification.rb | 4 ++-- app/utilities/renaming_util.rb | 4 ++-- config/initializers/constants.rb | 2 ++ 21 files changed, 44 insertions(+), 32 deletions(-) rename app/assets/stylesheets/{colors.scss => constants.scss} (60%) diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index df0949fc2..6cc7d2238 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -36,7 +36,7 @@ var DEFAULT_CONNECTOR_STYLE = } ]; var DEFAULT_CONNECTOR_STYLE_2 = { - strokeStyle: "<%= Constants::COLOR_WHITE %>", + strokeStyle: '<%= Constants::COLOR_WHITE %>', lineWidth: 1.5, outlineColor: "transparent", outlineWidth: 0 @@ -57,7 +57,7 @@ var EDIT_ENDPOINT_STYLE = } ]; var EDIT_CONNECTOR_STYLE_2 = { - strokeStyle: "<%= Constants::COLOR_WHITE %>", + strokeStyle: '<%= Constants::COLOR_WHITE %>', lineWidth: 3, outlineColor: "transparent", outlineWidth: 0 diff --git a/app/assets/javascripts/projects/index.js.erb b/app/assets/javascripts/projects/index.js.erb index db3fb15b3..3138f3266 100644 --- a/app/assets/javascripts/projects/index.js.erb +++ b/app/assets/javascripts/projects/index.js.erb @@ -466,12 +466,12 @@ .find('.form-submit-link') .css({ 'pointer-events': 'none', - 'color': <%= Constants::COLOR_ALTO %>}); + 'color': '<%= Constants::COLOR_ALTO %>'}); $(el) .find('[data-action="edit"]') .css({ 'pointer-events': 'none', - 'color': <%= Constants::COLOR_ALTO %>}); + 'color': '<%= Constants::COLOR_ALTO %>'}); }); } }); @@ -489,12 +489,12 @@ .find('.form-submit-link') .css({ 'pointer-events': 'auto', - 'color': <%= Constants::COLOR_NERO %>}); + 'color': '<%= Constants::COLOR_NERO %>'}); $(el) .find('[data-action="edit"]') .css({ 'pointer-events': 'auto', - 'color': <%= Constants::COLOR_NERO %>}); + 'color': '<%= Constants::COLOR_NERO %>'}); }); } diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 32c8f3c51..f6a6406b5 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -4,7 +4,7 @@ *= require jquery-ui/draggable *= require rails_bootstrap_forms *= require bootstrap-select - *= require colors + *= require constants *= require introjs *= stub reports_pdf */ diff --git a/app/assets/stylesheets/colors.scss b/app/assets/stylesheets/constants.scss similarity index 60% rename from app/assets/stylesheets/colors.scss rename to app/assets/stylesheets/constants.scss index 592cf1508..ad4d61071 100644 --- a/app/assets/stylesheets/colors.scss +++ b/app/assets/stylesheets/constants.scss @@ -1,3 +1,7 @@ +//============================================================================== +// Colors +//============================================================================== + // Theme colors $color-theme-primary: #37a0d9; $color-theme-secondary: #8fd13f; @@ -28,3 +32,10 @@ $color-candlelight: #ffda23; $color-mojo: #cf4b48; $color-apple-blossom: #a94442; $color-milano-red: #a70b05; + +//============================================================================== +// Other +//============================================================================== + +// Some big value which is still supported by all browsers +$infinity: 9999999; diff --git a/app/assets/stylesheets/extend/bootstrap.scss b/app/assets/stylesheets/extend/bootstrap.scss index 71f3a612d..5c5000a7a 100644 --- a/app/assets/stylesheets/extend/bootstrap.scss +++ b/app/assets/stylesheets/extend/bootstrap.scss @@ -1,6 +1,6 @@ /* Extending Bootstrap */ -@import "colors"; +@import 'constants'; /* navbar avatar image */ .navbar-nav .avatar { diff --git a/app/assets/stylesheets/notifications.scss b/app/assets/stylesheets/notifications.scss index 11ce9fa9a..a750bf9a5 100644 --- a/app/assets/stylesheets/notifications.scss +++ b/app/assets/stylesheets/notifications.scss @@ -1,4 +1,4 @@ -@import "colors"; +@import 'constants'; @import "mixins"; .notifications-container { @@ -56,7 +56,7 @@ font-size: 13px; height: 30px; padding-top: 5px; - width: 30px; + width: 30px; } .system-message { diff --git a/app/assets/stylesheets/partials/_sidebar.scss b/app/assets/stylesheets/partials/_sidebar.scss index a1f243132..7b14f5975 100644 --- a/app/assets/stylesheets/partials/_sidebar.scss +++ b/app/assets/stylesheets/partials/_sidebar.scss @@ -4,7 +4,7 @@ * For details, see http://www.apache.org/licenses/LICENSE-2.0. */ -@import "colors"; +@import 'constants'; @import "mixins"; $wrapper-width: 280px; diff --git a/app/assets/stylesheets/partials/_tree_view.scss b/app/assets/stylesheets/partials/_tree_view.scss index 7306512ae..4fbf45684 100644 --- a/app/assets/stylesheets/partials/_tree_view.scss +++ b/app/assets/stylesheets/partials/_tree_view.scss @@ -1,4 +1,4 @@ -@import "colors"; +@import 'constants'; @import "mixins"; .tree { diff --git a/app/assets/stylesheets/projects.scss b/app/assets/stylesheets/projects.scss index af670e79b..a5acb11a3 100644 --- a/app/assets/stylesheets/projects.scss +++ b/app/assets/stylesheets/projects.scss @@ -1,4 +1,4 @@ -@import "colors"; +@import 'constants'; @import "mixins"; // Some color definitions diff --git a/app/assets/stylesheets/reports.scss b/app/assets/stylesheets/reports.scss index 9bcf2cb79..a63a4c1d5 100644 --- a/app/assets/stylesheets/reports.scss +++ b/app/assets/stylesheets/reports.scss @@ -1,4 +1,4 @@ -@import "colors"; +@import 'constants'; @import "mixins"; /* Index page */ diff --git a/app/assets/stylesheets/reports_print.scss b/app/assets/stylesheets/reports_print.scss index 398d8654a..2aba8361d 100644 --- a/app/assets/stylesheets/reports_print.scss +++ b/app/assets/stylesheets/reports_print.scss @@ -1,4 +1,4 @@ -@import "colors"; +@import 'constants'; @import "mixins"; /** Custom CSS for report print (& PDF) */ diff --git a/app/assets/stylesheets/search.scss b/app/assets/stylesheets/search.scss index 17cea9116..932e1cce1 100644 --- a/app/assets/stylesheets/search.scss +++ b/app/assets/stylesheets/search.scss @@ -2,7 +2,7 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -@import 'colors'; +@import 'constants'; #search-content { background-color: $color-white; diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 1af6978e6..f80f78903 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1,4 +1,4 @@ -@import "colors"; +@import 'constants'; @import "mixins"; /** Layout **/ @@ -88,7 +88,7 @@ table { margin-left: 12px; padding: 1px 6px; position: relative; - z-index: 999999; + z-index: $infinity; } } @@ -1331,10 +1331,10 @@ html.turbolinks-progress-bar::before { } .introjs-tooltipReferenceLayer { - z-index: 999999 !important; + z-index: $infinity !important; &.max { - z-index: 99999999 !important; + z-index: calc($infinity + 1) !important; } } @@ -1355,7 +1355,7 @@ html.turbolinks-progress-bar::before { padding: 5px; border-radius: 6px; position: absolute; - z-index: 999999; + z-index: $infinity; } .modal-tooltip:hover .modal-tooltiptext { diff --git a/app/models/my_module.rb b/app/models/my_module.rb index e3ae232c5..ec892156e 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -153,7 +153,7 @@ class MyModule < ActiveRecord::Base # 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 = Constants::COMMENTS_SEARCH_LIMIT) - last_id = 9999999999999 if last_id <= 1 + last_id = Constants::INFINITY if last_id <= 1 comments = Comment.joins(:my_module_comment) .where(my_module_comments: { my_module_id: id }) .where('comments.id < ?', last_id) @@ -164,7 +164,7 @@ class MyModule < ActiveRecord::Base def last_activities(last_id = 1, count = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT) - last_id = 9999999999999 if last_id <= 1 + last_id = Constants::INFINITY if last_id <= 1 Activity.joins(:my_module) .where(my_module_id: id) .where('activities.id < ?', last_id) diff --git a/app/models/project.rb b/app/models/project.rb index a5a58c97d..c9b689671 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -81,7 +81,7 @@ class Project < ActiveRecord::Base # 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 = Constants::COMMENTS_SEARCH_LIMIT) - last_id = 9999999999999 if last_id <= 1 + last_id = Constants::INFINITY if last_id <= 1 comments = Comment.joins(:project_comment) .where(project_comments: { project_id: id }) .where('comments.id < ?', last_id) diff --git a/app/models/result.rb b/app/models/result.rb index 0a66b22b4..b9291b6e2 100644 --- a/app/models/result.rb +++ b/app/models/result.rb @@ -73,7 +73,7 @@ class Result < ActiveRecord::Base end def last_comments(last_id = 1, per_page = Constants::COMMENTS_SEARCH_LIMIT) - last_id = 9999999999999 if last_id <= 1 + last_id = Constants::INFINITY if last_id <= 1 comments = Comment.joins(:result_comment) .where(result_comments: { result_id: id }) .where('comments.id < ?', last_id) diff --git a/app/models/step.rb b/app/models/step.rb index d82449ead..e572dff2a 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -89,7 +89,7 @@ class Step < ActiveRecord::Base end def last_comments(last_id = 1, per_page = Constants::COMMENTS_SEARCH_LIMIT) - last_id = 9999999999999 if last_id <= 1 + last_id = Constants::INFINITY if last_id <= 1 comments = Comment.joins(:step_comment) .where(step_comments: { step_id: id }) .where('comments.id < ?', last_id) diff --git a/app/models/user.rb b/app/models/user.rb index 076b26a12..809389459 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -241,8 +241,7 @@ class User < ActiveRecord::Base # module. def last_activities(last_activity_id = nil, per_page = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT) - # TODO replace with some kind of Infinity value - last_activity_id = 999999999999999999999999 if last_activity_id < 1 + last_activity_id = Constants::INFINITY if last_activity_id < 1 Activity .joins(project: :user_projects) .joins("LEFT OUTER JOIN my_modules ON activities.my_module_id = my_modules.id") diff --git a/app/models/user_notification.rb b/app/models/user_notification.rb index e432c7405..5c83c8ba2 100644 --- a/app/models/user_notification.rb +++ b/app/models/user_notification.rb @@ -11,7 +11,7 @@ class UserNotification < ActiveRecord::Base last_notification_id = nil, per_page = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT ) - last_notification_id = 999999999999999999999999 if last_notification_id < 1 + last_notification_id = Constants::INFINITY if last_notification_id < 1 Notification.joins(:user_notifications) .where('user_notifications.user_id = ?', user.id) .where('notifications.id < ?', last_notification_id) @@ -23,7 +23,7 @@ class UserNotification < ActiveRecord::Base Notification.joins(:user_notifications) .where('user_notifications.user_id = ?', user.id) .order(created_at: :DESC) - .limit(Constants::COMMENTS_SEARCH_LIMIT) + .limit(Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT) end def self.unseen_notification_count(user) diff --git a/app/utilities/renaming_util.rb b/app/utilities/renaming_util.rb index eb5eeb078..ba8f13546 100644 --- a/app/utilities/renaming_util.rb +++ b/app/utilities/renaming_util.rb @@ -22,7 +22,7 @@ module RenamingUtil # Get the max. length validation, if it exist # IF MAX_LENGTH IS VERY LOW, this code here could # potentially cause trouble. Let's hope max_length is always 10+ - max_length = 99999 + max_length = Constants::INFINITY clazz .validators_on(name_col) .select{ |v| v.class == ActiveModel::Validations::LengthValidator } @@ -58,4 +58,4 @@ module RenamingUtil return record.valid? end -end \ No newline at end of file +end diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 212acdf0c..199f08fbb 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -24,6 +24,8 @@ class Constants # Standard max length for email EMAIL_MAX_LENGTH = 254 + INFINITY = 999999999999999999 + #============================================================================= # Query/display limits #=============================================================================