class RessourceList extends List { constructor(idOrElement, subscriberList, dataMapper=null, options={}) { super(idOrElement, {...RessourceList.options, ...options}); this.dataMapper = dataMapper; subscriberList.push(this); } _init(ressources) { this.addRessources(Object.values(ressources)); } _update(patch) { let item, pathArray; for (let operation of patch) { /* "/ressourceId/valueName" -> ["ressourceId", "valueName"] */ pathArray = operation.path.split("/").slice(1); switch(operation.op) { case "add": this.addRessources([operation.value]); break; case "remove": this.remove("id", pathArray[0]); break; case "replace": item = this.get("id", pathArray[0])[0]; switch(pathArray[1]) { case "status": item.values({status: operation.value}); break; default: break; } default: break; } } } addRessources(ressources) { if (this.dataMapper) { this.add(ressources.map(x => this.dataMapper(x))); } else { this.add(ressources); } } } RessourceList.dataMapper = { corpus: corpus => ({description: corpus.description, id: corpus.id, link: `/corpora/${corpus.id}`, service: "corpus", status: corpus.status, title: corpus.title}), job: job => ({description: job.description, id: job.id, link: `/jobs/${job.id}`, service: job.service, status: job.status, title: job.title}) }; RessourceList.options = { item: `
" + inspectBtn.outerHTML + "
"; // // get infos for right context of match // let rc_tokens = ""; // for (cpos of match["rc"]) { // tokenElement = document.createElement("span"); // tokenElement.classList.add("token"); // tokenElement.dataset.cpos = cpos; // token = chunk["cpos_lookup"][cpos]; // tokenElement.innerText = token["word"]; // rc_tokens += " " + tokenElement.outerHTML; // } // // put all infos into an javascribt object // textTitleElement = document.createElement("span"); // textTitleElement.classList.add("text-titles"); // textTitles = [...textTitles].join(","); // textTitleElement.innerText = textTitles; // // matchRowElement.appendChild(textTitleElement); // // matchRowElement.appendChild(lc_tokens); // // matchRowElement.appendChild(hit_tokens); // // matchRowElement.appendChild(rc_tokens); // // matchRowElement.appendChild(index); // } console.log(matchRowElement.outerHTML); return matchRowElement } }