updated theme branch, added postgresql support
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Paul 2020-06-02 02:17:50 +02:00
parent 23afca0244
commit bf1a033725
5 changed files with 111 additions and 30 deletions

View File

@ -40,9 +40,8 @@ func (config *Config) GetConfig() error {
config.Cron = qrzsection.Key("cron").MustString("@every 1h") config.Cron = qrzsection.Key("cron").MustString("@every 1h")
config.DbSchema = fmt.Sprintf(` config.DbSchema = fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s CREATE TABLE IF NOT EXISTS %[1]s (
( id serial NOT NULL PRIMARY KEY,
id int(8) NOT NULL AUTO_INCREMENT,
qrz varchar(25) NOT NULL, qrz varchar(25) NOT NULL,
name varchar(25) DEFAULT NULL, name varchar(25) DEFAULT NULL,
address varchar(50) DEFAULT NULL, address varchar(50) DEFAULT NULL,
@ -51,28 +50,47 @@ func (config *Config) GetConfig() error {
dept varchar(50) DEFAULT NULL, dept varchar(50) DEFAULT NULL,
country varchar(25) DEFAULT NULL, country varchar(25) DEFAULT NULL,
dmrid varchar(25) DEFAULT NULL, dmrid varchar(25) DEFAULT NULL,
PRIMARY KEY (id), fts tsvector NULL,
UNIQUE KEY qrz (qrz,name,city,dept) USING BTREE, CONSTRAINT qrz_unique UNIQUE(qrz, name, city, dept, country)
KEY test (country), );
FULLTEXT KEY city (city),
FULLTEXT KEY dept (dept) CREATE INDEX IF NOT EXISTS fts_idx ON %[1]s (fts);
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;`, CREATE OR REPLACE FUNCTION updateFTS() RETURNS trigger AS $fts_trigger$
BEGIN
IF pg_trigger_depth() <> 1 THEN
RETURN NEW;
END IF;
UPDATE %[1]s SET fts = to_tsvector(concat_ws(' ', qrz, name, city, dept, country)) WHERE id = NEW.id;
RETURN NEW;
END;
$fts_trigger$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS fts_trigger ON %[1]s;
CREATE TRIGGER fts_trigger
AFTER INSERT ON %[1]s
FOR EACH ROW EXECUTE PROCEDURE updateFTS();
`,
config.DbTable) config.DbTable)
config.DbStatements.Insert = fmt.Sprintf( config.DbStatements.Insert = fmt.Sprintf(`
`INSERT IGNORE INTO %s (qrz, dmrid, name, city, dept, country) INSERT INTO %[1]s (qrz, dmrid, name, city, dept, country)
VALUES (?,?,?,?,?,?);`, VALUES ($1, $2, $3, $4, $5, $6);
config.DbTable) `,
config.DbStatements.ExportCSV = fmt.Sprintf(
`SELECT qrz, name, city, dept, country
FROM %s;`,
config.DbTable) config.DbTable)
config.DbStatements.Countries = fmt.Sprintf( config.DbStatements.ExportCSV = fmt.Sprintf(`
`SELECT country SELECT qrz, name, city, dept, country
FROM %s FROM %[1]s;
GROUP BY country;`, `,
config.DbTable)
config.DbStatements.Countries = fmt.Sprintf(`
SELECT country
FROM %[1]s
GROUP BY country;
`,
config.DbTable) config.DbTable)
config.URLBase = `http://groupe-frs.hamstation.eu/index_qrz_liste_%s.php` config.URLBase = `http://groupe-frs.hamstation.eu/index_qrz_liste_%s.php`

View File

@ -168,4 +168,5 @@ type FrsEntry struct {
ZipCode sql.NullString `db:"zipcode"` ZipCode sql.NullString `db:"zipcode"`
Dept sql.NullString `db:"dept"` Dept sql.NullString `db:"dept"`
Country sql.NullString `db:"country"` Country sql.NullString `db:"country"`
Fts sql.NullString `db:"fts"`
} }

View File

