This commit is contained in:
Brieuc Dubois 2023-12-23 20:29:53 +01:00
parent 367f53062d
commit 3fe367ef38
4 changed files with 89 additions and 6 deletions

View File

@ -3,23 +3,93 @@
<head> <head>
<title>Dashboard</title> <title>Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0;
padding: 0;
}
h1 {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 20px 0;
margin: 0;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
}
th,
td {
padding: 10px;
border: 1px solid #ddd;
text-align: center;
}
th {
background-color: #4CAF50;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
a {
color: #4CAF50;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.create-new-link {
display: block;
width: fit-content;
margin: 20px auto;
padding: 10px 20px;
background-color: #4CAF50;
color: white;
text-decoration: none;
border-radius: 5px;
font-weight: bold;
}
.create-new-link:hover {
background-color: #367c39;
}
</style>
</head> </head>
<body> <body>
<h1>Tracking Pixel Dashboard</h1> <h1>Tracking Pixel Dashboard</h1>
<a href="/new" class="create-new-link">Create New Tracking Pixel</a>
<table> <table>
<tr> <tr>
<th>Title</th> <th>Title</th>
<th>Total Views</th> <th>Total Views</th>
<th>Unique Views</th> <th>Unique Views</th>
<th>Link</th> <th>UUID</th>
</tr> </tr>
{{range .}} {{range .}}
<tr> <tr>
<td>{{.Title}}</td> <td>{{.Title}}</td>
<td>{{.TotalViews}}</td> <td>{{.TotalViews}}</td>
<td>{{.UniqueViews}}</td> <td>{{.UniqueViews}}</td>
<td><a href="/p/{{.UUID}}" target="_blank">link</a></td> <td>
<a href='/p/{{.UUID}}'>
{{.UUID}}
</a>
</td>
</tr> </tr>
{{end}} {{end}}
</table> </table>

View File

@ -7,6 +7,8 @@
<style> <style>
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
margin: 0; margin: 0;
padding: 0; padding: 0;
display: flex; display: flex;
@ -20,9 +22,15 @@
padding: 20px; padding: 20px;
border: 1px solid #ddd; border: 1px solid #ddd;
border-radius: 5px; border-radius: 5px;
background-color: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
} }
h2 {
color: #4CAF50;
margin-bottom: 20px;
}
form { form {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -37,7 +45,7 @@
button { button {
padding: 10px; padding: 10px;
background-color: #007bff; background-color: #4CAF50;
color: white; color: white;
border: none; border: none;
border-radius: 3px; border-radius: 3px;
@ -45,7 +53,7 @@
} }
button:hover { button:hover {
background-color: #0056b3; background-color: #367c39;
} }
</style> </style>
</head> </head>

View File

@ -46,7 +46,7 @@ func createPixelHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
http.Redirect(w, r, "/dashboard", http.StatusSeeOther) http.Redirect(w, r, "/", http.StatusSeeOther)
} }
func pixelHandler(w http.ResponseWriter, r *http.Request) { func pixelHandler(w http.ResponseWriter, r *http.Request) {
@ -85,6 +85,11 @@ func pixelHandler(w http.ResponseWriter, r *http.Request) {
} }
func dashboardHandler(w http.ResponseWriter, r *http.Request) { func dashboardHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
query := ` query := `
SELECT p.title, p.uuid, COUNT(s.id) AS total_views, COUNT(DISTINCT s.ip) AS unique_views SELECT p.title, p.uuid, COUNT(s.id) AS total_views, COUNT(DISTINCT s.ip) AS unique_views
FROM pixels p FROM pixels p

View File

@ -22,7 +22,7 @@ func Server() {
http.HandleFunc("/new", newPixelPageHandler) http.HandleFunc("/new", newPixelPageHandler)
http.HandleFunc("/create-pixel", createPixelHandler) http.HandleFunc("/create-pixel", createPixelHandler)
http.HandleFunc("/p/", pixelHandler) http.HandleFunc("/p/", pixelHandler)
http.HandleFunc("/dashboard", dashboardHandler) http.HandleFunc("/", dashboardHandler)
port := getenv("PORT", "80") port := getenv("PORT", "80")