mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07: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" />
|
<DtSrThFilter {handler} filterBy="host" placeholder="Filter Host / IP" />
|
||||||
<th>
|
<th>
|
||||||
<select
|
<select
|
||||||
id="fNettype"
|
id="nettype"
|
||||||
name="fNettype"
|
name="nettype"
|
||||||
class="select variant-form-material"
|
class="select variant-form-material"
|
||||||
bind:value={filterNettype}
|
bind:value={filterNettype}
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
|
@ -212,8 +212,8 @@
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
<select
|
<select
|
||||||
id="fProtocol"
|
id="protocol"
|
||||||
name="fProtocol"
|
name="protocol"
|
||||||
class="select variant-form-material"
|
class="select variant-form-material"
|
||||||
bind:value={filterProtocol}
|
bind:value={filterProtocol}
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
|
@ -229,12 +229,12 @@
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
<select
|
<select
|
||||||
id="fCc"
|
id="cc"
|
||||||
name="fCc"
|
name="cc"
|
||||||
class="select variant-form-material"
|
class="select variant-form-material"
|
||||||
bind:value={filterCc}
|
bind:value={filterCc}
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
handler.filter(filterCc, 'country');
|
handler.filter(filterCc, 'cc');
|
||||||
handler.invalidate();
|
handler.invalidate();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -252,8 +252,8 @@
|
||||||
</th>
|
</th>
|
||||||
<th colspan="2">
|
<th colspan="2">
|
||||||
<select
|
<select
|
||||||
id="fStatus"
|
id="status"
|
||||||
name="fStatus"
|
name="status"
|
||||||
class="select variant-form-material"
|
class="select variant-form-material"
|
||||||
bind:value={filterStatus}
|
bind:value={filterStatus}
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
|
@ -267,12 +267,12 @@
|
||||||
</select>
|
</select>
|
||||||
</th>
|
</th>
|
||||||
<th colspan="2">
|
<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
|
<input
|
||||||
id="fCors"
|
id="cors"
|
||||||
|
name="cors"
|
||||||
class="checkbox"
|
class="checkbox"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="fCors"
|
|
||||||
bind:checked={checkboxCors}
|
bind:checked={checkboxCors}
|
||||||
on:change={() => {
|
on:change={() => {
|
||||||
handler.filter(checkboxCors === true ? 1 : -1, 'cors');
|
handler.filter(checkboxCors === true ? 1 : -1, 'cors');
|
||||||
|
|
|
@ -123,6 +123,11 @@ func MoneroNodes(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"),
|
||||||
Host: c.Query("host"),
|
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)
|
nodes, err := moneroRepo.Nodes(query)
|
||||||
|
|
|
@ -73,6 +73,11 @@ type MoneroNodes struct {
|
||||||
|
|
||||||
type MoneroQueryParams struct {
|
type MoneroQueryParams struct {
|
||||||
Host string
|
Host string
|
||||||
|
NetType string
|
||||||
|
Protocol string
|
||||||
|
CC string // 2 letter country code
|
||||||
|
Status int
|
||||||
|
Cors int
|
||||||
RowsPerPage int
|
RowsPerPage int
|
||||||
Page int
|
Page int
|
||||||
SortBy string
|
SortBy string
|
||||||
|
@ -89,6 +94,36 @@ func (repo *MoneroRepo) Nodes(q MoneroQueryParams) (MoneroNodes, error) {
|
||||||
queryParams = append(queryParams, "%"+q.Host+"%")
|
queryParams = append(queryParams, "%"+q.Host+"%")
|
||||||
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 {
|
if len(whereQueries) > 0 {
|
||||||
where = "WHERE " + strings.Join(whereQueries, " AND ")
|
where = "WHERE " + strings.Join(whereQueries, " AND ")
|
||||||
|
|
Loading…
Reference in a new issue