diff --git a/modele/Cellule.js b/modele/Cellule.js index 40efe3c30444c6d3057a6ad0ab4f3479c60e52a4..35496cc4e474cb8127416d803f5fc8e1da1e3262 100644 --- a/modele/Cellule.js +++ b/modele/Cellule.js @@ -11,6 +11,13 @@ class Cellule extends Component{ setExpression(expression){ this.#expression = expression; } + + toJSON(){ + return { + numero: this.#numero, + expression: this.#expression.toJSON() //voir si on garde expression ou si on met le type d'expression (ex nombre: 12) + } + } } module.exports = Cellule; \ No newline at end of file diff --git a/modele/Component.js b/modele/Component.js index 3f882ae4c432f7953f95cebccd97f8c66a66b6fe..6a5832899c337b06fe4992d3f4cc687a5a36c045 100644 --- a/modele/Component.js +++ b/modele/Component.js @@ -4,4 +4,8 @@ class Component{ constructor(name = ''){ this.#nom = name; } + + getNom(){ + return this.#nom; + } } \ No newline at end of file diff --git a/modele/Document.js b/modele/Document.js index b5af46df265b030cd443c0d8fe296d68e31ddddd..b813ad38b267010a79ee1be78cc59ba2e7b18687 100644 --- a/modele/Document.js +++ b/modele/Document.js @@ -41,6 +41,29 @@ class Document extends Component{ this.#dateModification = date; } + get nom(){ + return super.getNom(); + } + + get auteur(){ + return this.#auteur; + } + + toJSON(){ + + let feuillesJSON = []; + feuilles.forEach(feuille => feuillesJSON.push(feuille.toJSON())); + + return { + id: this.#id, + nom: super.getNom(), + auteur: this.#auteur, + feuilles: feuillesJSON, + dateCreation: this.#dateCreation, + dateModification: this.#dateModification + } + } + } module.exports = Document; \ No newline at end of file diff --git a/modele/Expression.js b/modele/Expression.js index 6496456604c0271de3e0b63e3a6579d4ca900f0f..ef00cd7dc72a2bfa595522f769289266262e6b02 100644 --- a/modele/Expression.js +++ b/modele/Expression.js @@ -16,4 +16,8 @@ class Expression{ isTexte(){ return false; } + + toJSON(){ + return this.#contenu; + } } \ No newline at end of file diff --git a/modele/Feuille.js b/modele/Feuille.js index 4f1cb8d85d81a033625da95c265cd07b21b63729..80ff5c4ab53a25feb8f804dd58567f059e14c1af 100644 --- a/modele/Feuille.js +++ b/modele/Feuille.js @@ -21,6 +21,17 @@ class Feuille extends Component{ clearCells(){ this.#cells = [[]]; } + + toJSON(){ + + let cellsJSON = []; + cells.forEach(cell => cellsJSON.push(cell.toJSON())); + + return { + nom: super.getNom(), + cells: cellsJSON + } + } } module.exports = Feuille; \ No newline at end of file