Browse Source

HUE-984 [oozie] min-height for completed job tables

Fixed a bug with minimum height and added a Jasmine test for it
Enrico Berti 13 years ago
parent
commit
999891e

+ 17 - 0
desktop/core/static/jasmine/jHueTableScrollerFixture.html

@@ -980,6 +980,23 @@
 </tbody>
 </table>
 
+<table id="shortMinHeightTable" class="table table-striped table-condensed">
+<thead>
+<tr>
+  <th>column0</th>
+  <th>column1</th>
+  <th>column2</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+  <td>vestibulum ipsum</td>
+  <td>Fusce eleifend.</td>
+  <td>nec, Quisque</td>
+</tr>
+</tbody>
+</table>
+
 <table id="disableMinHeightTable" class="table table-striped table-condensed" data-tablescroller-min-height-disable="true">
 <thead>
 <tr>

+ 6 - 2
desktop/core/static/jasmine/jHueTableScrollerSpec.js

@@ -20,7 +20,7 @@ describe("jHueTableScroller plugin", function () {
 
   it("should make the default table scroll with min height enabled", function () {
     expect($("#defaultTable").parent(".dataTables_wrapper").height()).toBeLessThan(defaultTableOriginalHeight);
-    expect($("#defaultTable").parent(".dataTables_wrapper").height()).toBe(500);
+    expect($("#defaultTable").parent(".dataTables_wrapper").height()).toBe(400);
   });
 
   it("should set a specific minimum height when data-tablescroller-min-height is specified", function () {
@@ -29,7 +29,11 @@ describe("jHueTableScroller plugin", function () {
   });
 
   it("should disable a minimum height when data-tablescroller-disable-min-height is specified", function () {
-    expect($("#disableMinHeightTable").parent(".dataTables_wrapper").height()).not.toEqual(500)
+    expect($("#disableMinHeightTable").parent(".dataTables_wrapper").height()).not.toEqual(400)
+  });
+
+  it("should ignore the minimum height when the table is smaller than 400", function () {
+    expect($("#shortMinHeightTable").parent(".dataTables_wrapper").height()).toBeLessThan(400)
   });
 
   it("should disable the plugin when data-tablescroller-disable is specified", function () {

+ 23 - 15
desktop/core/static/js/Source/jHue/jquery.tablescroller.js

@@ -27,7 +27,7 @@
 
   var pluginName = "jHueTableScroller",
       defaults = {
-        minHeight: 500
+        minHeight: 400
       };
 
   function Plugin(element, options) {
@@ -45,6 +45,8 @@
   Plugin.prototype.init = function () {
     var _this = this;
 
+    $(_this.element).data("original-height", $(_this.element).height());
+
     var disableScrollingTable = $(_this.element).find("table").eq(0).data("tablescroller-disable");
     if (disableScrollingTable == null || disableScrollingTable != true) {
       resizeScrollingTable(_this.element);
@@ -55,25 +57,31 @@
 
     function resizeScrollingTable(el) {
       $(el).css("overflow-y", "").css("height", "");
-      var disableMinHeight = $(_this.element).find("table").eq(0).data("tablescroller-min-height-disable");
-      if (disableMinHeight != null && disableMinHeight == true) {
-        var heightAfter = 0;
-        $(el).nextAll(":visible").each(function () {
-          heightAfter += $(this).outerHeight(true);
-        });
-        if ($(el).height() > ($(window).height() - $(el).offset().top - heightAfter)) {
-          $(el).css("overflow-y", "auto").height($(window).height() - $(el).offset().top - heightAfter);
-        }
-      }
-      else {
+      var heightAfter = 0;
+      $(el).nextAll(":visible").each(function () {
+        heightAfter += $(this).outerHeight(true);
+      });
+      if ($(el).height() > ($(window).height() - $(el).offset().top - heightAfter)) {
         var specificMinHeight = $(el).find("table").eq(0).data("tablescroller-min-height");
         var minHeightVal = _this.options.minHeight;
         if (!isNaN(parseFloat(specificMinHeight)) && isFinite(specificMinHeight)) {
           minHeightVal = parseFloat(specificMinHeight);
         }
-        $(el).css("overflow-y", "auto");
-        if ($(el).height() > minHeightVal) {
-          $(el).height(minHeightVal);
+        var disableMinHeight = $(_this.element).find("table").eq(0).data("tablescroller-min-height-disable");
+        if (disableMinHeight != null && disableMinHeight == true) {
+          if ($(el).height() > ($(window).height() - $(el).offset().top - heightAfter)) {
+            $(el).css("overflow-y", "auto").height($(window).height() - $(el).offset().top - heightAfter);
+          }
+        }
+        else {
+          if (($(window).height() - $(el).offset().top - heightAfter) > minHeightVal){
+            $(el).css("overflow-y", "auto").height($(window).height() - $(el).offset().top - heightAfter);
+          }
+          else {
+            if ($(el).data("original-height") > minHeightVal){
+              $(el).css("overflow-y", "auto").height(minHeightVal);
+            }
+          }
         }
       }
     }