Only show reports matching the selected version if filtered

This only affects the Crash view as the Reports view already behaved like that.
Moreover it is now possible to change Product and Version filters on detail views.
parent 85801de2
......@@ -4,6 +4,8 @@
* Add: `-config`-flag to specify config file when running CrashDragon
* Change: Now gracefully shutting down on `SIGINT` (See #25)
* Change: Only show reports matching the filtered version when in Crash-view
* Change: Allow changing Product and Version filters in detail views
* Fix: Show correct crash counts when filtered by version (See #40)
## Version 1.1.1
......
......@@ -95,6 +95,7 @@ func GetCrashes(c *gin.Context) {
// GetCrash returns details of a crash
func GetCrash(c *gin.Context) {
all, ver := GetVersionCookie(c)
var Crash database.Crash
database.Db.First(&Crash, "id = ?", c.Param("id"))
offset, err := strconv.Atoi(c.DefaultQuery("offset", "0"))
......@@ -102,8 +103,16 @@ func GetCrash(c *gin.Context) {
offset = 0
}
var count int
database.Db.Model(&database.Report{}).Where("crash_id = ?", Crash.ID).Count(&count)
database.Db.Model(&Crash).Preload("Product").Preload("Version").Order("created_at DESC").Offset(offset).Limit(50).Related(&Crash.Reports)
query := database.Db.Model(&database.Report{}).Where("crash_id = ?", Crash.ID)
if !all {
query = query.Where("version_id = ?", ver.ID)
}
query.Count(&count)
query = database.Db.Model(&Crash).Preload("Product").Preload("Version").Order("created_at DESC")
if !all {
query = query.Where("version_id = ?", ver.ID)
}
query.Offset(offset).Limit(50).Related(&Crash.Reports)
database.Db.Model(&Crash).Preload("User").Order("created_at ASC").Related(&Crash.Comments)
var next int
var prev int
......@@ -137,7 +146,6 @@ func GetCrash(c *gin.Context) {
c.HTML(http.StatusOK, "crash.html", gin.H{
"prods": database.Products,
"vers": database.Versions,
"detailView": true,
"title": "Crash",
"Crash": Crash,
"Versions": versions,
......
......@@ -217,14 +217,13 @@ func GetReport(c *gin.Context) {
}
if strings.HasPrefix(c.Request.Header.Get("Accept"), "text/html") {
c.HTML(http.StatusOK, "report.html", gin.H{
"prods": database.Products,
"vers": database.Versions,
"detailView": true,
"title": "Report",
"item": Item,
"report": Report.Report,
"result": result,
"comments": Report.Comments,
"prods": database.Products,
"vers": database.Versions,
"title": "Report",
"item": Item,
"report": Report.Report,
"result": result,
"comments": Report.Comments,
})
} else {
c.JSON(http.StatusOK, Report)
......
......@@ -38,14 +38,14 @@
</ul>
<form class="nav navbar-form navbar-right">
<div class="form-group">
<select class="form-control" id="product-filter" {{ if .detailView }}disabled="disabled"{{ end }}>
<select class="form-control" id="product-filter">
<option value="all" selected="selected">All Products</option>
<option value="" disabled="disabled">──────────</option>
{{ range .prods }}
<option value="{{ .Slug }}">{{ .Name }}</option>
{{ end }}
</select>
<select class="form-control" id="version-filter" {{ if .detailView }}disabled="disabled"{{ end }}>
<select class="form-control" id="version-filter">
<option value="all" selected="selected">All Versions</option>
<option value="" disabled="disabled">──────────</option>
{{ range .vers }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment