Friday, March 25, 2011 at 12:00 AM.
system.verbs.builtins.log2.view
on view (when=clock.now (), source=nil, maxitems=100, flHeaderFooter=false, flSingleDay=true, flNestedTable=true) {
<<Changes:
<<3/24/11; 11:43:55 PM by DW
<<New optional param, flNestedTable. If true, we display the table inside another table so there is a solid line betw cells. If it's false, you get a single table.
<<9/12/10; 12:12:32 AM by DW
<<Call new verb, date.viewDate to display the time/date of the log item.
<<9/4/10; 3:12:20 PM by DW
<<When displaying the time/date of the update, if it happened today, show the time -- if it happened before today, show the date.
<<8/28/09; 10:13:46 AM by DW
<<Add optional param, flSingleDay, default true. If false we go back into previous days if there are less than "maxitems" entries today.
<<7/17/09; 8:28:40 AM by DW
<<Turn off cache, for debugging. (Not clear it helps perf much.
<<7/17/09; 8:02:31 AM by DW
<<Add an optional parameter, flHeaderFooter, default false. If true, we display a navigation header and footer for the log readout.
<<7/16/09; 2:25:05 PM by DW
<<Remove dependencies on photoFanSuite.
<<7/16/09; 1:27:37 PM by DW
<<Add source param. If non-nil, we only include log elements from that source. Add maxitems param. Make the cache really work.
<<2/5/08; 12:32:18 PM by DW
<<Handle the case where there is no previous day (i.e. when you first install the software).
<<1/20/08; 5:28:03 AM by DW
<<Overhaul for new calendar-based event log. Accept a parameter that says what date to display events for.
<<11/25/07; 6:27:10 PM by DW
<<Relocate the cache to system.temp.photoFan.cache.viewEventsLog.
<<11/25/07; 6:23:46 PM by DW
<<Remove various FlickrRivr dependencies.
<<11/25/07; 5:15:03 PM by DW
<<Ported from FlickrRivr.
local (adrdata = log2.init (), framecolor = "DCDCDC", cellBgColor = "FFFFFF");
local (adrcal = @adrdata^.calendar, now = clock.now ());
local (flusecache = false, adrcache = @system.temp.log2.viewLogCache);
if flusecache {
if not defined (adrcache^) {
new (tabletype, adrcache)};
if source == nil {
adrcache = @adrcache^.["nil"]}
else {
adrcache = @adrcache^.[string (source)]};
if defined (adrcache^) {
return (adrcache^)}};
<<local (pta = html.getpagetableaddress ())
local (htmltext = "\r", indentlevel = 0, navtable);
on add (s) {
htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r"};
bundle { //add next/prev links
if flHeaderFooter {
local (prevlink = "Previous", nextlink = "Next");
bundle { //set prevlink
local (nomad = when);
loop {
nomad = date.yesterday (nomad);
if date.sameday (nomad, mainresponder.calendar.getfirstday (adrcal)) {
break};
try {
local (adrtable = mainresponder.calendar.getdayaddress (adrcal, nomad, false));
if defined (adrtable^) {
local (day, month, year, hour, minute, second);
date.get (nomad, @day, @month, @year, @hour, @minute, @second);
month = string.padwithzeros (month, 2);
day = string.padwithzeros (day, 2);
prevlink = "<a href=\"" + pta^.uri + "?d=" + year + "/" + month + "/" + day + "\">" + prevlink + "</a>";
break}}
else {
break}}};
bundle { //set nextlink
local (nomad = when);
loop {
if date.sameday (nomad, now) {
break};
nomad = date.tomorrow (nomad);
local (adrtable = mainresponder.calendar.getdayaddress (adrcal, nomad, false));
if defined (adrtable^) {
local (day, month, year, hour, minute, second);
date.get (nomad, @day, @month, @year, @hour, @minute, @second);
month = string.padwithzeros (month, 2);
day = string.padwithzeros (day, 2);
nextlink = "<a href=\"" + pta^.uri + "?d=" + year + "/" + month + "/" + day + "\">" + nextlink + "</a>";
break}}};
navtable = "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>" + date.longstring (when) + "</td><td align=\"right\">" + prevlink + " / " + nextlink + "</td></tr></table>";
add (navtable + "<br>")}};
add ("<center>"); indentlevel++;
if flNestedTable {
add ("<table cellspacing=\"0\" cellpadding=\"0\"><tr bgcolor=\"" + frameColor + "\"><td>"); indentlevel++};
add ("<table border=\"0\" cellspacing=\"1\" cellpadding=\"5\">"); indentlevel++;
bundle { //add header
add ("<tr bgcolor=\"" + cellBgColor + "\">"); indentlevel++;
add ("<td><b>Event</b></td>");
add ("<td><b>What Happened</b></td>");
<<add ("<td><center><b>Picture</b></center></td>") //11/23/07 by DW -- disabled
add ("<td align=\"right\"><b>When</b></td>");
add ("<td align=\"right\"><b>Seconds</b></td>");
add ("</tr>"); indentlevel--};
local (ct = 0);
on doOneItem (adritem) {
if source != nil { //7/16/09 by DW
if adritem^.source != source {
continue}};
if flusecache and defined (adritem^.cache) {
add (adritem^.cache)}
else {
local (s);
if flNestedTable {
s = s + "<tr bgcolor=\"" + cellBgColor + "\">"}
else {
s = s + "<tr>"};
s = s + "<td valign=\"top\" nowrap>" + adritem^.eventType + " </td>";
bundle { //add htmltext
local (htt = adritem^.htmlText);
htt = string.replaceall (htt, "/frimg/", "/pfi/");
s = s + "<td valign=\"top\">" + htt + "</td>"};
<<bundle //imghtml, you can simplify this tomorrow, //11/23/07 by DW -- disabled
<<if defined (adritem^.imghtml)
<<s = s + "<td valign=\"top\"><center>" + adritem^.imghtml + "</center></td>"
<<else
<<s = s + "<td valign=\"top\"> </td>"
local (when = date (xml.convertToDisplayName (nameof (adritem^))));
s = s + "<td valign=\"top\" align=\"right\" nowrap>" + date.viewDate (when) + "</td>";
s = s + "<td valign=\"top\" align=\"right\" nowrap>" + adritem^.secs + "</td>";
s = s + "</tr>";
adritem^.cache = s;
add (s)};
return (++ct < maxitems)};
if flSingleDay {
local (adrday = mainresponder.calendar.getdayaddress (adrcal, when), i);
for i = sizeof (adrday^) downto 1 {
if not doOneItem (@adrday^ [i]) {
break}}}
else {
mainresponder.calendar.visitReverseChronologic (adrcal, @doOneItem)};
if flNestedTable {
add ("</td></tr></table>"); indentlevel--};
add ("</table>"); indentlevel--;
add ("</center>"); indentlevel--;
if flHeaderFooter {
add ("<br>" + navtable)};
filemenu.savemyroot (adrcal);
if flusecache {
adrcache^ = htmlText};
return (htmlText)};
bundle { //test code
webbrowser.displaytext (view (source:"river2"))}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.