mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-02 21:39:35 +00:00
Statistik-Bereich um Tab für Projekte/Baugruppen erweitern
This commit is contained in:
parent
74513b748d
commit
d67e93064c
18 changed files with 754 additions and 1 deletions
45
assets/controllers/pages/statistics_assembly_controller.js
Normal file
45
assets/controllers/pages/statistics_assembly_controller.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
static values = {
|
||||
url: String,
|
||||
confirmMsg: String,
|
||||
successMsg: String,
|
||||
errorMsg: String
|
||||
}
|
||||
|
||||
static targets = ["count"]
|
||||
|
||||
async cleanup(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!confirm(this.confirmMsgValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(this.urlValue, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
alert(this.successMsgValue.replace('%count%', data.count));
|
||||
// Update the count displayed in the UI
|
||||
if (this.hasCountTarget) {
|
||||
this.countTarget.innerText = '0';
|
||||
}
|
||||
// Reload page to reflect changes if needed, or just let the user see 0
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert(this.errorMsgValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Cleanup failed:', error);
|
||||
alert(this.errorMsgValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue