From 3c1a275510adc10d96c15639c04e91a8ff1d7401 Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 13 Dec 2016 10:56:13 +0100 Subject: [PATCH 1/6] fixes invited user samples table [fixes SCI-790] --- app/controllers/user_samples_controller.rb | 1 + app/models/samples_table.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/user_samples_controller.rb b/app/controllers/user_samples_controller.rb index 2a3a33959..a499420e1 100644 --- a/app/controllers/user_samples_controller.rb +++ b/app/controllers/user_samples_controller.rb @@ -21,6 +21,7 @@ class UserSamplesController < ApplicationController def load_samples_table_status @samples_table_state = SamplesTable.find_status(current_user, current_organization).first + respond_to do |format| if @samples_table_state format.json do diff --git a/app/models/samples_table.rb b/app/models/samples_table.rb index 40ce10181..b3a324404 100644 --- a/app/models/samples_table.rb +++ b/app/models/samples_table.rb @@ -5,7 +5,7 @@ class SamplesTable < ActiveRecord::Base belongs_to :organization, inverse_of: :samples_tables scope :find_status, - ->(org, user) { where(user: user, organization: org).pluck(:status) } + ->(user, org) { where(user: user, organization: org).pluck(:status) } def self.update_samples_table_state(custom_field) samples_table = SamplesTable.where(user: custom_field.user, From c960230bf05caa9962388283bc095751591a8919 Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 13 Dec 2016 11:35:50 +0100 Subject: [PATCH 2/6] fixes dropdown height bug [fixes SCI-787] --- app/assets/javascripts/samples/sample_datatable.js | 14 ++++++++++++++ app/assets/stylesheets/themes/scinote.scss | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js index 362b90234..246a7c79f 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js @@ -1195,6 +1195,16 @@ function changeToEditMode() { }); } + // calculate the max height of window and adjust dropdown max-height + function dropdownOverflow() { + var windowHeight = $( window ).height(); + var offset = windowHeight - dropdownList.offset().top; + + if(dropdownList.height() >= offset) { + dropdownList.css('maxHeight', offset); + } + } + // initialze dropdown after the table is loaded function initDropdown() { table.on('init.dt', function() { @@ -1207,6 +1217,10 @@ function changeToEditMode() { $('#samples-columns-dropdown').on('show.bs.dropdown', function() { loadColumnsNames(); }); + + $('#samples-columns-dropdown').on('shown.bs.dropdown', function() { + dropdownOverflow(); + }) } initDropdown(); diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index cb1e0c311..873bda0c4 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1596,7 +1596,6 @@ textarea.textarea-sm { // new smart dropdown styles .smart-dropdown { - max-height: 400px; overflow-y: auto; padding: 0; width: 300px; From 24265397152b37b98823cdf0580a5f3ddeba3a1f Mon Sep 17 00:00:00 2001 From: zmagod Date: Tue, 13 Dec 2016 14:54:37 +0100 Subject: [PATCH 3/6] fixes long names in columns dropdown [fixes SCI-784] --- ...e_datatable.js => sample_datatable.js.erb} | 11 ++++++---- .../javascripts/sitewide/string_utils.js | 21 ++++++++++++++++--- config/initializers/constants.rb | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) rename app/assets/javascripts/samples/{sample_datatable.js => sample_datatable.js.erb} (99%) diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js.erb similarity index 99% rename from app/assets/javascripts/samples/sample_datatable.js rename to app/assets/javascripts/samples/sample_datatable.js.erb index 246a7c79f..172c3ca26 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -841,6 +841,7 @@ function changeToEditMode() { ''); }, success: function(data) { + debugger; var form = $('#new-column-form'); form.find('.help-block').remove(); if (form.hasClass('has-error')) { @@ -857,8 +858,8 @@ function changeToEditMode() { 'data-editable data-deletable ' + 'data-edit-url="' + data.edit_url + '" ' + 'data-destroy-html-url="' + data.destroy_html_url + '"' + - '>' + - data.name + ''); + '>' + truncateLongString(data.name, + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) + ''); var colOrder = table.colReorder.order(); colOrder.push(colOrder.length); // Remove all event handlers as we re-initialize them later with @@ -936,7 +937,8 @@ function changeToEditMode() { 'class="' + visLi + '"' + '>' + ' ' + - '' + el.innerText + ' ' + + '' + truncateLongString(el.innerText, + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) + ' ' + '' + '' + '' + @@ -1032,7 +1034,8 @@ function changeToEditMode() { data: {custom_field: {name: newName}}, dataType: 'json', success: function() { - text.text(newName); + text.text(truncateLongString(newName, + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>)); $(table.columns().header()).filter('#' + id).text(newName); cancelEditMode(); }, diff --git a/app/assets/javascripts/sitewide/string_utils.js b/app/assets/javascripts/sitewide/string_utils.js index ff59943e8..44ef3057c 100644 --- a/app/assets/javascripts/sitewide/string_utils.js +++ b/app/assets/javascripts/sitewide/string_utils.js @@ -2,15 +2,24 @@ * Truncate long strings where is necessary. */ function truncateLongString( el, chars ) { - var input = $.trim(el.text()); + if($.type(el) !== 'string'){ + var input = $.trim(el.text()); + } else { + var input = $.trim(el); + } var html = ""; - if( el.children().hasClass("glyphicon") ){ + if( $.type(el) !== 'string' && + el.children().hasClass("glyphicon")) { html = el.children()[0]; } if( input.length >= chars ){ - var newText = el.text().slice(0, chars); + if($.type(el) != 'string') { + var newText = el.text().slice(0, chars); + }else { + var newText = el.slice(0, chars); + } for( var i = newText.length; i > 0; i--){ if(newText[i] === ' ' && i > 10){ newText = newText.slice(0, i); @@ -21,8 +30,14 @@ function truncateLongString( el, chars ) { if ( html ) { el.html(html.outerHTML + newText + '...' ); } else { + if($.type(el) === 'string'){ + return newText + '...'; + } else { el.html(newText + '...' ); + } } + } else { + return el; } } diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index b6c48d551..a23da0f6d 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -9,6 +9,8 @@ class Constants NAME_MAX_LENGTH = 255 # Max characters for short text fields, after which they get truncated NAME_TRUNCATION_LENGTH = 25 + # Max characters for short text fields, in dropdownList + NAME_TRUNCATION_LENGTH_DROPDOWN = 20 # Max characters for long text fields TEXT_MAX_LENGTH = 10000 # Max characters for rich text fields (in html format) From 1ff98bb6df07fd3473f79ffe29ba2799a54d16f9 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 14 Dec 2016 13:36:10 +0100 Subject: [PATCH 4/6] adds tooltip to samples dropdown and column names --- .../samples/sample_datatable.js.erb | 23 +++++++++++++------ app/assets/stylesheets/themes/scinote.scss | 11 +++++++++ app/helpers/application_helper.rb | 9 ++++++++ app/views/shared/_samples.html.erb | 2 +- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index 172c3ca26..0b8d75839 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -841,7 +841,6 @@ function changeToEditMode() { ''); }, success: function(data) { - debugger; var form = $('#new-column-form'); form.find('.help-block').remove(); if (form.hasClass('has-error')) { @@ -858,8 +857,7 @@ function changeToEditMode() { 'data-editable data-deletable ' + 'data-edit-url="' + data.edit_url + '" ' + 'data-destroy-html-url="' + data.destroy_html_url + '"' + - '>' + truncateLongString(data.name, - <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) + ''); + '>' + generateColumnNameTooltip(data.name) + ''); var colOrder = table.colReorder.order(); colOrder.push(colOrder.length); // Remove all event handlers as we re-initialize them later with @@ -874,6 +872,7 @@ function changeToEditMode() { table = dataTableInit(); table.on('init.dt', function() { loadColumnsNames(); + dropdownOverflow(); }); }, url: url @@ -937,8 +936,7 @@ function changeToEditMode() { 'class="' + visLi + '"' + '>' + ' ' + - '' + truncateLongString(el.innerText, - <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) + ' ' + + '' + generateColumnNameTooltip(el.innerText) + ' ' + '' + '' + '' + @@ -1034,8 +1032,7 @@ function changeToEditMode() { data: {custom_field: {name: newName}}, dataType: 'json', success: function() { - text.text(truncateLongString(newName, - <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>)); + text.text(generateColumnNameTooltip(newName)); $(table.columns().header()).filter('#' + id).text(newName); cancelEditMode(); }, @@ -1208,6 +1205,18 @@ function changeToEditMode() { } } + function generateColumnNameTooltip(name) { + if( $.trim(name).length > + <%= Constants::NAME_TRUNCATION_LENGTH_DROPDOWN %>) { + return ''; + } else { + return name; + } + } + // initialze dropdown after the table is loaded function initDropdown() { table.on('init.dt', function() { diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 873bda0c4..14f31805e 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1453,6 +1453,7 @@ html.turbolinks-progress-bar::before { text-align: center; visibility: hidden; width: 200px; + word-wrap: break-word; z-index: $infinity; } } @@ -1600,6 +1601,11 @@ textarea.textarea-sm { padding: 0; width: 300px; + .modal-tooltiptext { + margin-left: 0; + z-index: 99999999; + } + li { background: $color-white; border: 1px solid $color-alto; @@ -1690,3 +1696,8 @@ textarea.textarea-sm { } } } + +th.custom-field .modal-tooltiptext { + margin-left: 0; + z-index: 99999999; +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c8fa861cd..a10ee5e6c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,4 +11,13 @@ module ApplicationHelper controller_name == 'projects' || (controller_name == 'reports' && action_name == 'index') end + + def display_tooltip(message, len = Constants::NAME_TRUNCATION_LENGTH) + if message.strip.length > Constants::NAME_TRUNCATION_LENGTH + "".html_safe + else + truncate(message.strip, length: len) + end + end end diff --git a/app/views/shared/_samples.html.erb b/app/views/shared/_samples.html.erb index 2a2a790e0..23110c9b8 100644 --- a/app/views/shared/_samples.html.erb +++ b/app/views/shared/_samples.html.erb @@ -144,7 +144,7 @@ <%= "data-edit-url='#{organization_custom_field_path(@organization, cf)}'" %> <%= "data-destroy-html-url='#{organization_custom_field_destroy_html_path(@organization, cf)}'" %> > - <%= cf.name %> + <%= display_tooltip(cf.name) %> <% end %> From a9f8239516d7192353329e4cc0e3af98e17797b4 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 14 Dec 2016 16:37:44 +0100 Subject: [PATCH 5/6] fixed edit action --- app/assets/javascripts/samples/sample_datatable.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index 0b8d75839..d78f3acd4 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -1032,7 +1032,7 @@ function changeToEditMode() { data: {custom_field: {name: newName}}, dataType: 'json', success: function() { - text.text(generateColumnNameTooltip(newName)); + text.html(generateColumnNameTooltip(newName)); $(table.columns().header()).filter('#' + id).text(newName); cancelEditMode(); }, From dfd472d37d4633c7b957dd134483dbf291ea7305 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 14 Dec 2016 16:47:39 +0100 Subject: [PATCH 6/6] fixed column name after edit --- app/assets/javascripts/samples/sample_datatable.js.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/samples/sample_datatable.js.erb b/app/assets/javascripts/samples/sample_datatable.js.erb index d78f3acd4..12b3a242f 100644 --- a/app/assets/javascripts/samples/sample_datatable.js.erb +++ b/app/assets/javascripts/samples/sample_datatable.js.erb @@ -1033,7 +1033,8 @@ function changeToEditMode() { dataType: 'json', success: function() { text.html(generateColumnNameTooltip(newName)); - $(table.columns().header()).filter('#' + id).text(newName); + $(table.columns().header()).filter('#' + id) + .html(generateColumnNameTooltip(newName)); cancelEditMode(); }, error: function(xhr) {