diff options
| author | jan <jan@ruken.pw> | 2015-12-30 15:10:35 (UTC) |
|---|---|---|
| committer | jan <jan@ruken.pw> | 2015-12-30 15:10:35 (UTC) |
| commit | bcab80f3e81b3aea7b1a6e84b39838bd19402975 (patch) | |
| tree | 5ba8fb024fde49f203863b57724158ed4171ff99 | |
| parent | 836099557e2327813668d50d5abb73ac43ad212d (diff) | |
nur noch eine datenbankabfrage. results sehen jetzt ziemlich leer aus, muss bestimmt mal neu gestaltet werden.
| -rw-r--r-- | modules/grils/gril.go | 10 | ||||
| -rw-r--r-- | modules/search/search.go | 25 | ||||
| -rw-r--r-- | views/instant_search_results.html | 5 |
3 files changed, 22 insertions, 18 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go index 89dd7c4..af84d04 100644 --- a/modules/grils/gril.go +++ b/modules/grils/gril.go | |||
| @@ -41,11 +41,11 @@ func (g *Gril) Slug() string { | |||
| 41 | strings.Replace(g.RomajiName, " ", "", -1)) | 41 | strings.Replace(g.RomajiName, " ", "", -1)) |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | func (g *Gril) ImagePath(prioritizeThumbnail bool) string { | 44 | func ImagePath(id int, prioritizeThumbnail bool) string { |
| 45 | var big string | 45 | var big string |
| 46 | exts := []string{"png", "jpg", "gif", "jpeg"} | 46 | exts := []string{"png", "jpg", "gif", "jpeg"} |
| 47 | for _, ext := range exts { | 47 | for _, ext := range exts { |
| 48 | path := fmt.Sprintf("assets/img/gril/%d/0.%s", g.ID, ext) | 48 | path := fmt.Sprintf("assets/img/gril/%d/0.%s", id, ext) |
| 49 | if _, err := os.Stat(path); err == nil { | 49 | if _, err := os.Stat(path); err == nil { |
| 50 | if prioritizeThumbnail { | 50 | if prioritizeThumbnail { |
| 51 | big = path | 51 | big = path |
| @@ -56,7 +56,7 @@ func (g *Gril) ImagePath(prioritizeThumbnail bool) string { | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | for _, ext := range exts { | 58 | for _, ext := range exts { |
| 59 | path := fmt.Sprintf("assets/img/gril/%d/1.%s", g.ID, ext) | 59 | path := fmt.Sprintf("assets/img/gril/%d/1.%s", id, ext) |
| 60 | if _, err := os.Stat(path); err == nil { | 60 | if _, err := os.Stat(path); err == nil { |
| 61 | return path | 61 | return path |
| 62 | } | 62 | } |
| @@ -64,3 +64,7 @@ func (g *Gril) ImagePath(prioritizeThumbnail bool) string { | |||
| 64 | 64 | ||
| 65 | return big | 65 | return big |
| 66 | } | 66 | } |
| 67 | |||
| 68 | func (g *Gril) ImagePath(prioritizeThumbnail bool) string { | ||
| 69 | return ImagePath(g.ID, prioritizeThumbnail) | ||
| 70 | } | ||
diff --git a/modules/search/search.go b/modules/search/search.go index da6d126..a614c08 100644 --- a/modules/search/search.go +++ b/modules/search/search.go | |||
| @@ -16,6 +16,12 @@ type Module struct { | |||
| 16 | grils *grils.GrilsModule | 16 | grils *grils.GrilsModule |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | type GrilResult struct { | ||
| 20 | ID int | ||
| 21 | ImagePath string | ||
| 22 | Name string | ||
| 23 | } | ||
| 24 | |||
| 19 | func New() *Module { | 25 | func New() *Module { |
| 20 | return &Module{} | 26 | return &Module{} |
| 21 | } | 27 | } |
| @@ -50,7 +56,7 @@ func (m *Module) instantSearchGril(w http.ResponseWriter, r *http.Request, p htt | |||
| 50 | return | 56 | return |
| 51 | } | 57 | } |
| 52 | 58 | ||
| 53 | rows, err := m.g.DB.Query(`SELECT id FROM grilist.search_grils($1)`, name) | 59 | rows, err := m.g.DB.Query(`SELECT id, name FROM grilist.search_grils($1)`, name) |
| 54 | if err != nil { | 60 | if err != nil { |
| 55 | log.Println("error in instant gril search:", err) | 61 | log.Println("error in instant gril search:", err) |
| 56 | return | 62 | return |
| @@ -58,24 +64,19 @@ func (m *Module) instantSearchGril(w http.ResponseWriter, r *http.Request, p htt | |||
| 58 | 64 | ||
| 59 | defer rows.Close() | 65 | defer rows.Close() |
| 60 | 66 | ||
| 61 | var ids []int | 67 | var results []GrilResult |
| 62 | for rows.Next() { | 68 | for rows.Next() { |
| 63 | var id int | 69 | result := GrilResult{} |
| 64 | if err := rows.Scan(&id); err != nil { | 70 | if err := rows.Scan(&result.ID, &result.Name); err != nil { |
| 65 | log.Println("error scanning in instant gril search", err) | 71 | log.Println("error scanning in instant gril search", err) |
| 66 | continue | 72 | continue |
| 67 | } | 73 | } |
| 68 | 74 | ||
| 69 | ids = append(ids, id) | 75 | result.ImagePath = grils.ImagePath(result.ID, true) |
| 70 | } | 76 | results = append(results, result) |
| 71 | |||
| 72 | grils, err := m.grils.FromIDs(ids) | ||
| 73 | if err != nil { | ||
| 74 | log.Println("error acquiring instant grils:", err) | ||
| 75 | return | ||
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | data := make(map[string]interface{}) | 79 | data := make(map[string]interface{}) |
| 79 | data["results"] = grils | 80 | data["results"] = results |
| 80 | m.g.Renderer.RenderPage("instant_search_results", w, data) | 81 | m.g.Renderer.RenderPage("instant_search_results", w, data) |
| 81 | } | 82 | } |
diff --git a/views/instant_search_results.html b/views/instant_search_results.html index a365b06..73eda26 100644 --- a/views/instant_search_results.html +++ b/views/instant_search_results.html | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | {{ define "instant_search_results" }} | 1 | {{ define "instant_search_results" }} |
| 2 | {{ range .results }} | 2 | {{ range .results }} |
| 3 | <li class="collection-item avatar hoverable"> | 3 | <li class="collection-item avatar hoverable"> |
| 4 | <img src="/{{ .ImagePath true }}" alt="" class="circle"> | 4 | <img src="/{{ .ImagePath }}" alt="" class="circle"> |
| 5 | <span class="title">{{ .RomajiName }}</span> | 5 | <span class="title">{{ .Name }}</span> |
| 6 | <p>{{ .KanjiName }}</p> | ||
| 7 | </li> | 6 | </li> |
| 8 | {{ end }} | 7 | {{ end }} |
| 9 | {{ end }} \ No newline at end of file | 8 | {{ end }} \ No newline at end of file |
