63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
import { vote } from "./main.js";
|
|
|
|
export default class Dataset {
|
|
#abstract;
|
|
#author;
|
|
#categories;
|
|
#date;
|
|
#description;
|
|
#id;
|
|
#rating;
|
|
#title;
|
|
#type;
|
|
#upvotes;
|
|
#url;
|
|
#votes;
|
|
|
|
constructor({abst: shortDescription, author, categories, date, description, id, rating, title, type, upvotes, url, votes}) {
|
|
this.#abstract = shortDescription;
|
|
this.#author = author;
|
|
this.#categories = categories;
|
|
this.#date = date;
|
|
this.#description = description;
|
|
this.#id = id;
|
|
this.#rating = rating;
|
|
this.#title = title;
|
|
this.#type = type;
|
|
this.#upvotes = upvotes;
|
|
this.#url = url;
|
|
this.#votes = votes;
|
|
}
|
|
|
|
createDatasetHTMLElement(votable, isUpVoted) {
|
|
let template = document.querySelector("#dataset-template");
|
|
const clone = template.content.cloneNode(true);
|
|
clone.querySelector(".dataset").dataset.id = this.#id;
|
|
clone.querySelector("h3").innerText = this.#title;
|
|
clone.querySelector("p").innerText = this.#description;
|
|
clone.querySelector("span").innerText = this.#upvotes;
|
|
if (!votable) {
|
|
let votedButton = clone.querySelector(isUpVoted? ".upvote-btn":".downvote-btn");
|
|
votedButton.classList.add("isVoted");
|
|
votedButton.disabled = true;
|
|
let notVotedButton = clone.querySelector(isUpVoted? ".downvote-btn":".upvote-btn");
|
|
notVotedButton.style.visibility = "hidden";
|
|
}
|
|
|
|
// Event Listeners
|
|
clone.querySelector(".upvote-btn").addEventListener("click", () => {
|
|
vote(this.#id, true);
|
|
});
|
|
|
|
clone.querySelector(".downvote-btn").addEventListener("click", () => {
|
|
vote(this.#id, false);
|
|
})
|
|
|
|
return clone;
|
|
}
|
|
|
|
getID() {
|
|
return this.#id;
|
|
}
|
|
}
|