Commit 796c022f authored by Project Open's avatar Project Open

Initial commit

parents
Pipeline #1122 failed with stages
intranet-timesheet2-weekly
\ No newline at end of file
<?xml version="1.0"?>
<!-- Generated by the OpenACS Package Manager -->
<package key="intranet-timesheet2-weekly" url="http://openacs.org/repository/apm/packages/intranet-timesheet2-" type="apm_application">
<package-name>]project-open[ Timesheet Weekly</package-name>
<pretty-plural>]project-open[ Timesheet Weekly</pretty-plural>
<initial-install-p>f</initial-install-p>
<singleton-p>t</singleton-p>
<implements-subsite-p>f</implements-subsite-p>
<inherit-templates-p>f</inherit-templates-p>
<auto-mount>intranet-timesheet2-weekly</auto-mount>
<version name="0.1d" url="http://openacs.org/repository/download/apm/intranet-timesheet2-weekly-0.1d.apm">
<owner url="mailto:frank.bergmann@project-open.com">Frank Bergmann</owner>
<summary>Weekly HTML5 timesheet with entry per task</summary>
<vendor url="https://www.project-open.com/">]project-open[ Business Solutions, S.L.</vendor>
<description format="text/plain">Weekly HTML5 timesheet with entry per task</description>
<maturity>0</maturity>
<provides url="intranet-timesheet2-weekly" version="0.1d"/>
<callbacks>
</callbacks>
<parameters>
<!-- No version parameters -->
</parameters>
</version>
</package>
This diff is collapsed.
# /packages/sencha-task-editor/lib/task-editor.tcl
#
# Copyright (C) 2012 ]project-open[
#
# All rights reserved. Please check
# https://www.project-open.com/license/ for details.
# ----------------------------------------------------------------------
#
# ---------------------------------------------------------------------
set current_user_id [ad_conn user_id]
# The following variables are expected in the environment
# defined by the calling /tcl/*.tcl libary:
# project_id
set data_list {}
# project_id may be overwritten by SQLs below
set main_project_id $project_id
im_project_permissions $current_user_id $main_project_id view_p read_p write_p admin_p
# Create a random ID for the task_editor
set task_editor_rand [expr round(rand() * 100000000.0)]
set task_editor_id "task_editor_$task_editor_rand"
# Start and end time for default combo box with time entry options
set time_entry_store_start_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-interval" -parameter TimeEntryStoreStartHour -default "9"]
set time_entry_store_end_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-interval" -parameter TimeEntryStoreEndHour -default "19"]
set week_start_day [parameter::get_from_package_key -package_key "intranet-timesheet2" -parameter WeekStartDay -default 1]
set please_add_note_required_l10n [lang::message::lookup "" intranet-timesheet2-inverval.Please_add_a_note_required "Please add a note (required)"]
# Default material and Unit of Measure: "Default" and "Hour"
set default_material_id [im_material_default_material_id]
set default_cost_center_id [im_cost_center_company]
set default_uom_id [im_uom_hour]
# 9722 = 'Fixed Work' is the default effort_driven_type
set default_effort_driven_type_id [parameter::get_from_package_key -package_key "intranet-ganttproject" -parameter "DefaultEffortDrivenTypeId" -default "9722"]
# Create a debug JSON object that controls logging verbosity
set debug_default "default 0"
set debug_list [parameter::get_from_package_key -package_key "intranet-gantt-editor" -parameter DebugHash -default $debug_default]
array set debug_hash $debug_list
set debug_json_list {}
foreach id [array names debug_hash] { lappend debug_json_list "'$id': $debug_hash($id)" }
set debug_json "{\n\t[join $debug_json_list ",\n\t"]\n}"
-- /packages/intranet-timesheet2-interval/sql/postgres/intranet-timesheet2-interval-create.sql
--
-- Copyright (C) 2014 ]project-open[
--
-- @author frank.bergmann@project-open.com
------------------------------------------------------------
-- Interval Hours
--
-- Start-Stop logging for hours
-- Create a fake object type, because im_hour_interval does not
-- "reference" acs_objects.
select acs_object_type__create_type (
'im_hour_interval', -- object_type
'Timesheet Interval Hour', -- pretty_name
'Timesheet Interval Hour', -- pretty_plural
'acs_object', -- supertype
'im_hour_intervals', -- table_name
'interval_id', -- id_column
null, -- package_name
'f', -- abstract_p
null, -- type_extension_table
'im_hour_interval__name' -- name_method
);
update acs_object_types set
status_type_table = null,
status_column = null,
type_column = null
where object_type = 'im_hour_interval';
-- Sequence to create fake object_ids for im_hour_intervals
create sequence im_hour_intervals_seq;
create table im_hour_intervals (
interval_id integer
default nextval('im_hour_intervals_seq')
constraint im_hour_intervals_pk
primary key,
user_id integer
constraint im_hour_intervals_user_id_nn
not null
constraint im_hour_intervals_user_id_fk
references users,
project_id integer
constraint im_hour_intervals_project_id_nn
not null
constraint im_hour_intervals_project_id_fk
references im_projects,
interval_start timestamptz
constraint im_hour_intervals_interval_start_nn
not null,
interval_end timestamptz
constraint im_hour_intervals_interval_end_nn
not null,
material_id integer
constraint im_hour_intervals_material_fk
references im_materials,
activity_id integer
constraint im_hour_intervals_activity_fk
references im_categories,
note text,
internal_note text
);
-- Unique constraint to avoid that you can add two identical rows
alter table im_hour_intervals
add constraint im_hour_intervals_unique unique (user_id, project_id, interval_start, interval_end);
create index im_hour_intervals_project_id_idx on im_hour_intervals(project_id);
create index im_hour_intervals_user_id_idx on im_hour_intervals(user_id);
create index im_hour_intervals_interval_start_idx on im_hour_intervals(interval_start);
-- ------------------------------------------------------------
-- Trigger for synchronization between intervals and hours
-- ------------------------------------------------------------
-- Create a new im_hour row for the interval or update an existing one.
create or replace function im_hour_interval_update_im_hours (integer, integer, date)
returns integer as $body$
DECLARE
p_user_id alias for $1;
p_project_id alias for $2;
p_day alias for $3;
v_hour_id integer;
v_sum_hours numeric;
v_sum_notes varchar;
row record;
BEGIN
-- Check if there is already an im_hours entry
select h.hour_id into v_hour_id
from im_hours h
where h.user_id = p_user_id and
h.project_id = p_project_id and
h.day = p_day;
-- Create a new entry if there wasnt one before
IF v_hour_id is null THEN
v_hour_id := nextval('im_hours_seq');
RAISE NOTICE 'im_hour_interval_insert_tr: About to insert a new im_hour with ID=%', v_hour_id;
insert into im_hours (
hour_id, user_id, project_id, day, hours, note
) values (
v_hour_id, p_user_id, p_project_id, p_day, 0, ''
);
END IF;
-- Sum up all interval properties into one hour row
v_sum_hours := 0.0;
v_sum_notes := '';
FOR row IN
select *
from im_hour_intervals
where user_id = p_user_id and
project_id = p_project_id and
interval_start::date = p_day
order by interval_id
LOOP
v_sum_hours := v_sum_hours +
coalesce(extract(epoch from row.interval_end - row.interval_start) / 3600.0, 0.0);
IF '' != v_sum_notes THEN
v_sum_notes := v_sum_notes || ', ';
END IF;
v_sum_notes := v_sum_notes ||
to_char(row.interval_start, 'HH24:MI') || '-' ||
to_char(row.interval_end, 'HH24:MI') || ': ' ||
translate(coalesce(row.note, ''), ',:', '.;');
END LOOP;
-- Update the im_hours entry with the sum of the values
update im_hours
set hours = v_sum_hours, note = v_sum_notes
where hour_id = v_hour_id;
return 0;
END;$body$ language 'plpgsql';
create or replace function im_hour_interval_insert_tr ()
returns trigger as $body$
BEGIN
PERFORM im_hour_interval_update_im_hours (new.user_id, new.project_id, new.interval_start::date);
return new;
END;$body$ language 'plpgsql';
create or replace function im_hour_interval_update_tr ()
returns trigger as $body$
BEGIN
PERFORM im_hour_interval_update_im_hours (new.user_id, new.project_id, new.interval_start::date);
IF new.interval_start::date != old.interval_start::date THEN
PERFORM im_hour_interval_update_im_hours (old.user_id, old.project_id, old.interval_start::date);
END IF;
return new;
END;$body$ language 'plpgsql';
create or replace function im_hour_interval_delete_tr ()
returns trigger as $body$
BEGIN
PERFORM im_hour_interval_update_im_hours (old.user_id, old.project_id, old.interval_start::date);
return old;
END;$body$ language 'plpgsql';
create trigger im_hour_interval_insert_tr after insert on im_hour_intervals for each row execute procedure im_hour_interval_insert_tr();
create trigger im_hour_interval_update_tr after update on im_hour_intervals for each row execute procedure im_hour_interval_update_tr();
create trigger im_hour_interval_delete_tr after delete on im_hour_intervals for each row execute procedure im_hour_interval_delete_tr();
-- ------------------------------------------------------------
-- Portlet
-- ------------------------------------------------------------
SELECT im_component_plugin__new (
null, 'im_component_plugin', now(), null, null, null,
'Timesheet Interval', -- plugin_name
'intranet-timesheet2-interval', -- package_name
'top', -- location
'/intranet/projects/view', -- page_url
null, -- view_name
30, -- sort_order
'im_timesheet_interval_portlet -project_id $project_id'
);
-- ------------------------------------------------------------
-- Resource leveling editor
-- ------------------------------------------------------------
SELECT im_menu__new (
null, 'im_menu', now(), null, null, null,
'sencha-task-editor', -- package_name
'resource_leveling_editor', -- label
'Resource Leveling Editor', -- name
'/sencha-task-editor/resource-leveling-editor/resource-leveling-editor', -- url
60, -- sort_order
(select menu_id from im_menus where label = 'resource_management'), -- parent_menu_id
null -- p_visible_tcl
);
SELECT acs_permission__grant_permission(
(select menu_id from im_menus where label = 'resource_leveling_editor'),
(select group_id from groups where group_name = 'Employees'),
'read'
);
-- /packages/intranet-timesheet2-interval/sql/postgres/intranet-timesheet2-interval-drop.sql
--
-- Copyright (C) 2021 ]project-open[
--
-- @author frank.bergmann@project-open.com
-- Drop plugins and menus for the module
--
select im_component_plugin__del_module('intranet-timesheet2-interval');
select im_menu__del_module('intranet-timesheet2-interval');
drop table if exists im_hour_intervals;
drop sequence if exists im_hour_intervals_seq;
drop function if exists im_hour_interval_insert_tr();
drop function if exists im_hour_interval_update_tr();
drop function if exists im_hour_interval_delete_tr();
drop function if exists im_hour_interval_update_im_hours (integer, integer, date);
SELECT acs_object_type__drop_type ('im_hour_interval', 't');
# /packages/intranet-timesheet2-weekly/tcl/intranet-timesheet2-weekly-procs.tcl
#
# Copyright (C) 2014 ]project-open[
#
# All rights reserved. Please check
# https://www.project-open.com/license/ for details.
ad_library {
@author frank.bergmann@project-open.com
}
# ----------------------------------------------------------------------
# Portlets
# ---------------------------------------------------------------------
ad_proc -public im_timesheet_weekly_portlet {
-project_id:required
} {
Returns a HTML code with a Sencha timesheet entry portlet.
} {
# Sencha check and permissions
if {![im_sencha_extjs_installed_p]} { return "" }
set current_user_id [ad_conn user_id]
im_project_permissions $current_user_id $project_id view_p read_p write_p admin_p
if {!$read_p} { return "" }
if {![im_permission $current_user_id add_hours]} { return "" }
im_sencha_extjs_load_libraries
set params [list \
[list project_id $project_id] \
]
set result [ad_parse_template -params $params "/packages/intranet-timesheet2-weekly/lib/timesheet-weekly"]
return [string trim $result]
}
# ---------------------------------------------------------------------
# Permissions
# ---------------------------------------------------------------------
ad_proc -public im_hour_weekly_permissions {user_id weekly_id view_var read_var write_var admin_var} {
Fill the "by-reference" variables read, write and admin
with the permissions of $user_id on $weekly_id.
A user is allowed to see, modify and delete his own
hour_weeklys.
} {
upvar $view_var view
upvar $read_var read
upvar $write_var write
upvar $admin_var admin
set current_user_id $user_id
set view 0
set read 0
set write 0
set admin 0
# Empty or bad weekly_id
if {"" == $weekly_id || ![string is integer $weekly_id]} { return }
# Get cached hour_weekly info
if {![db_0or1row hour_weekly_info "
select *
from im_hour_weeklys i
where i.weekly_id = :weekly_id
"]} {
# Thic can happen if this procedure is called while the hour_weekly hasn't yet been created
ns_log Error "im_hour_weekly_permissions: user_id=$user_id, weekly_id=$weekly_id: weekly_id not found"
return
}
# The owner and administrators can always read and write
if {$current_user_id == $user_id} {
set view 1
set read 1
set write 1
set admin 1
}
}
ad_proc -public im_hour_weekly_nuke {
{-current_user_id ""}
rest_oid
} {
Delete a hour weekly object.
This procedure is called from the intranet-rest interface
after receiving a DELETE HTTP verb
} {
# hour_weekly is not a real object, so we can just delete from the table
db_dml delete_hour_weekly "delete from im_hour_weeklys where weekly_id = :rest_oid"
return $rest_oid
}
This diff is collapsed.
This diff is collapsed.
# /packages/intranet-timesheet2-weekly/timesheet.tcl
#
# Copyright (C) 2012 ]project-open[
#
# All rights reserved. Please check
# https://www.project-open.com/license/ for details.
# ----------------------------------------------------------------------
#
# ---------------------------------------------------------------------
set current_user_id [ad_conn user_id]
im_sencha_extjs_load_libraries
set page_title "Timesheet Logging"
set left_navbar_html "<h1>xxx</h1>"
set left_navbar_html "&nbsp;"
# The following variables are expected in the environment
# defined by the calling /tcl/*.tcl libary:
set data_list {}
# Create a random ID for the task_editor
set task_editor_rand [expr round(rand() * 100000000.0)]
set task_editor_id "task_editor_$task_editor_rand"
# Start and end time for default combo box with time entry options
set time_entry_store_start_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-interval" -parameter TimeEntryStoreStartHour -default "9"]
set time_entry_store_end_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-interval" -parameter TimeEntryStoreEndHour -default "19"]
set week_start_day [parameter::get_from_package_key -package_key "intranet-timesheet2" -parameter WeekStartDay -default 1]
set please_add_note_required_l10n [lang::message::lookup "" intranet-timesheet2-inverval.Please_add_a_note_required "Please add a note (required)"]
# Default material and Unit of Measure: "Default" and "Hour"
set default_material_id [im_material_default_material_id]
set default_cost_center_id [im_cost_center_company]
set default_uom_id [im_uom_hour]
# 9722 = 'Fixed Work' is the default effort_driven_type
set default_effort_driven_type_id [parameter::get_from_package_key -package_key "intranet-ganttproject" -parameter "DefaultEffortDrivenTypeId" -default "9722"]
# Create a debug JSON object that controls logging verbosity
set debug_default "default 0"
set debug_list [parameter::get_from_package_key -package_key "intranet-gantt-editor" -parameter DebugHash -default $debug_default]
array set debug_hash $debug_list
set debug_json_list {}
foreach id [array names debug_hash] { lappend debug_json_list "'$id': $debug_hash($id)" }
set debug_json "{\n\t[join $debug_json_list ",\n\t"]\n}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment