2021-01-11 12:36:45 +00:00
|
|
|
class RessourceList {
|
|
|
|
/* A wrapper class for the list.js list.
|
|
|
|
* This class is not meant to be used directly, instead it should be used as
|
|
|
|
* a base class for concrete ressource list implementations.
|
|
|
|
*/
|
2021-12-02 15:25:48 +00:00
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
static autoInit() {
|
|
|
|
CorpusList.autoInit();
|
|
|
|
CorpusFileList.autoInit();
|
|
|
|
JobList.autoInit();
|
|
|
|
JobInputList.autoInit();
|
|
|
|
JobResultList.autoInit();
|
2022-12-05 15:25:54 +00:00
|
|
|
PublicCorporaList.autoInit();
|
2022-12-19 11:46:18 +00:00
|
|
|
PublicUserList.autoInit();
|
2022-11-16 13:15:52 +00:00
|
|
|
SpaCyNLPPipelineModelList.autoInit();
|
2022-11-15 14:11:16 +00:00
|
|
|
TesseractOCRPipelineModelList.autoInit();
|
2022-09-02 11:07:30 +00:00
|
|
|
UserList.autoInit();
|
2021-12-02 15:25:48 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
static options = {page: 5, pagination: {innerWindow: 4, outerWindow: 1}};
|
2021-12-02 15:25:48 +00:00
|
|
|
|
2021-01-11 12:36:45 +00:00
|
|
|
constructor(listElement, options = {}) {
|
2021-12-02 10:16:06 +00:00
|
|
|
if (!(listElement.hasAttribute('id'))) {
|
2022-09-02 11:07:30 +00:00
|
|
|
let i;
|
2021-12-02 10:16:06 +00:00
|
|
|
for (i = 0; true; i++) {
|
2022-01-14 13:14:04 +00:00
|
|
|
if (document.querySelector(`#ressource-list-${i}`)) {continue;}
|
2021-12-02 10:16:06 +00:00
|
|
|
listElement.id = `ressource-list-${i}`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-12-03 11:01:50 +00:00
|
|
|
options = {
|
|
|
|
...{pagination: {item: `<li><a class="page" href="#${listElement.id}"></a></li>`}},
|
|
|
|
...options
|
|
|
|
}
|
2022-12-12 14:37:33 +00:00
|
|
|
if ('ressourceMapper' in options && typeof options.ressourceMapper === 'function') {
|
2021-12-03 11:01:50 +00:00
|
|
|
this.ressourceMapper = options.ressourceMapper;
|
|
|
|
delete options.ressourceMapper;
|
|
|
|
}
|
2022-12-12 14:37:33 +00:00
|
|
|
if ('initialHtmlGenerator' in options && typeof options.initialHtmlGenerator === 'function') {
|
2022-09-02 11:07:30 +00:00
|
|
|
this.initialHtmlGenerator = options.initialHtmlGenerator;
|
|
|
|
listElement.innerHTML = this.initialHtmlGenerator(listElement.id);
|
|
|
|
delete options.initialHtmlGenerator;
|
|
|
|
}
|
|
|
|
if ('sortArgs' in options) {
|
|
|
|
this.sortArgs = options.sortArgs;
|
|
|
|
delete options.sortArgs;
|
2021-12-03 11:01:50 +00:00
|
|
|
}
|
2021-12-02 10:16:06 +00:00
|
|
|
this.listjs = new List(listElement, {...RessourceList.options, ...options});
|
|
|
|
this.listjs.list.innerHTML = `
|
2021-11-30 15:22:16 +00:00
|
|
|
<tr>
|
|
|
|
<td class="row" colspan="100%">
|
|
|
|
<div class="col s12"> </div>
|
|
|
|
<div class="col s3 m2 xl1">
|
|
|
|
<div class="preloader-wrapper active">
|
|
|
|
<div class="spinner-layer spinner-green-only">
|
|
|
|
<div class="circle-clipper left">
|
|
|
|
<div class="circle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="gap-patch">
|
|
|
|
<div class="circle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="circle-clipper right">
|
|
|
|
<div class="circle"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col s9 m6 xl5">
|
|
|
|
<span class="card-title">Waiting for data...</span>
|
|
|
|
<p>This list is not initialized yet.</p>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim();
|
2021-12-08 14:36:10 +00:00
|
|
|
this.userId = this.listjs.listContainer.dataset.userId;
|
2022-09-02 11:07:30 +00:00
|
|
|
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
2022-07-08 09:46:47 +00:00
|
|
|
this.isInitialized = false;
|
2021-11-30 15:22:16 +00:00
|
|
|
if (this.userId) {
|
2022-09-02 11:07:30 +00:00
|
|
|
app.subscribeUser(this.userId)
|
|
|
|
.then((response) => {
|
|
|
|
app.socket.on('PATCH', (patch) => {
|
|
|
|
if (this.isInitialized) {this.onPatch(patch);}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
app.getUser(this.userId)
|
|
|
|
.then((user) => {
|
|
|
|
this.init(user);
|
|
|
|
this.isInitialized = true;
|
|
|
|
});
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
_init(ressources) {
|
2021-12-02 10:16:06 +00:00
|
|
|
this.listjs.clear();
|
2021-01-11 12:36:45 +00:00
|
|
|
this.add(Object.values(ressources));
|
2022-09-02 11:07:30 +00:00
|
|
|
this.listjs.list.insertAdjacentHTML(
|
|
|
|
'afterbegin',
|
|
|
|
`
|
|
|
|
<tr class="show-if-only-child">
|
|
|
|
<td colspan="100%">
|
|
|
|
<span class="card-title"><i class="left material-icons" style="font-size: inherit;">file_download</i>Nothing here...</span>
|
|
|
|
<p>No ressource available.</p>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim()
|
|
|
|
);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
init(user) {throw 'Not implemented';}
|
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
onClick(event) {throw 'Not implemented';}
|
2021-11-30 15:22:16 +00:00
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
onPatch(patch) {throw 'Not implemented';}
|
2021-01-11 12:36:45 +00:00
|
|
|
|
2021-12-03 11:01:50 +00:00
|
|
|
add(ressources) {
|
|
|
|
let values = Array.isArray(ressources) ? ressources : [ressources];
|
|
|
|
if ('ressourceMapper' in this) {
|
2022-09-02 11:07:30 +00:00
|
|
|
values = values.map((value) => {return this.ressourceMapper(value);});
|
2021-12-03 11:01:50 +00:00
|
|
|
}
|
|
|
|
this.listjs.add(values, () => {
|
2022-09-02 11:07:30 +00:00
|
|
|
if ('sortArgs' in this) {
|
|
|
|
this.listjs.sort(...this.sortArgs);
|
2021-12-03 11:01:50 +00:00
|
|
|
}
|
2021-08-23 14:34:25 +00:00
|
|
|
});
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remove(id) {
|
2021-12-02 10:16:06 +00:00
|
|
|
this.listjs.remove('id', id);
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
replace(id, valueName, newValue) {
|
2022-09-02 11:07:30 +00:00
|
|
|
this.listjs.get('id', id)[0].values({[valueName]: newValue});
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|
|
|
|
}
|