|
@@ -1,7 +1,65 @@
|
|
|
|
|
+import { element } from "./element.js";
|
|
|
|
|
+import { submission } from "./submission.js";
|
|
|
|
|
+
|
|
|
class database {
|
|
class database {
|
|
|
|
|
+ #submissions;
|
|
|
|
|
+
|
|
|
constructor() {
|
|
constructor() {
|
|
|
|
|
+ this.clean();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ search(input) {
|
|
|
|
|
+ const phrase = input.trim();
|
|
|
|
|
+ const found = [];
|
|
|
|
|
|
|
|
|
|
+ this.submissions.forEach(name => {
|
|
|
|
|
+ const current = this.#submissions[name];
|
|
|
|
|
+
|
|
|
|
|
+ if (name.search(phrase) !== -1) {
|
|
|
|
|
+ found.push(current);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ current.elemenets.forEach(name => {
|
|
|
|
|
+ if (name.search(phrase) !== -1) {
|
|
|
|
|
+ found.push(current.get(name));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return found;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ clean() {
|
|
|
|
|
+ this.#submissions = {};
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ add(container) {
|
|
|
|
|
+ if (!(container instanceof submission)) {
|
|
|
|
|
+ throw "Trying to add something which is not an submission.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (container.name in this.#submissions) {
|
|
|
|
|
+ throw "Trying to add submission which already exists.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ this.#submissions[container.name] = container;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get submissions() {
|
|
|
|
|
+ return Object.keys(this.#submissions);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ get(name) {
|
|
|
|
|
+ if (typeof(name) !== "string") {
|
|
|
|
|
+ throw "Submission name must be an string.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!(name in this.#submissions)) {
|
|
|
|
|
+ throw "Trying to get submission which not exists.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return this.#submissions[name];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export { database };
|
|
export { database };
|