index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Ressource from './Ressource';
  2. import './Ressource';
  3. import dayjs from 'dayjs';
  4. var emptyTimeline = document.createElement("jc-timeline");
  5. var title = document.createElement("h2");
  6. title.innerText = "Empty Timeline";
  7. document.body.appendChild(title);
  8. document.body.appendChild(emptyTimeline);
  9. emptyTimeline.setAttribute("legendSpan", "1");
  10. emptyTimeline.setAttribute("slotWidth", "40");
  11. var timeline = document.createElement("jc-timeline");
  12. var rows = [
  13. { id: '1', title: "Ressource 1 DarkSlate", eventBgColor: "DarkSlateBlue" },
  14. { id: '3', title: "Ressource 3" },
  15. { id: '4', title: "Ressource 4" },
  16. { id: '5', title: "Ressource 5" }
  17. ].map(function (i) { return new Ressource(i); });
  18. rows[2].parent = rows[1];
  19. rows[0].parent = rows[1];
  20. var data = dayjs().startOf("hour").hour(9);
  21. var timeslots = [
  22. { id: '1', title: "Fixed ressource", ressourceId: '3', start: data.subtract(3, "h").toDate(), end: data.toDate(), ressourceEditable: false, bgColor: "darkgreen" },
  23. { id: '2', title: "Fixed time", ressourceId: '3', start: data.toDate(), end: data.endOf("hour").add(1, "h").toDate(), editable: false, bgColor: "FireBrick" },
  24. { id: '3', ressourceId: '4', start: data.add(1, "h").toDate(), end: data.endOf("hour").add(2, "h").toDate() },
  25. { id: '4', ressourceId: '3', start: data.startOf("day").subtract(1, "h").toDate(), end: dayjs().endOf("hour").add(1, "h").toDate() }
  26. ];
  27. for (var i = 5; i < 10; i++) {
  28. timeslots.push({
  29. id: i.toFixed(0),
  30. title: "event " + i,
  31. ressourceId: '1',
  32. start: data.add(i, 'h').toDate(),
  33. end: data.add(i, 'h').endOf("hour").add(1, "h").toDate(),
  34. });
  35. }
  36. timeline.addRessource(rows[1]);
  37. timeline.addRessource(rows[0]);
  38. timeline.addRessource(rows[2]);
  39. timeline.addRessource(rows[3]);
  40. timeslots.map(function (o) { return timeline.addTimeSlot(o); });
  41. timeline.addEventListener("item-selected", function (e) { console.log(e.detail); });
  42. title = document.createElement("h2");
  43. title.innerText = "Generic Timeline";
  44. document.body.appendChild(title);
  45. document.body.appendChild(timeline);
  46. var nestedTimeline = document.createElement("jc-timeline");
  47. title = document.createElement("h2");
  48. title.innerText = "Multiple level Timeline";
  49. document.body.appendChild(title);
  50. document.body.appendChild(nestedTimeline);
  51. var ressources = Array(8).fill(0).map(function (_, i) { return new Ressource({ id: "" + i, title: "level " + i }); });
  52. for (var i = 0; i < ressources.length - 1; i++) {
  53. ressources[i + 1].parent = ressources[i];
  54. }
  55. ressources.forEach(function (r) { return nestedTimeline.addRessource(r); });
  56. ressources[0].collapseChildren = true;
  57. var nItem = 32;
  58. var timeslots2 = Array(nItem).fill(0).map(function (_, i) {
  59. return {
  60. id: "" + i,
  61. ressourceId: "" + (i % 8),
  62. title: "I " + i,
  63. start: data.add(i / 2 - 5, 'h').toDate(),
  64. end: data.add(i / 2 - 4, 'h').toDate(),
  65. bgColor: "hsl(" + Math.round(i / (nItem - 1) * 360) + ", 100%, 50%)"
  66. };
  67. });
  68. timeslots2.forEach(function (r) { return nestedTimeline.addTimeSlot(r); });
  69. //# sourceMappingURL=index.js.map