-
Notifications
You must be signed in to change notification settings - Fork 2
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
10 changed files
with
241 additions
and
146 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package components | ||
|
||
import gen "github.com/dadav/gorge/pkg/gen/v3/openapi" | ||
|
||
templ ModuleView(module *gen.Module) { | ||
<h3>{ module.Name }</h3> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package components | ||
|
||
templ Page(title string, content templ.Component) { | ||
<!DOCTYPE html> | ||
<html> | ||
@Header(title) | ||
<body> | ||
<div class="main"> | ||
@content | ||
</div> | ||
</body> | ||
</html> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package components | ||
|
||
import ( | ||
"fmt" | ||
gen "github.com/dadav/gorge/pkg/gen/v3/openapi" | ||
) | ||
|
||
templ SearchView() { | ||
<div class="search"> | ||
<img id="logo" src="/assets/logo.png" width="300"/> | ||
<br/> | ||
<input | ||
class="form-control" | ||
type="search" | ||
name="query" | ||
placeholder="Name, author, version..." | ||
hx-get="/search" | ||
hx-params="*" | ||
hx-trigger="input changed delay:500ms, search, load" | ||
hx-target="#search-results" | ||
/> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Module</th> | ||
<th>Author</th> | ||
<th>Version</th> | ||
</tr> | ||
</thead> | ||
<tbody id="search-results"></tbody> | ||
</table> | ||
</div> | ||
} | ||
|
||
templ ModuleToTableRow(module *gen.Module) { | ||
<tr> | ||
<td><a href={ templ.URL(fmt.Sprintf("/modules/%s", module.Name)) }>{ module.Name }</a></td> | ||
<td>{ module.Owner.Username }</td> | ||
<td>{ module.CurrentRelease.Version }</td> | ||
</tr> | ||
} |
72 changes: 23 additions & 49 deletions
72
internal/v3/ui/index_templ.go → internal/v3/ui/components/search_templ.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ui | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/a-h/templ" | ||
"github.com/dadav/gorge/internal/log" | ||
"github.com/dadav/gorge/internal/v3/backend" | ||
"github.com/dadav/gorge/internal/v3/ui/components" | ||
"github.com/go-chi/chi/v5" | ||
) | ||
|
||
func IndexHandler(w http.ResponseWriter, r *http.Request) { | ||
templ.Handler(components.Page("Gorge", components.SearchView())).ServeHTTP(w, r) | ||
} | ||
|
||
func SearchHandler(w http.ResponseWriter, r *http.Request) { | ||
query := r.URL.Query().Get("query") | ||
modules, err := backend.ConfiguredBackend.GetAllModules() | ||
if err != nil { | ||
w.WriteHeader(500) | ||
log.Log.Error(err) | ||
return | ||
} | ||
|
||
for _, module := range modules { | ||
if strings.Contains(module.Name, query) || strings.Contains(module.Owner.Username, query) || strings.Contains(module.CurrentRelease.Version, query) { | ||
templ.Handler(components.ModuleToTableRow(module)).ServeHTTP(w, r) | ||
} | ||
} | ||
} | ||
|
||
func ModuleHandler(w http.ResponseWriter, r *http.Request) { | ||
moduleName := chi.URLParam(r, "module") | ||
modules, err := backend.ConfiguredBackend.GetAllModules() | ||
if err != nil { | ||
w.WriteHeader(500) | ||
log.Log.Error(err) | ||
return | ||
} | ||
|
||
for _, module := range modules { | ||
if module.Name == moduleName { | ||
templ.Handler(components.Page(module.Name, components.ModuleView(module))).ServeHTTP(w, r) | ||
return | ||
} | ||
} | ||
|
||
http.NotFound(w, r) | ||
} |
Oops, something went wrong.