mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-12-23 12:09:47 +00:00
Filter datatable (backend)
Adding filter by country, protocol, status, cors and nettype
This commit is contained in:
parent
3acfdd2905
commit
33aae21237
3 changed files with 52 additions and 12 deletions
|
@ -195,8 +195,8 @@
|
|||
<DtSrThFilter {handler} filterBy="host" placeholder="Filter Host / IP" />
|
||||
<th>
|
||||
<select
|
||||
id="fNettype"
|
||||
name="fNettype"
|
||||
id="nettype"
|
||||
name="nettype"
|
||||
class="select variant-form-material"
|
||||
bind:value={filterNettype}
|
||||
on:change={() => {
|
||||
|
@ -212,8 +212,8 @@
|
|||
</th>
|
||||
<th>
|
||||
<select
|
||||
id="fProtocol"
|
||||
name="fProtocol"
|
||||
id="protocol"
|
||||
name="protocol"
|
||||
class="select variant-form-material"
|
||||
bind:value={filterProtocol}
|
||||
on:change={() => {
|
||||
|
@ -229,12 +229,12 @@
|
|||
</th>
|
||||
<th>
|
||||
<select
|
||||
id="fCc"
|
||||
name="fCc"
|
||||
id="cc"
|
||||
name="cc"
|
||||
class="select variant-form-material"
|
||||
bind:value={filterCc}
|
||||
on:change={() => {
|
||||
handler.filter(filterCc, 'country');
|
||||
handler.filter(filterCc, 'cc');
|
||||
handler.invalidate();
|
||||
}}
|
||||
>
|
||||
|
@ -252,8 +252,8 @@
|
|||
</th>
|
||||
<th colspan="2">
|
||||
<select
|
||||
id="fStatus"
|
||||
name="fStatus"
|
||||
id="status"
|
||||
name="status"
|
||||
class="select variant-form-material"
|
||||
bind:value={filterStatus}
|
||||
on:change={() => {
|
||||
|
@ -267,12 +267,12 @@
|
|||
</select>
|
||||
</th>
|
||||
<th colspan="2">
|
||||
<label for="fCors" class="flex items-center justify-center space-x-2">
|
||||
<label for="cors" class="flex items-center justify-center space-x-2">
|
||||
<input
|
||||
id="fCors"
|
||||
id="cors"
|
||||
name="cors"
|
||||
class="checkbox"
|
||||
type="checkbox"
|
||||
name="fCors"
|
||||
bind:checked={checkboxCors}
|
||||
on:change={() => {
|
||||
handler.filter(checkboxCors === true ? 1 : -1, 'cors');
|
||||
|
|
|
@ -123,6 +123,11 @@ func MoneroNodes(c *fiber.Ctx) error {
|
|||
SortBy: c.Query("sort_by", "id"),
|
||||
SortDirection: c.Query("sort_direction", "desc"),
|
||||
Host: c.Query("host"),
|
||||
NetType: c.Query("nettype", "any"),
|
||||
Protocol: c.Query("protocol", "any"),
|
||||
CC: c.Query("cc", "any"),
|
||||
Status: c.QueryInt("status", -1),
|
||||
Cors: c.QueryInt("cors", -1),
|
||||
}
|
||||
|
||||
nodes, err := moneroRepo.Nodes(query)
|
||||
|
|
|
@ -73,6 +73,11 @@ type MoneroNodes struct {
|
|||
|
||||
type MoneroQueryParams struct {
|
||||
Host string
|
||||
NetType string
|
||||
Protocol string
|
||||
CC string // 2 letter country code
|
||||
Status int
|
||||
Cors int
|
||||
RowsPerPage int
|
||||
Page int
|
||||
SortBy string
|
||||
|
@ -89,6 +94,36 @@ func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (MoneroNodes, error) {
|
|||
queryParams = append(queryParams, "%"+q.Host+"%")
|
||||
queryParams = append(queryParams, "%"+q.Host+"%")
|
||||
}
|
||||
if q.NetType != "any" {
|
||||
whereQueries = append(whereQueries, "nettype = ?")
|
||||
queryParams = append(queryParams, q.NetType)
|
||||
}
|
||||
if q.Protocol != "any" {
|
||||
if q.Protocol == "tor" {
|
||||
whereQueries = append(whereQueries, "is_tor = ?")
|
||||
queryParams = append(queryParams, 1)
|
||||
} else {
|
||||
whereQueries = append(whereQueries, "(protocol = ? AND is_tor = ?)")
|
||||
queryParams = append(queryParams, q.Protocol)
|
||||
queryParams = append(queryParams, 0)
|
||||
}
|
||||
}
|
||||
if q.CC != "any" {
|
||||
whereQueries = append(whereQueries, "country = ?")
|
||||
if q.CC == "UNKNOWN" {
|
||||
queryParams = append(queryParams, "")
|
||||
} else {
|
||||
queryParams = append(queryParams, q.CC)
|
||||
}
|
||||
}
|
||||
if q.Status != -1 {
|
||||
whereQueries = append(whereQueries, "is_available = ?")
|
||||
queryParams = append(queryParams, q.Status)
|
||||
}
|
||||
if q.Cors != -1 {
|
||||
whereQueries = append(whereQueries, "cors_capable = ?")
|
||||
queryParams = append(queryParams, 1)
|
||||
}
|
||||
|
||||
if len(whereQueries) > 0 {
|
||||
where = "WHERE " + strings.Join(whereQueries, " AND ")
|
||||
|
|
Loading…
Reference in a new issue