Event.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. exports.Event = void 0;
  7. const dayjs_1 = __importDefault(require("dayjs"));
  8. class Event {
  9. constructor(obj) {
  10. this.id = obj.id;
  11. this.start = obj.start;
  12. this.end = obj.end;
  13. this.ressourceId = obj.ressourceId;
  14. this.title = (obj === null || obj === void 0 ? void 0 : obj.title) || this.id;
  15. this.isDisplayed = false;
  16. this.offset = 0;
  17. this.editable = (obj === null || obj === void 0 ? void 0 : obj.editable) === undefined ? null : obj.editable;
  18. this.ressourceEditable = (obj === null || obj === void 0 ? void 0 : obj.ressourceEditable) === undefined ? null : obj.ressourceEditable;
  19. this.moving = false;
  20. this.selected = false;
  21. this.bgColor = obj.bgColor;
  22. this.content = obj.content;
  23. }
  24. get startStr() {
  25. return this.start.toISOString();
  26. }
  27. get endStr() {
  28. return this.end.toISOString();
  29. }
  30. static toTimeSlot(obj) {
  31. if (obj instanceof Event) {
  32. return obj;
  33. }
  34. else {
  35. return new Event(obj);
  36. }
  37. }
  38. toJSON() {
  39. const output = {
  40. id: this.id,
  41. start: this.startStr,
  42. end: this.endStr,
  43. title: this.title,
  44. ressourceId: this.ressourceId,
  45. editable: this.editable,
  46. ressourceEditable: this.ressourceEditable,
  47. bgColor: this.bgColor,
  48. content: this.content,
  49. };
  50. if (this.bgColor) {
  51. output.bgColor = this.bgColor;
  52. }
  53. if (this.content) {
  54. output.content = this.content;
  55. }
  56. return output;
  57. }
  58. static fromJSON(input) {
  59. let obj;
  60. if (typeof input == "string") {
  61. obj = JSON.parse(input);
  62. }
  63. else {
  64. obj = input;
  65. }
  66. const start = dayjs_1.default(obj.start);
  67. const end = dayjs_1.default(obj.end);
  68. if (!start.isValid()) {
  69. throw new Error(`Error during the import of the Event '${obj.id}': Invalid starting date`);
  70. }
  71. else {
  72. if (!end.isValid()) {
  73. throw new Error(`Error during the import of the Event '${obj.id}': Invalid ending date`);
  74. }
  75. else {
  76. const iEvent = {
  77. id: obj.id,
  78. start: start.toDate(),
  79. end: end.toDate(),
  80. title: obj.title,
  81. ressourceId: obj.ressourceId,
  82. editable: obj.editable,
  83. ressourceEditable: obj.ressourceEditable,
  84. bgColor: obj.bgColor,
  85. content: obj.content,
  86. };
  87. if (obj.bgColor) {
  88. iEvent.bgColor = obj.bgColor;
  89. }
  90. if (obj.content) {
  91. iEvent.content = obj.content;
  92. }
  93. return new Event(iEvent);
  94. }
  95. }
  96. }
  97. }
  98. exports.Event = Event;
  99. exports.default = Event;
  100. //# sourceMappingURL=Event.js.map