2023-01-04 19:00:37 +00:00
|
|
|
class JobList extends ResourceList {
|
|
|
|
static autoInit() {
|
|
|
|
for (let jobListElement of document.querySelectorAll('.job-list:not(.no-autoinit)')) {
|
|
|
|
new JobList(jobListElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(listContainerElement, options = {}) {
|
|
|
|
super(listContainerElement, options);
|
|
|
|
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
|
|
|
this.isInitialized = false;
|
2023-06-05 11:44:07 +00:00
|
|
|
this.selectedItemIds = new Set();
|
2023-01-04 19:00:37 +00:00
|
|
|
this.userId = listContainerElement.dataset.userId;
|
2023-02-10 13:51:47 +00:00
|
|
|
if (this.userId === undefined) {return;}
|
2023-01-04 19:00:37 +00:00
|
|
|
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.jobs));
|
|
|
|
this.isInitialized = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get item() {
|
|
|
|
return `
|
2023-01-05 14:03:59 +00:00
|
|
|
<tr class="list-item clickable hoverable service-scheme">
|
2023-06-05 11:44:07 +00:00
|
|
|
<td>
|
|
|
|
<label class="list-action-trigger" data-list-action="select">
|
|
|
|
<input class="select-checkbox" type="checkbox">
|
|
|
|
<span class="disable-on-click"></span>
|
|
|
|
</label>
|
|
|
|
</td>
|
2023-01-04 19:00:37 +00:00
|
|
|
<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">
|
2023-01-05 14:03:59 +00:00
|
|
|
<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>
|
2023-01-04 19:00:37 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
get valueNames() {
|
|
|
|
return [
|
|
|
|
{data: ['id']},
|
|
|
|
{data: ['creation-date']},
|
|
|
|
{data: ['service']},
|
|
|
|
{name: 'status', attr: 'data-status'},
|
|
|
|
'description',
|
|
|
|
'title'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
initListContainerElement() {
|
|
|
|
if (!this.listContainerElement.hasAttribute('id')) {
|
|
|
|
this.listContainerElement.id = Utils.generateElementId('job-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>
|
2023-03-21 08:14:16 +00:00
|
|
|
<label for="${listSearchElementId}">Search Job</label>
|
2023-01-04 19:00:37 +00:00
|
|
|
</div>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2023-06-05 11:44:07 +00:00
|
|
|
<th>
|
|
|
|
<label class="selection-action-trigger" data-selection-action="select-all">
|
|
|
|
<input class="select-all-checkbox" type="checkbox">
|
|
|
|
<span></span>
|
|
|
|
</label>
|
|
|
|
</th>
|
2023-01-04 19:00:37 +00:00
|
|
|
<th>Service</th>
|
|
|
|
<th>Title and Description</th>
|
|
|
|
<th>Status</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="list"></tbody>
|
|
|
|
</table>
|
|
|
|
<ul class="pagination"></ul>
|
|
|
|
`.trim();
|
|
|
|
}
|
2023-01-05 07:11:27 +00:00
|
|
|
|
2023-01-04 19:00:37 +00:00
|
|
|
mapResourceToValue(job) {
|
|
|
|
return {
|
|
|
|
'id': job.id,
|
|
|
|
'creation-date': job.creation_date,
|
|
|
|
'description': job.description,
|
|
|
|
'service': job.service,
|
|
|
|
'status': job.status,
|
|
|
|
'title': job.title
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sort() {
|
|
|
|
this.listjs.sort('creation-date', {order: 'desc'});
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick(event) {
|
2023-01-10 09:03:27 +00:00
|
|
|
let listItemElement = event.target.closest('.list-item[data-id]');
|
2023-01-05 14:03:59 +00:00
|
|
|
if (listItemElement === null) {return;}
|
|
|
|
let itemId = listItemElement.dataset.id;
|
2023-01-10 09:03:27 +00:00
|
|
|
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
|
|
|
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
2023-01-05 14:03:59 +00:00
|
|
|
switch (listAction) {
|
2023-01-04 19:00:37 +00:00
|
|
|
case 'delete-request': {
|
2023-03-21 08:14:16 +00:00
|
|
|
let values = this.listjs.get('id', itemId)[0].values();
|
|
|
|
let modalElement = Utils.HTMLToElement(
|
|
|
|
`
|
|
|
|
<div class="modal">
|
|
|
|
<div class="modal-content">
|
|
|
|
<h4>Confirm Job deletion</h4>
|
|
|
|
<p>Do you really want to delete the Job <b>${values.title}</b>? 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 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) => {
|
|
|
|
Requests.jobs.entity.delete(itemId);
|
|
|
|
});
|
|
|
|
modal.open();
|
2023-01-04 19:00:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'view': {
|
2023-01-05 14:03:59 +00:00
|
|
|
window.location.href = `/jobs/${itemId}`;
|
2023-01-04 19:00:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-06-05 11:44:07 +00:00
|
|
|
case 'select': {
|
|
|
|
if (event.target.checked) {
|
|
|
|
this.selectedItemIds.add(itemId);
|
|
|
|
} else {
|
|
|
|
this.selectedItemIds.delete(itemId);
|
|
|
|
}
|
|
|
|
this.renderingItemSelection();
|
|
|
|
break;
|
|
|
|
}
|
2023-01-04 19:00:37 +00:00
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onPatch(patch) {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)`);
|
|
|
|
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
|
|
|
for (let operation of filteredPatch) {
|
|
|
|
switch(operation.op) {
|
|
|
|
case 'add': {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)$`);
|
|
|
|
if (re.test(operation.path)) {this.add(operation.value);}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'remove': {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)$`);
|
|
|
|
if (re.test(operation.path)) {
|
|
|
|
let [match, jobId] = operation.path.match(re);
|
|
|
|
this.remove(jobId);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'replace': {
|
|
|
|
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)/(service|status|description|title)$`);
|
|
|
|
if (re.test(operation.path)) {
|
|
|
|
let [match, jobId, valueName] = operation.path.match(re);
|
|
|
|
this.replace(jobId, valueName, operation.value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|