index.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  2. import { formats } from 'dayjs/locale/*';
  3. import Ressource from '../src/Ressource';
  4. import TimeLine from '../src/Timeline'
  5. import '../src/Ressource';
  6. import { IEvent } from '../src/Event';
  7. import dayjs from 'dayjs';
  8. // TimeLine.extendStyle.push(new_css)
  9. const emptyTimeline:TimeLine = document.createElement("jc-timeline") as TimeLine;
  10. let 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. const timeline:TimeLine = document.createElement("jc-timeline") as TimeLine;
  17. timeline.customStyle = `.bubble{
  18. height: 20px;
  19. width: 20px;
  20. display: flex;
  21. justify-content: center;
  22. align-items: center;
  23. position: absolute;
  24. right: -4px;
  25. bottom: -4px;
  26. border-radius: 50%;
  27. font-size: 12px;
  28. font-weight: bold;
  29. background: green;
  30. }
  31. bubble.red{
  32. background: red;
  33. }
  34. bubble.orange{
  35. background: orange;
  36. }`
  37. // timeline.defaultBackground = "maroon";
  38. const rows:Array<Ressource> = [
  39. {id:'1',title:"Ressource 1 DarkSlate",eventBgColor:"DarkSlateBlue"},
  40. {id:'3',title:"Ressource 3"},
  41. {id:'4',title:"Ressource 4"},
  42. {id:'5',title:"Ressource 5"}].map(i=> new Ressource(i));
  43. rows[2].parent = rows[1];
  44. rows[0].parent = rows[1];
  45. const data = dayjs().startOf("hour").hour(9);
  46. const timeslots:Array<IEvent> = [
  47. {id:'1', title:"Fixed ressource" ,ressourceId:'3', start:data.subtract(3,"h").toDate(), end:data.toDate(), ressourceEditable:false,bgColor:"darkgreen"},
  48. {id:'2', title:"Fixed time" , ressourceId:'3', start:data.toDate(), end:data.endOf("hour").add(1,"h").toDate(), editable:false,bgColor:"FireBrick"},
  49. {id:'3', ressourceId:'4', start:data.add(1,"h").toDate(), end:data.endOf("hour").add(2,"h").toDate(),content:'<div class="bubble">0</div>'},
  50. {id:'4', ressourceId:'3', start:data.startOf("day").subtract(1,"h").toDate(), end:dayjs().endOf("hour").add(1,"h").toDate()}
  51. ]
  52. for(let i = 5; i < 10; i++){
  53. timeslots.push({
  54. id : i.toFixed(0),
  55. title: "event " + i,
  56. ressourceId:'1',
  57. start:data.add(i,'h').toDate(),
  58. end:data.add(i,'h').endOf("hour").add(1,"h").toDate(),
  59. })
  60. }
  61. timeline.addRessource(rows[1]);
  62. timeline.addRessource(rows[0]);
  63. timeline.addRessource(rows[2]);
  64. timeline.addRessource(rows[3]);
  65. timeline.addEvents(timeslots)
  66. timeline.addEventListener("item-selected",(e)=>{console.log((e as CustomEvent).detail)})
  67. timeline.addEventListener("change-event",(e)=>{console.log((e as CustomEvent).detail)})
  68. timeline.addEventListener("reorder-ressource",(e)=>{console.log((e as CustomEvent).detail)})
  69. title = document.createElement("h2");
  70. title.innerText = "Generic Timeline"
  71. document.body.appendChild(title);
  72. document.body.appendChild(timeline);
  73. const nestedTimeline:TimeLine = document.createElement("jc-timeline") as TimeLine;
  74. title = document.createElement("h2");
  75. title.innerText = "Multiple level Timeline"
  76. document.body.appendChild(title);
  77. document.body.appendChild(nestedTimeline);
  78. const ressources = Array(8).fill(0).map((_,i)=>new Ressource({id:""+i,title:"level "+i}));
  79. for(let i = 0 ; i < ressources.length-1;i++){
  80. ressources[i+1].parent=ressources[i]
  81. }
  82. ressources.forEach(r=>nestedTimeline.addRessource(r));
  83. ressources[0].collapseChildren = true
  84. const nItem = 32;
  85. const timeslots2 = Array(nItem).fill(0).map((_,i)=>{
  86. return {
  87. id:""+i,
  88. ressourceId:"" + (i % 8),
  89. title:"Item "+i,
  90. start:data.add(i/2 - 5, 'h').toDate(),
  91. end:data.add(i/2 - 4, 'h').toDate(),
  92. bgColor:"hsl(" + Math.round(i / (nItem-1) * 360) + ", 100%, 50%)"
  93. }});
  94. nestedTimeline.addEvents(timeslots2);