Enhance list onClick handling

This commit is contained in:
Patrick Jentsch 2023-01-05 15:03:59 +01:00
parent 9977128cb9
commit 381716f87a
9 changed files with 120 additions and 97 deletions

View File

@ -24,15 +24,15 @@ class CorpusFileList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><span class="filename"></span></td>
<td><span class="author"></span></td>
<td><span class="title"></span></td>
<td><span class="publishing-year"></span></td>
<td class="right-align">
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete"><i class="material-icons">delete</i></a>
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -92,23 +92,26 @@ class CorpusFileList extends ResourceList {
}
onClick(event) {
let corpusFileElement = event.target.closest('tr');
if (corpusFileElement === null) {return;}
let corpusFileId = corpusFileElement.dataset.id;
if (corpusFileId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete': {
Utils.deleteCorpusFileRequest(this.userId, this.corpusId, corpusFileId);
Utils.deleteCorpusFileRequest(this.userId, this.corpusId, itemId);
break;
}
case 'download': {
window.location.href = `/corpora/${this.corpusId}/files/${corpusFileId}/download`;
window.location.href = `/corpora/${this.corpusId}/files/${itemId}/download`;
break;
}
case 'view': {
window.location.href = `/corpora/${this.corpusId}/files/${corpusFileId}`;
window.location.href = `/corpora/${this.corpusId}/files/${itemId}`;
break;
}
default: {

View File

@ -24,13 +24,13 @@ class CorpusList extends ResourceList {
// #region Mandatory getters and methods to implement
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><a class="btn-floating disabled"><i class="material-icons service-color darken" data-service="corpus-analysis">book</i></a></td>
<td><b class="title"></b><br><i class="description"></i></td>
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></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" data-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete-request"><i class="material-icons">delete</i></a>
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -87,19 +87,22 @@ class CorpusList extends ResourceList {
}
onClick(event) {
let corpusElement = event.target.closest('tr');
if (corpusElement === null) {return;}
let corpusId = corpusElement.dataset.id;
if (corpusId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete-request': {
Utils.deleteCorpusRequest(this.userId, corpusId);
Utils.deleteCorpusRequest(this.userId, itemId);
break;
}
case 'view': {
window.location.href = `/corpora/${corpusId}`;
window.location.href = `/corpora/${itemId}`;
break;
}
default: {

View File

@ -24,10 +24,10 @@ class JobInputList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><span class="filename"></span></td>
<td class="right-align">
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="download"><i class="material-icons">file_download</i></a>
</td>
</tr>
`.trim();
@ -78,15 +78,18 @@ class JobInputList extends ResourceList {
}
onClick(event) {
let jobInputElement = event.target.closest('tr');
if (jobInputElement === null) {return;}
let jobInputId = jobInputElement.dataset.id;
if (jobInputId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'download' : listActionElement.dataset.listAction;
switch (listAction) {
case 'download': {
window.location.href = `/jobs/${this.jobId}/inputs/${jobInputId}/download`;
window.location.href = `/jobs/${this.jobId}/inputs/${itemId}/download`;
break;
}
default: {

View File

@ -23,13 +23,13 @@ class JobList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable service-scheme">
<tr class="list-item clickable hoverable service-scheme">
<td><a class="btn-floating"><i class="nopaque-icons service-icons" data-service="inherit"></i></a></td>
<td><b class="title"></b><br><i class="description"></i></td>
<td><span class="badge new job-status-color job-status-text status" data-badge-caption=""></span></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 darken waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete-request"><i class="material-icons">delete</i></a>
<a class="list-action-trigger btn-floating darken waves-effect waves-light" data-list-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -88,19 +88,22 @@ class JobList extends ResourceList {
}
onClick(event) {
let jobElement = event.target.closest('tr');
if (jobElement === null) {return;}
let jobId = jobElement.dataset.id;
if (jobId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete-request': {
Utils.deleteJobRequest(this.userId, jobId);
Utils.deleteJobRequest(this.userId, itemId);
break;
}
case 'view': {
window.location.href = `/jobs/${jobId}`;
window.location.href = `/jobs/${itemId}`;
break;
}
default: {

View File

@ -24,11 +24,11 @@ class JobResultList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><span class="description"></span></td>
<td><span class="filename"></span></td>
<td class="right-align">
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="download"><i class="material-icons">file_download</i></a>
</td>
</tr>
`.trim();
@ -82,15 +82,18 @@ class JobResultList extends ResourceList {
}
onClick(event) {
let jobResultElement = event.target.closest('tr');
if (jobResultElement === null) {return;}
let jobResultId = jobResultElement.dataset.id;
if (jobResultId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'download' : listActionElement.dataset.listAction;
switch (listAction) {
case 'download': {
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
window.location.href = `/jobs/${this.jobId}/results/${itemId}/download`;
break;
}
default: {

View File

@ -12,7 +12,7 @@ class PublicUserList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><img alt="user-image" class="circle responsive-img avatar" style="width:50%"></td>
<td><b><span class="username"></span><b></td>
<td><span class="full-name"></span></td>
@ -20,7 +20,7 @@ class PublicUserList extends ResourceList {
<td><span class="organization"></span></td>
<td><span class="corpora-online"></span></td>
<td class="right-align">
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -86,13 +86,18 @@ class PublicUserList extends ResourceList {
}
onClick(event) {
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
let publicUserElement = event.target.closest('tr');
let publicUserId = publicUserElement.dataset.id;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'view': {
window.location.href = `/users/${publicUserId}`;
window.location.href = `/users/${itemId}`;
break;
}
default: {

View File

@ -32,11 +32,11 @@ class SpaCyNLPPipelineModelList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item 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">
<div class="list-action-trigger switch center-align" data-list-action="share-request">
<span class="share"></span>
<label>
<input type="checkbox" class="is_public">
@ -46,8 +46,8 @@ class SpaCyNLPPipelineModelList extends ResourceList {
</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>
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete-request"><i class="material-icons">delete</i></a>
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light service-2" data-list-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -117,8 +117,8 @@ class SpaCyNLPPipelineModelList extends ResourceList {
}
onChange(event) {
let actionSwitchElement = event.target.closest('.action-switch');
let action = actionSwitchElement.dataset.action;
let actionSwitchElement = event.target.closest('.list-action-trigger');
let action = actionSwitchElement.dataset.listAction;
let spaCyNLPPipelineModelElement = event.target.closest('tr');
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
switch (action) {
@ -141,8 +141,8 @@ class SpaCyNLPPipelineModelList extends ResourceList {
}
return;
}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
let actionButtonElement = event.target.closest('.list-action-trigger');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.listAction;
let spaCyNLPPipelineModelElement = event.target.closest('tr');
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
switch (action) {

View File

@ -32,11 +32,11 @@ class TesseractOCRPipelineModelList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item 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">
<div class="list-action-trigger switch center-align" data-list-action="share-request">
<span class="share"></span>
<label>
<input type="checkbox" class="is_public">
@ -46,8 +46,8 @@ class TesseractOCRPipelineModelList extends ResourceList {
</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>
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete-request"><i class="material-icons">delete</i></a>
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light service-2" data-list-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -117,8 +117,8 @@ class TesseractOCRPipelineModelList extends ResourceList {
}
onChange(event) {
let actionSwitchElement = event.target.closest('.action-switch');
let action = actionSwitchElement.dataset.action;
let actionSwitchElement = event.target.closest('.list-action-trigger');
let action = actionSwitchElement.dataset.listAction;
let tesseractOCRPipelineModelElement = event.target.closest('tr');
let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id;
switch (action) {
@ -141,8 +141,8 @@ class TesseractOCRPipelineModelList extends ResourceList {
}
return;
}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
let actionButtonElement = event.target.closest('.list-action-trigger');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.listAction;
let tesseractOCRPipelineModelElement = event.target.closest('tr');
let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id;
switch (action) {

View File

@ -12,16 +12,16 @@ class UserList extends ResourceList {
get item() {
return `
<tr class="clickable hoverable">
<tr class="list-item clickable hoverable">
<td><span class="id-1"></span></td>
<td><span class="username"></span></td>
<td><span class="email"></span></td>
<td><span class="last-seen"></span></td>
<td><span class="role"></span></td>
<td class="right-align">
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
<a class="action-button btn-floating waves-effect waves-light" data-action="edit"><i class="material-icons">edit</i></a>
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete"><i class="material-icons">delete</i></a>
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="edit"><i class="material-icons">edit</i></a>
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
@ -84,24 +84,27 @@ class UserList extends ResourceList {
}
onClick(event) {
let userElement = event.target.closest('tr');
if (userElement === null) {return;}
let userId = userElement.dataset.id;
if (userId === undefined) {return;}
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
switch (action) {
let listItemElement = event.target.closest('.list-item');
if (listItemElement === null) {return;}
if (!('id' in listItemElement.dataset)) {return;}
let itemId = listItemElement.dataset.id;
if (itemId === undefined) {return;}
let listActionElement = event.target.closest('.list-item .list-action-trigger');
let listAction =
listActionElement === null || !('listAction' in listActionElement.dataset)
? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'delete': {
Utils.deleteUserRequest(userId);
if (userId === currentUserId) {window.location.href = '/';}
Utils.deleteUserRequest(itemId);
if (itemId === currentUserId) {window.location.href = '/';}
break;
}
case 'edit': {
window.location.href = `/admin/users/${userId}/edit`;
window.location.href = `/admin/users/${itemId}/edit`;
break;
}
case 'view': {
window.location.href = `/admin/users/${userId}`;
window.location.href = `/admin/users/${itemId}`;
break;
}
default: {