Skip to content
Snippets Groups Projects
Commit 7e1be5a3 authored by VILLAUME Lucas's avatar VILLAUME Lucas
Browse files

fct pour lire JSON

parent e90439c3
No related branches found
No related tags found
No related merge requests found
const Component = require("./Component"); const Component = require("./Component");
const Nombre = require("./Nombre");
class Cellule extends Component{ class Cellule extends Component{
...@@ -21,6 +22,11 @@ class Cellule extends Component{ ...@@ -21,6 +22,11 @@ class Cellule extends Component{
expression: this.#expression.toJSON() //voir si on garde expression ou si on met le type d'expression (ex nombre: 12) expression: this.#expression.toJSON() //voir si on garde expression ou si on met le type d'expression (ex nombre: 12)
} }
} }
readJSON(json){
//TODO: gerer les autres expressions par la suite
this.#expression = new Nombre(json.expression);
}
} }
module.exports = Cellule; module.exports = Cellule;
\ No newline at end of file
...@@ -8,6 +8,10 @@ class Component{ ...@@ -8,6 +8,10 @@ class Component{
getNom(){ getNom(){
return this.#nom; return this.#nom;
} }
setNom(name){
this.#nom = name;
}
} }
module.exports = Component; module.exports = Component;
\ No newline at end of file
...@@ -67,6 +67,21 @@ class Document extends Component{ ...@@ -67,6 +67,21 @@ class Document extends Component{
} }
} }
readJSON(json){
super.setNom(json.nom);
this.#auteur = json.auteur;
this.#id = json.id;
this.#dateCreation = json.dateCreation;
this.#dateModification = json.dateModification;
this.clearFeuilles();
json.feuilles.forEach(feuille => {
let f = new Feuille(this);
f.readJSON(feuille);
this.addFeuille(f);
});
}
} }
module.exports = Document; module.exports = Document;
\ No newline at end of file
const Component = require("./Component"); const Component = require("./Component");
const Cellule = require("./Cellule");
class Feuille extends Component{ class Feuille extends Component{
...@@ -37,6 +38,22 @@ class Feuille extends Component{ ...@@ -37,6 +38,22 @@ class Feuille extends Component{
cells: cellsJSON cells: cellsJSON
} }
} }
readJSON(json){
super.setNom(json.nom);
let tmp = [];
this.#cells = []; //reset du tableau
for (let i = 0; i < json.cells.length; i++){
json.cells[i].forEach(cell => {
let cellule = new Cellule(cell.numero);
cellule.readJSON(cell);
tmp.push(cellule);
});
this.#cells.push(tmp);
tmp = [];
}
}
} }
module.exports = Feuille; module.exports = Feuille;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment