permalink.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { Graph } from "./graphs/graph";
  2. import { graphs } from "./main";
  3. export function addPermalink()
  4. {
  5. // Permalink stuff
  6. const permalinkContainer = document.getElementById("permalinkContainer") as HTMLDivElement;
  7. const permalinkButton = document.getElementById("permalinkButton") as HTMLButtonElement;
  8. const permalinkCopyButton = document.getElementById("permalinkCopyButton") as HTMLButtonElement;
  9. const rprunCopyButton = document.getElementById("permalinkCopyButton-rprun") as HTMLButtonElement;
  10. const permalinkOptionsButton = document.getElementById("hideOptions") as HTMLInputElement;
  11. const permalinkLatestMonth = document.getElementById("latestMonth") as HTMLInputElement;
  12. permalinkButton?.addEventListener("click", function(e) {
  13. e.stopPropagation();
  14. const currentDisplay = permalinkContainer.style.display;
  15. if(currentDisplay == "none")
  16. {
  17. permalinkContainer.style.display = "block";
  18. }
  19. else
  20. {
  21. permalinkContainer.style.display = "none";
  22. }
  23. });
  24. document.addEventListener("click", function(e: any) {
  25. if(!permalinkContainer.contains(e.target) && !permalinkButton.contains(e.target))
  26. {
  27. permalinkContainer.style.display = "none";
  28. }
  29. });
  30. permalinkCopyButton.addEventListener("click", function() {
  31. const permalinkElem = document.getElementById("permalink") as HTMLInputElement;
  32. if(permalinkElem.value && permalinkElem.value != "")
  33. {
  34. navigator.clipboard.writeText(permalinkElem.value);
  35. }
  36. });
  37. rprunCopyButton.addEventListener("click", function() {
  38. const permalinkElem = document.getElementById("permalink-rprun") as HTMLInputElement;
  39. if(permalinkElem.value && permalinkElem.value != "")
  40. {
  41. navigator.clipboard.writeText(permalinkElem.value);
  42. }
  43. });
  44. permalinkOptionsButton.addEventListener("change", function() {
  45. updatePermalink();
  46. });
  47. permalinkLatestMonth.addEventListener("change", function() {
  48. updatePermalink();
  49. });
  50. }
  51. export function updatePermalink()
  52. {
  53. const graphSelect = document.getElementById("graphType") as HTMLSelectElement;
  54. const permalinkInput = document.getElementById("permalink") as HTMLInputElement;
  55. const rprunInput = document.getElementById("permalink-rprun") as HTMLInputElement;
  56. const hideOptionsButton = document.getElementById("hideOptions") as HTMLInputElement;
  57. const latestMonthButton = document.getElementById("latestMonth") as HTMLInputElement;
  58. var permalink = "https://pmmg-products.github.io/reports/?type=" + graphSelect.value;
  59. var rprunLink = "XIT PRUNSTATS type-" + graphSelect.value;
  60. const graph = graphs.find(obj => obj.id == graphSelect.value);
  61. graph?.configFieldIDs.forEach(subtype => {
  62. if(subtype == "month" && latestMonthButton.checked){return;}
  63. const inputElem = document.getElementById(subtype) as HTMLInputElement;
  64. if(inputElem.value && inputElem.value != "")
  65. {
  66. permalink += "&" + subtype + "=" + inputElem.value;
  67. rprunLink += " " + subtype + "-" + inputElem.value;
  68. }
  69. });
  70. if(hideOptionsButton.checked)
  71. {
  72. permalink += "&hideOptions";
  73. rprunLink += " hideOptions";
  74. }
  75. permalinkInput.value = permalink;
  76. rprunInput.value = rprunLink;
  77. return;
  78. }