-
+ |
-
-
-
+
+
-
-
-
-
- |
-
+
+
+
+
+
+
+
-
+
+
+
+
+ No users
+ |
+
+
+
+
+
|
-
- Project:
- @selected_project_name@
-
-
- Projects:
- All
-
+
+
+
+
+
+ Project:
+ @selected_project_name@
+
+
+ Projects:
+ All
+
-
- Variable:
- @selected_variable_name@
-
+
+
+
+ Variable:
+ @selected_variable_name@
+
+
+
+
+
+ User:
+ @selected_user_name@
+
+
+ Users:
+ All
+
+ |
+
+
+ |
+
+
+
-
- There are no matching log entries
-
-
-
-
-
-
- @entries.action_links@ |
-
- @entries.project_name@ |
-
- @entries.time_stamp@ |
- @entries.variable_name@ |
- @entries.value@ @entries.unit@ |
- @entries.description@ |
-
-
-
-
+
|
Index: openacs-4/packages/logger/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/index.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/logger/www/index.tcl 25 Apr 2003 09:48:37 -0000 1.2
+++ openacs-4/packages/logger/www/index.tcl 30 Apr 2003 12:21:02 -0000 1.3
@@ -5,105 +5,172 @@
@creation-date 2003-04-08
@cvs-id $Id$
} {
- project_id:optional,integer
- variable_id:optional,integer
+ {selected_project_id:integer ""}
+ {selected_variable_id:integer ""}
+ {selected_user_id:integer ""}
+ {start_date:array {}}
+ {end_date:array {}}
}
set package_id [ad_conn package_id]
set user_id [ad_conn user_id]
set admin_p [permission::permission_p -object_id $package_id -privilege admin]
-# Default variable_id to the id of the variable the user last logged in
-# At any one time exactly one variable is selected on this page
-if { ![exists_and_not_null variable_id] } {
- set variable_id [db_string last_logged_variable_id {
- select variable_id
- from logger_entries le
- where le.time_stamp = (select max(time_stamp)
- from logger_entries)
- } -default ""]
-}
+###########
+#
+# Date handling
+#
+###########
-# Need the selected variable id in the adp as variable_id will be set to some other value
-# in the multiple loop
-set selected_variable_id $variable_id
-logger::variable::get -variable_id $variable_id -array variable_array
-set selected_variable_name $variable_array(name)
+# Set default values for start and end date if the form hasn't been submitted yet
+if { [array size start_date] == 0 } {
+ # Default end date is now (today)
+ set default_end_date_seconds [clock seconds]
-# Likewise need the selected project id in the adp
-if { [exists_and_not_null project_id] } {
- set selected_project_id $project_id
- logger::project::get -project_id $project_id -array project_array
- set selected_project_name $project_array(name)
-} else {
- set selected_project_id ""
+ set end_date(year) [clock format $default_end_date_seconds -format "%Y"]
+ set end_date(month) [clock format $default_end_date_seconds -format "%m"]
+ set end_date(day) [clock format $default_end_date_seconds -format "%d"]
+
+ # Default start date is N days back
+ set number_of_days_back 31
+ set seconds_per_day [expr 60*60*24]
+ set default_start_date_seconds [expr $default_end_date_seconds - 31 * $seconds_per_day]
+
+ set start_date(year) [clock format $default_start_date_seconds -format "%Y"]
+ set start_date(month) [clock format $default_start_date_seconds -format "%m"]
+ set start_date(day) [clock format $default_start_date_seconds -format "%d"]
}
+# Get the ANSI representations of the dates
+set start_date_ansi "$start_date(year)-$start_date(month)-$start_date(day)"
+set end_date_ansi "$end_date(year)-$end_date(month)-$end_date(day)"
+
###########
#
-# Log entries
+# Project and variable default values and names
#
###########
-set where_clauses [list]
-if { [exists_and_not_null project_id] } {
- # Only selected project
- lappend where_clauses "lp.project_id = :project_id"
+# We need the name of the selected project in the adp
+if { ![empty_string_p $selected_project_id] } {
+ logger::project::get -project_id $selected_project_id -array project_array
+ set selected_project_name $project_array(name)
} else {
- # All projects mapped to the package
- lappend where_clauses \
- "exists (select 1
- from logger_project_pkg_map
- where project_id = lp.project_id
- and package_id = :package_id
- )"
+ set selected_project_name ""
}
-if { [exists_and_not_null variable_id] } {
- lappend where_clauses "lm.variable_id = :variable_id"
+# Likewise, need the name of the selected user in the adp
+if { ![empty_string_p $selected_user_id] } {
+ set selected_user_name [person::name -person_id $selected_user_id]
}
-db_multirow -extend action_links entries select_entries "
- select lm.entry_id as id,
- acs_permission.permission_p(lm.entry_id, :user_id, 'write') as write_p,
- acs_permission.permission_p(lm.entry_id, :user_id, 'delete') as delete_p,
- lm.time_stamp,
- lv.name as variable_name,
- lm.value,
- lv.unit,
- lm.description,
- lp.name as project_name
- from logger_entries lm,
- logger_variables lv,
- logger_projects lp
- where lm.variable_id = lv.variable_id
- and lm.project_id = lp.project_id
- [ad_decode $where_clauses "" "" "and [join $where_clauses "\n and "]"]
- order by lm.time_stamp desc
-" {
- set description_max_length 50
- if { [string length $description] > $description_max_length } {
- set description "[string range $description 0 [expr $description_max_length - 4]]..."
+# Find a suitable default variable_id
+# No more than one variable will be selected on this page
+# Under unusual circumstances no variable will be selected
+# (variable_id will be the empty string)
+if { [empty_string_p $selected_variable_id] } {
+ # No variable selected
+
+ # First default to the variable the user last logged hours in
+ # Use any selected project and all projects otherwise
+ if { ![empty_string_p $selected_project_id] } {
+ set project_clause "le.project_id = :selected_project_id"
+ } else {
+ set project_clause ""
}
+ set selected_variable_id [db_string last_logged_variable_id "
+ select variable_id
+ from logger_entries le,
+ acs_objects ao
+ where ao.creation_date = (select max(ao.creation_date)
+ from logger_entries le,
+ acs_objects ao
+ where ao.object_id = le.entry_id
+ [ad_decode $project_clause "" "" "and $project_clause"]
+ )
+ and ao.object_id = le.entry_id
+ [ad_decode $project_clause "" "" "and $project_clause"]
+ " -default ""]
- set action_links_list [list]
- if { $write_p } {
- lappend action_links_list "edit"
+ if { [empty_string_p $selected_variable_id] } {
+ # The user has not logger hours yet
+
+ if { ![empty_string_p $selected_project_id] } {
+ # A project is selected - use the primary variable
+ set selected_variable_id [logger::project::get_primary_variable -project_id $selected_project_id]
+ } else {
+ # No project is selected and the user has never logged hours before
+ # Should we use time in this unusual case? For now we don't select any variable
+ set selected_variable_id ""
+ }
}
- if { $delete_p } {
- set onclick_script "return confirm('Are you sure you want to delete log entry with $value $unit $variable_name on $time_stamp?');"
- lappend action_links_list "delete"
- }
- set action_links "\[ [join $action_links_list " | "] \]"
}
+# Need the name of the selected variable in the adp
+if { ![empty_string_p $selected_variable_id] } {
+ logger::variable::get -variable_id $selected_variable_id -array variable_array
+ set selected_variable_name $variable_array(name)
+ set selected_variable_unit $variable_array(unit)
+} else {
+ set selected_variable_name ""
+ set selected_variable_unit ""
+}
+
###########
#
+# Time Filter
+#
+###########
+
+# Create the form
+template::form create time_filter -method GET
+# Export the other filter variables
+template::element create time_filter selected_project_id \
+ -widget hidden \
+ -value $selected_project_id
+template::element create time_filter selected_variable_id \
+ -widget hidden \
+ -value $selected_variable_id
+template::element create time_filter selected_user_id \
+ -widget hidden \
+ -value $selected_user_id
+template::element create time_filter start_date \
+ -label "Start day:" \
+ -widget date \
+ -datatype date
+template::element create time_filter end_date \
+ -label "End day:" \
+ -widget date \
+ -datatype date
+
+# Set the values of the start and end date in the form
+element set_properties time_filter start_date \
+ -value [eval template::util::date::create $start_date(year) $start_date(month) $start_date(day)]
+element set_properties time_filter end_date \
+ -value [eval template::util::date::create $end_date(year) $end_date(month) $end_date(day)]
+
+###########
+#
+# Log entries
+#
+###########
+
+# We let start date be beginning of day but end date be end of day so that if
+# both are the same day you get the entries during that day
+set end_date_seconds [clock scan "$end_date(year)-$end_date(month)-$end_date(day)"]
+set end_date_plus_one_seconds [expr $end_date_seconds + 60*60*24]
+set end_date_plus_one_ansi [clock format $end_date_plus_one_seconds -format "%Y-%m-%d"]
+
+# template lib/entries-table is included - see adp
+
+
+###########
+#
# Projects
#
###########
-set all_projects_url "index?[export_vars {{variable_id $selected_variable_id}}]"
+set all_projects_url "index?[export_vars {{selected_variable_id $selected_variable_id} {selected_user_id $selected_user_id}}]"
db_multirow -extend { url log_url } projects select_projects {
select lp.project_id,
@@ -114,7 +181,7 @@
and lppm.package_id = :package_id
order by lp.name
} {
- set url "index?[export_vars project_id]"
+ set url "index?[export_vars {{selected_project_id $project_id}}]"
set log_url "log?[export_vars { project_id {variable_id $selected_variable_id}}]"
}
@@ -125,8 +192,8 @@
###########
set where_clauses [list]
-if { [exists_and_not_null project_id] } {
- lappend where_clauses "lp.project_id = :project_id"
+if { ![empty_string_p $selected_project_id] } {
+ lappend where_clauses "lp.project_id = :selected_project_id"
} else {
lappend where_clauses \
"exists (select 1
@@ -146,13 +213,52 @@
where lp.project_id = lpvm.project_id
and lv.variable_id = lpvm.variable_id
[ad_decode $where_clauses "" "" "and [join $where_clauses "\n and "]"]
+ group by lv.variable_id, lv.name, lv.unit
" {
- set url "index?[export_vars {variable_id project_id}]"
- if { [exists_and_not_null selected_project_id] } {
+ set url "index?[export_vars {{selected_variable_id $variable_id} {selected_project_id $selected_project_id} {selected_user_id $selected_user_id}}]"
+ if { ![empty_string_p $selected_project_id] } {
# A project is selected - enable logging
set log_url "log?[export_vars { variable_id {project_id $selected_project_id}}]"
} else {
# No project selected - we wont enable those url:s
set log_url ""
}
}
+
+###########
+#
+# Users
+#
+###########
+
+set all_users_url "index?[export_vars {{selected_variable_id $selected_variable_id} {selected_project_id $selected_project_id}}]"
+
+set where_clauses [list]
+if { ![empty_string_p $selected_project_id] } {
+ # Select all users who have logged in selected project
+ lappend where_clauses "le.project_id = :selected_project_id"
+} else {
+ # Select all users who have logged in any project mapped to
+ # this package
+ lappend where_clauses \
+ "exists (select 1
+ from logger_project_pkg_map
+ where project_id = le.project_id
+ and package_id = :package_id
+ )"
+}
+
+db_multirow -extend { url } users select_users "
+ select submitter.user_id as user_id,
+ submitter.first_names as first_names,
+ submitter.last_name as last_name
+ from cc_users submitter,
+ logger_entries le,
+ acs_objects ao
+ where ao.object_id = le.entry_id
+ and submitter.user_id = ao.creation_user
+ [ad_decode $where_clauses "" "" "and [join $where_clauses "\n and "]"]
+ group by submitter.user_id, submitter.first_names, submitter.last_name
+" {
+ set url "index?[export_vars {{selected_user_id $user_id} {selected_project_id $selected_project_id} {selected_variable_id $selected_variable_id}}]"
+}
Index: openacs-4/packages/logger/www/log.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/log.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/log.adp 22 Apr 2003 09:26:17 -0000 1.1
+++ openacs-4/packages/logger/www/log.adp 30 Apr 2003 12:21:02 -0000 1.2
@@ -3,5 +3,9 @@
@context@
-
+
+
+Log History for last 31 Days
+
+
Index: openacs-4/packages/logger/www/log.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/log.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/logger/www/log.tcl 25 Apr 2003 09:48:37 -0000 1.2
+++ openacs-4/packages/logger/www/log.tcl 30 Apr 2003 12:21:02 -0000 1.3
@@ -19,7 +19,18 @@
}
set package_id [ad_conn package_id]
+set user_id [ad_conn user_id]
+if { [exists_and_not_null entry_id] } {
+ set entry_exists_p [db_string entry_exists_p {
+ select count(*)
+ from logger_entries
+ where entry_id = :entry_id
+ }]
+} else {
+ set entry_exists_p 0
+}
+
if { [string equal [form get_action log_entry_form] "done"] } {
# User is done editing - redirect back to index page
ad_returnredirect .
@@ -41,21 +52,44 @@
set context [list $page_title]
# Build the log entry form elements
+set actions [list]
+if { $entry_exists_p && [permission::permission_p -object_id $entry_id -privilege write] } {
+ lappend actions { Edit formbuilder::edit }
+}
+lappend actions { Done done }
+
ad_form -name log_entry_form -cancel_url index -mode $ad_form_mode \
- -actions { { Edit formbuilder::edit } { Done done } } -form {
+ -actions $actions -form {
entry_id:key(acs_object_id_seq)
}
# On various occasions we need to know if we are dealing with a submit with the
# form or an initial request (could also be with error message after unaccepted submit)
set submit_p [form is_valid log_entry_form]
-# Add project and variable elements to the form
+
+###########
+#
+# Get project and variable info
+#
+###########
+
+# Get project and variable id
+if { $entry_exists_p } {
+ permission::require_permission -object_id $entry_id -privilege read
+
+ # We have the entry_id so try to get project and variable_id from the database
+ # for that entry
+ logger::entry::get -entry_id $entry_id -array entry_array
+ set project_id $entry_array(project_id)
+ set variable_id $entry_array(variable_id)
+}
+
# Get project_id if it's not provided
if { ![exists_and_not_null project_id] } {
logger::entry::get -entry_id $entry_id -array entry
set project_id $entry(project_id)
-}
+}
# Default the variable we are logging in to the primary variable of the project
if { ![exists_and_not_null variable_id] } {
@@ -65,6 +99,13 @@
# We need project and variable names
logger::project::get -project_id $project_id -array project_array
logger::variable::get -variable_id $variable_id -array variable_array
+
+###########
+#
+# Build the form
+#
+###########
+
ad_form -extend -name log_entry_form -form {
{project:text(inform)
{label Project}
@@ -81,26 +122,33 @@
}
# Add form elements common to all modes
-# The form builder date datatype doesn't understand standard ANSI format date strings
-regsub -all -- {-} [dt_systime] { } default_date
+# The form builder date datatype doesn't take ANSI format date strings
+# but wants dates in list format
+set default_date [clock format [clock seconds] -format "%Y %m %d"]
ad_form -extend -name log_entry_form -form {
{value:float
{label $variable_array(name)}
{after_html $variable_array(unit)}
+ {html {size 10}}
}
- {time_stamp:date
- {label Date}
- {value $default_date}
- }
-
{description:text,optional
{label Description}
{html {size 50}}
}
+
+ {time_stamp:date
+ {label Date}
+ {value $default_date}
+ }
}
+###########
+#
# Execute the form
+#
+###########
+
ad_form -extend -name log_entry_form -select_query {
select project_id,
variable_id,
@@ -122,20 +170,19 @@
-value $value \
-time_stamp $time_stamp_ansi \
-description $description
+
+ # Present the user with an add form again for quick logging
+ ad_returnredirect "[ad_conn url]?[export_vars {project_id variable_id}]"
+ ad_script_abort
+
} -edit_data {
set time_stamp_ansi "[lindex $time_stamp 0]-[lindex $time_stamp 1]-[lindex $time_stamp 2]"
logger::entry::edit -entry_id $entry_id \
-value $value \
-time_stamp $time_stamp_ansi \
-description $description
-} -on_submit {
-
- ns_log Notice "pm debug on_submit"
-
} -after_submit {
- ns_log Notice "pm debug after_submit"
-
ad_returnredirect "[ad_conn url]?entry_id=$entry_id"
ad_script_abort
}
Index: openacs-4/packages/logger/www/style.css
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/Attic/style.css,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/logger/www/style.css 25 Apr 2003 09:48:37 -0000 1.2
+++ openacs-4/packages/logger/www/style.css 30 Apr 2003 12:21:02 -0000 1.3
@@ -1,7 +1,6 @@
.no_items_text {
font-style: italic;
- font-weight: bold;
}
.logger_explanation_text {
Index: openacs-4/packages/logger/www/admin/project.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/project.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/admin/project.adp 22 Apr 2003 09:27:03 -0000 1.1
+++ openacs-4/packages/logger/www/admin/project.adp 30 Apr 2003 12:21:16 -0000 1.2
@@ -3,5 +3,5 @@
@context@
-
+
Index: openacs-4/packages/logger/www/admin/project.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/project.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/logger/www/admin/project.tcl 25 Apr 2003 09:49:25 -0000 1.2
+++ openacs-4/packages/logger/www/admin/project.tcl 30 Apr 2003 12:21:16 -0000 1.3
@@ -37,9 +37,13 @@
project_id:key(acs_object_id_seq)
- name:text
+ {name:text
+ {html {size 50}}
+ }
- description:text(textarea),optional
+ {description:text(textarea),optional
+ {html {cols 60 rows 13}}
+ }
}
if { [exists_and_not_null project_id] } {
Index: openacs-4/packages/logger/www/admin/variable.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/variable.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/admin/variable.adp 22 Apr 2003 09:27:03 -0000 1.1
+++ openacs-4/packages/logger/www/admin/variable.adp 30 Apr 2003 12:21:16 -0000 1.2
@@ -3,5 +3,5 @@
@context@
-
+
Index: openacs-4/packages/logger/www/admin/variable.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/admin/variable.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/admin/variable.tcl 22 Apr 2003 09:27:03 -0000 1.1
+++ openacs-4/packages/logger/www/admin/variable.tcl 30 Apr 2003 12:21:16 -0000 1.2
@@ -23,11 +23,15 @@
set context [list $page_title]
ad_form -name variable_form -cancel_url index -mode $ad_form_mode -form {
- variable_id:key(logger_variables_seq)
+ variable_id:key(acs_object_id_seq)
- name:text
+ {name:text
+ {html {size 50}}
+ }
- unit:text
+ {unit:text
+ {html {size 50}}
+ }
{type:text(radio)
{options {{Additive additive} {Non-Additive non-additive}}}
Index: openacs-4/packages/logger/www/lib/master.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/lib/Attic/master.adp,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/lib/master.adp 22 Apr 2003 09:28:13 -0000 1.1
+++ openacs-4/packages/logger/www/lib/master.adp 30 Apr 2003 12:21:30 -0000 1.2
@@ -21,9 +21,8 @@
-
+
|
Index: openacs-4/packages/logger/www/lib/nav-bar.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/lib/Attic/nav-bar.tcl,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/logger/www/lib/nav-bar.tcl 25 Apr 2003 09:50:13 -0000 1.2
+++ openacs-4/packages/logger/www/lib/nav-bar.tcl 30 Apr 2003 12:21:30 -0000 1.3
@@ -32,7 +32,6 @@
set selected_p [logger::ui::navbar_link_selected_p $url]
}
- ns_log Notice "pm debug appending navbar link $label $url $selected_p"
multirow append links $label $url $selected_p
}