mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
163 lines
5.9 KiB
JavaScript
163 lines
5.9 KiB
JavaScript
class SpaCyNLPPipelineModelList extends ResourceList {
|
|
static autoInit() {
|
|
for (let spaCyNLPPipelineModelListElement of document.querySelectorAll('.spacy-nlp-pipeline-model-list:not(.no-autoinit)')) {
|
|
new SpaCyNLPPipelineModelList(spaCyNLPPipelineModelListElement);
|
|
}
|
|
}
|
|
|
|
constructor(listContainerElement, options = {}) {
|
|
super(listContainerElement, options);
|
|
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
|
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
|
this.isInitialized = false;
|
|
this.userId = listContainerElement.dataset.userId;
|
|
app.subscribeUser(this.userId).then((response) => {
|
|
app.socket.on('PATCH', (patch) => {
|
|
if (this.isInitialized) {this.onPatch(patch);}
|
|
});
|
|
});
|
|
app.getUser(this.userId).then((user) => {
|
|
this.add(Object.values(user.spacy_nlp_pipeline_models));
|
|
for (let uncheckedCheckbox of this.listjs.list.querySelectorAll('input[data-checked="True"]')) {
|
|
uncheckedCheckbox.setAttribute('checked', '');
|
|
}
|
|
if (user.role.name !== ('Administrator' || 'Contributor')) {
|
|
for (let switchElement of this.listjs.list.querySelectorAll('.is_public')) {
|
|
switchElement.setAttribute('disabled', '');
|
|
}
|
|
}
|
|
this.isInitialized = true;
|
|
});
|
|
}
|
|
|
|
get item() {
|
|
return `
|
|
<tr class="clickable hoverable">
|
|
<td><b><span class="title"></span> <span class="version"></span></b><br><i><span class="description"></span></i></td>
|
|
<td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>)<br><a class="publishing-url"><span class="publishing-url-2"></span></a></td>
|
|
<td>
|
|
<div class="switch action-switch center-align" data-action="share-request">
|
|
<span class="share"></span>
|
|
<label>
|
|
<input type="checkbox" class="is_public">
|
|
<span class="lever"></span>
|
|
public
|
|
</label>
|
|
</div>
|
|
</td>
|
|
<td class="right-align">
|
|
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
|
<a class="action-button btn-floating service-color darken waves-effect waves-light service-2" data-action="view"><i class="material-icons">send</i></a>
|
|
</td>
|
|
</tr>
|
|
`.trim();
|
|
}
|
|
|
|
get valueNames() {
|
|
return [
|
|
{data: ['id']},
|
|
{data: ['creation-date']},
|
|
{name: 'publisher-url', attr: 'href'},
|
|
{name: 'publishing-url', attr: 'href'},
|
|
'description',
|
|
'publisher',
|
|
'publishing-url-2',
|
|
'publishing-year',
|
|
'title',
|
|
'title-2',
|
|
'version',
|
|
{name: 'is_public', attr: 'data-checked'}
|
|
];
|
|
}
|
|
|
|
initListContainerElement() {
|
|
if (!this.listContainerElement.hasAttribute('id')) {
|
|
this.listContainerElement.id = Utils.generateElementId('spacy-nlp-pipeline-model-list-');
|
|
}
|
|
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
|
this.listContainerElement.innerHTML = `
|
|
<div class="input-field">
|
|
<i class="material-icons prefix">search</i>
|
|
<input id="${listSearchElementId}" class="search" type="text"></input>
|
|
<label for="${listSearchElementId}">Search SpaCy NLP Pipeline Model</label>
|
|
</div>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Title and Description</th>
|
|
<th>Publisher</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="list"></tbody>
|
|
</table>
|
|
<ul class="pagination"></ul>
|
|
`.trim();
|
|
}
|
|
|
|
mapResourceToValue(spaCyNLPPipelineModel) {
|
|
return {
|
|
'id': spaCyNLPPipelineModel.id,
|
|
'creation-date': spaCyNLPPipelineModel.creation_date,
|
|
'description': spaCyNLPPipelineModel.description,
|
|
'publisher': spaCyNLPPipelineModel.publisher,
|
|
'publisher-url': spaCyNLPPipelineModel.publisher_url,
|
|
'publishing-url': spaCyNLPPipelineModel.publishing_url,
|
|
'publishing-url-2': spaCyNLPPipelineModel.publishing_url,
|
|
'publishing-year': spaCyNLPPipelineModel.publishing_year,
|
|
'title': spaCyNLPPipelineModel.title,
|
|
'title-2': spaCyNLPPipelineModel.title,
|
|
'version': spaCyNLPPipelineModel.version,
|
|
'is_public': spaCyNLPPipelineModel.is_public ? 'True' : 'False'
|
|
};
|
|
}
|
|
|
|
sort() {
|
|
this.listjs.sort('creation-date', {order: 'desc'});
|
|
}
|
|
|
|
onChange(event) {
|
|
let actionSwitchElement = event.target.closest('.action-switch');
|
|
let action = actionSwitchElement.dataset.action;
|
|
let spaCyNLPPipelineModelElement = event.target.closest('tr');
|
|
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
|
|
switch (action) {
|
|
case 'share-request': {
|
|
let is_public = actionSwitchElement.querySelector('input').checked;
|
|
Utils.shareSpaCyNLPPipelineModelRequest(this.userId, spaCyNLPPipelineModelId, is_public);
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
onClick(event) {
|
|
if (event.target.closest('.action-switch')) {
|
|
let userRole = app.data.users[this.userId].role.name;
|
|
if (userRole !== ('Administrator' || 'Contributor')) {
|
|
app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error');
|
|
}
|
|
return;
|
|
}
|
|
let actionButtonElement = event.target.closest('.action-button');
|
|
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
|
let spaCyNLPPipelineModelElement = event.target.closest('tr');
|
|
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
|
|
switch (action) {
|
|
case 'delete-request': {
|
|
Utils.deleteSpaCyNLPPipelineModelRequest(this.userId, spaCyNLPPipelineModelId);
|
|
break;
|
|
}
|
|
case 'view': {
|
|
window.location.href = `/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModelId}`;
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|