Эх сурвалжийг харах

Start working on data structures.

cixo 1 жил өмнө
parent
commit
b1ba354774

+ 1 - 1
assets/app.js

@@ -5,7 +5,7 @@ class app {
     #current_submission;
     
     constructor() {
-        
+            
     }
 }
 

+ 4 - 0
assets/app_parts.js

@@ -2,6 +2,10 @@ import { applet_animations, applet_builder } from "./applet.js";
 import { dom_manager } from "./functions.js";
 import { dictionary } from "./dictionary.js";
 
+class submissions_list {
+        
+}
+
 class submission_part {
     #header;
     #image;

+ 19 - 0
assets/element.js

@@ -0,0 +1,19 @@
+import { type_manager } from "./functions.js";
+
+class element {
+    #name;
+
+    constructor(name) {
+        if (!type_manager.is_string(name)) {
+            throw "Name of the element must be string.";
+        }
+
+        this.#name = name;
+    }
+
+    get name() {
+        return this.#name;
+    }
+}
+
+export { element };

+ 48 - 0
assets/elements_list.js

@@ -0,0 +1,48 @@
+import { element } from "./element.js";
+import { type_manager } from "./functions.js";
+
+class elements_list {
+    #content;
+
+    constructor() {
+        this.#content = {};
+    }
+
+    append(target) {
+        if (!(target instanceof element)) {
+            throw "New target on list must be instance of an element.";
+        }
+
+        if (this.exists(target)) {
+            throw "This element already exists on list.";
+        }
+
+        this.#content[target.name] = target;
+    }
+
+    exists(target) {
+        if (target instanceof element) {
+            target = target.name;
+        }
+
+        if (!(type_manager.is_string(target))) {
+            throw "Target must be instance of string or element.";
+        }
+
+        return this.#content.hasOwnProperty(target);
+    }
+
+    get(target) {
+        if (!this.exists(target)) {
+            throw "Element with that name not exists on list.";
+        }
+
+        return this.#content[target];
+    }
+
+    get content() {
+        return Object.assign({}, this.#content);
+    }
+}
+
+export { elements_list };

+ 4 - 0
assets/functions.js

@@ -14,6 +14,10 @@ class type_manager {
     static is_function(target) {
         return typeof(target) === 'function';
     }
+
+    static is_string(target) {
+        return String(target) === target;
+    }
 }
 
 export { dom_manager, type_manager };

+ 51 - 0
assets/submission.js

@@ -0,0 +1,51 @@
+import { type_manager } from "./functions.js";
+import { element } from "./element.js";
+import { elements_list } from "./elements_list.js";
+
+class submission {
+    #title;
+    #description;
+    #picture;
+    #elements;
+
+    constructor(title, description, picture, elements) {
+        if (!type_manager.is_string(title)) {
+            throw "Title must be an string.";
+        }
+
+        if (!type_manager.is_string(description)) {
+            throw "Description must be an string.";
+        }
+
+        if (!type_manager.is_string(picture)) {
+            throw "Picture must be URL.";
+        }
+
+        if (!(elements instanceof elements_list)) {
+            throw "Elements list must be instance of elements_list.";
+        }
+
+        this.#title = title;
+        this.#description = description;
+        this.#picture = picture;
+        this.#elements = elements;
+    }
+
+    get title() {
+        return this.#title;
+    }
+
+    get description() {
+        return this.#description;
+    }
+
+    get picture() {
+        return this.#picture;
+    }
+
+    get elements() {
+        return Array.from(this.#elements);
+    }
+}
+
+export { submission };