mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +00:00
List Selection expansion & select all fix
This commit is contained in:
parent
526fd1769e
commit
0e786803ee
@ -81,7 +81,7 @@ class CorpusFileList extends ResourceList {
|
||||
<th>
|
||||
<label class="selection-action-trigger ${this.listContainerElement.dataset?.hasPermissionView == 'true' ? '' : 'hide'}" data-selection-action="select-all">
|
||||
<input class="select-all-checkbox" type="checkbox">
|
||||
<span></span>
|
||||
<span class="disable-on-click"></span>
|
||||
</label>
|
||||
</th>
|
||||
<th>Filename</th>
|
||||
@ -199,15 +199,16 @@ class CorpusFileList extends ResourceList {
|
||||
case 'select-all': {
|
||||
let selectedIds = new Set(Array.from(items)
|
||||
.map(item => item.values().id))
|
||||
if (event.target.checked !== undefined) {
|
||||
if (event.target.checked) {
|
||||
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
||||
this.selectedItemIds = selectedIds;
|
||||
} else {
|
||||
selectableItems.forEach(checkbox => checkbox.checked = false);
|
||||
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
||||
|
||||
}
|
||||
this.renderingItemSelection();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
@ -326,6 +327,14 @@ class CorpusFileList extends ResourceList {
|
||||
actionButton.classList.remove('hide');
|
||||
});
|
||||
}
|
||||
|
||||
// Check select all checkbox if all items are selected
|
||||
let selectAllCheckbox = document.querySelector('.select-all-checkbox[type="checkbox"]');
|
||||
if (selectableItems.length === this.selectedItemIds.size && selectAllCheckbox.checked === false) {
|
||||
selectAllCheckbox.checked = true;
|
||||
} else if (selectableItems.length !== this.selectedItemIds.size && selectAllCheckbox.checked === true) {
|
||||
selectAllCheckbox.checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
|
@ -8,7 +8,11 @@ class CorpusList extends ResourceList {
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
document.querySelectorAll('.corpus-list-selection-action-trigger[data-selection-action]').forEach((element) => {
|
||||
element.addEventListener('click', (event) => {this.onSelectionAction(event)});
|
||||
});
|
||||
this.isInitialized = false
|
||||
this.selectedItemIds = new Set();
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
if (this.userId === undefined) {return;}
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
@ -22,13 +26,18 @@ class CorpusList extends ResourceList {
|
||||
get item() {
|
||||
return (values) => {
|
||||
return `
|
||||
<tr class="${values['is-owner'] ? '' : 'deep-purple lighten-5'} 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>
|
||||
<tr class="${values['is-owner'] ? '' : 'deep-purple lighten-5'} list-item">
|
||||
<td>
|
||||
<label class="list-action-trigger ${values['is-owner'] ? '' : 'hide'}" data-list-action="select">
|
||||
<input class="select-checkbox" type="checkbox">
|
||||
<span class="disable-on-click"></span>
|
||||
</label>
|
||||
</td>
|
||||
<td><b class="title"></b><br><i class="description"></i></td>
|
||||
<td><span class="owner"></span></td>
|
||||
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></td>
|
||||
<td class="right-align">
|
||||
<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 red waves-effect waves-light ${values['is-owner'] ? '' : 'hide'}" 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>
|
||||
@ -61,11 +70,18 @@ class CorpusList extends ResourceList {
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>
|
||||
<label class="corpus-list-selection-action-trigger" data-selection-action="select-all">
|
||||
<input class="corpus-list-select-all-checkbox" type="checkbox">
|
||||
<span></span>
|
||||
</label>
|
||||
</th>
|
||||
<th>Title and Description</th>
|
||||
<th>Owner</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
<th class="right-align">
|
||||
<a class="corpus-list-selection-action-trigger btn-floating red waves-effect waves-light hide" data-selection-action="delete"><i class="material-icons">delete</i></a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
@ -95,7 +111,7 @@ class CorpusList extends ResourceList {
|
||||
if (listItemElement === null) {return;}
|
||||
let itemId = listItemElement.dataset.id;
|
||||
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
||||
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
||||
let listAction = listActionElement === null ? '' : listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'delete-request': {
|
||||
let values = this.listjs.get('id', itemId)[0].values();
|
||||
@ -135,12 +151,149 @@ class CorpusList extends ResourceList {
|
||||
window.location.href = `/corpora/${itemId}`;
|
||||
break;
|
||||
}
|
||||
case 'select': {
|
||||
|
||||
if (event.target.checked) {
|
||||
this.selectedItemIds.add(itemId);
|
||||
} else {
|
||||
this.selectedItemIds.delete(itemId);
|
||||
}
|
||||
this.renderingItemSelection();
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSelectionAction(event) {
|
||||
let selectionActionElement = event.target.closest('.corpus-list-selection-action-trigger[data-selection-action]');
|
||||
let selectionAction = selectionActionElement.dataset.selectionAction;
|
||||
let items = Array.from(this.listjs.items).filter(item => item._values["is-owner"] === true);
|
||||
let selectableItems = Array.from(items)
|
||||
.filter(item => item.elm)
|
||||
.map(item => item.elm.querySelector('.select-checkbox[type="checkbox"]'));
|
||||
|
||||
switch (selectionAction) {
|
||||
case 'select-all': {
|
||||
let selectedIds = new Set(Array.from(items)
|
||||
.map(item => item.values().id))
|
||||
if (event.target.checked !== undefined) {
|
||||
if (event.target.checked) {
|
||||
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
||||
this.selectedItemIds = selectedIds;
|
||||
} else {
|
||||
selectableItems.forEach(checkbox => checkbox.checked = false);
|
||||
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
||||
}
|
||||
this.renderingItemSelection();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
let modalElement = Utils.HTMLToElement(
|
||||
`
|
||||
<div class="modal">
|
||||
<div class="modal-content">
|
||||
<h4>Confirm Corpus File deletion</h4>
|
||||
<p>Do you really want to delete this Corpora?</p>
|
||||
<ul id="selected-items-list"></ul>
|
||||
<p>All corpora will be permanently deleted!</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn modal-close waves-effect waves-light">Cancel</a>
|
||||
<a class="action-button btn modal-close red waves-effect waves-light" data-action="confirm">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
);
|
||||
document.querySelector('#modals').appendChild(modalElement);
|
||||
let itemList = document.querySelector('#selected-items-list');
|
||||
this.selectedItemIds.forEach(selectedItemId => {
|
||||
let listItem = this.listjs.get('id', selectedItemId)[0].elm;
|
||||
let values = this.listjs.get('id', listItem.dataset.id)[0].values();
|
||||
let itemElement = Utils.HTMLToElement(`<li> - ${values.title}</li>`);
|
||||
itemList.appendChild(itemElement);
|
||||
});
|
||||
let modal = M.Modal.init(
|
||||
modalElement,
|
||||
{
|
||||
dismissible: false,
|
||||
onCloseEnd: () => {
|
||||
modal.destroy();
|
||||
modalElement.remove();
|
||||
}
|
||||
}
|
||||
);
|
||||
let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
|
||||
confirmElement.addEventListener('click', (event) => {
|
||||
this.selectedItemIds.forEach(selectedItemId => {
|
||||
Requests.corpora.entity.delete(selectedItemId);
|
||||
});
|
||||
this.selectedItemIds.clear();
|
||||
this.renderingItemSelection();
|
||||
});
|
||||
modal.open();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderingItemSelection() {
|
||||
let selectionActionButtons = document.querySelectorAll('.corpus-list-selection-action-trigger:not([data-selection-action="select-all"])');
|
||||
let selectableItems = this.listjs.items;
|
||||
let actionButtons = [];
|
||||
|
||||
Object.values(selectableItems).forEach(selectableItem => {
|
||||
if (selectableItem._values["is-owner"] === false && this.selectedItemIds.size > 0) {
|
||||
selectableItem.elm.classList.add('hide');
|
||||
} else if (selectableItem._values["is-owner"] === false && this.selectedItemIds.size === 0) {
|
||||
selectableItem.elm.classList.remove('hide');
|
||||
} else {
|
||||
if (selectableItem.elm) {
|
||||
let checkbox = selectableItem.elm.querySelector('.select-checkbox[type="checkbox"]');
|
||||
if (checkbox.checked) {
|
||||
selectableItem.elm.classList.add('grey', 'lighten-3');
|
||||
} else {
|
||||
selectableItem.elm.classList.remove('grey', 'lighten-3');
|
||||
}
|
||||
let itemActionButtons = selectableItem.elm.querySelectorAll('.list-action-trigger:not([data-list-action="select"])');
|
||||
itemActionButtons.forEach(itemActionButton => {
|
||||
actionButtons.push(itemActionButton);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// Hide item action buttons if > 0 item is selected and show selection action buttons
|
||||
if (this.selectedItemIds.size > 0) {
|
||||
selectionActionButtons.forEach(selectionActionButton => {
|
||||
selectionActionButton.classList.remove('hide');
|
||||
});
|
||||
actionButtons.forEach(actionButton => {
|
||||
actionButton.classList.add('hide');
|
||||
});
|
||||
} else {
|
||||
selectionActionButtons.forEach(selectionActionButton => {
|
||||
selectionActionButton.classList.add('hide');
|
||||
});
|
||||
actionButtons.forEach(actionButton => {
|
||||
actionButton.classList.remove('hide');
|
||||
});
|
||||
}
|
||||
|
||||
// Check select all checkbox if all items are selected
|
||||
let filteredItems = Object.values(selectableItems).filter(item => item._values["is-owner"] === true)
|
||||
let selectAllCheckbox = document.querySelector('.corpus-list-select-all-checkbox[type="checkbox"]');
|
||||
if (filteredItems.length === this.selectedItemIds.size && selectAllCheckbox.checked === false) {
|
||||
selectAllCheckbox.checked = true;
|
||||
} else if (filteredItems.length !== this.selectedItemIds.size && selectAllCheckbox.checked === true) {
|
||||
selectAllCheckbox.checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)`);
|
||||
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||
|
@ -7,7 +7,11 @@ class JobList extends ResourceList {
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.documentJobArea = document.querySelector('#jobs');
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
document.querySelectorAll('.job-list-selection-action-trigger[data-selection-action]').forEach((element) => {
|
||||
element.addEventListener('click', (event) => {this.onSelectionAction(event)});
|
||||
});
|
||||
this.isInitialized = false;
|
||||
this.selectedItemIds = new Set();
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
@ -25,7 +29,7 @@ class JobList extends ResourceList {
|
||||
|
||||
get item() {
|
||||
return `
|
||||
<tr class="list-item clickable hoverable service-scheme">
|
||||
<tr class="list-item service-scheme">
|
||||
<td>
|
||||
<label class="list-action-trigger" data-list-action="select">
|
||||
<input class="select-checkbox" type="checkbox">
|
||||
@ -69,15 +73,17 @@ class JobList extends ResourceList {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<label class="selection-action-trigger" data-selection-action="select-all">
|
||||
<input class="select-all-checkbox" type="checkbox">
|
||||
<span></span>
|
||||
<label class="job-list-selection-action-trigger" data-selection-action="select-all">
|
||||
<input class="job-list-select-all-checkbox" type="checkbox">
|
||||
<span class="disable-on-click"></span>
|
||||
</label>
|
||||
</th>
|
||||
<th>Service</th>
|
||||
<th>Title and Description</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
<th class="right-align">
|
||||
<a class="job-list-selection-action-trigger btn-floating red waves-effect waves-light hide" data-selection-action="delete"><i class="material-icons">delete</i></a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
@ -106,7 +112,7 @@ class JobList extends ResourceList {
|
||||
if (listItemElement === null) {return;}
|
||||
let itemId = listItemElement.dataset.id;
|
||||
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
||||
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
||||
let listAction = listActionElement === null ? '' : listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'delete-request': {
|
||||
let values = this.listjs.get('id', itemId)[0].values();
|
||||
@ -161,6 +167,130 @@ class JobList extends ResourceList {
|
||||
}
|
||||
}
|
||||
|
||||
onSelectionAction(event) {
|
||||
let selectionActionElement = event.target.closest('.job-list-selection-action-trigger[data-selection-action]');
|
||||
let selectionAction = selectionActionElement.dataset.selectionAction;
|
||||
let items = this.listjs.items;
|
||||
let selectableItems = Array.from(items)
|
||||
.filter(item => item.elm)
|
||||
.map(item => item.elm.querySelector('.select-checkbox[type="checkbox"]'));
|
||||
switch (selectionAction) {
|
||||
case 'select-all': {
|
||||
let selectedIds = new Set(Array.from(items)
|
||||
.map(item => item.values().id))
|
||||
if (event.target.checked !== undefined) {
|
||||
if (event.target.checked) {
|
||||
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
||||
this.selectedItemIds = selectedIds;
|
||||
} else {
|
||||
selectableItems.forEach(checkbox => checkbox.checked = false);
|
||||
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
||||
}
|
||||
this.renderingItemSelection();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'delete': {
|
||||
let modalElement = Utils.HTMLToElement(
|
||||
`
|
||||
<div class="modal">
|
||||
<div class="modal-content">
|
||||
<h4>Confirm Corpus File deletion</h4>
|
||||
<p>Do you really want to delete the Jobs?</p>
|
||||
<ul id="selected-items-list"></ul>
|
||||
<p>All files will be permanently deleted!</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="btn modal-close waves-effect waves-light">Cancel</a>
|
||||
<a class="action-button btn modal-close red waves-effect waves-light" data-action="confirm">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
);
|
||||
document.querySelector('#modals').appendChild(modalElement);
|
||||
let itemList = document.querySelector('#selected-items-list');
|
||||
this.selectedItemIds.forEach(selectedItemId => {
|
||||
let listItem = this.listjs.get('id', selectedItemId)[0].elm;
|
||||
let values = this.listjs.get('id', listItem.dataset.id)[0].values();
|
||||
let itemElement = Utils.HTMLToElement(`<li> - ${values.title}</li>`);
|
||||
itemList.appendChild(itemElement);
|
||||
});
|
||||
let modal = M.Modal.init(
|
||||
modalElement,
|
||||
{
|
||||
dismissible: false,
|
||||
onCloseEnd: () => {
|
||||
modal.destroy();
|
||||
modalElement.remove();
|
||||
}
|
||||
}
|
||||
);
|
||||
let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
|
||||
confirmElement.addEventListener('click', (event) => {
|
||||
this.selectedItemIds.forEach(selectedItemId => {
|
||||
Requests.corpora.entity.files.ent.delete(this.corpusId, selectedItemId);
|
||||
});
|
||||
this.selectedItemIds.clear();
|
||||
this.renderingItemSelection();
|
||||
});
|
||||
modal.open();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderingItemSelection() {
|
||||
let selectionActionButtons = document.querySelectorAll('.job-list-selection-action-trigger:not([data-selection-action="select-all"])');
|
||||
let selectableItems = this.listjs.items;
|
||||
let actionButtons = [];
|
||||
|
||||
Object.values(selectableItems).forEach(selectableItem => {
|
||||
if (selectableItem.elm) {
|
||||
let checkbox = selectableItem.elm.querySelector('.select-checkbox[type="checkbox"]');
|
||||
if (checkbox.checked) {
|
||||
selectableItem.elm.classList.add('grey', 'lighten-3');
|
||||
} else {
|
||||
selectableItem.elm.classList.remove('grey', 'lighten-3');
|
||||
}
|
||||
let itemActionButtons = selectableItem.elm.querySelectorAll('.list-action-trigger:not([data-list-action="select"])');
|
||||
itemActionButtons.forEach(itemActionButton => {
|
||||
actionButtons.push(itemActionButton);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Hide item action buttons if > 0 item is selected and show selection action buttons
|
||||
if (this.selectedItemIds.size > 0) {
|
||||
selectionActionButtons.forEach(selectionActionButton => {
|
||||
selectionActionButton.classList.remove('hide');
|
||||
});
|
||||
actionButtons.forEach(actionButton => {
|
||||
actionButton.classList.add('hide');
|
||||
});
|
||||
} else {
|
||||
selectionActionButtons.forEach(selectionActionButton => {
|
||||
selectionActionButton.classList.add('hide');
|
||||
});
|
||||
actionButtons.forEach(actionButton => {
|
||||
actionButton.classList.remove('hide');
|
||||
});
|
||||
}
|
||||
|
||||
// Check select all checkbox if all items are selected
|
||||
let selectAllCheckbox = document.querySelector('.job-list-select-all-checkbox[type="checkbox"]');
|
||||
if (selectableItems.length === this.selectedItemIds.size && selectAllCheckbox.checked === false) {
|
||||
selectAllCheckbox.checked = true;
|
||||
} else if (selectableItems.length !== this.selectedItemIds.size && selectAllCheckbox.checked === true) {
|
||||
selectAllCheckbox.checked = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)`);
|
||||
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||
|
Loading…
Reference in New Issue
Block a user