Ressource.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Ressource = void 0;
  4. var Ressource = (function () {
  5. function Ressource(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 === null || obj === void 0 ? void 0 : obj.collapseChildren) === undefined ? false : obj.collapseChildren;
  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. }
  22. Object.defineProperty(Ressource.prototype, "parentId", {
  23. get: function () {
  24. var _a;
  25. return ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.id) || "";
  26. },
  27. enumerable: false,
  28. configurable: true
  29. });
  30. Object.defineProperty(Ressource.prototype, "depth", {
  31. get: function () {
  32. return this.parent ? this.parent.depth + 1 : 0;
  33. },
  34. enumerable: false,
  35. configurable: true
  36. });
  37. Object.defineProperty(Ressource.prototype, "show", {
  38. get: function () {
  39. return this.parent === undefined ? true : (this.parent.show && !this.parent.collapseChildren);
  40. },
  41. enumerable: false,
  42. configurable: true
  43. });
  44. Ressource.prototype.childOf = function (potentialParent) {
  45. return this.parent === undefined ? false : (this.parent.id === potentialParent.id || this.parent.childOf(potentialParent));
  46. };
  47. Ressource.prototype.toPlainObject = function (parent) {
  48. var _this = this;
  49. return {
  50. id: this.id,
  51. title: this.title,
  52. children: this.children.map(function (o) { return o.toPlainObject(_this); }),
  53. parent: parent
  54. };
  55. };
  56. Ressource.toRessource = function (obj) {
  57. if (obj instanceof Ressource) {
  58. return obj;
  59. }
  60. else {
  61. return new Ressource(obj);
  62. }
  63. };
  64. return Ressource;
  65. }());
  66. exports.Ressource = Ressource;
  67. exports.default = Ressource;
  68. //# sourceMappingURL=Ressource.js.map