yarn.dt.plugins.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // Licensed to the Apache Software Foundation (ASF) under one or more
  2. // contributor license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright ownership.
  4. // The ASF licenses this file to You under the Apache License, Version 2.0
  5. // (the "License"); you may not use this file except in compliance with
  6. // the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. if (!jQuery.fn.dataTableExt.fnVersionCheck("1.7.5")) {
  16. alert("These plugins requires dataTables 1.7.5+");
  17. }
  18. // don't filter on hidden html elements for an sType of title-numeric
  19. $.fn.dataTableExt.ofnSearch['title-numeric'] = function ( sData ) {
  20. return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
  21. }
  22. // 'title-numeric' sort type
  23. jQuery.fn.dataTableExt.oSort['title-numeric-asc'] = function(a,b) {
  24. var x = a.match(/title=["']?(-?\d+\.?\d*)/)[1];
  25. var y = b.match(/title=["']?(-?\d+\.?\d*)/)[1];
  26. x = parseFloat( x );
  27. y = parseFloat( y );
  28. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  29. };
  30. jQuery.fn.dataTableExt.oSort['title-numeric-desc'] = function(a,b) {
  31. var x = a.match(/title=["']?(-?\d+\.?\d*)/)[1];
  32. var y = b.match(/title=["']?(-?\d+\.?\d*)/)[1];
  33. x = parseFloat( x );
  34. y = parseFloat( y );
  35. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  36. };
  37. jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
  38. var
  39. _that = this,
  40. iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
  41. this.each( function ( i ) {
  42. $.fn.dataTableExt.iApiIndex = i;
  43. var
  44. $this = this,
  45. oTimerId = null,
  46. sPreviousSearch = null,
  47. anControl = $( 'input', _that.fnSettings().aanFeatures.f );
  48. anControl.unbind( 'keyup' ).bind( 'keyup', function() {
  49. var $$this = $this;
  50. if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
  51. window.clearTimeout(oTimerId);
  52. sPreviousSearch = anControl.val();
  53. oSettings.oApi._fnProcessingDisplay(oSettings, true);
  54. oTimerId = window.setTimeout(function() {
  55. $.fn.dataTableExt.iApiIndex = i;
  56. _that.fnFilter( anControl.val() );
  57. oSettings.oApi._fnProcessingDisplay(oSettings, false);
  58. }, iDelay);
  59. }
  60. });
  61. return this;
  62. } );
  63. return this;
  64. }
  65. function renderHadoopDate(data, type, full) {
  66. if (type === 'display' || type === 'filter') {
  67. if(data === '0'|| data === '-1') {
  68. return "N/A";
  69. }
  70. var date = new Date(parseInt(data));
  71. var monthList = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
  72. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  73. var weekdayList = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  74. var offsetMinutes = date.getTimezoneOffset();
  75. var offset
  76. if (offsetMinutes <= 0) {
  77. offset = "+" + zeroPad(-offsetMinutes / 60 * 100, 4);
  78. } else {
  79. offset = "-" + zeroPad(offsetMinutes / 60 * 100, 4);
  80. }
  81. // EEE MMM dd HH:mm:ss Z yyyy
  82. return weekdayList[date.getDay()] + " " +
  83. monthList[date.getMonth()] + " " +
  84. date.getDate() + " " +
  85. zeroPad(date.getHours(), 2) + ":" +
  86. zeroPad(date.getMinutes(), 2) + ":" +
  87. zeroPad(date.getSeconds(), 2) + " " +
  88. offset + " " +
  89. date.getFullYear();
  90. }
  91. // 'sort', 'type' and undefined all just use the number
  92. // If date is 0, then for purposes of sorting it should be consider max_int
  93. return data === '0' ? '9007199254740992' : data;
  94. }
  95. function zeroPad(n, width) {
  96. n = n + '';
  97. return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
  98. }
  99. function renderHadoopElapsedTime(data, type, full) {
  100. if (type === 'display' || type === 'filter') {
  101. var timeDiff = parseInt(data);
  102. if(timeDiff < 0)
  103. return "N/A";
  104. var hours = Math.floor(timeDiff / (60*60*1000));
  105. var rem = (timeDiff % (60*60*1000));
  106. var minutes = Math.floor(rem / (60*1000));
  107. rem = rem % (60*1000);
  108. var seconds = Math.floor(rem / 1000);
  109. var toReturn = "";
  110. if (hours != 0){
  111. toReturn += hours;
  112. toReturn += "hrs, ";
  113. }
  114. if (minutes != 0){
  115. toReturn += minutes;
  116. toReturn += "mins, ";
  117. }
  118. toReturn += seconds;
  119. toReturn += "sec";
  120. return toReturn;
  121. }
  122. // 'sort', 'type' and undefined all just use the number
  123. return data;
  124. }
  125. //JSON array element is formatted like
  126. //"<a href="/proxy/application_1360183373897_0001>">application_1360183373897_0001</a>"
  127. //this function removes <a> tag and return a string value for sorting
  128. function parseHadoopID(data, type, full) {
  129. if (type === 'display') {
  130. return data;
  131. }
  132. //Return the visible string rather than the entire HTML tag
  133. return data.split('>')[1].split('<')[0];
  134. }
  135. //JSON array element is "20000 attempt_1360183373897_0001_m_000002_0"
  136. function parseHadoopAttemptID(data, type, full) {
  137. if (type === 'display' || type === 'filter') {
  138. return data.split(' ')[1];
  139. }
  140. //For sorting use the order as defined in the JSON element
  141. return data.split(' ')[0];
  142. }
  143. function parseHadoopProgress(data, type, full) {
  144. if (type === 'display') {
  145. return data;
  146. }
  147. //Return the title attribute for 'sort', 'filter', 'type' and undefined
  148. return data.split("'")[1];
  149. }