Ressource.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Ressource = void 0;
  4. class Ressource {
  5. constructor(obj) {
  6. this.id = obj.id;
  7. this.title = obj.title || obj.id;
  8. if (obj.children) {
  9. this.children = obj.children.map(Ressource.toRessource);
  10. }
  11. else {
  12. this.children = [];
  13. }
  14. this.collapseChildren = obj.collapseChildren ? obj.collapseChildren : false;
  15. this.parent = obj.parent ? Ressource.toRessource(obj.parent) : undefined;
  16. this.height = obj.height;
  17. this.eventEditable = (obj === null || obj === void 0 ? void 0 : obj.eventEditable) === undefined ? true : obj.eventEditable;
  18. this.eventRessourceEditable =
  19. (obj === null || obj === void 0 ? void 0 : obj.eventRessourceEditable) === undefined ? true : obj.eventRessourceEditable;
  20. this.eventBgColor = obj.eventBgColor;
  21. this.selected = false;
  22. this.children.forEach((o) => (o.parent = this));
  23. }
  24. get parentId() {
  25. var _a;
  26. return ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.id) || "";
  27. }
  28. get depth() {
  29. return this.parent ? this.parent.depth + 1 : 0;
  30. }
  31. get show() {
  32. return this.parent === undefined ? true : this.parent.show && !this.parent.collapseChildren;
  33. }
  34. descendantOf(potentialParent) {
  35. return this.parent === undefined
  36. ? false
  37. : this.parent.id === potentialParent.id || this.parent.descendantOf(potentialParent);
  38. }
  39. toPlainObject(parent) {
  40. return {
  41. id: this.id,
  42. title: this.title,
  43. children: this.children.map((o) => o.toPlainObject(this)),
  44. parent: parent,
  45. };
  46. }
  47. toJSON() {
  48. return {
  49. id: this.id,
  50. title: this.title,
  51. collapseChildren: this.collapseChildren,
  52. parentId: this.parentId,
  53. height: this.height,
  54. eventEditable: this.eventEditable,
  55. eventRessourceEditable: this.eventRessourceEditable,
  56. eventBgColor: this.eventBgColor,
  57. };
  58. }
  59. static toRessource(obj) {
  60. if (obj instanceof Ressource) {
  61. return obj;
  62. }
  63. else {
  64. return new Ressource(obj);
  65. }
  66. }
  67. }
  68. exports.Ressource = Ressource;
  69. exports.default = Ressource;
  70. //# sourceMappingURL=Ressource.js.map