index.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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', content:"Fixed ressource" ,ressourceId:'3', start:data.subtract(3,"h").toDate(), end:data.toDate(), ressourceEditable:false,bgColor:"darkgreen"},
  27. {id:'2', content:"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. content: "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. timeline.addEventListener("change-event",(e)=>{console.log((e as CustomEvent).detail)})
  47. timeline.addEventListener("reorder-ressource",(e)=>{console.log((e as CustomEvent).detail)})
  48. title = document.createElement("h2");
  49. title.innerText = "Generic Timeline"
  50. document.body.appendChild(title);
  51. document.body.appendChild(timeline);
  52. const nestedTimeline:TimeLine = document.createElement("jc-timeline") as TimeLine;
  53. title = document.createElement("h2");
  54. title.innerText = "Multiple level Timeline"
  55. document.body.appendChild(title);
  56. document.body.appendChild(nestedTimeline);
  57. const ressources = Array(8).fill(0).map((_,i)=>new Ressource({id:""+i,title:"level "+i}));
  58. for(let i = 0 ; i < ressources.length-1;i++){
  59. ressources[i+1].parent=ressources[i]
  60. }
  61. ressources.forEach(r=>nestedTimeline.addRessource(r));
  62. ressources[0].collapseChildren = true
  63. const nItem = 32;
  64. const timeslots2 = Array(nItem).fill(0).map((_,i)=>{
  65. return {
  66. id:""+i,
  67. ressourceId:"" + (i % 8),
  68. title:"Item "+i,
  69. start:data.add(i/2 - 5, 'h').toDate(),
  70. end:data.add(i/2 - 4, 'h').toDate(),
  71. bgColor:"hsl(" + Math.round(i / (nItem-1) * 360) + ", 100%, 50%)"
  72. }});
  73. nestedTimeline.addEvents(timeslots2);