Index: openacs-4/packages/logger/logger.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/logger.info,v diff -u -r1.9.2.2 -r1.9.2.3 --- openacs-4/packages/logger/logger.info 17 Sep 2004 23:53:20 -0000 1.9.2.2 +++ openacs-4/packages/logger/logger.info 18 Nov 2004 01:40:17 -0000 1.9.2.3 @@ -7,24 +7,24 @@ f f - + Lars Pind Peter Marklund Jade Rubick Time and expenses reporting. - 2004-09-17 + 2004-11-17 Collaboraid Logger lets you keep track of measurements over time. The primary use case is time and expenses reporting, an area where we are being guided by the HR-XML Time Expense Reporting 2.0 standard. However, the intention is to allow for reporting of arbitrary types of numerical data such as financial results - account balance, revenue etc. You could even use this application to monitor your weight. The full specification is here: <a href="http://www.collaboraid.biz/developer/logger-spec">http://www.collaboraid.biz/developer/logger-spec<a> Logger can be optionally integrated with project-manager, for logging of time against projects and tasks. - + - + Index: openacs-4/packages/logger/tcl/entry-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/entry-procs.tcl,v diff -u -r1.3.8.1 -r1.3.8.2 --- openacs-4/packages/logger/tcl/entry-procs.tcl 17 Sep 2004 21:06:04 -0000 1.3.8.1 +++ openacs-4/packages/logger/tcl/entry-procs.tcl 18 Nov 2004 01:40:25 -0000 1.3.8.2 @@ -224,3 +224,114 @@ } { return [db_string task_id { } -default ""] } + + +ad_proc -public logger::entry::pm_before_change { + {-task_item_id:required} +} { + Stores the state of the task before the hour are logged and the + percent complete changed. + + @author (jader-ibr@bread.com) + @creation-date 2004-11-17 + + @param task_item_id + + @return + + @error +} { + + pm::task::get \ + -tasks_item_id [list $task_item_id] \ + -one_line_array old_one_line \ + -description_array old_description \ + -description_mime_type_array old_description_mime_type \ + -estimated_hours_work_array old_estimated_hours_work \ + -estimated_hours_work_min_array old_estimated_hours_work_min \ + -estimated_hours_work_max_array old_estimated_hours_work_max \ + -dependency_array old_dependency \ + -percent_complete_array old_percent_complete \ + -end_date_day_array old_end_date_day \ + -end_date_month_array old_end_date_month \ + -end_date_year_array old_end_date_year \ + -project_item_id_array old_project_item_id \ + -set_client_properties_p t +} + + +ad_proc -public logger::entry::pm_after_change { + {-task_item_id:required} + {-new_percent_complete:required} + {-old_percent_complete:required} +} { + Updates total percent complete for project manager, + adds a comment on the changes made, and if the change opens + or closes the task, sends out an email notification. + + @author (jader-ibr@bread.com) + @creation-date 2004-11-17 + + @param task_item_id + + @param new_percent_complete + + @param old_percent_complete + + @return + + @error +} { + + set user_id [ad_conn user_id] + set peeraddr [ad_conn peeraddr] + + pm::task::update_percent \ + -task_item_id $task_item_id \ + -percent_complete $new_percent_complete + + # figure out what changed and notify everyone + + set task_item_id_array(1) $task_item_id + set number 1 + set comments(1) "" + set comments_mime_type(1) "text/html" + + pm::task::what_changed \ + -task_item_id_array task_item_id_array \ + -number $number \ + -comments_array comments \ + -comments_mime_type_array comments_mime_type + + if {[string length $comments(1)] > 0} { + + # add comment to task + pm::util::general_comment_add \ + -object_id $task_item_id \ + -title [pm::task::name -task_item_id $task_item_id] \ + -comment $comments(1) \ + -mime_type $comments_mime_type(1) \ + -user_id $user_id \ + -peeraddr $peeraddr \ + -type "task" \ + -send_email_p f + + # if the old_percent was >= 100 and now less, or + # the old_percent was < 100 and is now more, then + # we need to send out an email to notify everyone + + if { \ + $old_percent_complete >= 100 && \ + $new_percent_complete < 100 || \ + $old_percent_complete < 100 && \ + $new_percent_complete >= 100} { + + # send email notification + pm::task::email_alert \ + -task_item_id $task_item_id \ + -edit_p t \ + -comment $comments(1) \ + -comment_mime_type $comments_mime_type(1) + } + } +} Index: openacs-4/packages/logger/www/log.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/log.tcl,v diff -u -r1.21.2.2 -r1.21.2.3 --- openacs-4/packages/logger/www/log.tcl 22 Oct 2004 20:26:42 -0000 1.21.2.2 +++ openacs-4/packages/logger/www/log.tcl 18 Nov 2004 01:40:32 -0000 1.21.2.3 @@ -1,3 +1,12 @@ +ns_log notice it's my page! +set mypage [ns_getform] +if {[string equal "" $mypage]} { + ns_log notice no form was submitted on my page +} else { + ns_log notice the following form was submitted on my page + ns_set print $mypage +} + ad_page_contract { Add/edit/display a log entry. @@ -29,6 +38,7 @@ set package_id [ad_conn package_id] set current_user_id [ad_maybe_redirect_for_registration] +set peeraddr [ad_conn peeraddr] if { [exists_and_not_null entry_id] && [logger::util::project_manager_linked_p]} { set entry_exists_p [db_string entry_exists_p {}] @@ -182,8 +192,17 @@ set task_options [list] - set task_options [pm::task::options_list \ - -project_item_id $pm_project_id] + if {[exists_and_not_null pm_task_id]} { + + set task_options [pm::task::options_list \ + -project_item_id $pm_project_id \ + -dependency_task_ids [list $pm_task_id]] + } else { + + set task_options [pm::task::options_list \ + -project_item_id $pm_project_id] + + } } # Add form elements common to all modes @@ -205,30 +224,21 @@ } # Additions to form if project-manager is involved. -if {[exists_and_not_null pm_task_id]} { +if {[exists_and_not_null pm_project_id]} { # do I really need this both here and in the -on_refresh block? -jr - db_1row get_task_values " - SELECT - title as task_title, - case when percent_complete is null then 0 - else percent_complete end as percent_complete, - estimated_hours_work, - estimated_hours_work_min, - estimated_hours_work_max, - s.description as status_description - FROM - pm_tasks_revisionsx p, - cr_items i, - pm_task_status s, - pm_tasks t - WHERE i.item_id = p.item_id and - p.item_id = :pm_task_id and - i.item_id = t.task_id and - t.status = s.status_id and - p.revision_id = i.live_revision" + if {[exists_and_not_null pm_task_id]} { + db_1row get_task_values { } + set my_task_id $pm_task_id + } else { + + set my_task_id "" + + } + + ad_form -extend -name log_entry_form -form { {pm_project_id:text(hidden) @@ -239,7 +249,7 @@ {label "Subject"} {options {$task_options}} {html {onChange "document.log_entry_form.__refreshing_p.value='1';submit()"}} - {value $pm_task_id} + {value $my_task_id} {help} {help_text "If you change this, please wait for the page to refresh"} } @@ -248,19 +258,25 @@ } } - set display_hours [pm::task::hours_remaining \ - -estimated_hours_work $estimated_hours_work \ - -estimated_hours_work_min $estimated_hours_work_min \ - -estimated_hours_work_max $estimated_hours_work_max \ - -percent_complete $percent_complete \ - ] + if {[exists_and_not_null pm_task_id]} { + set display_hours [pm::task::hours_remaining \ + -estimated_hours_work $estimated_hours_work \ + -estimated_hours_work_min $estimated_hours_work_min \ + -estimated_hours_work_max $estimated_hours_work_max \ + -percent_complete $percent_complete \ + ] + + set total_hours_work [pm::task::estimated_hours_work \ + -estimated_hours_work $estimated_hours_work \ + -estimated_hours_work_min $estimated_hours_work_min \ + -estimated_hours_work_max $estimated_hours_work_max \ + ] + } else { + set display_hours 0 + set total_hours_work 0 + set percent_complete 0 + } - set total_hours_work [pm::task::estimated_hours_work \ - -estimated_hours_work $estimated_hours_work \ - -estimated_hours_work_min $estimated_hours_work_min \ - -estimated_hours_work_max $estimated_hours_work_max \ - ] - ad_form -extend -name log_entry_form -form { {remaining_work:text(inform) @@ -335,6 +351,17 @@ } -default "0"] if { !$exists_p } { + + # we want to keep track of what has changed if we are + # logging against project manager + if {[exists_and_not_null pm_task_id]} { + + set old_percent_complete $percent_complete + logger::entry::pm_before_change \ + -task_item_id $pm_task_id + + } + logger::entry::new \ -entry_id $entry_id \ -project_id $project_id \ @@ -347,13 +374,25 @@ if {[exists_and_not_null pm_task_id]} { - pm::task::update_percent \ + logger::entry::pm_after_change \ -task_item_id $pm_task_id \ - -percent_complete $percent_complete + -new_percent_complete $percent_complete \ + -old_percent_complete $old_percent_complete } } else { + + # we want to keep track of what has changed if we are + # logging against project manager + if {[exists_and_not_null pm_task_id]} { + + set old_percent_complete $percent_complete + logger::entry::pm_before_change \ + -task_item_id $pm_task_id + + } + logger::entry::edit \ -entry_id $entry_id \ -value $value \ @@ -363,11 +402,12 @@ -project_item_id "$pm_project_id" if {[exists_and_not_null pm_task_id]} { - - pm::task::update_percent \ - -task_item_id "$pm_task_id" \ - -percent_complete "$percent_complete" - + + pm::task::pm_after_change \ + -task_item_id $pm_task_id \ + -new_percent_complete $percent_complete \ + -old_percent_complete $old_percent_complete + } } @@ -382,21 +422,46 @@ # Remember this date, as the next entry is likely to be for the same date ad_set_client_property logger time_stamp $time_stamp - # Present the user with an add form again for quick logging - ad_returnredirect -message "Log entry for $value $variable_array(unit) with description \"$description\" added." [export_vars -base [ad_conn url] { project_id variable_id pm_project_id pm_task_id}] - ad_script_abort + if {[exists_and_not_null return_url]} { + ad_returnredirect -message "Log entry for $value $variable_array(unit) with description \"$description\" added." $return_url + ad_script_abort + } else { + # Present the user with an add form again for quick logging + ad_returnredirect -message "Log entry for $value $variable_array(unit) with description \"$description\" added." [export_vars -base [ad_conn url] { project_id variable_id pm_project_id pm_task_id}] + ad_script_abort + } } -edit_data { db_transaction { if {[info exists pm_task_id] && [info exists pm_project_id]} { + + if {[exists_and_not_null pm_task_id]} { + + set old_percent_complete $percent_complete + logger::entry::pm_before_change \ + -task_item_id $pm_task_id + + } + + logger::entry::edit \ -entry_id $entry_id \ -value $value \ -time_stamp $time_stamp \ -description $description \ -task_item_id "$pm_task_id" \ -project_item_id "$pm_project_id" + + if {[exists_and_not_null pm_task_id]} { + + logger::entry::pm_after_change \ + -task_item_id $pm_task_id \ + -new_percent_complete $percent_complete \ + -old_percent_complete $old_percent_complete + + } + } else { logger::entry::edit \ -entry_id $entry_id \ @@ -420,10 +485,6 @@ if {![string equal $this_task_id -1] && [exists_and_not_null percent_complete]} { - pm::task::update_percent \ - -task_item_id "$this_task_id" \ - -percent_complete "$percent_complete" - pm::task::update_hours \ -task_item_id $this_task_id \ -update_tasks_p t @@ -441,43 +502,35 @@ ad_script_abort } -on_refresh { - db_1row get_task_values " - SELECT - title as task_title, - case when percent_complete is null then 0 - else percent_complete end as percent_complete, - estimated_hours_work, - estimated_hours_work_min, - estimated_hours_work_max, - s.description as status_description - FROM - pm_tasks_revisionsx p, - cr_items i, - pm_task_status s, - pm_tasks t - WHERE i.item_id = p.item_id and - p.item_id = :pm_task_id and - i.item_id = t.task_id and - t.status = s.status_id and - p.revision_id = i.live_revision" + if {[exists_and_not_null pm_task_id]} { + db_1row get_task_values { } + } else { + set my_task_id "" + } foreach element [list percent_complete status_description] { template::element set_value log_entry_form $element [set $element] } - set display_hours [pm::task::hours_remaining \ - -estimated_hours_work $estimated_hours_work \ - -estimated_hours_work_min $estimated_hours_work_min \ - -estimated_hours_work_max $estimated_hours_work_max \ - -percent_complete $percent_complete \ - ] + if {[exists_and_not_null pm_task_id]} { + set display_hours [pm::task::hours_remaining \ + -estimated_hours_work $estimated_hours_work \ + -estimated_hours_work_min $estimated_hours_work_min \ + -estimated_hours_work_max $estimated_hours_work_max \ + -percent_complete $percent_complete \ + ] + + set total_hours_work [pm::task::estimated_hours_work \ + -estimated_hours_work $estimated_hours_work \ + -estimated_hours_work_min $estimated_hours_work_min \ + -estimated_hours_work_max $estimated_hours_work_max \ + ] + } else { + set display_hours 0 + set total_hours_work 0 + set percent_complete 0 + } - set total_hours_work [pm::task::estimated_hours_work \ - -estimated_hours_work $estimated_hours_work \ - -estimated_hours_work_min $estimated_hours_work_min \ - -estimated_hours_work_max $estimated_hours_work_max \ - ] - template::element set_value log_entry_form remaining_work $display_hours template::element set_value log_entry_form total_hours_work $total_hours_work