|
|
@@ -1,5 +1,7 @@
|
|
|
+import { type_manager } from "./functions.js";
|
|
|
import { project } from "./project.js";
|
|
|
import { element } from "./element.js";
|
|
|
+import { element_builder } from "./element_builder.js";
|
|
|
import { elements_list } from "./elements_list.js";
|
|
|
import { submission } from "./submission.js";
|
|
|
import { submissions_list } from "./submissions_list.js";
|
|
|
@@ -9,32 +11,36 @@ class database {
|
|
|
#project;
|
|
|
#submissions;
|
|
|
|
|
|
- constructor(content) {
|
|
|
- if (!(content instanceof Object)) {
|
|
|
- throw "Content to into database from must be an object.";
|
|
|
- }
|
|
|
+ #parse_element(name, content) {
|
|
|
+ const builder = new element_builder();
|
|
|
|
|
|
- this.#load(content);
|
|
|
- }
|
|
|
+ builder.name = name;
|
|
|
+ builder.description = "";
|
|
|
|
|
|
- #load(content) {
|
|
|
- const loader = new parser(content, "root");
|
|
|
- const project = loader.get_parser("project");
|
|
|
- const submissions = loader.get_parser("submissions");
|
|
|
+ if (content.exists("description")) {
|
|
|
+ builder.description = content.get("description");
|
|
|
+ }
|
|
|
|
|
|
- this.#project = this.#parse_project(project);
|
|
|
- this.#submissions = this.#parse_submissions(submissions);
|
|
|
- }
|
|
|
+ const adder = (property, how) => {
|
|
|
+ if (!content.exists(property)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- #parse_project(content) {
|
|
|
- const name = content.get("name");
|
|
|
- let description = "";
|
|
|
+ const list = content.get(property);
|
|
|
|
|
|
- if (content.exists("description")) {
|
|
|
- description = content.get("description");
|
|
|
+ if (!type_manager.is_array(list)) {
|
|
|
+ throw "Property " + property + " of " + name + " not array.";
|
|
|
+ }
|
|
|
+
|
|
|
+ list.forEach((item) => how(item));
|
|
|
}
|
|
|
|
|
|
- return new project(name, description);
|
|
|
+ adder("pictures", (target) => builder.add_picture(target));
|
|
|
+ adder("order", (target) => builder.add_order(target));
|
|
|
+ adder("meshes", (target) => builder.add_mesh(target));
|
|
|
+ adder("solids", (target) => builder.add_solid(target));
|
|
|
+
|
|
|
+ return builder.result;
|
|
|
}
|
|
|
|
|
|
#parse_elements(content) {
|
|
|
@@ -42,12 +48,8 @@ class database {
|
|
|
|
|
|
content.properties.forEach(name => {
|
|
|
const loader = content.get_parser(name);
|
|
|
-
|
|
|
- const result = new element(
|
|
|
- name
|
|
|
- );
|
|
|
-
|
|
|
- list.append(result);
|
|
|
+
|
|
|
+ list.append(this.#parse_element(name, loader));
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
@@ -76,9 +78,37 @@ class database {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ #load(content) {
|
|
|
+ const loader = new parser(content, "root");
|
|
|
+ const project = loader.get_parser("project");
|
|
|
+ const submissions = loader.get_parser("submissions");
|
|
|
+
|
|
|
+ this.#project = this.#parse_project(project);
|
|
|
+ this.#submissions = this.#parse_submissions(submissions);
|
|
|
+ }
|
|
|
+
|
|
|
+ #parse_project(content) {
|
|
|
+ const name = content.get("name");
|
|
|
+ let description = "";
|
|
|
+
|
|
|
+ if (content.exists("description")) {
|
|
|
+ description = content.get("description");
|
|
|
+ }
|
|
|
+
|
|
|
+ return new project(name, description);
|
|
|
+ }
|
|
|
+
|
|
|
get project() {
|
|
|
return this.#project;
|
|
|
}
|
|
|
+
|
|
|
+ constructor(content) {
|
|
|
+ if (!(content instanceof Object)) {
|
|
|
+ throw "Content to into database from must be an object.";
|
|
|
+ }
|
|
|
+
|
|
|
+ this.#load(content);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export { database };
|