index.ts 3.1 KB

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