Commit a2608ea07af21af40cf5c09eaa14f4c6bc7e6e61

Authored by totoro
1 parent d4860695

add helper for cell when there is only one Cell_option and one content

fix the retrieving session from disk and change the method to determine the saving filename. Now the filename is determined by the session id.
Showing 1 changed file with 68 additions and 58 deletions   Show diff stats
web/CXM_making_a_web_site.anubis
... ... @@ -558,13 +558,15 @@ define WEB_Session -> String // the function constructed returns the name of
558 558 ) =
559 559 (WEB_Session s_var) |->
560 560 //Set the new timeout
561   - with time_stamp = now+timeout,
562   - s = to_WEB_Session_No_Var(s_var),
563   - to_be_saved = (time_stamp,s),
  561 + with time_stamp = now+timeout,
  562 + s = to_WEB_Session_No_Var(s_var),
  563 + to_be_saved = (time_stamp,s),
564 564 //generate new session name
565   - session_name = to_ascii(sha1(s)),
  565 + //session_name = to_ascii(sha1(s)),
  566 + session_name = s_var.session_id,
566 567 //println("make_save_state_function " + state_directory+"/s"+state_name);
567 568 if save(to_be_saved,state_directory+"/"+session_name) is ok then
  569 + println("----- session ["+session_name+"] saved"+dump_WEB_Session_Fields(*s_var.fields));
568 570 session_name
569 571 else
570 572 println("Cannot create session file in '"+state_directory+"'.\n");
... ... @@ -625,15 +627,24 @@ define (List(String) file_names) -> One
625 627 {
626 628 [ ] then unique,
627 629 [h . t] then
  630 + if h = "." | h = ".." then
  631 + df(t)
  632 + else
628 633 with file_path = state_directory+"/"+h,
629   - if (RetrieveResult((Int, WEB_Session)))retrieve(file_path) is ok(d)
630   - then (
631   - if d is (time_stamp,data) then
632   - if time_stamp < now
633   - then (forget(remove(file_path)); df(t))
634   - else df(t)
635   - )
636   - else (forget(remove(file_path)); df(t))
  634 + if (RetrieveResult((Int, WEB_Session_No_Var)))retrieve(file_path) is ok(d) then
  635 + (
  636 + if d is (time_stamp, data) then
  637 + if time_stamp < now then
  638 + //println("session "+h+" out date will be deleted timestamp ["+time_stamp+"] now ["+now+"]");
  639 + (forget(remove(file_path));
  640 + df(t))
  641 + else
  642 + //println("Session "+h+" still valid ["+time_stamp+"] now ["+now+"]");
  643 + df(t)
  644 + )
  645 + else
  646 + println("Can't retreive session "+h+", hence will be deleted");
  647 + (forget(remove(file_path)); df(t))
637 648 }.
638 649  
639 650 define One
... ... @@ -1296,12 +1307,22 @@ public type HTML_Header_Cell($T):
1296 1307 convenience, we define the following particular case:
1297 1308  
1298 1309 public define HTML_Cell($T)
1299   - cell
1300   - (
1301   - $T content
1302   - ) =
1303   - cell([],content).
1304   -
  1310 + cell
  1311 + (
  1312 + $T content
  1313 + )=
  1314 + cell([],content)
  1315 +.
  1316 +
  1317 +public define HTML_Cell($T)
  1318 + cell
  1319 + (
  1320 + Cell_Option option,
  1321 + $T content
  1322 + ) =
  1323 + cell([option],content)
  1324 +.
  1325 +
