Skip to content

Commit d322612

Browse files
committed
refactor and fix table display and sorting
1 parent 3d13876 commit d322612

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

bale/interfaces/sshdl.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ async def _display(self):
226226
with el.DBody(height="fit", width="[90vw]"):
227227
with el.WColumn().classes("col"):
228228
filesystems = await self._zfs.filesystems
229-
self._filesystem = el.DSelect(
230-
list(filesystems.data.keys()), label="filesystem", with_input=True, on_change=self._update_grid
231-
)
229+
self._filesystem = el.DSelect(list(filesystems.data.keys()), label="filesystem", with_input=True, on_change=self._update_grid)
232230
self._pattern = el.DInput("Pattern", on_change=self._update_grid)
233231
self._grid = ui.aggrid(
234232
{
@@ -237,12 +235,14 @@ async def _display(self):
237235
{"field": "name", "headerName": "Name", "flex": 1, "sort": "desc", "resizable": True},
238236
{"field": "location", "headerName": "Location", "flex": 1, "resizable": True},
239237
{
240-
"field": "modified_datetime",
241238
"headerName": "Modified",
239+
"field": "modified_timestamp",
240+
"filter": "agTextColumnFilter",
242241
"maxWidth": 200,
243-
":comparator": """(valueA, valueB, nodeA, nodeB, isInverted) => {
244-
return (nodeA.data.modified_timestamp > nodeB.data.modified_timestamp) ? -1 : 1;
245-
}""",
242+
":cellRenderer": """(data) => {
243+
var date = new Date(data.value * 1000).toLocaleString(undefined, {dateStyle: 'short', timeStyle: 'short', hour12: false});;
244+
return date;
245+
}""",
246246
},
247247
{
248248
"field": "size",

bale/interfaces/zfs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ async def find_files_in_snapshots(self, filesystem: str, pattern: str) -> Result
180180
if matches is not None:
181181
md = matches.groupdict()
182182
md["path"] = f"{md['location']}/{md['name']}"
183-
md["size"] = format_bytes(int(md["bytes"]))
183+
md["bytes"] = int(md["bytes"])
184+
md["size"] = format_bytes(md["bytes"])
184185
md["modified_datetime"] = datetime.fromtimestamp(float(md["modified_timestamp"])).strftime("%Y/%m/%d %H:%M:%S")
186+
md["modified_timestamp"] = float(md["modified_timestamp"])
185187
files.append(md)
186188
result.data = files
187189
return result
@@ -219,9 +221,11 @@ async def snapshots(self) -> Result:
219221
matches = re.match("^(?P<filesystem>[^@]+)@(?P<name>[^\t]+)\t(?P<used_bytes>[^\t]+)\t(?P<creation>[^\t]+)\t(?P<userrefs>[^\n]+)", line)
220222
if matches is not None:
221223
md = matches.groupdict()
222-
md["creation_date"] = datetime.fromtimestamp(int(md["creation"])).strftime("%Y/%m/%d")
223-
md["creation_time"] = datetime.fromtimestamp(int(md["creation"])).strftime("%H:%M")
224-
md["used"] = format_bytes(int(md["used_bytes"]))
224+
md["used_bytes"] = int(md["used_bytes"])
225+
md["creation"] = int(md["creation"])
226+
md["creation_date"] = datetime.fromtimestamp(md["creation"]).strftime("%Y/%m/%d")
227+
md["creation_time"] = datetime.fromtimestamp(md["creation"]).strftime("%H:%M")
228+
md["used"] = format_bytes(md["used_bytes"])
225229
snapshot = f"{md['filesystem']}@{md['name']}"
226230
snapshots[snapshot] = md
227231
self._last_data[query] = snapshots

bale/tabs/history.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ async def display_result(e):
4747
"filter": "agTextColumnFilter",
4848
"flex": 1,
4949
},
50-
{"headerName": "Date", "field": "date", "filter": "agDateColumnFilter", "maxWidth": 100},
51-
{"headerName": "Time", "field": "time", "maxWidth": 100},
50+
{
51+
"headerName": "Timestamp",
52+
"field": "timestamp",
53+
"filter": "agTextColumnFilter",
54+
"maxWidth": 200,
55+
":cellRenderer": """(data) => {
56+
var date = new Date(data.value * 1000).toLocaleString(undefined, {dateStyle: 'short', timeStyle: 'short', hour12: false});;
57+
return date;
58+
}""",
59+
},
5260
{
5361
"headerName": "Status",
5462
"field": "status",

bale/tabs/manage.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,19 @@ def set_default(value) -> None:
7575
"field": "used",
7676
"maxWidth": 100,
7777
":comparator": """(valueA, valueB, nodeA, nodeB, isInverted) => {
78-
return (nodeA.data.used_bytes > nodeB.data.used_bytes) ? -1 : 1;
79-
}""",
78+
return (nodeA.data.used_bytes > nodeB.data.used_bytes) ? -1 : 1;
79+
}""",
80+
},
81+
{
82+
"headerName": "Created",
83+
"field": "creation",
84+
"filter": "agTextColumnFilter",
85+
"maxWidth": 200,
86+
":cellRenderer": """(data) => {
87+
var date = new Date(data.value * 1000).toLocaleString(undefined, {dateStyle: 'short', timeStyle: 'short', hour12: false});;
88+
return date;
89+
}""",
8090
},
81-
{"headerName": "Creation Date", "field": "creation_date", "filter": "agDateColumnFilter", "maxWidth": 150},
82-
{"headerName": "Creation Time", "field": "creation_time", "maxWidth": 150},
8391
{"headerName": "Holds", "field": "userrefs", "filter": "agNumberColumnFilter", "maxWidth": 100},
8492
],
8593
"rowData": [],

0 commit comments

Comments
 (0)