Year view.
authorrich <rich>
Thu, 7 Oct 2004 18:56:47 +0000 (18:56 +0000)
committerrich <rich>
Thu, 7 Oct 2004 18:56:47 +0000 (18:56 +0000)
MANIFEST
html/_css/standard.css
html/_graphics/pinkhatch.png [new file with mode: 0644]
scripts/cocanwiki_ext_calendar.ml
templates/calendar_year.html
templates/calendar_year_1m.html [new file with mode: 0644]

index cb13c83..14fabbf 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -29,6 +29,7 @@ html/_graphics/mailto.png
 html/_graphics/markup-preview.png
 html/_graphics/newpage.png
 html/_graphics/ok.png
+html/_graphics/pinkhatch.png
 html/_graphics/tick.png
 html/_graphics/xml.png
 html/_js/editor.js
@@ -59,6 +60,7 @@ scripts/cocanwiki_create_host.mli
 scripts/cocanwiki_date.ml
 scripts/cocanwiki_diff.ml
 scripts/cocanwiki_emailnotify.ml
+scripts/cocanwiki_ext_calendar.ml
 scripts/cocanwiki_files.ml
 scripts/cocanwiki_images.ml
 scripts/cocanwiki_images.mli
@@ -162,6 +164,10 @@ templates/admin/edit_emails_form.html
 templates/admin/edit_host_css_form.html
 templates/admin/edit_hostnames_form.html
 templates/admin/host.html
+templates/calendar_day.html
+templates/calendar_month.html
+templates/calendar_year.html
+templates/calendar_year_1m.html
 templates/change_password_form.html
 templates/contact.txt
 templates/contact_show.html
index 70c16d7..a85365b 100644 (file)
@@ -1,5 +1,5 @@
 /* Stylesheet for COCANWIKI.
- * $Id: standard.css,v 1.8 2004/10/07 16:54:24 rich Exp $
+ * $Id: standard.css,v 1.9 2004/10/07 18:56:48 rich Exp $
  */
 
 body {
@@ -346,3 +346,70 @@ table.cal_month tr.cal_month_row li {
   display: inline;
   margin-right: 2em;
 }
+
+table.cal_year {
+  border-collapse: collapse;
+  border: 1px solid #eee;
+  width: 90%;
+  margin-left: 5%;
+  margin-right: 5%;
+}
+
+table.cal_year th.cal_year_header {
+  background-color: #eef;
+}
+
+table.cal_year th.cal_year_header a.cal_year_left {
+  margin-right: 2em;
+}
+
+table.cal_year th.cal_year_header a.cal_year_right {
+  margin-left: 2em;
+}
+
+table.cal_year td.cal_year_month {
+  vertical-align: top;
+}
+
+table.cal_year_1m th.cal_year_1m_header {
+  background-color: #eef;
+}
+
+table.cal_year_1m th.cal_year_1m_header_weekend {
+  background-color: #fef;
+}
+
+/*
+table.cal_year_1m tr.cal_year_1m_row td {
+  height: 1.4em;
+}
+*/
+
+table.cal_year_1m tr.cal_year_1m_row a {
+  text-decoration: none;
+}
+
+table.cal_year_1m tr.cal_year_1m_row td.cal_year_1m_weekend {
+  background-color: #fef;
+}
+
+table.cal_year_1m tr.cal_year_1m_row td.cal_year_1m_events {
+  border: 2px solid #000;
+}
+
+/*
+table.cal_year_1m tr.cal_year_1m_row td.cal_year_1m_empty {
+  background: url(/_graphics/pinkhatch.png) repeat;
+}
+*/
+
+table.cal_year td.cal_year_events ul {
+  list-style: none;
+  padding: 0px;
+  margin: 0px;
+}
+
+table.cal_year td.cal_year_events ul {
+  display: inline;
+  margin-right: 2em;
+}
diff --git a/html/_graphics/pinkhatch.png b/html/_graphics/pinkhatch.png
new file mode 100644 (file)
index 0000000..8f95f7c
Binary files /dev/null and b/html/_graphics/pinkhatch.png differ
index 2e35698..e4e2506 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_ext_calendar.ml,v 1.1 2004/10/07 16:54:24 rich Exp $
+ * $Id: cocanwiki_ext_calendar.ml,v 1.2 2004/10/07 18:56:53 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,6 +36,7 @@ open Cocanwiki_date
 let day_template = _get_template "calendar_day.html"
 let month_template = _get_template "calendar_month.html"
 let year_template = _get_template "calendar_year.html"
+let year_1m_template = _get_template "calendar_year_1m.html"
 
 let rec range a b =
   if a <= b then
@@ -99,7 +100,7 @@ let extension (dbh : Dbi.connection) hostid url =
                 | _ -> assert false) in
     List.filter_map
       (fun (from_url, title, to_url) ->
-        try let date = valid_date to_url in Some (date, title, from_url)
+        try let date = valid_date to_url in Some (date, (title, from_url))
         with Not_found -> None) results in
   let pages = List.sort pages in
 
@@ -113,13 +114,67 @@ let extension (dbh : Dbi.connection) hostid url =
        "<p>" ^ url ^ " is not an actual date.</p>"
     | Some (yyyy, 0, 0) ->             (* Year view. *)
        let template = year_template in
-       failwith "not impl";
-
-
-
-
 
