2021-01-11 12:36:45 +00:00
|
|
|
class QueryResultList extends RessourceList {
|
2021-12-02 15:25:48 +00:00
|
|
|
static options = {
|
|
|
|
item: `
|
2021-12-08 10:25:52 +00:00
|
|
|
<tr class="hoverable">
|
2021-12-02 15:25:48 +00:00
|
|
|
<td><b class="title"></b><br><i class="description"></i><br></td>
|
|
|
|
<td><span class="corpus_title"></span><br><span class="query"></span></td>
|
|
|
|
<td class="right-align">
|
|
|
|
<a class="action-button btn-floating red tooltipped waves-effect waves-light" data-action="delete" data-position="top" data-tooltip="Delete"><i class="material-icons">delete</i></a>
|
|
|
|
<a class="action-button btn-floating tooltipped waves-effect waves-light" data-action="view" data-position="top" data-tooltip="View"><i class="material-icons">send</i></a>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim(),
|
2021-12-03 11:01:50 +00:00
|
|
|
ressourceMapper: queryResult => {
|
|
|
|
return {
|
|
|
|
id: queryResult.id,
|
|
|
|
corpusTitle: queryResult.corpus_title,
|
|
|
|
creationDate: queryResult.creation_date,
|
|
|
|
description: queryResult.description,
|
|
|
|
query: queryResult.query,
|
|
|
|
title: queryResult.title
|
|
|
|
};
|
|
|
|
},
|
|
|
|
sortValueName: 'creationDate',
|
|
|
|
valueNames: [
|
|
|
|
{data: ['id']},
|
|
|
|
{data: ['creationDate']},
|
|
|
|
'corpusTitle',
|
|
|
|
'description',
|
|
|
|
'query',
|
|
|
|
'title'
|
|
|
|
]
|
2021-12-02 15:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-11 12:36:45 +00:00
|
|
|
constructor(listElement, options = {}) {
|
|
|
|
super(listElement, {...QueryResultList.options, ...options});
|
2021-01-12 14:25:54 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
init(user) {
|
2021-12-02 10:16:06 +00:00
|
|
|
super._init(user.query_results);
|
2021-01-14 11:30:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 14:25:54 +00:00
|
|
|
onclick(event) {
|
2021-12-01 13:15:20 +00:00
|
|
|
let action;
|
|
|
|
let actionButtonElement;
|
|
|
|
let deleteModal;
|
|
|
|
let deleteModalElement;
|
|
|
|
let queryResultElement;
|
|
|
|
let queryResultId;
|
|
|
|
let tmp;
|
|
|
|
|
|
|
|
queryResultElement = event.target.closest('tr[data-id]');
|
2021-11-30 15:22:16 +00:00
|
|
|
if (queryResultElement === null) {return;}
|
2021-12-01 13:15:20 +00:00
|
|
|
queryResultId = queryResultElement.dataset.id;
|
|
|
|
actionButtonElement = event.target.closest('.action-button[data-action]');
|
|
|
|
action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
2021-01-12 14:25:54 +00:00
|
|
|
switch (action) {
|
|
|
|
case 'delete':
|
2021-12-01 13:15:20 +00:00
|
|
|
tmp = document.createElement('div');
|
|
|
|
tmp.innerHTML = `
|
2021-11-30 15:22:16 +00:00
|
|
|
<div class="modal">
|
|
|
|
<div class="modal-content">
|
|
|
|
<h4>Confirm query result deletion</h4>
|
|
|
|
<p>Do you really want to delete the query result <b>${app.users[this.userId].query_results[queryResultId].title}</b>? It will be permanently deleted!</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<a href="#!" class="btn modal-close waves-effect waves-light">Cancel</a>
|
|
|
|
<a class="btn modal-close red waves-effect waves-light" href="/query_results/${queryResultId}/delete"><i class="material-icons left">delete</i>Delete</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`.trim();
|
2021-12-01 13:15:20 +00:00
|
|
|
deleteModalElement = document.querySelector('#modals').appendChild(tmp.firstChild);
|
|
|
|
deleteModal = M.Modal.init(
|
|
|
|
deleteModalElement,
|
|
|
|
{
|
|
|
|
onCloseEnd: () => {
|
|
|
|
deleteModal.destroy();
|
|
|
|
deleteModalElement.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2021-01-12 14:25:54 +00:00
|
|
|
deleteModal.open();
|
|
|
|
break;
|
|
|
|
case 'view':
|
2021-11-30 15:22:16 +00:00
|
|
|
window.location.href = `/query_results/${queryResultId}`;
|
2021-01-12 14:25:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:22:16 +00:00
|
|
|
usersPatchHandler(patch) {
|
2021-12-01 13:15:20 +00:00
|
|
|
let filteredPatch;
|
|
|
|
let match;
|
|
|
|
let operation;
|
|
|
|
let queryResultId;
|
|
|
|
let re;
|
|
|
|
let valueName;
|
|
|
|
|
|
|
|
re = new RegExp(`^/users/${this.userId}/query_results/([A-Za-z0-9]*)`);
|
|
|
|
filteredPatch = patch.filter(operation => re.test(operation.path));
|
|
|
|
for (operation of filteredPatch) {
|
2021-01-12 14:25:54 +00:00
|
|
|
switch(operation.op) {
|
|
|
|
case 'add':
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/query_results/([A-Za-z0-9]*)$`);
|
2021-12-01 13:15:20 +00:00
|
|
|
if (re.test(operation.path)) {
|
|
|
|
this.add(operation.value);
|
|
|
|
}
|
2021-01-12 14:25:54 +00:00
|
|
|
break;
|
|
|
|
case 'remove':
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/query_results/([A-Za-z0-9]*)$`);
|
2021-01-12 14:25:54 +00:00
|
|
|
if (re.test(operation.path)) {
|
2021-12-01 13:15:20 +00:00
|
|
|
[match, queryResultId] = operation.path.match(re);
|
2021-11-30 15:22:16 +00:00
|
|
|
this.remove(queryResultId);
|
2021-01-12 14:25:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'replace':
|
2021-11-30 15:22:16 +00:00
|
|
|
re = new RegExp(`^/users/${this.userId}/query_results/([A-Za-z0-9]*)/(corpus_title|description|query|title)$`);
|
2021-01-12 14:25:54 +00:00
|
|
|
if (re.test(operation.path)) {
|
2021-12-01 13:15:20 +00:00
|
|
|
[match, queryResultId, valueName] = operation.path.match(re);
|
2021-11-30 15:22:16 +00:00
|
|
|
this.replace(queryResultId, valueName, operation.value);
|
2021-01-12 14:25:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-11 12:36:45 +00:00
|
|
|
}
|