-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
433 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
|
||
|
||
// Call the dataTables jQuery plugin | ||
function getIdSelections(table) { | ||
return $.map(table.bootstrapTable('getSelections'), function (row) { | ||
return row.internal_ip | ||
}) | ||
} | ||
|
||
function responseHandler(res) { | ||
$.each(res.rows, function (i, row) { | ||
row.state = $.inArray(row.internal_ip, selections) !== -1 | ||
}) | ||
return res | ||
} | ||
|
||
function ownersFormatter(values, row) { | ||
let a = document.createElement('a') | ||
a.href = '/management/users/?username=' + encodeURIComponent(row.owner) | ||
a.innerText = row.owner | ||
|
||
return a.outerHTML | ||
} | ||
|
||
function lockedFormatter(value) { | ||
let p = document.createElement('p') | ||
if (value === true) { | ||
p.className = "badge badge-danger" | ||
} | ||
p.innerText = value | ||
return p.outerHTML | ||
} | ||
|
||
|
||
$(function () { | ||
let table = createTable('#devicesTable', [ | ||
{ | ||
field: 'state', | ||
checkbox: true, | ||
align: 'center', | ||
escape: "true" | ||
}, { | ||
title: 'Owner', | ||
field: 'owner', | ||
align: 'center', | ||
sortable: true, | ||
formatter: ownersFormatter | ||
}, { | ||
field: 'active', | ||
title: 'Active', | ||
sortable: true, | ||
align: 'center', | ||
escape: "true" | ||
}, { | ||
field: 'is_locked', | ||
title: 'Locked', | ||
sortable: true, | ||
align: 'center', | ||
formatter: lockedFormatter | ||
}, { | ||
field: 'internal_ip', | ||
title: 'Address', | ||
sortable: true, | ||
align: 'center', | ||
escape: "true" | ||
}, { | ||
field: 'public_key', | ||
title: 'Public Key', | ||
sortable: true, | ||
align: 'center', | ||
escape: "true" | ||
}, { | ||
field: 'last_endpoint', | ||
title: 'Last Endpoint Address', | ||
sortable: true, | ||
align: 'center', | ||
escape: "true" | ||
} | ||
]) | ||
|
||
var $remove = $('#remove') | ||
var $lock = $('#lock') | ||
var $unlock = $('#unlock') | ||
|
||
|
||
table.on('check.bs.table uncheck.bs.table ' + | ||
'check-all.bs.table uncheck-all.bs.table', | ||
function () { | ||
let enableModifications = !table.bootstrapTable('getSelections').length; | ||
|
||
$("#removeStart").prop('disabled', enableModifications) | ||
$lock.prop('disabled', enableModifications) | ||
$unlock.prop('disabled', enableModifications) | ||
|
||
// save your data, here just save the current page | ||
selections = getIdSelections(table) | ||
// push or splice the selections if you want to save all data selections | ||
}) | ||
$lock.on("click", function () { | ||
var ids = getIdSelections(table) | ||
action(ids, "lock", table) | ||
}) | ||
|
||
$unlock.on("click", function () { | ||
var ids = getIdSelections(table) | ||
action(ids, "unlock", table) | ||
}) | ||
|
||
$remove.on("click", function () { | ||
var ids = getIdSelections(table) | ||
table.bootstrapTable('remove', { | ||
field: 'internal_ip', | ||
values: ids | ||
}) | ||
|
||
|
||
fetch("/management/devices/data", { | ||
method: 'DELETE', | ||
mode: 'same-origin', | ||
cache: 'no-cache', | ||
credentials: 'same-origin', | ||
redirect: 'follow', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'WAG-CSRF': $("#csrf_token").val() | ||
}, | ||
body: JSON.stringify(ids) | ||
}).then((response) => { | ||
if (response.status == 200) { | ||
table.bootstrapTable('refresh') | ||
$("#issue").hide() | ||
return | ||
} | ||
|
||
response.text().then(txt => { | ||
|
||
$("#issue").text(txt) | ||
$("#issue").show() | ||
}) | ||
}) | ||
}) | ||
|
||
$('#clearFilter').on("click", function () { | ||
table.bootstrapTable('filterBy', {}) | ||
$('#clearFilter').hide() | ||
}) | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
if (urlParams.toString().length > 0) { | ||
$('#clearFilter').show() | ||
|
||
let filter = {} | ||
|
||
if (urlParams.has('owner')) { | ||
filter.owner = urlParams.get('owner') | ||
} | ||
|
||
if (urlParams.has('is_locked')) { | ||
filter.is_locked = urlParams.get('is_locked') == "true" | ||
} | ||
|
||
if (urlParams.has('active')) { | ||
filter.active = urlParams.get('active') == "true" | ||
} | ||
|
||
table.bootstrapTable('filterBy', filter) | ||
} | ||
|
||
}); | ||
|
||
function action(onDevices, action, table) { | ||
let data = { | ||
"action": action, | ||
"addresses": onDevices, | ||
} | ||
|
||
fetch("/management/devices/data", { | ||
method: 'PUT', | ||
mode: 'same-origin', | ||
cache: 'no-cache', | ||
credentials: 'same-origin', | ||
redirect: 'follow', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'WAG-CSRF': $("#csrf_token").val() | ||
}, | ||
body: JSON.stringify(data) | ||
}).then((response) => { | ||
if (response.status == 200) { | ||
table.bootstrapTable('refresh') | ||
$("#issue").hide() | ||
return | ||
} | ||
|
||
response.text().then(txt => { | ||
$("#issue").text(txt) | ||
$("#issue").show() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ui | ||
|
||
import "github.com/NHAS/wag/internal/data" | ||
|
||
var ( | ||
clusterState string | ||
serverID string | ||
) | ||
|
||
func watchClusterHealth(state string, _ int) { | ||
clusterState = state | ||
serverID = data.GetServerID() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{{define "Content"}} | ||
|
||
|
||
<link href="/vendor/bootstrap-table/css/bootstrap-table.min.css" rel="stylesheet"> | ||
|
||
<div class="card shadow mb-4"> | ||
<div class="card-header py-3"> | ||
<h1 class="m-0 text-gray-900">Cluster</h1> | ||
<div class="d-sm-flex justify-content-between"> | ||
<p> | ||
Wag ETCd cluster nodes | ||
</p> | ||
</div> | ||
</div> | ||
<div class="card-body"> | ||
<div id="toolbar"> | ||
<button id="add" class="btn btn-primary"> | ||
<i class="icon-plus"></i> Add | ||
</button> | ||
<button id="removeStart" class="btn btn-danger" disabled data-toggle='modal' data-target='#deleteModal'> | ||
<i class="icon-trash"></i> Remove | ||
</button> | ||
</div> | ||
<table id="devicesTable" data-toolbar="#toolbar" data-search="true" data-show-refresh="true" | ||
data-show-columns="true" data-show-columns-toggle-all="true" data-minimum-count-columns="2" | ||
data-show-pagination-switch="true" data-pagination="true" data-id-field="username" | ||
data-page-list="[10, 25, 50, 100, all]" data-side-pagination="client" data-url="/management/clustering/data" | ||
data-response-handler="responseHandler"> | ||
</table> | ||
</div> | ||
</div> | ||
|
||
<script src="/vendor/bootstrap-table/js/bootstrap-table.min.js"></script> | ||
<script src="/vendor/bootstrap-table/js/bootstrap-table-locale-all.min.js"></script> | ||
<script src="/js/default_table.min.js"></script> | ||
<script src="/js/clustering.min.js"></script> | ||
|
||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.