diff --git a/app/static/css/nopaque.css b/app/static/css/nopaque.css index 3cdd89ac..9094c451 100644 --- a/app/static/css/nopaque.css +++ b/app/static/css/nopaque.css @@ -90,6 +90,9 @@ indicator will show up how the column is sorted right now.; */ .service[data-service]:before { content: "help"; } +.service[data-service="corpus"]:before { + content: "book"; +} .service[data-service="merge_images"]:before { content: "burst_mode"; } diff --git a/app/static/js/nopaque.lists.js b/app/static/js/nopaque.lists.js index 8f72fc92..da255d30 100644 --- a/app/static/js/nopaque.lists.js +++ b/app/static/js/nopaque.lists.js @@ -1,106 +1,25 @@ -class CorpusList extends List { - constructor(idOrElement, subscriberList, options={}) { - super(idOrElement, {...CorpusList.DEFAULT_OPTIONS, ...options}); +class RessourceList extends List { + constructor(idOrElement, subscriberList, dataMapper=null, options={}) { + super(idOrElement, {...RessourceList.options, ...options}); + this.dataMapper = dataMapper; subscriberList.push(this); } - _init(corpora) { - this.addCorpora(Object.values(corpora)); + _init(ressources) { + this.addRessources(Object.values(ressources)); } _update(patch) { - let item, corpusStatusElement, operation, pathArray; + let item, pathArray; - for (operation of patch) { - /* "/corpusId/valueName" -> ["corpusId", "valueName"] */ + for (let operation of patch) { + /* "/ressourceId/valueName" -> ["ressourceId", "valueName"] */ pathArray = operation.path.split("/").slice(1); switch(operation.op) { case "add": - this.addCorpora([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, _status: operation.value}); - break; - default: - break; - } - default: - break; - } - } - } - - - addCorpora(corpora) { - let data = []; - for (let corpus of corpora) { - data.push({description: corpus.description, - id: corpus.id, - link: `/corpora/${corpus.id}`, - status: corpus.status, - title: corpus.title}); - } - this.add(data); - } -} -CorpusList.DEFAULT_OPTIONS = { - item: ` - - - book - - - -
- - - - - - - Viewsend - - `, - page: 4, - pagination: {innerWindow: 8, outerWindow: 1}, - valueNames: ["description", - "title", - {data: ["id"]}, - {name: "link", attr: "href"}, - {name: "status", attr: "data-status"}]}; - - - -class JobList extends List { - constructor(idOrElement, subscriberList, options={}) { - super(idOrElement, {...JobList.DEFAULT_OPTIONS, ...options}); - subscriberList.push(this); - } - - - _init(jobs) { - this.addJobs(Object.values(jobs)); - } - - - _update(patch) { - let item, jobStatusElement, operation, pathArray; - - for (operation of patch) { - /* "/jobId/valueName" -> ["jobId", "valueName"] */ - pathArray = operation.path.split("/").slice(1); - switch(operation.op) { - case "add": - if (pathArray.includes("results")) {break;} - this.addJobs([operation.value]); + this.addRessources([operation.value]); break; case "remove": this.remove("id", pathArray[0]); @@ -121,20 +40,29 @@ class JobList extends List { } - addJobs(jobs) { - let data = []; - for (let job of jobs) { - data.push({description: job.description, - id: job.id, - link: `/jobs/${job.id}`, - service: job.service, - status: job.status, - title: job.title}); + addRessources(ressources) { + if (this.dataMapper) { + this.add(ressources.map(x => this.dataMapper(x))); + } else { + this.add(ressources); } - this.add(data); } } -JobList.DEFAULT_OPTIONS = { +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: ` diff --git a/app/templates/main/dashboard.html.j2 b/app/templates/main/dashboard.html.j2 index 1b175270..2373050d 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -86,7 +86,7 @@ {% endblock %}