* Tasks view is now pretty.
authorArt Cancro <ajc@citadel.org>
Wed, 4 Aug 2004 03:52:24 +0000 (03:52 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 4 Aug 2004 03:52:24 +0000 (03:52 +0000)
* Tasks view now displays date due for each task.
* Tasks view is now sorted by date due.
* Tasks view now displays overdue tasks in red.

webcit/ChangeLog
webcit/calendar.c
webcit/calendar_view.c
webcit/messages.c
webcit/webcit.h

index a2a53c814c2a503d0d8f59ec23dded6aa5f96027..8d6960a17eca4b57c2adedcfe07c1d3e74242b5c 100644 (file)
@@ -1,4 +1,10 @@
 $Log$
+Revision 522.21  2004/08/04 03:52:23  ajc
+* Tasks view is now pretty.
+* Tasks view now displays date due for each task.
+* Tasks view is now sorted by date due.
+* Tasks view now displays overdue tasks in red.
+
 Revision 522.20  2004/08/03 03:55:37  ajc
 * Tasks view now uses the same buffer/dump logic as the calendar views, so
   we can sort them by due date and do a prettier display.  (Only the logic is
@@ -1994,4 +2000,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index f1f23b7aaaef630fc35552761523bf5cbdeaff20..300d0ebb81f9f18e611bf2af064b739b352baf9d 100644 (file)
@@ -472,12 +472,10 @@ void display_individual_cal(icalcomponent *cal, long msgnum) {
        WC->num_cal += 1;
 
        WC->disp_cal = realloc(WC->disp_cal,
-                       (sizeof(icalcomponent *) * WC->num_cal) );
-       WC->disp_cal[WC->num_cal - 1] = icalcomponent_new_clone(cal);
+                       (sizeof(struct disp_cal) * WC->num_cal) );
+       WC->disp_cal[WC->num_cal - 1].cal = icalcomponent_new_clone(cal);
 
-       WC->cal_msgnum = realloc(WC->cal_msgnum,
-                       (sizeof(long) * WC->num_cal) );
-       WC->cal_msgnum[WC->num_cal - 1] = msgnum;
+       WC->disp_cal[WC->num_cal - 1].cal_msgnum = msgnum;
 }
 
 
index 70c4d537daec5ae9a8f8a5b2d5f39a63d179bb02..42829f9ab1aa43b38ff27c6608e0404c780f94e2 100644 (file)
@@ -62,7 +62,7 @@ void calendar_month_view_display_events(time_t thetime) {
        year = today_tm.tm_year + 1900;
 
        for (i=0; i<(WC->num_cal); ++i) {
-               p = icalcomponent_get_first_property(WC->disp_cal[i],
+               p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
                                                ICAL_DTSTART_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
@@ -92,7 +92,7 @@ lprintf(9, "Event: %04d/%02d/%02d, Now: %04d/%02d/%02d\n",
                           && (event_tm.tm_mday == today_tm.tm_mday)) {
 
                                p = icalcomponent_get_first_property(
-                                                       WC->disp_cal[i],
+                                                       WC->disp_cal[i].cal,
                                                        ICAL_SUMMARY_PROPERTY);
                                if (p != NULL) {
 
@@ -104,7 +104,7 @@ lprintf(9, "Event: %04d/%02d/%02d, Now: %04d/%02d/%02d\n",
 
                                        wprintf("<FONT SIZE=-1>"
                                                "<A HREF=\"/display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
-                                               WC->cal_msgnum[i],
+                                               WC->disp_cal[i].cal_msgnum,
                                                bstr("calview"),
                                                bstr("year"),
                                                bstr("month"),
@@ -274,7 +274,7 @@ void calendar_day_view_display_events(int year, int month,
        }
 
        for (i=0; i<(WC->num_cal); ++i) {
-               p = icalcomponent_get_first_property(WC->disp_cal[i],
+               p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
                                                ICAL_DTSTART_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
@@ -296,7 +296,7 @@ void calendar_day_view_display_events(int year, int month,
 
 
                                p = icalcomponent_get_first_property(
-                                                       WC->disp_cal[i],
+                                                       WC->disp_cal[i].cal,
                                                        ICAL_SUMMARY_PROPERTY);
                                if (p != NULL) {
 
@@ -308,7 +308,7 @@ void calendar_day_view_display_events(int year, int month,
 
                                        wprintf("<FONT SIZE=-1>"
                                                "<A HREF=\"/display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
-                                               WC->cal_msgnum[i],
+                                               WC->disp_cal[i].cal_msgnum,
                                                year, month, day
                                        );
                                        escputs((char *)
@@ -488,7 +488,7 @@ void calendar_summary_view(void) {
        memcpy(&today_tm, localtime(&now), sizeof(struct tm));
 
        for (i=0; i<(WC->num_cal); ++i) {
-               p = icalcomponent_get_first_property(WC->disp_cal[i],
+               p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
                                                ICAL_DTSTART_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
@@ -510,7 +510,7 @@ void calendar_summary_view(void) {
 
 
                                p = icalcomponent_get_first_property(
-                                                       WC->disp_cal[i],
+                                                       WC->disp_cal[i].cal,
                                                        ICAL_SUMMARY_PROPERTY);
                                if (p != NULL) {
                                        escputs((char *)
@@ -528,13 +528,11 @@ void calendar_summary_view(void) {
 void free_calendar_buffer(void) {
        int i;
        if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
-               icalcomponent_free(WC->disp_cal[i]);
+               icalcomponent_free(WC->disp_cal[i].cal);
        }
        WC->num_cal = 0;
        free(WC->disp_cal);
        WC->disp_cal = NULL;
-       free(WC->cal_msgnum);
-       WC->cal_msgnum = NULL;
 }
 
 
@@ -583,27 +581,116 @@ void do_calendar_view(void) {
 }
 
 
+/*
+ * Helper function for do_tasks_view().  Returns the date/time due.
+ */
+time_t get_task_due_date(icalcomponent *vtodo) {
+       icalproperty *p;
+
+       if (vtodo == NULL) {
+               return(0L);
+       }
+
+       /* If we're looking at a fully encapsulated VCALENDAR
+        * rather than a VTODO component, recurse into the data
+        * structure until we get a VTODO.
+        */
+       if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
+               return get_task_due_date(
+                       icalcomponent_get_first_component(
+                               vtodo, ICAL_VTODO_COMPONENT
+                       )
+               );
+       }
+
+       p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
+       if (p != NULL) {
+               return(icaltime_as_timet(icalproperty_get_due(p)));
+       }
+       else {
+               return(0L);
+       }
+}
+
+
+/*
+ * Compare the due dates of two tasks (this is for sorting)
+ */
+int task_due_cmp(const void *task1, const void *task2) {
+       time_t t1;
+       time_t t2;
+
+       t1 =  get_task_due_date(((struct disp_cal *)task1)->cal);
+       t2 =  get_task_due_date(((struct disp_cal *)task2)->cal);
+
+       if (t1 < t2) return(-1);
+       if (t1 > t2) return(1);
+       return(0);
+}
+
+
+
+
+
 void do_tasks_view(void) {
        int i;
+       time_t due;
+       int bg = 0;
+       char buf[SIZ];
        icalproperty *p;
 
+       do_template("beginbox_nt");
+
+       wprintf("<TABLE BORDER=0 CELLSPACING=0 WIDTH=100%%>\n<TR>\n"
+               "<TH>Name of task</TH>\n"
+               "<TH>Date due</TH></TR>\n"
+       );
+
+       /* Sort them if necessary */
+       if (WC->num_cal > 1) {
+               qsort(WC->disp_cal,
+                       WC->num_cal,
+                       sizeof(struct disp_cal),
+                       task_due_cmp
+               );
+       }
+
        if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
-               p = icalcomponent_get_first_property(WC->disp_cal[i],
+
+               bg = 1 - bg;
+               wprintf("<TR BGCOLOR=\"#%s\"><TD>",
+                       (bg ? "DDDDDD" : "FFFFFF")
+               );
+
+               p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
                                                        ICAL_SUMMARY_PROPERTY);
                wprintf("<A HREF=\"/display_edit_task?msgnum=%ld&taskrm=",
-                       WC->cal_msgnum[i] );
+                       WC->disp_cal[i].cal_msgnum );
                urlescputs(WC->wc_roomname);
                wprintf("\">");
                if (p != NULL) {
                        escputs((char *)icalproperty_get_comment(p));
                }
-               wprintf("</A><BR>\n");
+               wprintf("</A>\n");
+               wprintf("</TD>\n");
+
+               due = get_task_due_date(WC->disp_cal[i].cal);
+               fmt_date(buf, due);
+               wprintf("<TD><FONT");
+               if (due < time(NULL)) {
+                       wprintf(" COLOR=\"#FF0000\"");
+               }
+               wprintf(">%s</FONT></TD></TR>\n", buf);
        }
 
-       wprintf("<BR><BR><A HREF=\"/display_edit_task?msgnum=0\">"
+       wprintf("</TABLE>\n");
+
+       wprintf("<HR><A HREF=\"/display_edit_task?msgnum=0\">"
                "Add new task</A>\n"
        );
 
+       do_template("endbox");
+
 
        /* Free the list */
        free_calendar_buffer();
index e30cc1820cd3474f98e7b849cd09dc98e9987f5b..37fc21196f65c7a3b48ad47b00c9a6f3f8ae723f 100644 (file)
@@ -1582,18 +1582,24 @@ void display_enter(void)
                bstr("recp"));
        wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
                now);
+
+       wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>\n");
+       wprintf("<TR><TD ALIGN=LEFT>");
        wprintf("<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \">");
                /* "onLoad=\"document.enterform.msgtext.focus();\" " */
        wprintf("<FONT SIZE=-1>Subject (optional):</FONT>"
                "<INPUT TYPE=\"text\" NAME=\"subject\" VALUE=\"");
        escputs(bstr("subject"));
-       wprintf("\" MAXLENGTH=70>"
+       wprintf("\" SIZE=40 MAXLENGTH=70>"
                "&nbsp;"
        );
+       wprintf("</TD>");
 
+       wprintf("<TD ALIGN=RIGHT>");
        wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
                "&nbsp;"
                "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
+       wprintf("</TD></TR></TABLE>\n");
 
        wprintf("<SCRIPT language=\"JavaScript\" type=\"text/javascript\" "
                "src=\"static/richtext_compressed.js\"></SCRIPT>\n"
index 435bd1df8af7d225dbef83676c23164e4cccc6cf..e1b4a46d7562fdbede6ce7e0c2c95289d6866f0b 100644 (file)
@@ -220,8 +220,10 @@ struct wcsession {
        char http_host[SIZ];            /* HTTP Host: header */
        char *preferences;
 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
-       icalcomponent **disp_cal;       /* store calendar items for display */
-       long *cal_msgnum;               /* store calendar msgids for display */
+       struct disp_cal {
+               icalcomponent *cal;             /* cal items for display */
+               long cal_msgnum;                /* cal msgids for display */
+       } *disp_cal;
        int num_cal;
 #endif
        struct wc_attachment *first_attachment;