+ This proc requires there to be an HTTP connection as the creation_user and creation_ip
+ variables are taken from ad_conn.
+
+
+ @param entry_id An optional pre-generated id of the entry
+ @param project_id The id of the project the entry is for
+ @param variable_id The id of the variable the entry is for
+ @param value The value of the measurment
+ @param time_stamp The point in time the measurment is tied to. Must be on ANSI format.
+ Can be a date or a date and a time.
+ @param description A short (less than 4000 chars) text describing the entry.
+
+ @return The entry_id of the created project.
+
+ @author Peter Marklund
+} {
+ logger::util::set_vars_from_ad_conn {creation_user creation_ip}
+
+ set entry_id [db_exec_plsql insert_entry {}]
+
+ return $entry_id
+}
+
+ad_proc -public logger::entry::edit {
+ {-entry_id:required}
+ {-value:required}
+ {-time_stamp:required}
+ {-description ""}
+} {
+ Edit a entry.
+
+ @param entry_id The id of the entry to edit
+ @param value The new value of the entry
+ @param time_stamp The new time stamp of the entry
+ @param description The new description of the entry
+
+ @return The return value from db_dml
+
+ @author Peter Marklund
+} {
+ db_dml update_entry {}
+}
+
+ad_proc -public logger::entry::delete {
+ {-entry_id:required}
+} {
+ Delete the entry with given id.
+
+ @param entry_id The id of the entry to delete
+
+ @return The return value from db_exec_plsql
+
+ @author Peter Marklund
+} {
+ db_exec_plsql delete_entry {}
+}
+
+ad_proc -public logger::entry::get {
+ {-entry_id:required}
+ {-array:required}
+} {
+ Retrieve info about the entry with given id into an
+ array (using upvar) in the callers scope. The
+ array will contain the keys measruement_id, project_id, variable_id,
+ value, time_stamp, description.
+
+ @param entry_id The id of the entry to retrieve information about
+ @param array The name of the array in the callers scope where the information will
+ be stored
+
+ @return The return value from db_1row. Throws an error if the entry doesn't exist.
+
+ @author Peter Marklund
+} {
+ upvar $array entry_array
+
+ db_1row select_entry {} -column_array entry_array
+}
Index: openacs-4/packages/logger/tcl/entry-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/entry-procs.xql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/logger/tcl/entry-procs.xql 25 Apr 2003 09:47:11 -0000 1.1
@@ -0,0 +1,28 @@
+
+
+
-
Index: openacs-4/packages/logger/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/index.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/index.tcl 22 Apr 2003 09:26:17 -0000 1.1
+++ openacs-4/packages/logger/www/index.tcl 25 Apr 2003 09:48:37 -0000 1.2
@@ -6,37 +6,106 @@
@cvs-id $Id$
} {
project_id:optional,integer
+ variable_id:optional,integer
}
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 ""]
+}
+
+# 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)
+
+# 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 ""
+}
+
+###########
+#
+# Log entries
+#
+###########
+
set where_clauses [list]
if { [exists_and_not_null project_id] } {
+ # Only selected project
lappend where_clauses "lp.project_id = :project_id"
+} 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
+ )"
}
-db_multirow measurements select_measurements "
- select lm.measurement_id as id,
+if { [exists_and_not_null variable_id] } {
+ lappend where_clauses "lm.variable_id = :variable_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
- from logger_measurements lm,
+ 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
- and exists (select 1
- from logger_project_pkg_map
- where project_id = lp.project_id
- and package_id = :package_id)
- [ad_decode $where_clauses "" "" "and [join $where_clauses "\n and"]"]
+ [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]]..."
+ }
-db_multirow -extend url projects select_projects {
+ set action_links_list [list]
+ if { $write_p } {
+ lappend action_links_list "edit"
+ }
+ 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 " | "] \]"
+}
+
+###########
+#
+# Projects
+#
+###########
+
+set all_projects_url "index?[export_vars {{variable_id $selected_variable_id}}]"
+
+db_multirow -extend { url log_url } projects select_projects {
select lp.project_id,
lp.name
from logger_projects lp,
@@ -46,4 +115,44 @@
order by lp.name
} {
set url "index?[export_vars project_id]"
+ set log_url "log?[export_vars { project_id {variable_id $selected_variable_id}}]"
}
+
+###########
+#
+# Variables
+#
+###########
+
+set where_clauses [list]
+if { [exists_and_not_null project_id] } {
+ lappend where_clauses "lp.project_id = :project_id"
+} else {
+ lappend where_clauses \
+ "exists (select 1
+ from logger_project_pkg_map
+ where project_id = lp.project_id
+ and package_id = :package_id
+ )"
+}
+
+db_multirow -extend { url log_url } variables select_variables "
+ select lv.variable_id,
+ lv.name,
+ lv.unit
+ from logger_variables lv,
+ logger_projects lp,
+ logger_project_var_map lpvm
+ where lp.project_id = lpvm.project_id
+ and lv.variable_id = lpvm.variable_id
+ [ad_decode $where_clauses "" "" "and [join $where_clauses "\n and "]"]
+" {
+ set url "index?[export_vars {variable_id project_id}]"
+ if { [exists_and_not_null 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 ""
+ }
+}
Index: openacs-4/packages/logger/www/log.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/log.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/logger/www/log.tcl 22 Apr 2003 09:26:17 -0000 1.1
+++ openacs-4/packages/logger/www/log.tcl 25 Apr 2003 09:48:37 -0000 1.2
@@ -5,30 +5,30 @@
@creation-date 2003-04-16
@cvs-id $Id$
} {
- measurement_id:integer,optional
+ entry_id:integer,optional
project_id:integer,optional
variable_id:integer,optional
} -validate {
project_id_required_in_add_mode {
# For the sake of simplicity of the form
# we are requiring a project_id to be provided in add mode
- if { ![exists_and_not_null measurement_id] && ![exists_and_not_null project_id] } {
- ad_complain "When adding a log entry a project_id must be provided (either measurement_id or project_id must be present)."
+ if { ![exists_and_not_null entry_id] && ![exists_and_not_null project_id] } {
+ ad_complain "When adding a log entry a project_id must be provided (either entry_id or project_id must be present)."
}
}
}
set package_id [ad_conn package_id]
-if { ![empty_string_p [ns_set iget [rp_getform] formbutton:done_button]] } {
+if { [string equal [form get_action log_entry_form] "done"] } {
# User is done editing - redirect back to index page
- ad_returnredirect index
+ ad_returnredirect .
ad_script_abort
}
# Different page title and form mode when adding a log entry
# versus displaying/editing one
-if { [exists_and_not_null measurement_id] } {
+if { [exists_and_not_null entry_id] } {
# Initial request in display or edit mode or a submit of the form
set page_title "One Log Entry"
set ad_form_mode display
@@ -41,64 +41,63 @@
set context [list $page_title]
# Build the log entry form elements
-ad_form -name log_entry_form -cancel_url index -mode $ad_form_mode -actions [list [list Edit "formbuilder::edit"] [list Done done_button]] -form {
- measurement_id:key(acs_object_id_seq)
+ad_form -name log_entry_form -cancel_url index -mode $ad_form_mode \
+ -actions { { Edit formbuilder::edit } { Done done } } -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]
-# Initial request of form or input error
-if { ! $submit_p } {
+# Add project and variable elements to the form
+# 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)
+}
- # Add project and variable elements to the form
- # Get project_id if it's not provided
- if { ![exists_and_not_null project_id] } {
- logger::measurement::get -measurement_id $measurement_id -array measurement
- set project_id $measurement(project_id)
- }
- # For simplicity - use the primary variable of the
- # project
+# Default the variable we are logging in to the primary variable of the project
+if { ![exists_and_not_null variable_id] } {
set variable_id [logger::project::get_primary_variable -project_id $project_id]
- # We need project and variable names
- logger::project::get -project_id $project_id -array project
- logger::variable::get -variable_id $variable_id -array variable
- ad_form -extend -name log_entry_form -form {
- {project:text(inform)
- {label Project}
- {value $project(name)}
- }
+}
- {variable:text(inform)
- {label Variable}
- {value "$variable(name) ($variable(unit))"}
- }
+# 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
+ad_form -extend -name log_entry_form -form {
+ {project:text(inform)
+ {label Project}
+ {value $project_array(name)}
+ }
- {project_id:integer(hidden)
- {value $project_id}
- }
+ {project_id:integer(hidden)
+ {value $project_id}
+ }
- {variable_id:integer(hidden)
- {value $variable_id}
- }
- }
-}
+ {variable_id:integer(hidden)
+ {value $variable_id}
+ }
+}
# 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
ad_form -extend -name log_entry_form -form {
- {value:integer
- {label Value}
+ {value:float
+ {label $variable_array(name)}
+ {after_html $variable_array(unit)}
}
{time_stamp:date
{label Date}
{value $default_date}
}
- description:text,optional
+ {description:text,optional
+ {label Description}
+ {html {size 50}}
+ }
}
# Execute the form
@@ -108,19 +107,24 @@
value,
to_char(time_stamp, 'YYYY MM DD') as time_stamp,
description
- from logger_measurements
- where measurement_id = :measurement_id
+ from logger_entries
+ where entry_id = :entry_id
+} -validate {
+ {value
+ { [regexp {^([^.]+|[^.]*\.[0-9]{0,2})$} $value] }
+ {The value may not contain more than two decimals}
+ }
} -new_data {
set time_stamp_ansi "[lindex $time_stamp 0]-[lindex $time_stamp 1]-[lindex $time_stamp 2]"
- logger::measurement::new -measurement_id $measurement_id \
+ logger::entry::new -entry_id $entry_id \
-project_id $project_id \
-variable_id $variable_id \
-value $value \
-time_stamp $time_stamp_ansi \
-description $description
} -edit_data {
set time_stamp_ansi "[lindex $time_stamp 0]-[lindex $time_stamp 1]-[lindex $time_stamp 2]"
- logger::measurement::edit -measurement_id $measurement_id \
+ logger::entry::edit -entry_id $entry_id \
-value $value \
-time_stamp $time_stamp_ansi \
-description $description
@@ -132,6 +136,6 @@
ns_log Notice "pm debug after_submit"
- ad_returnredirect "[ad_conn url]?measurement_id=$measurement_id"
+ 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.1 -r1.2
--- openacs-4/packages/logger/www/style.css 22 Apr 2003 09:26:17 -0000 1.1
+++ openacs-4/packages/logger/www/style.css 25 Apr 2003 09:48:37 -0000 1.2
@@ -4,8 +4,17 @@
font-weight: bold;
}
+.logger_explanation_text {
+ font-style: italic;
+}
+
+.logger_emphasized_text {
+ font-weight: bold;
+}
+
table.logger_navbar {
- background-color: #41329c;
+ background-color: #41329c;
+ clear: both;
}
a.logger_navbar {
color: white;
@@ -15,7 +24,8 @@
text-decoration: underline;
}
.logger_navbar_selected_link {
- font-weight: bold;
+ font-weight: bold;
+ color: white;
}
.logger_filter_bar_header {
font-weight: bold;
@@ -24,3 +34,31 @@
.logger_filter_bar_section_header {
font-weight: bold;
}
+
+.logger_filter_bar {
+ background-color: #ddddff;
+ float: left;
+ width: 25%;
+}
+
+.logger_body {
+ background-color: white;
+ valign: center;
+ padding-left: 10px;
+}
+
+hr {
+ clear: both;
+}
+
+table.logger_table {
+ background-color: #999999;
+ margin: 10px;
+}
+.logger_table_header {
+ background-color: #dddddd;
+}
+.logger_table_rows {
+ background-color: white;
+}
+
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.1 -r1.2
--- openacs-4/packages/logger/www/admin/project.tcl 22 Apr 2003 09:27:03 -0000 1.1
+++ openacs-4/packages/logger/www/admin/project.tcl 25 Apr 2003 09:49:25 -0000 1.2
@@ -10,6 +10,12 @@
set package_id [ad_conn package_id]
+if { ![empty_string_p [ns_set iget [rp_getform] formbutton:done_button]] } {
+ # User is done editing - redirect back to index page
+ ad_returnredirect index
+ ad_script_abort
+}
+
if { [exists_and_not_null project_id] } {
# Initial request in display or edit mode or a submit of the form
set page_title "One Project"
@@ -22,7 +28,13 @@
set context [list $page_title]
-ad_form -name project_form -cancel_url index -mode $ad_form_mode -form {
+set actions_list [list [list Edit "formbuilder::edit"] [list Done done_button]]
+ad_form -name project_form \
+ -cancel_url index \
+ -mode $ad_form_mode \
+ -actions $actions_list \
+ -form {
+
project_id:key(acs_object_id_seq)
name:text
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.1 -r1.2
--- openacs-4/packages/logger/www/lib/nav-bar.tcl 22 Apr 2003 09:28:13 -0000 1.1
+++ openacs-4/packages/logger/www/lib/nav-bar.tcl 25 Apr 2003 09:50:13 -0000 1.2
@@ -11,7 +11,7 @@
if { [ad_conn user_id] != 0 } {
lappend link_list "${package_url}"
- lappend link_list "My log entries"
+ lappend link_list "Log entries"
}
if { $admin_p } {