Skip to content

Commit

Permalink
Use new datatable column handling description for rollouts
Browse files Browse the repository at this point in the history
  • Loading branch information
UpstreamData authored and b-rowan committed Dec 3, 2024
1 parent 8600217 commit 6aa1677
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
12 changes: 12 additions & 0 deletions goosebit/ui/bff/common/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ class DeviceColumns:
last_ip = DTColumnDescription(title="Last IP", data="last_ip")
polling = DTColumnDescription(title="Polling", data="polling")
last_seen = DTColumnDescription(title="Last Seen", data="last_seen")


class RolloutColumns:
id = DTColumnDescription(title="ID", data="id", visible=False)
created_at = DTColumnDescription(title="Created", data="created_at", name="created_at", orderable=True)
name = DTColumnDescription(title="Name", data="name", name="name", searchable=True, orderable=True)
feed = DTColumnDescription(title="Feed", data="feed", name="feed", searchable=True, orderable=True)
sw_file = DTColumnDescription(title="Software File", data="sw_file", name="sw_file")
sw_version = DTColumnDescription(title="Software Version", data="sw_version", name="sw_version")
paused = DTColumnDescription(title="Paused", name="paused", data="paused")
success_count = DTColumnDescription(title="Success Count", data="success_count", name="success_count")
failure_count = DTColumnDescription(title="Failure Count", data="failure_count", name="failure_count")
1 change: 1 addition & 0 deletions goosebit/ui/bff/common/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DTColumnDescription(BaseModel):

searchable: bool | None = None
orderable: bool | None = None
visible: bool | None = None


class DTColumns(BaseModel):
Expand Down
27 changes: 27 additions & 0 deletions goosebit/ui/bff/rollouts/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from goosebit.ui.bff.common.requests import DataTableRequest
from goosebit.ui.bff.common.util import parse_datatables_query

from ..common.columns import RolloutColumns
from ..common.responses import DTColumns
from .responses import BFFRolloutsResponse

router = APIRouter(prefix="/rollouts")
Expand Down Expand Up @@ -52,3 +54,28 @@ def search_filter(search_value):
dependencies=[Security(validate_user_permissions, scopes=["rollout.delete"])],
name="bff_rollouts_delete",
)


@router.get(
"/columns",
dependencies=[Security(validate_user_permissions, scopes=["rollout.read"])],
response_model_exclude_none=True,
)
async def devices_get_columns() -> DTColumns:
columns = list(
filter(
None,
[
RolloutColumns.id,
RolloutColumns.created_at,
RolloutColumns.name,
RolloutColumns.feed,
RolloutColumns.sw_file,
RolloutColumns.sw_version,
RolloutColumns.paused,
RolloutColumns.success_count,
RolloutColumns.failure_count,
],
)
)
return DTColumns(columns=columns)
55 changes: 26 additions & 29 deletions goosebit/ui/static/js/rollouts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
let dataTable;

const renderFunctions = {
paused: (data, type) => {
if (type === "display") {
const color = data ? "danger" : "muted";
return `
<div class="text-${color}">
</div>
`;
}
return data;
},
created_at: (data, type) => new Date(data).toLocaleString(),
};

document.addEventListener("DOMContentLoaded", async () => {
const columnConfig = await get_request("/ui/bff/rollouts/columns");
for (const col in columnConfig.columns) {
const colDesc = columnConfig.columns[col];
const colName = colDesc.data;
if (renderFunctions[colName]) {
columnConfig.columns[col].render = renderFunctions[colName];
}
}

dataTable = new DataTable("#rollout-table", {
responsive: true,
paging: true,
Expand Down Expand Up @@ -32,37 +56,10 @@ document.addEventListener("DOMContentLoaded", async () => {
targets: "_all",
searchable: false,
orderable: false,
render: (data) => data || "-",
},
],
columns: [
{ data: "id", visible: false },
{
data: "created_at",
name: "created_at",
orderable: true,
render: (data) => new Date(data).toLocaleString(),
},
{ data: "name", name: "name", searchable: true, orderable: true },
{ data: "feed", name: "feed", searchable: true, orderable: true },
{ data: "sw_file" },
{ data: "sw_version" },
{
data: "paused",
render: (data, type) => {
if (type === "display") {
const color = data ? "danger" : "muted";
return `
<div class="text-${color}">
</div>
`;
}
return data;
},
},
{ data: "success_count" },
{ data: "failure_count" },
],
columns: columnConfig.columns,
layout: {
top1Start: {
buttons: [],
Expand Down
15 changes: 0 additions & 15 deletions goosebit/ui/templates/rollouts.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@
<div class="row p-2 d-flex justify-content-center">
<div class="col">
<table id="rollout-table" class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Created</th>
<th>Name</th>
<th>Feed</th>
<th>Software File</th>
<th>Software Version</th>
<th>Paused</th>
<th>Success Count</th>
<th>Failure Count</th>
</tr>
</thead>
<tbody id="rollouts-list">
</tbody>
</table>
</div>
</div>
Expand Down

0 comments on commit 6aa1677

Please sign in to comment.