From 51dacdeb068bae787f77713b175bb195401ae40e Mon Sep 17 00:00:00 2001 From: Lucas <lucas.villaume8@etu.univ-lorraine.fr> Date: Sat, 25 Nov 2023 21:22:29 +0100 Subject: [PATCH] Ajout de la fct toJSON() --- modele/Cellule.js | 7 +++++++ modele/Component.js | 4 ++++ modele/Document.js | 23 +++++++++++++++++++++++ modele/Expression.js | 4 ++++ modele/Feuille.js | 11 +++++++++++ 5 files changed, 49 insertions(+) diff --git a/modele/Cellule.js b/modele/Cellule.js index 40efe3c..35496cc 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 3f882ae..6a58328 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 b5af46d..b813ad3 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 6496456..ef00cd7 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 4f1cb8d..80ff5c4 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 -- GitLab