Version bump: sorted words properly and also added /lang URLS
Getty Ritter
8 years ago
1 | 1 | name: inf-dict |
2 |
version: 1.0. |
|
2 | version: 1.0.4 | |
3 | 3 | -- synopsis: |
4 | 4 | -- description: |
5 | 5 | license: BSD3 |
46 | 46 | get "search" $ do |
47 | 47 | html (rPage rSearch) |
48 | 48 | |
49 | get ("lang") $ do | |
50 | ls <- db allLanguages | |
51 | html (rPage (rLangList ls)) | |
52 | ||
53 | get ("lang" <//> var) $ \ lang -> do | |
54 | es <- db (getWordsByLanguage lang) | |
55 | respondWith es | |
56 | ||
49 | 57 | get "word" $ do |
50 | 58 | es <- db getAllWords |
51 | 59 | respondWith es |
1 | 1 | module Render where |
2 | 2 | |
3 | 3 | import Control.Monad (when) |
4 | import Data.Monoid ((<>)) | |
4 | 5 | import Data.Text (Text, pack) |
5 | 6 | import Data.Text.Lazy (toStrict) |
6 | 7 | import Lucid |
32 | 33 | menu :: Html () |
33 | 34 | menu = ul_ $ do |
34 | 35 | li_ $ a_ [ href_ "/" ] "index" |
35 |
li_ $ a_ [ href_ "/ |
|
36 | li_ $ a_ [ href_ "/lang" ] "languages" | |
37 | li_ $ a_ [ href_ "/word" ] "everything" | |
36 | 38 | li_ $ a_ [ href_ "/add" ] "add" |
37 | 39 | li_ $ a_ [ href_ "/search" ] "search" |
38 | 40 | |
113 | 115 | textarea_ [ rows_ "4", cols_ "100", name_ "notes" ] $ |
114 | 116 | toHtml (eNotes e) |
115 | 117 | div_ $ input_ [ type_ "submit" ] |
118 | ||
119 | rLangList :: [Language] -> Html () | |
120 | rLangList ls = do | |
121 | ul_ [ class_ "langs" ] $ do | |
122 | sequence_ [ li_ $ a_ [ href_ ("/lang/" <> langName l) ] | |
123 | (toHtml (langName l)) | |
124 | | l <- ls | |
125 | ] |
122 | 122 | getAllWords conn = do |
123 | 123 | let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \ |
124 | 124 | \ FROM words w, languages l \ |
125 |
\ WHERE w.language = l.id |
|
125 | \ WHERE w.language = l.id \ | |
126 | \ ORDER BY w.word ASC" | |
126 | 127 | query_ conn q |
128 | ||
129 | getWordsByLanguage :: Text -> DB [Entry] | |
130 | getWordsByLanguage lang conn = do | |
131 | let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \ | |
132 | \ FROM words w, languages l \ | |
133 | \ WHERE w.language = l.id AND l.name = ? \ | |
134 | \ ORDER BY w.word ASC" | |
135 | query conn q (Only lang) | |
127 | 136 | |
128 | 137 | searchText :: Text -> Text |
129 | 138 | searchText t = "%" <> t <> "%" |
133 | 142 | let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \ |
134 | 143 | \ FROM words w, languages l \ |
135 | 144 | \ WHERE w.language = l.id AND \ |
136 |
\ (w.word LIKE ? OR w.trans LIKE ?) |
|
145 | \ (w.word LIKE ? OR w.trans LIKE ?) \ | |
146 | \ ORDER BY w.word ASC" | |
137 | 147 | query conn q (searchText t, searchText t) |
138 | 148 | |
139 | 149 | searchMeaning :: Text -> DB [Entry] |
141 | 151 | let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \ |
142 | 152 | \ FROM words w, languages l \ |
143 | 153 | \ WHERE w.language = l.id AND \ |
144 |
\ (w.meaning LIKE ? OR w.notes LIKE ?) |
|
154 | \ (w.meaning LIKE ? OR w.notes LIKE ?) \ | |
155 | \ ORDER BY w.word ASC" | |
145 | 156 | query conn q (searchText t, searchText t) |
146 | 157 | |
147 | 158 | searchAll :: Text -> DB [Entry] |
149 | 160 | let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \ |
150 | 161 | \ FROM words w, languages l \ |
151 | 162 | \ WHERE w.language = l.id AND \ |
152 |
\ (w.word LIKE ? OR w.trans LIKE ? OR |
|
163 | \ (w.word LIKE ? OR w.trans LIKE ? OR \ | |
164 | \ w.meaning LIKE ? OR w.notes LIKE ?) \ | |
165 | \ ORDER BY w.word ASC" | |
153 | 166 | query conn q (searchText t, searchText t, searchText t, searchText t) |
129 | 129 | list-style-type: none; |
130 | 130 | padding-left: 20px; |
131 | 131 | padding-right: 20px; |
132 |
} |
|
132 | } | |
133 | ||
134 | .langs li { | |
135 | list-style-type: none; | |
136 | padding-top: 10px; | |
137 | padding-bottom: 10px; | |
138 | padding-left: 20%; | |
139 | font-size: 18pt; | |
140 | letter-spacing: 0.1em; | |
141 | } | |
142 | ||
143 | .langs li:before { | |
144 | content: "◊ "; | |
145 | } |