1305 1326 public define HTML_Header_Cell($T)
1306 1327 header_cell
1307 1328 (
... ... @@ -2026,9 +2047,10 @@ public type HTML_Off_Form:
2026 2047  
2027 2048 'HTML_Off_Form' defines all the elements you may put outside any form.
2028 2049  
2029   -public define HTML_Off_Form text(List(CoreAttrs) lto, Int i) = text(lto, to_decimal(i)).
  2050 +public define HTML_Off_Form text(List(CoreAttrs) lto, Int i) = text(lto, to_decimal(i)).
2030 2051 public define HTML_Off_Form text(Int i) = text([], i).
2031 2052 public define HTML_Off_Form text(String s) = text([], s).
  2053 +public define HTML_Off_Form text(CoreAttrs attr, String s) = text([attr], s).
2032 2054  
2033 2055 public define HTML_Off_Form a(A_href _href) = a([], _href, _self, []).
2034 2056 public define HTML_Off_Form a(List(CoreAttrs) attrs, A_href _href) = a(attrs, _href, _self, []).
... ... @@ -2056,12 +2078,13 @@ public define HTML_Off_Form br
2056 2078 public define HTML_Off_Form br(List(CoreAttrs) attrs) = html_void_tag("br", attrs).
2057 2079  
2058 2080 // <button>
2059   -public define HTML_Off_Form button(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("button", attrs, content).
2060   -public define HTML_Off_Form button(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("button", attrs, [content]).
2061   -public define HTML_Off_Form button(CoreAttrs attr, List(HTML_Off_Form) content) = html_tag("button", [attr], content).
2062   -public define HTML_Off_Form button(CoreAttrs attr, HTML_Off_Form content) = html_tag("button", [attr], [content]).
2063   -public define HTML_Off_Form button(List(HTML_Off_Form) content) = html_tag("button", [], content).
2064   -public define HTML_Off_Form button(HTML_Off_Form content) = html_tag("button", [], [content]).
  2081 +public define HTML_Off_Form button(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("button", attrs, content).
  2082 +public define HTML_Off_Form button(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("button", attrs, [content]).
  2083 +public define HTML_Off_Form button(CoreAttrs attr, List(HTML_Off_Form) content) = html_tag("button", [attr], content).
  2084 +public define HTML_Off_Form button(CoreAttrs attr, HTML_Off_Form content) = html_tag("button", [attr], [content]).
  2085 +public define HTML_Off_Form button(List(CoreAttrs) attrs) = html_tag("button", attrs, []).
  2086 +public define HTML_Off_Form button(List(HTML_Off_Form) content) = html_tag("button", [], content).
  2087 +public define HTML_Off_Form button(HTML_Off_Form content) = html_tag("button", [], [content]).
2065 2088  
2066 2089 // <datalist>
2067 2090 public define HTML_Off_Form datalist(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("datalist", attrs, content).
... ... @@ -2070,13 +2093,19 @@ public define HTML_Off_Form datalist(List(HTML_Off_Form) content)
2070 2093 public define HTML_Off_Form datalist(HTML_Off_Form content) = html_tag("datalist", [], [content]).
2071 2094  
2072 2095 // <div>
2073   -public define HTML_Off_Form div(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("div", attrs, content).
2074   -public define HTML_Off_Form div(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("div", attrs, [content]).
  2096 +public define HTML_Off_Form div(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("div", attrs, content).
  2097 +public define HTML_Off_Form div(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("div", attrs, [content]).
2075 2098 public define HTML_Off_Form div(CoreAttrs attr, List(HTML_Off_Form) content) = html_tag("div", [attr], content).
2076 2099 public define HTML_Off_Form div(CoreAttrs attr, HTML_Off_Form content) = html_tag("div", [attr], [content]).
2077   -public define HTML_Off_Form div(List(HTML_Off_Form) content) = html_tag("div", [], content).
2078   -public define HTML_Off_Form div(HTML_Off_Form content) = html_tag("div", [], [content]).
2079   -public define HTML_Off_Form div(List(CoreAttrs) attrs) = html_tag("div", attrs, [empty]).
  2100 +public define HTML_Off_Form div(List(HTML_Off_Form) content) = html_tag("div", [], content).
  2101 +public define HTML_Off_Form div(HTML_Off_Form content) = html_tag("div", [], [content]).
  2102 +public define HTML_Off_Form div(List(CoreAttrs) attrs) = html_tag("div", attrs, [empty]).
  2103 +public define HTML_Off_Form div(CoreAttrs attr) = html_tag("div", [attr], []).
  2104 +
  2105 +public define HTML_Off_Form div(List(CoreAttrs) attrs, HTML_Partial_Content content) = div(attrs, [content]).
  2106 +public define HTML_Off_Form div(List(HTML_Partial_Content) content) = div([], content).
  2107 +public define HTML_Off_Form div(CoreAttrs attr, HTML_Partial_Content content) = div([attr], [content]).
  2108 +public define HTML_Off_Form div(HTML_Partial_Content content) = div([], [content]).
2080 2109  
2081 2110 // <dd>
2082 2111 public define HTML_Off_Form dd(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("dd", attrs, content).
... ... @@ -2138,6 +2167,10 @@ public define HTML_Off_Form h6(HTML_Off_Form content)
2138 2167 public define HTML_Off_Form hr = html_void_tag("hr", []).
2139 2168 public define HTML_Off_Form hr(List(CoreAttrs) attrs) = html_void_tag("hr", attrs).
2140 2169  
  2170 + // <input>
  2171 +public define HTML_Off_Form input(List(CoreAttrs) attrs) = html_void_tag("input", attrs).
  2172 +public define HTML_Off_Form input(CoreAttrs attr) = html_void_tag("input", [attr]).
  2173 +
2141 2174 // <img>
2142 2175 public define HTML_Off_Form img(List(CoreAttrs) attrs, String src, String alt) = html_void_tag("img", attrs + [attr("src",src), attr("alt",alt)] ).
2143 2176 public define HTML_Off_Form img(String src) = img([], src, "").
... ... @@ -2148,10 +2181,11 @@ public define HTML_Off_Form img(List(CoreAttrs) attrs, String src, String alt, I
2148 2181 html_void_tag("img", attrs + [attr("src",src), attr("alt",alt), attr("witdh",to_String(width)), attr("height",to_String(height))]).
2149 2182  
2150 2183 // <li>
2151   -public define HTML_Off_Form li(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("li", attrs, content).
2152   -public define HTML_Off_Form li(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("li", attrs, [content]).
2153   -public define HTML_Off_Form li(List(HTML_Off_Form) content) = html_tag("li", [], content).
2154   -public define HTML_Off_Form li(HTML_Off_Form content) = html_tag("li", [], [content]).
  2184 +public define HTML_Off_Form li(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("li", attrs, content).
  2185 +public define HTML_Off_Form li(List(CoreAttrs) attrs, HTML_Off_Form content) = html_tag("li", attrs, [content]).
  2186 +public define HTML_Off_Form li(CoreAttrs attr, HTML_Off_Form content) = html_tag("li", [attr], [content]).
  2187 +public define HTML_Off_Form li(List(HTML_Off_Form) content) = html_tag("li", [], content).
  2188 +public define HTML_Off_Form li(HTML_Off_Form content) = html_tag("li", [], [content]).
2155 2189  
2156 2190 // <nav>
2157 2191 public define HTML_Off_Form nav(List(CoreAttrs) attrs, List(HTML_Off_Form) content) = html_tag("nav", attrs, content).
... ... @@ -2448,30 +2482,6 @@ public define HTML_Off_Form
2448 2482 .
2449 2483  
2450 2484  
2451   -public define HTML_Off_Form
2452   - div
2453   - (
2454   - HTML_Partial_Content element
2455   - )=
2456   - div([], [element])
2457   -.
2458   -
2459   -public define HTML_Off_Form
2460   - div
2461   - (
2462   - List(CoreAttrs) attrs,
2463   - HTML_Partial_Content element
2464   - )=
2465   - div(attrs, [element])
2466   -.
2467   -
2468   -public define HTML_Off_Form
2469   - div
2470   - (
2471   - List(HTML_Partial_Content) elements
2472   - )=
2473   - div([], elements)
2474   -.
2475 2485  
2476 2486 public define HTML_In_Form
2477 2487 hr
... ...