index.js 3.3 KB

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