+       template#set "yyyy" (string_of_int yyyy);
+       template#set "prev_yyyy" (string_of_int (yyyy - 1));
+       template#set "next_yyyy" (string_of_int (yyyy + 1));
+
+       (* Return true if there are any events on a particular day. *)
+       let has_events date = List.exists (fun (d, _) -> date = d) pages in
+
+       (* Generate each month template separately ...
+        * Wow, finally found a place I can use a for loop.
+        *)
+       for mm = 1 to 12 do
+         let str =
+           let template = year_1m_template in
+           template#set "yyyy" (string_of_int yyyy);
+           template#set "mm" (sprintf "%02d" mm);
+           template#set "month_name" (long_month mm);
+           let dow = GregorianDate.day_of_week (yyyy, mm, 1) in
+           let dow = if dow = 7 then 0 else dow in
+           let max_dd = GregorianDate.days_in_month yyyy mm in
+           let dd = ref (1-dow) in
+           let rows = ref [] in
+           for r = 0 to 5 do           (* up to 5 rows ... *)
+             let cols = ref [] in
+             for c = 0 to 6 do         (* 7 columns, Sunday - Saturday *)
+               let is_day = !dd >= 1 && !dd <= max_dd in
+               let clasz =
+                 if is_day then (
+                   let date = yyyy, mm, !dd in
+                   let is_weekend = GregorianDate.day_of_week date >= 6 in
+                   let events = has_events date in
+                   (if is_weekend then "cal_year_1m_weekend " else "") ^
+                   (if events then "cal_year_1m_events" else "")
+                 ) else
+                   "cal_year_1m_empty" in
+               let col =
+                 [ "is_day", Template.VarConditional is_day;
+                   "dd", Template.VarString (sprintf "%02d" !dd);
+                   "class", Template.VarString clasz ] in
+               cols := col :: !cols;
+               incr dd
+             done;
+             rows := [ "cols", Template.VarTable (List.rev !cols) ] :: !rows;
+             cols := []
+           done;
+
+           template#table "rows" (List.rev !rows);
+
+           template#to_string in
+         template#set ("month" ^ string_of_int mm) str
+       done;
+
+       (* Annual events. *)
+       let events =
+         List.filter (function ((_, 0, 0), _) -> true | _ -> false) pages in
 
+       let table =
+         List.map (fun (_, (title, page)) ->
+                     [ "title", Template.VarString title;
+                       "page", Template.VarString page ]) events in
+       template#table "events" table;
 
        template#to_string
 
@@ -143,12 +198,12 @@ let extension (dbh : Dbi.connection) hostid url =
 
        (* Get all monthly events and all daily events. *)
        let monthly_events, daily_events =
-         List.partition (function ((_, _, 0), _, _) -> true | _ -> false)
+         List.partition (function ((_, _, 0), _) -> true | _ -> false)
            pages in
 
        (* Table of monthly events. *)
        let table =
-         List.map (fun (_, title, page) ->
+         List.map (fun (_, (title, page)) ->
                      [ "title", Template.VarString title;
                        "page", Template.VarString page ]) monthly_events in
        template#table "monthly_events" table;
@@ -160,10 +215,10 @@ let extension (dbh : Dbi.connection) hostid url =
        let table =
          List.map (fun dd ->
                      let events =
-                       List.filter (fun ((_, _, d), _, _) -> d = dd)
+                       List.filter (fun ((_, _, d), _) -> d = dd)
                          daily_events in
                      let table =
-                       List.map (fun (_, title, page) ->
+                       List.map (fun (_, (title, page)) ->
                                    [ "title", Template.VarString title;
                                      "page", Template.VarString page ])
                          events in
index e69de29..cd8fee1 100644 (file)
@@ -0,0 +1,37 @@
+<table class="cal_year">
+<tr>
+<th colspan="3" class="cal_year_header">
+    <a href="/::prev_yyyy::" class="cal_year_left" title="Previous year">&lt;&lt;</a>
+    ::yyyy::
+    <a href="/::next_yyyy::" class="cal_year_right" title="Next year">&gt;&gt;</a>
+</th>
+</tr>
+<tr>
+  <td class="cal_year_month">::month1::</td>
+  <td class="cal_year_month">::month2::</td>
+  <td class="cal_year_month">::month3::</td>
+</tr>
+<tr>
+  <td class="cal_year_month">::month4::</td>
+  <td class="cal_year_month">::month5::</td>
+  <td class="cal_year_month">::month6::</td>
+</tr>
+<tr>
+  <td class="cal_year_month">::month7::</td>
+  <td class="cal_year_month">::month8::</td>
+  <td class="cal_year_month">::month9::</td>
+</tr>
+<tr>
+  <td class="cal_year_month">::month10::</td>
+  <td class="cal_year_month">::month11::</td>
+  <td class="cal_year_month">::month12::</td>
+</tr>
+<tr class="cal_year_events">
+<td colspan="3" class="cal_year_events">
+Pages which link to this year:
+<ul>
+::table(events)::<li><a href="/::page::">::title_html::</a></li>::end::
+</ul>
+</td>
+</tr>
+</table>
\ No newline at end of file
diff --git a/templates/calendar_year_1m.html b/templates/calendar_year_1m.html
new file mode 100644 (file)
index 0000000..ec3f784
--- /dev/null
@@ -0,0 +1,17 @@
+<table class="cal_year_1m">
+<tr>
+<th colspan="7" class="cal_year_1m_header"><a href="/::yyyy::/::mm::">::month_name_html:: ::yyyy::</a></th>
+</tr>
+<tr class="cal_year_1m_header_days">
+<th class="cal_year_1m_header_weekend">Su</th><th>Mo</th><th>Tu</th><th>We</th><th>Th</th><th>Fr</th><th class="cal_year_1m_header_weekend">Sa</th>
+</tr>
+::table(rows)::
+<tr class="cal_year_1m_row">
+::table(cols)::
+<td class="::class::">
+  ::if(is_day)::<a href="/::yyyy::/::mm::/::dd::">::dd::</a>::end::
+</td>
+::end::
+</tr>
+::end::
+</table>
\ No newline at end of file