-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
224 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,61 @@ | ||
{{define "report"}} | ||
<div class="w3-container w3-center" id="content"> | ||
<h1>This is the report page</h1> | ||
<p>Report Page 1</p> | ||
<p>Line 1</p> | ||
<p>Line 2</p> | ||
<p>Line 3</p> | ||
<p>Line 4</p> | ||
<p>Line 5</p> | ||
<br> | ||
<br> | ||
<br> | ||
<h1>Reports</h1> | ||
<div class="w3-row"> | ||
<div class="w3-third"><br></div> | ||
<div class="w3-third"> | ||
<form class="w3-container" hx-post="/reports" hx-target="#content"> | ||
<p><label>Start Date</label></p> | ||
<p><input type="date" name="start" value="{{.DefaultDate}}" required></p> | ||
<p><label>End Date</label></p> | ||
<p><input type="date" name="end" value="{{.DefaultDate}}" required></p> | ||
<p><label>Limit to Project</label></p> | ||
<p><select class="w3-select" name="project"> | ||
<option value=""></option> | ||
{{range .Projects}} | ||
<option value="{{.}}">{{.}}</option> | ||
{{end}} | ||
</select></p> | ||
<p><button class="w3-button w3-theme-dark w3-padding large" type="button" hx-get="/" | ||
hx-target="#main">Cancel</button> | ||
<button class="w3-button w3-theme-dark w3-padding large" type="submit">Submit</button> | ||
</p> | ||
</form> | ||
</div> | ||
</div> | ||
{{end}} | ||
|
||
{{define "results"}} | ||
<h1>TimeTrace Report</h1> | ||
{{range .}} | ||
<h2>Project {{.Project}}</h2> | ||
{{range .Items}} | ||
<button hx-get="/records/{{ .ID }}" hx-target="#content" type="button"> | ||
{{.Start.Format "Jan 02, 2006 15:04"}} {{.End.Format "Jan 02, 2006 15:04"}} | ||
</button><br> | ||
{{end}} | ||
<h2>{{.Total}}</h2> | ||
{{end}} | ||
{{end}} | ||
|
||
{{define "editRecord"}} | ||
<h1>Edit Record</h1> | ||
<div class="w3-row"> | ||
<div class="w3-third"><br></div> | ||
<div class="w3-third"> | ||
<form action="/records/{{ .ID }}" method="post"> | ||
<input type="hidden" name="ID" value="{{.ID}}"> | ||
<label>Start</label> | ||
<input class="w3-input" type="date" name="Start" value='{{.Start.Format "2006-01-02"}}'> | ||
<input class="w3-input" type="time" name="StartTime" value='{{.Start.Format "15:04"}}'> | ||
<label>End</label> | ||
<input class="w3-input" type="date" name="End" value='{{.End.Format "2006-01-02"}}'> | ||
<input class="w3-input" type="time" name="EndTime" value='{{.End.Format "15:04"}}'> | ||
|
||
<p><button class="w3-button w3-theme-dark w3-padding-large" type="button" hx-get="/" | ||
hx-target="#main">Cancel</button> | ||
<button class="w3-button w3-theme-dark w3-padding-large" type="submit">Submit</button> | ||
</p> | ||
</form> | ||
</div> | ||
</div> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package models | ||
|
||
import "time" | ||
import ( | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
type Report struct { | ||
Project string | ||
Total time.Duration | ||
Total string | ||
Items []ReportRecord | ||
} | ||
|
||
type ReportRecord struct { | ||
ID uuid.UUID | ||
Start time.Time | ||
End time.Time | ||
} | ||
|
||
type ReportRequest struct { | ||
Start time.Time | ||
End time.Time | ||
Projects []string | ||
Users []string | ||
Start string `form:"start"` | ||
End string `form:"end"` | ||
Project string `form:"project"` | ||
} | ||
|
||
type DatabaseReportRequest struct { | ||
Start time.Time | ||
End time.Time | ||
Project string | ||
User string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"net/http" | ||
"sort" | ||
"time" | ||
|
||
"github.com/devilcove/timetraced/database" | ||
"github.com/devilcove/timetraced/models" | ||
"github.com/gin-contrib/sessions" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func getReport(c *gin.Context) { | ||
var err error | ||
projectsToQuery := []string{} | ||
session := sessions.Default(c) | ||
dbRequest := models.DatabaseReportRequest{ | ||
User: session.Get("user").(string), | ||
} | ||
reportRequest := models.ReportRequest{} | ||
if err := c.BindJSON(&reportRequest); err != nil { | ||
if err := c.Bind(&reportRequest); err != nil { | ||
processError(c, http.StatusBadRequest, "could not decode request") | ||
return | ||
} | ||
reportData, err := database.GetReportRecords(reportRequest) | ||
dbRequest.Start, err = time.Parse("2006-01-02", reportRequest.Start) | ||
if err != nil { | ||
processError(c, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
dbRequest.End, err = time.Parse("2006-01-02", reportRequest.End) | ||
if err != nil { | ||
processError(c, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
sort.Slice(reportData, func(i, j int) bool { | ||
return reportData[i].Project < reportData[j].Project | ||
}) | ||
c.JSON(http.StatusOK, reportData) | ||
if reportRequest.Project == "" { | ||
allProjects, err := database.GetAllProjects() | ||
if err != nil { | ||
processError(c, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
for _, project := range allProjects { | ||
projectsToQuery = append(projectsToQuery, project.Name) | ||
} | ||
} else { | ||
projectsToQuery = append(projectsToQuery, reportRequest.Project) | ||
} | ||
displayRecords := []models.Report{} | ||
for _, project := range projectsToQuery { | ||
displayRecord := models.Report{} | ||
reportRecord := models.ReportRecord{} | ||
reportRecords := []models.ReportRecord{} | ||
dbRequest.Project = project | ||
data, err := database.GetReportRecords(dbRequest) | ||
if err != nil { | ||
processError(c, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
var total time.Duration | ||
for _, d := range data { | ||
total = d.End.Sub(d.Start) | ||
reportRecord.End = d.End | ||
reportRecord.Start = d.Start | ||
reportRecord.ID = d.ID | ||
reportRecords = append(reportRecords, reportRecord) | ||
} | ||
if total != 0 { | ||
displayRecord.Project = project | ||
displayRecord.Total = models.FmtDuration(total) | ||
displayRecord.Items = reportRecords | ||
displayRecords = append(displayRecords, displayRecord) | ||
} | ||
} | ||
c.HTML(http.StatusOK, "results", displayRecords) | ||
|
||
} | ||
|
||
func report(c *gin.Context) { | ||
c.HTML(http.StatusOK, "report", "") | ||
session := sessions.Default(c) | ||
user := session.Get("user").(string) | ||
page := models.GetUserPage(user) | ||
populate(&page, user) | ||
projects, err := database.GetAllProjects() | ||
if err != nil { | ||
slog.Error(err.Error()) | ||
} else { | ||
for _, project := range projects { | ||
page.Projects = append(page.Projects, project.Name) | ||
} | ||
} | ||
c.HTML(http.StatusOK, "report", page) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters