diff options
author | Simon Rettberg | 2017-12-04 12:35:32 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-12-04 12:35:32 +0100 |
commit | 327b8c93ab15b17196b4d936359d378014ebb5f9 (patch) | |
tree | 0fba1eea815e7fbcb2be8aadff2c90e8c408c66c /modules-available/statistics | |
parent | [inc/Util] Util::redirect() can now be told to redirect to $_POST['redirect'] (diff) | |
download | slx-admin-327b8c93ab15b17196b4d936359d378014ebb5f9.tar.gz slx-admin-327b8c93ab15b17196b4d936359d378014ebb5f9.tar.xz slx-admin-327b8c93ab15b17196b4d936359d378014ebb5f9.zip |
[statistics] Add delete functionality
Diffstat (limited to 'modules-available/statistics')
6 files changed, 76 insertions, 5 deletions
diff --git a/modules-available/statistics/lang/de/messages.json b/modules-available/statistics/lang/de/messages.json index e3dff61c..c9667f7b 100644 --- a/modules-available/statistics/lang/de/messages.json +++ b/modules-available/statistics/lang/de/messages.json @@ -1,4 +1,5 @@ { + "deleted-n-machines": "{{0}} Clients gel\u00f6scht", "invalid-filter-argument": "Das Argument {{1}} ist nicht g\u00fcltig f\u00fcr den Filter {{0}}", "invalid-filter-key": "{{0}} ist kein g\u00fcltiges Filterkriterium", "notes-saved": "Anmerkungen gespeichert", diff --git a/modules-available/statistics/lang/de/template-tags.json b/modules-available/statistics/lang/de/template-tags.json index 56cf55d7..3cdde813 100644 --- a/modules-available/statistics/lang/de/template-tags.json +++ b/modules-available/statistics/lang/de/template-tags.json @@ -74,6 +74,7 @@ "lang_showVisualization": "Visualisierung", "lang_sockets": "Sockel", "lang_subnet": "Subnetz", + "lang_sureDeletePermanent": "M\u00f6chten Sie diese(n) Rechner wirklich unwiderruflich aus der Datenbank entfernen?\r\n\r\nWichtig: L\u00f6schen verhindert nicht, dass ein Rechner nach erneutem Starten von bwLehrpool wieder in die Datenbank aufgenommen wird.", "lang_tempPart": "Temp. Partition", "lang_tempPartStats": "Tempor\u00e4re Partition", "lang_thoseAreProjectors": "Diese Modellnamen werden als Beamer behandelt, auch wenn die EDID-Informationen des Ger\u00e4tes anderes berichten.", diff --git a/modules-available/statistics/lang/en/messages.json b/modules-available/statistics/lang/en/messages.json index ae6c47af..3471c472 100644 --- a/modules-available/statistics/lang/en/messages.json +++ b/modules-available/statistics/lang/en/messages.json @@ -1,4 +1,5 @@ { + "deleted-n-machines": "Deleted {{0}} clients", "invalid-filter-argument": "{{1}} is not a vald argument for filter {{0}}", "invalid-filter-key": "{{0}} is not a valid filter", "notes-saved": "Notes have been saved", diff --git a/modules-available/statistics/lang/en/template-tags.json b/modules-available/statistics/lang/en/template-tags.json index ab7a7d0a..35c4e68a 100644 --- a/modules-available/statistics/lang/en/template-tags.json +++ b/modules-available/statistics/lang/en/template-tags.json @@ -74,6 +74,7 @@ "lang_showVisualization": "Visualization", "lang_sockets": "Sockets", "lang_subnet": "Subnet", + "lang_sureDeletePermanent": "Are your sure you want to delete the selected machine(s) from the database? This cannot be undone.\r\n\r\nNote: Deleting machines from the database does not prevent booting up bwLehrpool again, which would recreate their respective database entries.", "lang_tempPart": "Temp. partition", "lang_tempPartStats": "Temporary partition", "lang_thoseAreProjectors": "These model names will always be treated as beamers, even if the device's EDID data says otherwise.", diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 5716a09c..df12c568 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -195,6 +195,35 @@ class Page_Statistics extends Page Util::redirect('?do=Statistics&uuid=' . $uuid); } elseif ($action === 'addprojector' || $action === 'delprojector') { $this->handleProjector($action); + } elseif ($action === 'delmachines') { + $this->deleteMachines(); + Util::redirect('?do=statistics', true); + } + } + + private function deleteMachines() + { + $ids = Request::post('uuid', [], 'array'); + $ids = array_values($ids); + if (empty($ids)) { + Message::addError('main.parameter-empty', 'uuid'); + return; + } + $res = Database::simpleQuery('SELECT machineuuid, locationid FROM machine WHERE machineuuid IN (:ids)', compact('ids')); + $ids = array_flip($ids); + $delete = []; + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + // TODO: Check locationid permissions + unset($ids[$row['machineuuid']]); + $delete[] = $row['machineuuid']; + } + if (!empty($delete)) { + Database::exec('DELETE FROM machine WHERE machineuuid IN (:delete)', compact('delete')); + Message::addSuccess('deleted-n-machines', count($delete)); + } + if (!empty($ids)) { + // TODO: Warn permissions + Message::addWarning('unknown-machine', implode(', ', array_keys($ids))); } } @@ -638,7 +667,8 @@ class Page_Statistics extends Page 'sortColumn' => $filterSet->getSortColumn(), 'columns' => json_encode(Page_Statistics::$columns), 'showList' => 1, - 'show' => 'list' + 'show' => 'list', + 'redirect' => $_SERVER['QUERY_STRING'] )); } diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html index 01ca82f1..b20b202e 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -1,6 +1,8 @@ +<form method="post" action="?do=statistics"> +<input type="hidden" name="token" value="{{token}}"> +<input type="hidden" name="redirect" value="?{{redirect}}"> <table class="stupidtable table table-condensed table-striped"> - <thead> <tr> <td></td> @@ -45,6 +47,10 @@ {{#rows}} <tr> <td data-sort-value="{{hostname}}" class="text-nowrap"> + <div class="checkbox checkbox-inline"> + <input type="checkbox" name="uuid[]" value="{{machineuuid}}"> + <label></label> + </div> {{#hasnotes}}<span class="glyphicon glyphicon-exclamation-sign pull-right"></span>{{/hasnotes}} {{#state_OFFLINE}} <span class="glyphicon glyphicon-off" title="{{lang_machineOff}}"></span> @@ -68,10 +74,10 @@ <td data-sort-value="{{gbram}}" class="text-right {{ramclass}}">{{gbram}} GiB</td> <td data-sort-value="{{gbtmp}}" class="text-right {{hddclass}}"> {{gbtmp}} GiB - {{#badsectors}}<div> - <span class="glyphicon glyphicon-exclamation-sign" data-toggle="tooltip" title="{{lang_reallocatedSectors}}" data-placement="left"></span> + {{#badsectors}}<div><span data-toggle="tooltip" title="{{lang_reallocatedSectors}}" data-placement="left"> + <span class="glyphicon glyphicon-exclamation-sign"></span> {{badsectors}} - </div>{{/badsectors}} + </span></div>{{/badsectors}} {{#nohdd}}<div> <span class="glyphicon glyphicon-hdd red"></span> </div>{{/nohdd}} @@ -81,6 +87,37 @@ {{/rows}} </tbody> </table> + <div class="text-right buttonbar"> + <button type="reset" class="btn btn-default"> + <span class="glyphicon glyphicon-remove"></span> + {{lang_reset}} + </button> + <button type="button" class="btn btn-danger" onclick="$('#del-confirm').modal()"> + <span class="glyphicon glyphicon-trash"></span> + {{lang_delete}} + </button> + </div> + <div class="modal fade" id="del-confirm" tabindex="-1" role="dialog"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal">×</button> + <b>{{lang_delete}}</b> + </div> + <div class="modal-body"> + {{lang_sureDeletePermanent}} + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button> + <button type="submit" class="btn btn-danger" name="action" value="delmachines"> + <span class="glyphicon glyphicon-trash"></span> + {{lang_delete}} + </button> + </div> + </div> + </div> + </div> +</form> <script type="application/javascript"><!-- document.addEventListener("DOMContentLoaded", function () { |