add new export actions erasure

This commit is contained in:
Cayo Puigdefabregas 2022-09-21 11:35:31 +02:00
parent b006ec1973
commit 47736c8679
4 changed files with 64 additions and 2 deletions

View file

@ -901,6 +901,43 @@ class ExportsView(View):
def actions_erasures(self):
data = StringIO()
cw = csv.writer(
data,
delimiter=';',
lineterminator="\n",
quotechar='"',
quoting=csv.QUOTE_ALL,
)
cw.writerow(
[
'Data Storage Serial',
'Snapshot ID',
'Type of Erasure',
'PHID Erasure Host',
'Result',
'Time',
]
)
args = request.args.get('ids')
ids = args.split(',') if args else []
query = EraseBasic.query.filter_by(author=g.user)
query = query.filter(EraseBasic.id.in_(ids))
query = query.order_by(EraseBasic.created.desc())
for ac in query:
row = [
ac.device.serial_number.upper(),
ac.snapshot.uuid,
ac.type,
ac.get_phid(),
ac.severity,
ac.created.strftime('%Y-%m-%d %H:%M:%S'),
]
cw.writerow(row)
return self.response_csv(data, "Erasures.csv")
def build_erasure_certificate(self):

View file

@ -322,6 +322,19 @@ function export_file(type_file) {
}
}
function export_actions_erasure(type_file) {
const actions = TableController.getSelectedDevices();
const actions_id = $.map(actions, (x) => $(x).attr("data-action-erasure")).join(",");
if (actions_id) {
const url = `/inventory/export/${type_file}/?ids=${actions_id}`;
window.location.href = url;
} else {
$("#exportAlertModal").click();
}
}
class lotsSearcher {
static enable() {
if (this.lotsSearchElement) this.lotsSearchElement.disabled = false;

View file

@ -308,6 +308,17 @@ function export_file(type_file) {
}
}
function export_actions_erasure(type_file) {
const actions = TableController.getSelectedDevices();
const actions_id = $.map(actions, (x) => $(x).attr("data-action-erasure")).join(",");
if (actions_id) {
const url = `/inventory/export/${type_file}/?ids=${actions_id}`;
window.location.href = url;
} else {
$("#exportAlertModal").click();
}
}
class lotsSearcher {
static lots = [];

View file

@ -29,7 +29,7 @@
<span class="d-none" id="exportAlertModal" data-bs-toggle="modal" data-bs-target="#exportErrorModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnExport">
<li>
<a href="javascript:export_file('actions_erasures')" class="dropdown-item">
<a href="javascript:export_actions_erasure('actions_erasures')" class="dropdown-item">
<i class="bi bi-file-spreadsheet"></i>
Data Storage Spreadsheet
</a>
@ -64,6 +64,7 @@
<input type="checkbox" class="deviceSelect" data="{{ ac.device.id }}"
data-device-type="{{ ac.device.type }}" data-device-manufacturer="{{ ac.device.manufacturer }}"
data-device-dhid="{{ ac.device.dhid }}" data-device-vname="{{ ac.device.verbose_name }}"
data-action-erasure="{{ ac.id }}"
{% if form_new_allocate.type.data and ac.device.id in list_devices %}
checked="checked"
{% endif %}
@ -90,7 +91,7 @@
<td>
{{ ac.severity }}
</td>
<td>{{ ac.created.strftime('%Y-%m-%d %H:%M:%S')}}</td>
<td>{{ ac.created.strftime('%Y-%m-%d %H:%M:%S') }}</td>
<td>
<a href="{{ url_for('inventory.export', export_id='snapshot') }}?id={{ ac.snapshot.uuid }}">
<i class="bi bi-box-arrow-up-right"></i>