workspace.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { submission } from "./submission.js";
  2. import { items_list } from "./items_list.js";
  3. class workspace {
  4. #container;
  5. constructor() {
  6. this.#container = document.createElement("div");
  7. this.#container.className = "workspace";
  8. }
  9. #clean() {
  10. while (this.#container.firstChild) {
  11. this.#container.firstChild.remove();
  12. }
  13. }
  14. click_element(item) {
  15. console.log(item.name);
  16. }
  17. update(item) {
  18. if (!(item instanceof submission)) {
  19. throw "Element in workspace must be an submission.";
  20. }
  21. this.#clean();
  22. const thumbnail_container = document.createElement("div");
  23. thumbnail_container.className = "thumbnail-container";
  24. const thumbnail = document.createElement("img");
  25. thumbnail.className = "thumbnail";
  26. thumbnail.src = item.thumbnail;
  27. thumbnail_container.appendChild(thumbnail);
  28. const elements = document.createElement("div");
  29. const list = new items_list(elements, this.click_element);
  30. list.update(item.elements);
  31. const title = document.createElement("p");
  32. title.innerText = item.name;
  33. const description = document.createElement("p");
  34. description.innerText = item.description;
  35. const header = document.createElement("div");
  36. header.className = "header";
  37. header.appendChild(title);
  38. header.appendChild(description);
  39. const bottom = document.createElement("div");
  40. bottom.className = "bottom";
  41. bottom.appendChild(thumbnail_container);
  42. const left = document.createElement("div");
  43. left.className = "left";
  44. const right = document.createElement("div");
  45. right.className = "right";
  46. left.appendChild(header);
  47. left.appendChild(bottom);
  48. right.appendChild(elements);
  49. this.#container.appendChild(left);
  50. this.#container.appendChild(right);
  51. }
  52. get ui() {
  53. return this.#container;
  54. }
  55. }
  56. export { workspace };