Ressource.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 = (obj === null || obj === void 0 ? void 0 : obj.eventRessourceEditable) === undefined ? true : obj.eventRessourceEditable;
  19. this.eventBgColor = obj.eventBgColor;
  20. this.selected = false;
  21. this.children.forEach(o => o.parent = this);
  22. }
  23. get parentId() {
  24. var _a;
  25. return ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.id) || "";
  26. }
  27. get depth() {
  28. return this.parent ? this.parent.depth + 1 : 0;
  29. }
  30. get show() {
  31. return this.parent === undefined ? true : (this.parent.show && !this.parent.collapseChildren);
  32. }
  33. descendantOf(potentialParent) {
  34. return this.parent === undefined ? false : (this.parent.id === potentialParent.id || this.parent.descendantOf(potentialParent));
  35. }
  36. toPlainObject(parent) {
  37. return {
  38. id: this.id,
  39. title: this.title,
  40. children: this.children.map(o => o.toPlainObject(this)),
  41. parent: parent
  42. };
  43. }
  44. toJSON() {
  45. return {
  46. id: this.id,
  47. title: this.title,
  48. collapseChildren: this.collapseChildren,
  49. parent: this.parent,
  50. height: this.height,
  51. eventEditable: this.eventEditable,
  52. eventRessourceEditable: this.eventRessourceEditable,
  53. eventBgColor: this.eventBgColor
  54. };
  55. }
  56. static toRessource(obj) {
  57. if (obj instanceof Ressource) {
  58. return obj;
  59. }
  60. else {
  61. return new Ressource(obj);
  62. }
  63. }
  64. }
  65. exports.Ressource = Ressource;
  66. exports.default = Ressource;
  67. //# sourceMappingURL=Ressource.js.map