Add filter log by failed reason and status

This commit is contained in:
ditatompel 2024-05-07 21:31:40 +07:00
parent 9271e67e7a
commit 2a4721b8de
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
3 changed files with 19 additions and 24 deletions

View file

@ -20,7 +20,6 @@
export let data; export let data;
let pageId = '0'; let pageId = '0';
let filterProberId = 0;
let filterStatus = -1; let filterStatus = -1;
/** @type {MoneroNode | null} */ /** @type {MoneroNode | null} */
@ -67,10 +66,10 @@
} }
}; };
$: startInterval(); // Automatically start the interval on change $: startInterval();
onDestroy(() => { onDestroy(() => {
clearInterval(intervalId); // Clear the interval when the component is destroyed clearInterval(intervalId);
}); });
onMount(() => { onMount(() => {
pageId = new URLSearchParams(window.location.search).get('node_id') || '0'; pageId = new URLSearchParams(window.location.search).get('node_id') || '0';
@ -161,7 +160,7 @@
<thead> <thead>
<tr> <tr>
<th>#ID</th> <th>#ID</th>
<th><label for="prober_id">Prober</label></th> <th>Prober ID</th>
<th><label for="status">Status</label></th> <th><label for="status">Status</label></th>
<th>Height</th> <th>Height</th>
<th>Adjusted Time</th> <th>Adjusted Time</th>
@ -172,21 +171,7 @@
<DtSrThSort {handler} orderBy="fetch_runtime">Runtime</DtSrThSort> <DtSrThSort {handler} orderBy="fetch_runtime">Runtime</DtSrThSort>
</tr> </tr>
<tr> <tr>
<th colspan="2"> <th colspan="3">
<select
id="prober_id"
name="prober_id"
class="select variant-form-material"
bind:value={filterProberId}
on:change={() => {
handler.filter(filterProberId, 'prober_id');
handler.invalidate();
}}
>
<option value={0}>Any</option>
</select>
</th>
<th colspan="2">
<select <select
id="status" id="status"
name="status" name="status"
@ -206,7 +191,7 @@
{handler} {handler}
filterBy="failed_reason" filterBy="failed_reason"
placeholder="Filter reason" placeholder="Filter reason"
colspan={6} colspan={7}
/> />
</tr> </tr>
</thead> </thead>

View file

@ -189,6 +189,8 @@ func ProbeLogs(c *fiber.Ctx) error {
SortBy: c.Query("sort_by", "id"), SortBy: c.Query("sort_by", "id"),
SortDirection: c.Query("sort_direction", "desc"), SortDirection: c.Query("sort_direction", "desc"),
NodeId: c.QueryInt("node_id", 0), NodeId: c.QueryInt("node_id", 0),
Status: c.QueryInt("status", -1),
FailedReason: c.Query("failed_reason"),
} }
logs, err := moneroRepo.Logs(query) logs, err := moneroRepo.Logs(query)

View file

@ -190,10 +190,10 @@ func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (MoneroNodes, error) {
} }
type MoneroLogQueryParams struct { type MoneroLogQueryParams struct {
NodeId int // 0 fpr all, >0 for specific node NodeId int // 0 fpr all, >0 for specific node
WorkerId int // 0 for all, >0 for specific worker WorkerId int // 0 for all, >0 for specific worker
Status int // -1 for all, 0 for failed, 1 for success Status int // -1 for all, 0 for failed, 1 for success
FailReason string // empty for all, if not empty, will be used as search from failed_reaso FailedReason string // empty for all, if not empty, will be used as search from failed_reaso
RowsPerPage int RowsPerPage int
Page int Page int
@ -231,6 +231,14 @@ func (repo *MoneroRepo) Logs(q MoneroLogQueryParams) (MoneroNodeFetchLogs, error
whereQueries = append(whereQueries, "node_id = ?") whereQueries = append(whereQueries, "node_id = ?")
queryParams = append(queryParams, q.NodeId) queryParams = append(queryParams, q.NodeId)
} }
if q.Status != -1 {
whereQueries = append(whereQueries, "is_available = ?")
queryParams = append(queryParams, q.Status)
}
if q.FailedReason != "" {
whereQueries = append(whereQueries, "failed_reason LIKE ?")
queryParams = append(queryParams, "%"+q.FailedReason+"%")
}
if len(whereQueries) > 0 { if len(whereQueries) > 0 {
where = "WHERE " + strings.Join(whereQueries, " AND ") where = "WHERE " + strings.Join(whereQueries, " AND ")