Skip to content

Commit

Permalink
Detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Aug 31, 2022
1 parent 34d1941 commit 9a63e68
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
4 changes: 2 additions & 2 deletions webui/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func (web *WebUI) renderGameIconCard(titleID uint64) string {
if titleDeets.IconURL != "" {

template := `<div class="three columns">
<a href="%s" class="card">
<a href="%s%d" class="card">
<h6>%s</h6>
<img class="u-max-full-width" src="%s" />
</a>
</div>
`
return fmt.Sprintf(template, "#", titleDeets.Name, titleDeets.IconURL)
return fmt.Sprintf(template, "/info/", titleID, titleDeets.Name, titleDeets.IconURL)

} else {
// Todo, non image card
Expand Down
45 changes: 45 additions & 0 deletions webui/templates/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Switchhost</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.googleapis.com/css?family=Raleway:400,300,600"
rel="stylesheet"
type="text/css"
/>
<link rel="stylesheet" href="skeleton.min.css" />
<link rel="icon" type="image/png" href="images/favicon.png" />
</head>

<body>
<div class="container">
<div class="row">
<h1>Switch Host</h1>
<hr />
<img height="512" src="{GameBannerImageURI}" />
</div>
<div class="row">
<h3>{GameTitle}</h3>
<img height="512" src="{GameImageURI}" />

</div>
<div class="row">
<table class="u-full-width">
<thead>
<tr>
<th>Name</th>
<th>Version</th>
<th>Size</th>
</tr>
</thead>
<tbody>
{GameDetailsTableContents}
</tbody>
</table>
</div>
</div>
<br />
</body>
</html>
28 changes: 26 additions & 2 deletions webui/title_info.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
package webui

import "io"
import (
"fmt"
"io"
"strings"
)

func (web *WebUI) RenderTitleInfo(path string, writer io.Writer) {
func (web *WebUI) RenderTitleInfo(titleID uint64, writer io.Writer) error {
//Render out a web page of the info we have on the title
titleDetails, ok := web.titleDB.QueryGameFromTitleID(titleID)
if !ok {
return ErrBadTemplate
}
template := detailPageTemplate

template = strings.Replace(template, "{GameImageURI}", titleDetails.IconURL, -1)
template = strings.Replace(template, "{GameBannerImageURI}", titleDetails.BannerURL, -1)
template = strings.Replace(template, "{GameTitle}", titleDetails.Name, -1)
//Generate info table
filesTracked := web.lib.FileIndex.GetAllRecordsForTitle(titleID)
tableInfo := ""
for _, record := range filesTracked {
tableInfo += fmt.Sprintf("<tr><td>%s</td><td>%d</td><td>%d</td></tr>\n", record.Name, record.Version, record.Size)
}
template = strings.Replace(template, "{GameDetailsTableContents}", tableInfo, -1)
if _, err := writer.Write([]byte(template)); err != nil {
return ErrBadTemplate
}
return nil
}
3 changes: 3 additions & 0 deletions webui/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
//go:embed templates/index.html
var titlePageTemplate string

//go:embed templates/detail.html
var detailPageTemplate string

//go:embed templates/skeleton.min.css
var SkeletonCss []byte

Expand Down

0 comments on commit 9a63e68

Please sign in to comment.