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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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