@ -109,7 +109,7 @@ func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (rows *sqlx.Rows,
if err != nil { if err != nil {
return nil, err return nil, err
} }
searchstatement, err = SetSearchStatement(config, qrzdt) searchstatement, err = SetSearchLikeStatement(config, qrzdt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -120,16 +120,36 @@ func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (rows *sqlx.Rows,
} }
// BuildQueryCountFiltered builds query for counting filtered // BuildQueryCountFiltered builds query for counting filtered
<<<<<<< Updated upstream
func BuildQueryCountFiltered(config config.Config, qrzdt QrzDatatableInput) (cnt int, err error) { func BuildQueryCountFiltered(config config.Config, qrzdt QrzDatatableInput) (cnt int, err error) {
searchstatement, err := SetSearchStatement(config, qrzdt) searchstatement, err := SetSearchStatement(config, qrzdt)
err = config.Db.Get(&cnt, fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE %s;", config.DbTable, searchstatement)) err = config.Db.Get(&cnt, fmt.Sprintf("SELECT COUNT(*) FROM %s WHERE %s;", config.DbTable, searchstatement))
=======
func BuildQueryCountFiltered(config config.Config, qrzdt DatatableInput) (cnt int, err error) {
searchstatement, err := SetSearchLikeStatement(config, qrzdt)
query := `
SELECT COUNT(*)
FROM %s
WHERE %s;`
err = config.Db.Get(&cnt, fmt.Sprintf(query, config.DbTable, searchstatement))
>>>>>>> Stashed changes
return return
} }
// BuildQueryCountTotal builds query for counting totals // BuildQueryCountTotal builds query for counting totals
<<<<<<< Updated upstream
func BuildQueryCountTotal(config config.Config, qrzdt QrzDatatableInput) (cnt int, err error) { func BuildQueryCountTotal(config config.Config, qrzdt QrzDatatableInput) (cnt int, err error) {
err = config.Db.Get(&cnt, fmt.Sprintf("SELECT COUNT(*) FROM %s;", config.DbTable)) err = config.Db.Get(&cnt, fmt.Sprintf("SELECT COUNT(*) FROM %s;", config.DbTable))
=======
func BuildQueryCountTotal(config config.Config, qrzdt DatatableInput) (cnt int, err error) {
query := `
SELECT COUNT(*) FROM %s;
`
err = config.Db.Get(&cnt, fmt.Sprintf(query, config.DbTable))
>>>>>>> Stashed changes
return return
} }
@ -190,8 +210,13 @@ func SetLimitStatement(config config.Config, qrzdt QrzDatatableInput) (limitstmt
return return
} }
<<<<<<< Updated upstream
// SetSearchStatement build the where clause in sql statement // SetSearchStatement build the where clause in sql statement
func SetSearchStatement(config config.Config, qrzdt QrzDatatableInput) (searchstmt string, err error) { func SetSearchStatement(config config.Config, qrzdt QrzDatatableInput) (searchstmt string, err error) {
=======
// SetSearchLikeStatement build the where clause in sql statement
func SetSearchLikeStatement(config config.Config, qrzdt DatatableInput) (searchstmt string, err error) {
>>>>>>> Stashed changes
var searchstmtslice []string var searchstmtslice []string
if len(qrzdt.Columns) > 0 { if len(qrzdt.Columns) > 0 {
for id, i := range qrzdt.Columns { for id, i := range qrzdt.Columns {
@ -208,6 +233,16 @@ func SetSearchStatement(config config.Config, qrzdt QrzDatatableInput) (searchst
return return
} }
// SetSearchFTSStatement build the where clause in sql statement
func SetSearchFTSStatement(config config.Config, qrzdt DatatableInput) (searchstmt string, err error) {
if len(qrzdt.Columns) > 0 {
searchstmt = fmt.Sprintf("fts @@ plainto_tsquery('%s')", qrzdt.Search.Value)
} else {
searchstmt = "1=1"
}
return
}
// RunCSVExport runs the main loop // RunCSVExport runs the main loop
func RunCSVExport(c echo.Context, config config.Config) (data []byte, mime string, err error) { func RunCSVExport(c echo.Context, config config.Config) (data []byte, mime string, err error) {
mime = "text/csv" mime = "text/csv"

View File

@ -2,3 +2,18 @@ body
{ {
font-family: "Helvetica Neue", "HelveticaNeue", "Helvetica", "Arial", "sans-serif"; font-family: "Helvetica Neue", "HelveticaNeue", "Helvetica", "Arial", "sans-serif";
} }
<<<<<<< Updated upstream
=======
#main_table_length
{
float: left;
}
#main_table_filter
{
float: right;
}
#main_table_paginate
>>>>>>> Stashed changes

View File

@ -3,14 +3,22 @@
<head> <head>
<link rel="stylesheet" type="text/css" href="static/css/main.css" media="screen"> <link rel="stylesheet" type="text/css" href="static/css/main.css" media="screen">
<link rel="stylesheet" type="text/css" href="static/css/font-awesome/all.css"> <link rel="stylesheet" type="text/css" href="static/css/font-awesome/all.css">
<<<<<<< Updated upstream
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="static/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="static/css/materialize.min.css"> <link rel="stylesheet" type="text/css" href="static/css/materialize.min.css">
=======
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="static/css/dataTables.bootstrap4.min.css">
>>>>>>> Stashed changes
<script type="text/javascript" src="static/js/jquery.js"></script> <script type="text/javascript" src="static/js/jquery.js"></script>
<script type="text/javascript" src="static/js/jquery.dataTables.min.js"></script> <script type="text/javascript" src="static/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="static/js/bootstrap.min.js"></script> <script type="text/javascript" src="static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/dataTables.bootstrap4.min.js"></script> <script type="text/javascript" src="static/js/dataTables.bootstrap4.min.js"></script>
<<<<<<< Updated upstream
<script type="text/javascript" src="static/js/materialize.min.js"></script> <script type="text/javascript" src="static/js/materialize.min.js"></script>
=======
>>>>>>> Stashed changes
<script type="text/javascript" src="static/js/axios.min.js"></script> <script type="text/javascript" src="static/js/axios.min.js"></script>
<script type="text/javascript" src="static/js/vue.min.js"></script> <script type="text/javascript" src="static/js/vue.min.js"></script>
<script type="text/javascript" src="static/js/datatable.js"></script> <script type="text/javascript" src="static/js/datatable.js"></script>
@ -21,7 +29,11 @@
<h1 class="display-3">FRS QRZ database</h1> <h1 class="display-3">FRS QRZ database</h1>
<p>Mirror of <a href="http://groupe-frs.hamstation.eu">http://groupe-frs.hamstation.eu</a> list of users</p> <p>Mirror of <a href="http://groupe-frs.hamstation.eu">http://groupe-frs.hamstation.eu</a> list of users</p>
<div> <div>
<<<<<<< Updated upstream
<table id="main_table" class="striped highlight responsive-table"> <table id="main_table" class="striped highlight responsive-table">
=======
<table id="main_table" class="display table table-hover">
>>>>>>> Stashed changes
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<td>QRZ</td> <td>QRZ</td>