gdritter repos inf-dict / 518f0fd
Version bump: sorted words properly and also added /lang URLS Getty Ritter 7 years ago
5 changed file(s) with 51 addition(s) and 7 deletion(s). Collapse all Expand all
11 name: inf-dict
2 version: 1.0.3
2 version: 1.0.4
33 -- synopsis:
44 -- description:
55 license: BSD3
4646 get "search" $ do
4747 html (rPage rSearch)
4848
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
4957 get "word" $ do
5058 es <- db getAllWords
5159 respondWith es
11 module Render where
22
33 import Control.Monad (when)
4 import Data.Monoid ((<>))
45 import Data.Text (Text, pack)
56 import Data.Text.Lazy (toStrict)
67 import Lucid
3233 menu :: Html ()
3334 menu = ul_ $ do
3435 li_ $ a_ [ href_ "/" ] "index"
35 li_ $ a_ [ href_ "/word" ] "browse"
36 li_ $ a_ [ href_ "/lang" ] "languages"
37 li_ $ a_ [ href_ "/word" ] "everything"
3638 li_ $ a_ [ href_ "/add" ] "add"
3739 li_ $ a_ [ href_ "/search" ] "search"
3840
113115 textarea_ [ rows_ "4", cols_ "100", name_ "notes" ] $
114116 toHtml (eNotes e)
115117 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 ]
122122 getAllWords conn = do
123123 let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \
124124 \ FROM words w, languages l \
125 \ WHERE w.language = l.id"
125 \ WHERE w.language = l.id \
126 \ ORDER BY w.word ASC"
126127 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)
127136
128137 searchText :: Text -> Text
129138 searchText t = "%" <> t <> "%"
133142 let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \
134143 \ FROM words w, languages l \
135144 \ 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"
137147 query conn q (searchText t, searchText t)
138148
139149 searchMeaning :: Text -> DB [Entry]
141151 let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \
142152 \ FROM words w, languages l \
143153 \ 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"
145156 query conn q (searchText t, searchText t)
146157
147158 searchAll :: Text -> DB [Entry]
149160 let q = "SELECT w.id, w.word, w.trans, w.meaning, w.notes, l.id, l.name \
150161 \ FROM words w, languages l \
151162 \ WHERE w.language = l.id AND \
152 \ (w.word LIKE ? OR w.trans LIKE ? OR w.meaning LIKE ? OR w.notes LIKE ?)"
163 \ (w.word LIKE ? OR w.trans LIKE ? OR \
164 \ w.meaning LIKE ? OR w.notes LIKE ?) \
165 \ ORDER BY w.word ASC"
153166 query conn q (searchText t, searchText t, searchText t, searchText t)
129129 list-style-type: none;
130130 padding-left: 20px;
131131 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 }