2023-01-04 19:00:37 +00:00
|
|
|
class ResourceList {
|
|
|
|
/* 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 resource list implementations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static autoInit() {
|
|
|
|
CorpusList.autoInit();
|
|
|
|
CorpusFileList.autoInit();
|
|
|
|
JobList.autoInit();
|
|
|
|
JobInputList.autoInit();
|
|
|
|
JobResultList.autoInit();
|
|
|
|
SpaCyNLPPipelineModelList.autoInit();
|
|
|
|
TesseractOCRPipelineModelList.autoInit();
|
2023-01-11 12:47:09 +00:00
|
|
|
UserList.autoInit();
|
2023-01-09 07:45:47 +00:00
|
|
|
AdminUserList.autoInit();
|
2023-02-20 09:40:33 +00:00
|
|
|
CorpusFollowerList.autoInit();
|
2023-01-04 19:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultOptions = {
|
|
|
|
page: 5,
|
|
|
|
pagination: {
|
|
|
|
innerWindow: 2,
|
|
|
|
outerWindow: 2
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-09 07:45:47 +00:00
|
|
|
constructor(listContainerElement, options = {}) {
|
|
|
|
if ('items' in options) {
|
|
|
|
throw '"items" is not supported as an option, define it as a getter in the list class';
|
|
|
|
}
|
|
|
|
if ('valueNames' in options) {
|
|
|
|
throw '"valueNames" is not supported as an option, define it as a getter in the list class';
|
|
|
|
}
|
|
|
|
let _options = Utils.mergeObjectsDeep(
|
|
|
|
{item: this.item, valueNames: this.valueNames},
|
|
|
|
ResourceList.defaultOptions,
|
|
|
|
options
|
|
|
|
);
|
2023-01-04 19:00:37 +00:00
|
|
|
this.listContainerElement = listContainerElement;
|
|
|
|
this.initListContainerElement();
|
|
|
|
this.listjs = new List(listContainerElement, _options);
|
|
|
|
}
|
|
|
|
|
|
|
|
add(resources, callback) {
|
2023-02-21 15:23:10 +00:00
|
|
|
let tmp = Array.isArray(resources) ? resources : [resources];
|
|
|
|
let values = tmp.map((resource) => {
|
2023-01-04 19:00:37 +00:00
|
|
|
return this.mapResourceToValue(resource);
|
|
|
|
});
|
|
|
|
this.listjs.add(values, (items) => {
|
|
|
|
this.sort();
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
callback(items);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
remove(id) {
|
|
|
|
this.listjs.remove('id', id);
|
|
|
|
}
|
|
|
|
|
|
|
|
replace(id, key, value) {
|
|
|
|
let item = this.listjs.get('id', id)[0];
|
|
|
|
item.values({[key]: value});
|
|
|
|
}
|
|
|
|
|
|
|
|
// #region Mandatory getters and methods to implement
|
|
|
|
get item() {throw 'Not implemented';}
|
|
|
|
|
|
|
|
get valueNames() {throw 'Not implemented';}
|
|
|
|
|
|
|
|
initListContainerElement() {throw 'Not implemented';}
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
// #region Optional methods to implement
|
|
|
|
mapResourceToValue(resource) {return resource;}
|
|
|
|
|
|
|
|
sort() {return;}
|
|
|
|
// #endregion
|
|
|
|
}
|