mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
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();
|
|
PublicUserList.autoInit();
|
|
SpaCyNLPPipelineModelList.autoInit();
|
|
TesseractOCRPipelineModelList.autoInit();
|
|
UserList.autoInit();
|
|
}
|
|
|
|
static defaultOptions = {
|
|
page: 5,
|
|
pagination: {
|
|
innerWindow: 2,
|
|
outerWindow: 2
|
|
}
|
|
};
|
|
|
|
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 = _.merge({item: this.item, valueNames: this.valueNames}, ResourceList.defaultOptions, options);
|
|
this.listContainerElement = listContainerElement;
|
|
this.initListContainerElement();
|
|
this.listjs = new List(listContainerElement, _options);
|
|
}
|
|
|
|
add(resources, callback) {
|
|
let values = resources.map((resource) => {
|
|
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
|
|
}
|