Explorar el Código

Add base structures to interpretate database.

cixo hace 1 año
padre
commit
17c3c62f44
Se han modificado 3 ficheros con 166 adiciones y 25 borrados
  1. 24 25
      assets/element.js
  2. 60 0
      assets/project.js
  3. 82 0
      assets/submission.js

+ 24 - 25
assets/element.js

@@ -1,7 +1,4 @@
-import { lang } from "./lang.js";
-
 class element {
-    #id;
     #pictures;
     #mesh;
     #name;
@@ -10,34 +7,36 @@ class element {
     #links;
     #thumbnail;
 
-    constructor(id) {
-        if (typeof(id) !== "number") {
-            throw "ID must be number.";
+    constructor(name) {
+        if (typeof(name) !== "string") {
+            throw "Name must be an string.";
         }
-
-        this.#id = id;
+        
+        this.#name = name;
+        
+        this.#description = "";
+        this.#mesh = "";
+        this.#thumbnail = "";
+        
         this.#pictures = new Set();
         this.#params = new Map();
         this.#links = new Map();
-        this.#name = undefined;
-        this.#mesh = undefined;
-        this.#thumbnail = undefined;
     }
 
-    get id() {
-        return this.#id;
+    get name() {
+        return this.#name;
+    }
+
+    get description() {
+        return this.#description;
     }
 
-    set name(content) {
+    set description(content) {
         if (typeof(content) !== "string") {
-            throw "Name must be string.";
+            throw "Description must be an string.";
         }
 
-        this.#name = content;
-    }
-
-    get name() {
-        return this.#name;
+        this.#description = content;
     }
 
     get mesh() {
@@ -52,16 +51,16 @@ class element {
         this.#mesh = content;
     }
 
+    get thumbnail() {
+        return this.#thumbnail;
+    }
+    
     set thumbnail(content) {
         if (typeof(content) !== "string") {
             throw "Thumbnail URL must be string.";
         }   
     }
-    
-    get thumbnail() {
-        return this.#thumbnail;
-    }
-    
+
     get links() {
         return this.#links;
     }

+ 60 - 0
assets/project.js

@@ -0,0 +1,60 @@
+import { submission } from "./submission.js";
+
+class project {
+    #name;
+    #description;
+    #submissions;
+
+    constructor(name) {
+        this.#name = name;
+        this.#description = "";
+
+        this.clean();
+    }
+
+    get name() {
+        return this.#name;
+    }
+
+    get description() {
+        return this.#description;
+    }
+
+    set description(content) {
+        if (typeof(content) !== "string") {
+            throw "Description must be an string.";
+        }
+
+        this.#description = content;
+    }
+
+    get submissions() {
+        return Object.keys(this.#submissions);
+    }
+
+    get(name) {
+        if (typeof(name) !== "string") {
+            throw "Name of submission must be an string.";
+        }
+
+        return this.#submissions[name];
+    }
+
+    add(content) {
+        if (!(content instanceof submission)) {
+            throw "New submission must be instance of submission class.";
+        } 
+
+        if (content.name in this.#submissions) {
+            throw "Trying to add submission which already exists.";
+        }
+
+        this.#submissions[content.name] = content;
+    }
+
+    clean() {
+        this.#submissions = {};
+    }
+}
+
+export { project };

+ 82 - 0
assets/submission.js

@@ -0,0 +1,82 @@
+import { element } from "./element.js";
+
+class submission {
+    #name;
+    #description;
+    #thumbnail;
+    #elements;
+
+    constructor(name) {
+        if (typeof(name) !== "string") {
+            throw "Name must be an string.";
+        }
+
+        this.#name = name;
+        this.#description = "";
+        this.#thumbnail = "";
+
+        this.clean();
+    }
+
+    get name() { 
+        return this.#name; 
+    }
+    
+    get description() { 
+        return this.#description; 
+    }
+
+    set description(content) {
+        if (typeof(content) !== "string") {
+            throw "Description must be an string.";
+        }
+
+        this.#description = content;
+    }
+
+    get thumbnail() {
+        return this.#thumbnail;
+    }
+
+    set thumbnail(content) {
+        if (typeof(content) !== "string") {
+            throw "Thumbnail must be an string.";
+        }
+
+        this.#thumbnail = content;
+    }
+
+    get elements() {
+        return Object.keys(this.#elements);
+    }
+
+    add(item) {
+        if (!(item instanceof element)) {
+            throw "Trying to add something which is not an element.";
+        }
+
+        if (item.name in this.#elements) {
+            throw "Trying to add element which already exists in submission.";
+        }   
+
+        this.#elements[item.name] = item;
+    }
+
+    get(name) {
+        if (typeof(name) !== "string") {
+            throw "Name must be an string.";
+        }
+
+        if (!(name in this.#elements)) {
+            throw "Trying to get element which not exists.";
+        }
+
+        return this.#elements[name];
+    }
+
+    clean() {
+        this.#elements = {};
+    }
+}
+
+export { submission };