comparison demo/more/grid.ur @ 965:e9c5992bc9bc

Progress on sorting + filtering
author Adam Chlipala <adamc@hcoop.net>
date Sat, 19 Sep 2009 14:42:36 -0400
parents fbc3a0eef45a
children bb3fc575cfe7
comparison
equal deleted inserted replaced
964:fbc3a0eef45a 965:e9c5992bc9bc
104 fun sync {Cols = cols, Rows = rows, ...} = 104 fun sync {Cols = cols, Rows = rows, ...} =
105 Dlist.clear rows; 105 Dlist.clear rows;
106 init <- rpc M.list; 106 init <- rpc M.list;
107 rs <- List.mapM (newRow cols) init; 107 rs <- List.mapM (newRow cols) init;
108 Dlist.replace rows rs 108 Dlist.replace rows rs
109
110 fun myFilter grid all =
111 row <- signal all.Row;
112 foldR3 [colMeta M.row] [fst3] [thd3] [fn _ => M.row -> signal bool]
113 (fn [nm :: Name] [p :: (Type * Type * Type)]
114 [rest :: {(Type * Type * Type)}] [[nm] ~ rest]
115 meta state filter combinedFilter row =>
116 previous <- combinedFilter row;
117 this <- (meta.Handlers state).Filter filter row;
118 return (previous && this))
119 (fn _ => return True)
120 [_] M.folder M.cols grid.Cols grid.Filters row
109 121
110 fun render (grid : grid) = <xml> 122 fun render (grid : grid) = <xml>
111 <table class={tabl}> 123 <table class={tabl}>
112 <tr class={tr}> 124 <tr class={tr}>
113 <th/> <th/> <th><button value="No sort" onclick={set grid.Sort None}/></th> 125 <th/> <th/> <th><button value="No sort" onclick={set grid.Sort None}/></th>
219 return <xml/>}/> 231 return <xml/>}/>
220 </td></xml>) 232 </td></xml>)
221 [_] M.folder grid.Cols M.cols cols)}/> 233 [_] M.folder grid.Cols M.cols cols)}/>
222 </tr></xml> 234 </tr></xml>
223 end) 235 end)
224 {StartPosition = Monad.mp Some (signal grid.Position), 236 {StartPosition = case M.pageLength of
237 None => return None
238 | Some len =>
239 avail <- Dlist.numPassing (myFilter grid) grid.Rows;
240 pos <- signal grid.Position;
241 return (Some (if pos >= avail then
242 0
243 else
244 pos)),
225 MaxLength = return M.pageLength, 245 MaxLength = return M.pageLength,
226 Filter = fn all => 246 Filter = myFilter grid,
227 row <- signal all.Row;
228 foldR3 [colMeta M.row] [fst3] [thd3] [fn _ => M.row -> signal bool]
229 (fn [nm :: Name] [p :: (Type * Type * Type)]
230 [rest :: {(Type * Type * Type)}] [[nm] ~ rest]
231 meta state filter combinedFilter row =>
232 previous <- combinedFilter row;
233 this <- (meta.Handlers state).Filter filter row;
234 return (previous && this))
235 (fn _ => return True)
236 [_] M.folder M.cols grid.Cols grid.Filters row,
237 Sort = f <- signal grid.Sort; 247 Sort = f <- signal grid.Sort;
238 return (Option.mp (fn f r1 r2 => r1 <- signal r1.Row; 248 return (Option.mp (fn f r1 r2 => r1 <- signal r1.Row;
239 r2 <- signal r2.Row; 249 r2 <- signal r2.Row;
240 return (f r1 r2)) f)} 250 return (f r1 r2)) f)}
241 grid.Rows} 251 grid.Rows}
265 </table> 275 </table>
266 276
267 {case M.pageLength of 277 {case M.pageLength of
268 None => <xml/> 278 None => <xml/>
269 | Some plen => <xml> 279 | Some plen => <xml>
270 <dyn signal={avail <- Dlist.size grid.Rows; 280 <dyn signal={avail <- Dlist.numPassing (myFilter grid) grid.Rows;
271 return (if avail <= plen then 281 return (if avail <= plen then
272 <xml/> 282 <xml/>
273 else 283 else
274 let 284 let
275 val numPages = avail / plen 285 val numPages = avail / plen