datasetUtils.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*!
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /* global $, isoDateToTimeEl, document */
  20. import { getMetaValue } from "./utils";
  21. export function openDatasetModal(dagId, summary, nextDatasets, error) {
  22. const datasetEvents = nextDatasets.events || [];
  23. const expression = nextDatasets.dataset_expression;
  24. const datasetsUrl = getMetaValue("datasets_url");
  25. $("#dataset_expression").empty();
  26. $("#datasets_tbody").empty();
  27. $("#datasets_error").hide();
  28. $("#dag_id").text(dagId);
  29. $("#dataset_expression").text(JSON.stringify(expression, null, 2));
  30. $("#datasetNextRunModal").modal({});
  31. if (summary) $("#next_run_summary").text(summary);
  32. datasetEvents.forEach((d) => {
  33. const row = document.createElement("tr");
  34. const uriCell = document.createElement("td");
  35. const datasetLink = document.createElement("a");
  36. datasetLink.href = `${datasetsUrl}?uri=${encodeURIComponent(d.uri)}`;
  37. datasetLink.innerText = d.uri;
  38. uriCell.append(datasetLink);
  39. const timeCell = document.createElement("td");
  40. if (d.lastUpdate) timeCell.append(isoDateToTimeEl(d.lastUpdate));
  41. row.append(uriCell);
  42. row.append(timeCell);
  43. $("#datasets_tbody").append(row);
  44. });
  45. if (error) {
  46. $("#datasets_error_msg").text(error);
  47. $("#datasets_error").show();
  48. }
  49. }
  50. export function getDatasetTooltipInfo(dagId, run, setNextDatasets) {
  51. let nextRunUrl = getMetaValue("next_run_datasets_url");
  52. if (dagId) {
  53. if (nextRunUrl.includes("__DAG_ID__")) {
  54. nextRunUrl = nextRunUrl.replace("__DAG_ID__", dagId);
  55. }
  56. $.get(nextRunUrl)
  57. .done((nextDatasets) => {
  58. const datasetEvents = nextDatasets.events;
  59. let count = 0;
  60. let title = "<strong>Pending datasets:</strong><br>";
  61. setNextDatasets(nextDatasets);
  62. datasetEvents.forEach((d) => {
  63. if (!d.created_at) {
  64. if (count < 4) title += `${d.uri}<br>`;
  65. count += 1;
  66. }
  67. });
  68. if (count > 4) {
  69. title += `<br>And ${count - 4} more.`;
  70. }
  71. title += "<br>Click to see more details.";
  72. $(run).attr("data-original-title", () => title);
  73. })
  74. .fail((response, textStatus, err) => {
  75. const description =
  76. (response.responseJSON && response.responseJSON.error) ||
  77. "Something went wrong.";
  78. const error = `${textStatus}: ${err} ${description}`;
  79. setNextDatasets([], error);
  80. });
  81. }
  82. }