Index: openacs-4/packages/logger/logger.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/logger.info,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/logger.info 22 Apr 2003 09:23:48 -0000 1.2 +++ openacs-4/packages/logger/logger.info 25 Apr 2003 09:44:30 -0000 1.3 @@ -14,10 +14,14 @@ 2003-04-16 Collaboraid - + + + + + Index: openacs-4/packages/logger/sql/oracle/logger-packages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-packages-create.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/logger/sql/oracle/logger-packages-create.sql 6 Apr 2003 09:26:18 -0000 1.3 +++ openacs-4/packages/logger/sql/oracle/logger-packages-create.sql 25 Apr 2003 09:45:15 -0000 1.4 @@ -13,15 +13,15 @@ as function new ( project_id in integer default null, - name in cr_revisions.title%TYPE, - description in cr_revisions.description%TYPE default null, + name in logger_projects.name%TYPE, + description in logger_projects.description%TYPE default null, project_lead in integer, creation_user in acs_objects.creation_user%TYPE, creation_ip in acs_objects.creation_ip%TYPE default null, package_id in apm_packages.package_id%TYPE ) return integer; - procedure delete ( + procedure del ( project_id in integer ); @@ -33,28 +33,52 @@ / show errors; -create or replace package logger_measurement +create or replace package logger_variable as function new ( - measurement_id in logger_measurements.measurement_id%TYPE default null, - project_id in logger_measurements.project_id%TYPE, - variable_id in logger_measurements.variable_id%TYPE, - value in logger_measurements.value%TYPE, - time_stamp in logger_measurements.time_stamp%TYPE, - description in logger_measurements.description%TYPE default null, + variable_id in integer default null, + name in logger_variables.name%TYPE, + unit in logger_variables.unit%TYPE, + type in logger_variables.type%TYPE, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE default null, + package_id in apm_packages.package_id%TYPE + ) return integer; + + procedure del ( + variable_id in integer + ); + + function name ( + variable_id in integer + ) return varchar2; + +end logger_variable; +/ +show errors; + +create or replace package logger_entry +as + function new ( + entry_id in logger_entries.entry_id%TYPE default null, + project_id in logger_entries.project_id%TYPE, + variable_id in logger_entries.variable_id%TYPE, + value in logger_entries.value%TYPE, + time_stamp in logger_entries.time_stamp%TYPE, + description in logger_entries.description%TYPE default null, creation_user in acs_objects.creation_user%TYPE, creation_ip in acs_objects.creation_ip%TYPE default null ) return integer; - procedure delete ( - measurement_id in integer + procedure del ( + entry_id in integer ); function name ( - measurement_id in integer + entry_id in integer ) return varchar2; -end logger_measurement; +end logger_entry; / show errors; @@ -66,8 +90,8 @@ as function new ( project_id in integer default null, - name in cr_revisions.title%TYPE, - description in cr_revisions.description%TYPE default null, + name in logger_projects.name%TYPE, + description in logger_projects.description%TYPE default null, project_lead in integer, creation_user in acs_objects.creation_user%TYPE, creation_ip in acs_objects.creation_ip%TYPE default null, @@ -93,41 +117,41 @@ return v_project_id; end new; - procedure delete ( + procedure del ( project_id in integer ) is begin - -- Delete all measurements in the project - for rec in (select measurement_id - from logger_measurements - where project_id = logger_project.delete.project_id + -- Delete all entries in the project + for rec in (select entry_id + from logger_entries + where project_id = logger_project.del.project_id ) loop - logger_measurement.delete(rec.measurement_id); + logger_entry.del(rec.entry_id); end loop; -- Delete all variables only mapped to this project. for rec in (select variable_id from logger_variables where exists (select 1 from logger_project_pkg_map - where project_id = logger_project.delete.project_id + where project_id = logger_project.del.project_id ) and not exists (select 1 from logger_project_pkg_map - where project_id <> logger_project.delete.project_id + where project_id <> logger_project.del.project_id ) ) loop - delete from logger_variables where variable_id = rec.variable_id; + logger_variable.del(rec.variable_id); end loop; -- Delete the project acs object. This will cascade the row in the logger_projects table -- as well as all projections in the project acs_object.delete(project_id); - end delete; + end del; function name ( project_id in integer @@ -147,60 +171,115 @@ / show errors; -create or replace package body logger_measurement +create or replace package body logger_variable as function new ( - measurement_id in logger_measurements.measurement_id%TYPE default null, - project_id in logger_measurements.project_id%TYPE, - variable_id in logger_measurements.variable_id%TYPE, - value in logger_measurements.value%TYPE, - time_stamp in logger_measurements.time_stamp%TYPE, - description in logger_measurements.description%TYPE default null, + variable_id in integer default null, + name in logger_variables.name%TYPE, + unit in logger_variables.unit%TYPE, + type in logger_variables.type%TYPE, + creation_user in acs_objects.creation_user%TYPE, + creation_ip in acs_objects.creation_ip%TYPE default null, + package_id in apm_packages.package_id%TYPE + ) return integer + is + v_variable_id integer; + begin + v_variable_id := acs_object.new( + object_id => variable_id, + object_type => 'logger_variable', + context_id => package_id, + creation_ip => creation_ip, + creation_user => creation_user + ); + + insert into logger_variables (variable_id, name, unit, type, package_id) + values (v_variable_id, name, unit, type, package_id); + + return v_variable_id; + end new; + + procedure del ( + variable_id in integer + ) + is + begin + -- Everything should be set up to cascade + acs_object.delete(variable_id); + end del; + + function name ( + variable_id in integer + ) return varchar2 + is + v_name logger_projects.name%TYPE; + begin + select name + into v_name + from logger_variables + where variable_id = name.variable_id; + + return v_name; + end name; + +end logger_variable; +/ +show errors; + +create or replace package body logger_entry +as + function new ( + entry_id in logger_entries.entry_id%TYPE default null, + project_id in logger_entries.project_id%TYPE, + variable_id in logger_entries.variable_id%TYPE, + value in logger_entries.value%TYPE, + time_stamp in logger_entries.time_stamp%TYPE, + description in logger_entries.description%TYPE default null, creation_user in acs_objects.creation_user%TYPE, creation_ip in acs_objects.creation_ip%TYPE default null ) return integer is - v_measurement_id integer; + v_entry_id integer; begin - v_measurement_id := acs_object.new( - object_id => measurement_id, - object_type => 'logger_measurement', + v_entry_id := acs_object.new( + object_id => entry_id, + object_type => 'logger_entry', context_id => project_id, creation_ip => creation_ip, creation_user => creation_user ); - insert into logger_measurements (measurement_id, project_id, variable_id, value, + insert into logger_entries (entry_id, project_id, variable_id, value, time_stamp, description) - values (v_measurement_id, project_id, variable_id, value, time_stamp, description); + values (v_entry_id, project_id, variable_id, value, time_stamp, description); - return v_measurement_id; + return v_entry_id; end new; - procedure delete ( - measurement_id in integer + procedure del ( + entry_id in integer ) is begin - -- The row in the measurements table will cascade - acs_object.delete(measurement_id); - end delete; + -- The row in the entries table will cascade + acs_object.delete(entry_id); + end del; function name ( - measurement_id in integer + entry_id in integer ) return varchar2 is v_name logger_projects.name%TYPE; begin -- TODO: Should we only return the say 20 first characters here? select description into v_name - from logger_measurements - where measurement_id = logger_measurement.name.measurement_id; + from logger_entries + where entry_id = logger_entry.name.entry_id; return v_name; end name; -end logger_measurement; +end logger_entry; / show errors; Index: openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql 6 Apr 2003 08:02:45 -0000 1.2 +++ openacs-4/packages/logger/sql/oracle/logger-packages-drop.sql 25 Apr 2003 09:45:15 -0000 1.3 @@ -5,6 +5,8 @@ -- @author Peter Marklund (peter@collaboraid.biz) -- @creation-date 2003-03-28 -drop package logger_measurement; +drop package logger_entry; +drop package logger_variable; + drop package logger_project; Index: openacs-4/packages/logger/sql/oracle/logger-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-tables-create.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/logger/sql/oracle/logger-tables-create.sql 22 Apr 2003 09:24:47 -0000 1.4 +++ openacs-4/packages/logger/sql/oracle/logger-tables-create.sql 25 Apr 2003 09:45:15 -0000 1.5 @@ -74,7 +74,10 @@ create table logger_variables ( variable_id integer constraint logger_variables_pk - primary key, + primary key + constraint logger_variables_pid_fk + references acs_objects(object_id) + on delete cascade, name varchar(200), unit varchar(200), type varchar(50) @@ -89,7 +92,7 @@ ); comment on column logger_variables.type is ' - Indicates if measurements of this variable should be added together or not. + Indicates if entries of this variable should be added together or not. Examples of additive variables are time and money spent at different times during a project. A non-additive variable would be the amount of money in a bank account. '; @@ -98,7 +101,23 @@ The id of the package that the variable was created in. '; -create sequence logger_variables_seq; +-- We make variables acs objects to be able to use permissions +begin + acs_object_type.create_type ( + 'logger_variable', + 'Logger variable', + 'Logger variables', + 'acs_object', + 'logger_variables', + 'variable_id', + null, + 'f', + null, + 'logger_variable.name' + ); +end; +/ +show errors create table logger_project_var_map ( project_id integer @@ -163,38 +182,38 @@ comment on column logger_projections.value is ' For additive variables the projection value will represent the expected or targeted - sum of measurements during the time range and for non-additive variables it will + sum of entries during the time range and for non-additive variables it will represent an average. '; create sequence logger_projections_seq; -create table logger_measurements ( - measurement_id integer - constraint logger_measurements_pk +create table logger_entries ( + entry_id integer + constraint logger_entries_pk primary key - constraint logger_measurements_mid_fk + constraint logger_entries_mid_fk references acs_objects(object_id) on delete cascade, project_id integer - constraint logger_measurements_pid_fk + constraint logger_entries_pid_fk references acs_objects(object_id) on delete cascade, variable_id integer - constraint logger_measurements_v_id_fk + constraint logger_entries_v_id_fk references logger_variables(variable_id) on delete cascade, value number - constraint logger_measurements_value_nn + constraint logger_entries_value_nn not null, time_stamp date default sysdate - constraint logger_measurements_ts_nn + constraint logger_entries_ts_nn not null, description varchar(4000) ); -comment on table logger_measurements is ' +comment on table logger_entries is ' This is the center piece of the logger datamodel that holds the actually reported data - namely numbers bound to points in time. Given the HR-XML Time and Reporting standard (see http://www.hr-xml.org) we considered allowing @@ -207,20 +226,20 @@ much difficulty. '; --- Measurments need to be acs objects if we are to categorize the with the categories +-- Entries need to be acs objects if we are to categorize the with the categories -- package begin acs_object_type.create_type ( - 'logger_measurement', - 'Logger measurement', - 'Logger measurements', + 'logger_entry', + 'Logger entry', + 'Logger entries', 'acs_object', - 'logger_measurements', - 'measurement_id', + 'logger_entries', + 'entry_id', null, 'f', null, - 'logger_measurement.name' + 'logger_entry.name' ); end; / Index: openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql 6 Apr 2003 08:02:45 -0000 1.3 +++ openacs-4/packages/logger/sql/oracle/logger-tables-drop.sql 25 Apr 2003 09:45:15 -0000 1.4 @@ -8,11 +8,11 @@ -- @author Peter Marklund (peter@collaboraid.biz) -- @creation-date 3:d of April 2003 -drop table logger_measurements; +drop table logger_entries; begin acs_object_type.drop_type ( - 'logger_measurement' + 'logger_entry' ); end; / @@ -26,7 +26,13 @@ drop table logger_variables; -drop sequence logger_variables_seq; +begin + acs_object_type.drop_type ( + 'logger_variable' + ); +end; +/ +show errors drop table logger_project_pkg_map; Index: openacs-4/packages/logger/sql/postgresql/logger-packages-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/postgresql/logger-packages-create.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/sql/postgresql/logger-packages-create.sql 8 Apr 2003 12:12:40 -0000 1.1 +++ openacs-4/packages/logger/sql/postgresql/logger-packages-create.sql 25 Apr 2003 09:45:49 -0000 1.2 @@ -41,13 +41,13 @@ declare project_id alias for $1; begin - -- Delete all measurements in the project - for rec in (select measurement_id - from logger_measurements + -- Delete all entries in the project + for rec in (select entry_id + from logger_entries where project_id = logger_project.delete.project_id ) loop - logger_measurement.delete(rec.measurement_id); + logger_entry.delete(rec.entry_id); end loop; -- Delete all variables only mapped to this project. @@ -86,10 +86,10 @@ return v_name; end; ' language 'plpgsql'; -create function logger_measurement__new (integer, integer, integer, integer, date, varchar, integer, varchar, integer) +create function logger_entry__new (integer, integer, integer, integer, date, varchar, integer, varchar, integer) returns integer as ' declare - measurement_id alias for $1; -- default null + entry_id alias for $1; -- default null project_id alias for $2; variable_id alias for $3; value alias for $4; @@ -98,41 +98,41 @@ creation_user alias for $7; creation_ip alias for $8; -- default null - v_measurement_id integer; + v_entry_id integer; begin - v_measurement_id := acs_object__new( - measurement_id, - ''logger_measurement'', + v_entry_id := acs_object__new( + entry_id, + ''logger_entry'', project_id, creation_ip, creation_user ); - insert into logger_measurements (measurement_id, project_id, variable_id, value, + insert into logger_entries (entry_id, project_id, variable_id, value, time_stamp, description) - values (v_measurement_id, project_id, variable_id, value, time_stamp, description); + values (v_entry_id, project_id, variable_id, value, time_stamp, description); - return v_measurement_id; + return v_entry_id; end; ' language 'plpgsql'; -create function logger_measurement__delete (integer) +create function logger_entry__delete (integer) returns integer as ' declare - measurement_id alias for $1; -- default null + entry_id alias for $1; -- default null begin - -- The row in the measurements table will cascade - acs_object.delete(measurement_id); + -- The row in the entries table will cascade + acs_object.delete(entry_id); end; ' language 'plpgsql'; -create function logger_measurement__name (integer) +create function logger_entry__name (integer) returns varchar as ' declare v_name logger_projects.name%TYPE; begin -- TODO: Should we only return the say 20 first characters here? select description into v_name - from logger_measurements - where measurement_id = logger_measurement.name.measurement_id; + from logger_entries + where entry_id = logger_entry.name.entry_id; return v_name; end; ' language 'plpgsql'; Index: openacs-4/packages/logger/sql/postgresql/logger-packages-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/postgresql/logger-packages-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/sql/postgresql/logger-packages-drop.sql 8 Apr 2003 12:12:40 -0000 1.1 +++ openacs-4/packages/logger/sql/postgresql/logger-packages-drop.sql 25 Apr 2003 09:45:49 -0000 1.2 @@ -8,6 +8,6 @@ drop function logger_project__new (integer, varchar, varchar, integer, integer, varchar, integer) ; drop function logger_project__delete (integer) ; drop function logger_project__name (integer) ; -drop function logger_measurement__new (integer, integer, integer, integer, date, varchar, integer, varchar, integer) ; -drop function logger_measurement__delete (integer) ; -drop function logger_measurement__name (integer) ; +drop function logger_entry__new (integer, integer, integer, integer, date, varchar, integer, varchar, integer) ; +drop function logger_entry__delete (integer) ; +drop function logger_entry__name (integer) ; Index: openacs-4/packages/logger/sql/postgresql/logger-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/postgresql/logger-tables-create.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/sql/postgresql/logger-tables-create.sql 8 Apr 2003 12:12:40 -0000 1.1 +++ openacs-4/packages/logger/sql/postgresql/logger-tables-create.sql 25 Apr 2003 09:45:49 -0000 1.2 @@ -90,7 +90,7 @@ ); comment on column logger_variables.type is ' - Indicates if measurements of this variable should be added together or not. + Indicates if entries of this variable should be added together or not. Examples of additive variables are time and money spent at different times during a project. A non-additive variable would be the amount of money in a bank account. '; @@ -160,38 +160,38 @@ comment on column logger_projections.value is ' For additive variables the projection value will represent the expected or targeted - sum of measurements during the time range and for non-additive variables it will + sum of entries during the time range and for non-additive variables it will represent an average. '; create sequence logger_projections_seq; -create table logger_measurements ( - measurement_id integer - constraint logger_measurements_pk +create table logger_entries ( + entry_id integer + constraint logger_entries_pk primary key - constraint logger_measurements_mid_fk + constraint logger_entries_mid_fk references acs_objects(object_id) on delete cascade, project_id integer - constraint logger_measurements_pid_fk + constraint logger_entries_pid_fk references acs_objects(object_id) on delete cascade, variable_id integer - constraint logger_measurements_v_id_fk + constraint logger_entries_v_id_fk references logger_variables(variable_id) on delete cascade, value integer - constraint logger_measurements_value_nn + constraint logger_entries_value_nn not null, time_stamp date default now () - constraint logger_measurements_ts_nn + constraint logger_entries_ts_nn not null, description varchar(4000) ); -comment on table logger_measurements is ' +comment on table logger_entries is ' This is the center piece of the logger datamodel that holds the actually reported data - namely numbers bound to points in time. Given the HR-XML Time and Reporting standard (see http://www.hr-xml.org) we considered allowing @@ -204,22 +204,22 @@ much difficulty. '; --- Measurements need to be acs objects if we are to categorize the with the categories +-- Entries need to be acs objects if we are to categorize the with the categories -- package create function inline_0 () returns integer as ' begin PERFORM acs_object_type__create_type ( - ''logger_measurement'', -- object_type - ''Logger measurement'', -- pretty_name - ''Logger measurements'', -- pretty_plural + ''logger_entry'', -- object_type + ''Logger entry'', -- pretty_name + ''Logger entries'', -- pretty_plural ''acs_object'', -- supertype - ''logger_measurements'', -- table_name - ''measurement_id'', -- id_column + ''logger_entries'', -- table_name + ''entry_id'', -- id_column null, -- package_name ''f'', -- abstract_p null, -- type_extension_table - ''logger_measurement.name'' -- name_method + ''logger_entry.name'' -- name_method ); return 0; end;' language 'plpgsql'; Index: openacs-4/packages/logger/sql/postgresql/logger-tables-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/sql/postgresql/logger-tables-drop.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/sql/postgresql/logger-tables-drop.sql 8 Apr 2003 12:12:40 -0000 1.1 +++ openacs-4/packages/logger/sql/postgresql/logger-tables-drop.sql 25 Apr 2003 09:45:49 -0000 1.2 @@ -8,13 +8,13 @@ -- @author Peter Marklund (peter@collaboraid.biz) -- @creation-date 3:d of April 2003 -drop table logger_measurements; +drop table logger_entries; create function inline_0 () returns integer as ' begin perform acs_object_type__drop_type ( - ''logger_measurement'', ''f'' + ''logger_entry'', ''f'' ); return null; Index: openacs-4/packages/logger/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/apm-callback-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/tcl/apm-callback-procs.tcl 5 Apr 2003 10:16:42 -0000 1.1 +++ openacs-4/packages/logger/tcl/apm-callback-procs.tcl 25 Apr 2003 09:47:11 -0000 1.2 @@ -8,6 +8,17 @@ namespace eval logger::apm {} +ad_proc -public logger::apm::after_install {} { + The Logger application is primarily intended for time and expenses reporting + so lets create those variables so that they don't need to be setup manually + + @author Peter Marklund +} { + logger::variable::new -name "Time" -unit "hours" -pre_installed_p 1 + + logger::variable::new -name "Expense" -unit "Euro" -pre_installed_p 1 +} + ad_proc -public logger::apm::before_uninstantiate { {-package_id:required} } { Index: openacs-4/packages/logger/tcl/entry-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/entry-procs-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/entry-procs-oracle.xql 25 Apr 2003 09:47:11 -0000 1.1 @@ -0,0 +1,31 @@ + + + + oracle8.1.6 + + + + begin + :1 := logger_entry.new ( + entry_id => :entry_id, + project_id => :project_id, + variable_id => :variable_id, + value => :value, + time_stamp => :time_stamp, + description => :description, + creation_user => :creation_user, + creation_ip => :creation_ip + ); + end; + + + + + + begin + logger_entry.del(:entry_id); + end; + + + + 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/logger/tcl/entry-procs.tcl 25 Apr 2003 09:47:11 -0000 1.1 @@ -0,0 +1,102 @@ +ad_library { + Procedures in the logger::entry namespace. Those procedures + operate on logger entry objects. + + @creation-date 4:th of April 2003 + @author Peter Marklund (peter@collaboraid.biz) + @cvs-id $Id: entry-procs.tcl,v 1.1 2003/04/25 09:47:11 peterm Exp $ +} + +namespace eval logger::entry {} + +ad_proc -public logger::entry::new { + {-entry_id ""} + {-project_id:required} + {-variable_id:required} + {-value:required} + {-time_stamp:required} + {-description ""} +} { +

+ Create a logger entry. +

+ +

+ 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 @@ + + + + + + + select entry_id, + project_id, + variable_id, + value, + time_stamp, + description + from logger_entries + where entry_id = :entry_id + + + + + + update logger_entries + set value = :value, + time_stamp = :time_stamp, + description = :description + where entry_id = :entry_id + + + + Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/logger/tcl/measurement-procs-oracle.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/logger/tcl/measurement-procs.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/logger/tcl/measurement-procs.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/logger/tcl/package-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/package-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/logger/tcl/package-procs.tcl 22 Apr 2003 09:25:40 -0000 1.2 +++ openacs-4/packages/logger/tcl/package-procs.tcl 25 Apr 2003 09:47:11 -0000 1.3 @@ -55,7 +55,9 @@ } { Executes a db_multirow that returns all variables created in the current package and all variables mapped to projects - in the current package. + in the current package. Also returns the default variables + that come with the installation of the Logger - Time and Expense + (created in no particular package instance). @param not_in_project_id Exclude variables already mapped to the given project_id. Index: openacs-4/packages/logger/tcl/project-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/project-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/logger/tcl/project-procs.tcl 22 Apr 2003 09:25:40 -0000 1.3 +++ openacs-4/packages/logger/tcl/project-procs.tcl 25 Apr 2003 09:47:11 -0000 1.4 @@ -36,16 +36,7 @@ @author Peter Marklund } { # Use ad_conn to initialize variables - # The lists are on the following array format - # var_name1 ad_conn_arg_name1 var_name2 ad_conn_arg_name2 ... - set ad_conn_vars [list package_id package_id creation_user user_id creation_ip peeraddr] - if { [ad_conn isconnected] } { - foreach {var_name ad_conn_name} $ad_conn_vars { - set $var_name [ad_conn $ad_conn_name] - } - } else { - error "logger::project::new - this proc requires an ad_conn connection" - } + logger::util::set_vars_from_ad_conn {package_id creation_user creation_ip} # Project lead defaults to creation user if { [empty_string_p $project_lead] } { @@ -85,7 +76,7 @@ ad_proc -public logger::project::delete { {-project_id:required} } { - Delete a logger project and all logger measurements and projections + Delete a logger project and all logger entries and projections contained within it. Also deletes all logger variables mapped to this project that are not mapped to other projects. Index: openacs-4/packages/logger/tcl/variable-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/variable-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/logger/tcl/variable-procs.tcl 22 Apr 2003 09:25:40 -0000 1.3 +++ openacs-4/packages/logger/tcl/variable-procs.tcl 25 Apr 2003 09:47:11 -0000 1.4 @@ -14,8 +14,9 @@ {-name:required} {-unit:required} {-type "additive"} + {-pre_installed_p 0} } { - Create a new variable to use for logger measurements. The + Create a new variable to use for logger entries. The variable can be tied to logger projects through the logger::project::add_variable proc. @@ -24,22 +25,25 @@ @param unit The unit of the variable, for example hours, minutes, or a currency code such as USD or EUR. @param type Must be either additive (default) or non-additive. + @param pre_installed_p Indicates whether this is a variable that is comes pre-installed + with the logger application (1) or not (0). Default is 0. @return The id of the created variable. @author Peter Marklund } { ad_assert_arg_value_in_list type {additive non-additive} - # Default variable_id to next id in a sequence - if { [empty_string_p $variable_id] } { - set variable_id [db_nextval logger_variables_seq] + # Use ad_conn to initialize variables + logger::util::set_vars_from_ad_conn {package_id creation_user creation_ip} + + if { $pre_installed_p } { + # Pre-installed vars are not associated with any particular package + set package_id [db_null] } - set package_id [ad_conn package_id] + db_exec_plsql insert_variable {} - db_dml insert_variable {} - return $variable_id } @@ -78,7 +82,7 @@ @author Peter Marklund } { - db_dml delete_variable {} + db_exec_plsql delete_variable {} } ad_proc -public logger::variable::get { Index: openacs-4/packages/logger/tcl/test/logger-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/tcl/test/logger-test-init.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/logger/tcl/test/logger-test-init.tcl 8 Apr 2003 12:13:46 -0000 1.4 +++ openacs-4/packages/logger/tcl/test/logger-test-init.tcl 25 Apr 2003 09:47:47 -0000 1.5 @@ -9,7 +9,7 @@ aa_register_case logger_create_package { Test creation and deletion of logger package along with a project, - a few measurements, and other logger data. + a few entries, and other logger data. @author Peter Marklund } { @@ -41,7 +41,7 @@ set projection_start_time "2003-04-10" set projection_end_time "2003-04-20" set projection_value "10" - array set hour_measurement_1 { + array set hour_entry_1 { value 11 time_stamp "2003-04-15" description "I worked on the time logger" @@ -122,16 +122,16 @@ $projection_value # Create mesurements - set hour_measurement_1_id [logger::measurement::new -project_id $project_id \ + set hour_entry_1_id [logger::entry::new -project_id $project_id \ -variable_id $hours_var_id \ - -value $hour_measurement_1(value) \ - -time_stamp $hour_measurement_1(time_stamp) \ - -description $hour_measurement_1(description)] + -value $hour_entry_1(value) \ + -time_stamp $hour_entry_1(time_stamp) \ + -description $hour_entry_1(description)] - # Check that measurements are retrievable - logger::measurement::get -measurement_id $hour_measurement_1_id -array hour_measurement_1_retr - aa_equals "Value of measurements is retrievable" $hour_measurement_1_retr(value) \ - $hour_measurement_1(value) + # Check that entries are retrievable + logger::entry::get -entry_id $hour_entry_1_id -array hour_entry_1_retr + aa_equals "Value of entries is retrievable" $hour_entry_1_retr(value) \ + $hour_entry_1(value) # Add a test category tree # TODO when the categories package is stabilized Index: openacs-4/packages/logger/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/logger/www/index.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/logger/www/index.adp 22 Apr 2003 09:26:17 -0000 1.1 +++ openacs-4/packages/logger/www/index.adp 25 Apr 2003 09:48:37 -0000 1.2 @@ -2,71 +2,128 @@ Logger Application - - +
- -
- + + +

Filter

+ -

- Projects + Projects show all

- @projects.name@ log + + @projects.name@ + + + @projects.name@ + + +
-
- + + + + + - - There are no matching log entries - - -
+

+ Variables +

+
+ - - - - - + - - - - - - - - -
TimeValueVariableDescription  + + @variables.name@ (@variables.unit@) + + + @variables.name@ (@variables.unit@) + + + + + + +
@measurements.time_stamp@@measurements.value@@measurements.variable_name@ (@measurements.unit@)@measurements.description@[ Edit ]
- +
+ + + - - - + + + + + Project: + @selected_project_name@
+
+ + Projects: + All
+
+ + + Variable: + @selected_variable_name@ + +
+ + + There are no matching log entries + + + + + + + + + + + + + + + + + + + + + + + + + +
 ProjectDateVariableValueDescription
@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.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 } {