dashboard-utils.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. function getStatusClass(status, prefix) {
  17. if (prefix == null) {
  18. prefix = "label-";
  19. }
  20. var klass = "";
  21. if (['SUCCEEDED', 'OK', 'DONE'].indexOf(status) > -1) {
  22. klass = prefix + "success";
  23. }
  24. else if (['RUNNING', 'READY', 'PREP', 'WAITING', 'SUSPENDED', 'PREPSUSPENDED', 'PREPPAUSED', 'PAUSED',
  25. 'SUBMITTED',
  26. 'SUSPENDEDWITHERROR',
  27. 'PAUSEDWITHERROR'].indexOf(status) > -1) {
  28. klass = prefix + "warning";
  29. }
  30. else {
  31. klass = prefix + "important";
  32. if (prefix == "bar-") {
  33. klass = prefix + "danger";
  34. }
  35. }
  36. return klass;
  37. }
  38. function emptyStringIfNull(obj) {
  39. if (obj != null && obj != undefined) {
  40. return obj;
  41. }
  42. return "";
  43. }
  44. var PersistedButtonsFilters = function (oSettings, aData, iDataIndex) {
  45. var urlHashes = "";
  46. var statusBtn = $("a.btn-status.active");
  47. var statusFilter = true;
  48. if (statusBtn.length > 0) {
  49. var statuses = [];
  50. $.each(statusBtn, function () {
  51. statuses.push($(this).attr("data-value"));
  52. });
  53. var _statusColumn = aData[2];
  54. if (typeof $(_statusColumn).attr("data-type") == "undefined") {
  55. _statusColumn = aData[1];
  56. }
  57. statusFilter = _statusColumn.match(RegExp(statuses.join('|'), "i")) != null;
  58. }
  59. var dateBtn = $("a.btn-date.active");
  60. var dateFilter = true;
  61. if (dateBtn.length > 0) {
  62. var minAge = new Date() - parseInt(dateBtn.attr("data-value")) * 1000 * 60 * 60 * 24;
  63. var _dateColumn = aData[1];
  64. if (typeof $(_dateColumn).attr("data-type") == "undefined" || $(_dateColumn).attr("data-type") == "status") {
  65. _dateColumn = aData[0];
  66. }
  67. if (typeof _dateColumn == "string") {
  68. _dateColumn = $(_dateColumn).attr("data-sort-value");
  69. }
  70. dateFilter = _dateColumn * 1000 >= minAge;
  71. }
  72. var submittedBtn = $("a.btn-submitted.active");
  73. var submittedByFilter = true;
  74. if (submittedBtn.length > 0) {
  75. var statuses = [];
  76. $.each(submittedBtn, function () {
  77. statuses.push($(this).attr("data-value"));
  78. });
  79. var _statusColumn = aData[aData.length - 1];
  80. if (statuses.length == 1) {
  81. if(statuses[0] == 'MANUALLY') {
  82. submittedByFilter = _statusColumn == null;
  83. } else {
  84. submittedByFilter = _statusColumn != null;
  85. }
  86. }
  87. }
  88. return statusFilter && dateFilter && submittedByFilter;
  89. }