comparison demo/more/grid.ur @ 964:fbc3a0eef45a

Paging mostly working; just need to get it working properly with filtering
author Adam Chlipala <adamc@hcoop.net>
date Sat, 19 Sep 2009 14:21:25 -0400
parents 6f9d1565de56
children e9c5992bc9bc
comparison
equal deleted inserted replaced
963:6f9d1565de56 964:fbc3a0eef45a
35 val folder : folder cols 35 val folder : folder cols
36 36
37 con aggregates :: {Type} 37 con aggregates :: {Type}
38 val aggregates : $(map (aggregateMeta row) aggregates) 38 val aggregates : $(map (aggregateMeta row) aggregates)
39 val aggFolder : folder aggregates 39 val aggFolder : folder aggregates
40
41 val pageLength : option int
40 end) = struct 42 end) = struct
41 style tabl 43 style tabl
42 style tr 44 style tr
43 style th 45 style th
44 style td 46 style td
57 Cols : source ($(map snd3 M.cols)), 59 Cols : source ($(map snd3 M.cols)),
58 Updating : source bool, 60 Updating : source bool,
59 Selected : source bool}, 61 Selected : source bool},
60 Selection : source bool, 62 Selection : source bool,
61 Filters : $(map thd3 M.cols), 63 Filters : $(map thd3 M.cols),
62 Sort : source (option (M.row -> M.row -> bool))} 64 Sort : source (option (M.row -> M.row -> bool)),
65 Position : source int}
63 66
64 fun newRow cols row = 67 fun newRow cols row =
65 rowS <- source row; 68 rowS <- source row;
66 cols <- makeAll cols row; 69 cols <- makeAll cols row;
67 colsS <- source cols; 70 colsS <- source cols;
87 [_] M.folder M.cols cols; 90 [_] M.folder M.cols cols;
88 91
89 rows <- Dlist.create; 92 rows <- Dlist.create;
90 sel <- source False; 93 sel <- source False;
91 sort <- source None; 94 sort <- source None;
95 pos <- source 0;
92 96
93 return {Cols = cols, 97 return {Cols = cols,
94 Rows = rows, 98 Rows = rows,
95 Selection = sel, 99 Selection = sel,
96 Filters = filters, 100 Filters = filters,
97 Sort = sort} 101 Sort = sort,
102 Position = pos}
98 103
99 fun sync {Cols = cols, Rows = rows, ...} = 104 fun sync {Cols = cols, Rows = rows, ...} =
100 Dlist.clear rows; 105 Dlist.clear rows;
101 init <- rpc M.list; 106 init <- rpc M.list;
102 rs <- List.mapM (newRow cols) init; 107 rs <- List.mapM (newRow cols) init;
214 return <xml/>}/> 219 return <xml/>}/>
215 </td></xml>) 220 </td></xml>)
216 [_] M.folder grid.Cols M.cols cols)}/> 221 [_] M.folder grid.Cols M.cols cols)}/>
217 </tr></xml> 222 </tr></xml>
218 end) 223 end)
219 {StartPosition = return (Some 1), 224 {StartPosition = Monad.mp Some (signal grid.Position),
220 MaxLength = return (Some 2), 225 MaxLength = return M.pageLength,
221 Filter = fn all => 226 Filter = fn all =>
222 row <- signal all.Row; 227 row <- signal all.Row;
223 foldR3 [colMeta M.row] [fst3] [thd3] [fn _ => M.row -> signal bool] 228 foldR3 [colMeta M.row] [fst3] [thd3] [fn _ => M.row -> signal bool]
224 (fn [nm :: Name] [p :: (Type * Type * Type)] 229 (fn [nm :: Name] [p :: (Type * Type * Type)]
225 [rest :: {(Type * Type * Type)}] [[nm] ~ rest] 230 [rest :: {(Type * Type * Type)}] [[nm] ~ rest]
256 (fn [nm :: Name] [p :: (Type * Type * Type)] [rest :: {(Type * Type * Type)}] [[nm] ~ rest] 261 (fn [nm :: Name] [p :: (Type * Type * Type)] [rest :: {(Type * Type * Type)}] [[nm] ~ rest]
257 meta state filter => <xml><td>{(meta.Handlers state).DisplayFilter filter}</td></xml>) 262 meta state filter => <xml><td>{(meta.Handlers state).DisplayFilter filter}</td></xml>)
258 [_] M.folder M.cols grid.Cols grid.Filters} 263 [_] M.folder M.cols grid.Cols grid.Filters}
259 </tr> 264 </tr>
260 </table> 265 </table>
266
267 {case M.pageLength of
268 None => <xml/>
269 | Some plen => <xml>
270 <dyn signal={avail <- Dlist.size grid.Rows;
271 return (if avail <= plen then
272 <xml/>
273 else
274 let
275 val numPages = avail / plen
276 val numPages = if numPages * plen < avail then
277 numPages + 1
278 else
279 numPages
280
281 fun pages n =
282 if n * plen >= avail then
283 <xml/>
284 else
285 <xml>
286 <dyn signal={pos <- signal grid.Position;
287 return (if n * plen = pos then
288 <xml><b>{[n + 1]}</b></xml>
289 else
290 <xml>
291 <button value={show (n + 1)}
292 onclick={set grid.Position
293 (n * plen)
294 }/></xml>)}/>
295 {if (n + 1) * plen >= avail then <xml/> else <xml>|</xml>}
296 {pages (n + 1)}
297 </xml>
298 in
299 <xml><p><b>Pages:</b> {pages 0}</p></xml>
300 end)}/>
301 </xml>}
261 302
262 <button value="New row" onclick={row <- rpc M.new; 303 <button value="New row" onclick={row <- rpc M.new;
263 addRow grid.Cols grid.Rows row}/> 304 addRow grid.Cols grid.Rows row}/>
264 <button value="Refresh" onclick={sync grid}/> 305 <button value="Refresh" onclick={sync grid}/>
265 </xml> 306 </xml>