Commit d9583c01 authored by Frank Bergmann's avatar Frank Bergmann

- Sencha Portfolio Reports:

  - Added a simple Project Timeline chart
parent 0b477182
<if @project_count@ ge 2>
<div id=@diagram_id@></div>
<script type='text/javascript'>
Ext.require(['Ext.chart.*', 'Ext.Window', 'Ext.fx.target.Sprite', 'Ext.layout.container.Fit']);
window.store1 = Ext.create('Ext.data.JsonStore', {
fields: ['x_axis', 'y_axis', 'color', 'diameter', 'caption'],
data: @data_json;noquote@
});
function createHandler(fieldName) {
return function(sprite, record, attr, index, store) {
return Ext.apply(attr, {
radius: record.get('diameter'),
fill: record.get('color')
});
};
}
Ext.onReady(function () {
var fields = [@project_json;noquote@];
chart = new Ext.chart.Chart({
width: @diagram_width@,
height: @diagram_height@,
animate: false,
store: store1,
renderTo: '@diagram_id@',
legend: { position: 'right' },
axes: [{
type: 'Numeric',
position: 'left',
fields: fields,
grid: true
}, {
type: 'Category',
position: 'bottom',
fields: ['date']
}],
series: [{
type: 'area',
axis: 'left',
xField: 'name',
yField: fields,
highlight: true
}]
}
)});
</script>
</if>
# /packages/sencha-reporting-portfolio/lib/project-timeline.tcl
#
# Copyright (C) 2012 ]project-open[
#
# All rights reserved. Please check
# http://www.project-open.com/license/ for details.
# ----------------------------------------------------------------------
#
# ---------------------------------------------------------------------
# The following variables are expected in the environment
# defined by the calling /tcl/*.tcl libary:
# diagram_width
# diagram_height
# diagram_start_date
# diagram_end_date
# diagram_caption
if {"" == $diagram_width} { set diagram_width 1000 }
if {"" == $diagram_height} { set diagram_width 400 }
if {"" == $diagram_start_date} { set diagram_start_date [db_string diagram_start_date "select now()::date - 1000"] }
if {"" == $diagram_end_date} { set diagram_end_date [db_string diagram_end_date "select now()::date + 360"] }
if {"" == $diagram_caption} { set diagram_caption [lang::message::lookup "" sencha-reporting-portfolio.List_of_projects_over_time "Projects Over Time"] }
# Create a random ID for the diagram
set diagram_id "project_timeline_[expr round(rand() * 100000000.0)]"
set x_axis 0
set y_axis 0
set color "yellow"
set diameter 5
set title ""
set workload_sql "
select day.day,
to_char(day.day, 'YYYY-MM') as month,
main_p.project_id,
main_p.project_nr,
main_p.project_name,
abs(coalesce(main_p.end_date::date - main_p.start_date::date, 0.0)) as project_duration_days,
(select coalesce(sum(planned_units * uom_factor), 0.0) / 8.0 from (
select t.planned_units,
CASE WHEN t.uom_id = 321 THEN 8.0 ELSE 1.0 END as uom_factor
from im_projects sub_p,
im_timesheet_tasks t
where sub_p.project_id = t.task_id and
sub_p.tree_sortkey between main_p.tree_sortkey and tree_right(main_p.tree_sortkey)
) t) as estimated_days
from im_projects main_p,
im_day_enumerator(:diagram_start_date, :diagram_end_date) day
where main_p.parent_id is null and
main_p.project_status_id in (select * from im_sub_categories([im_project_status_open])) and
main_p.start_date <= day.day and
main_p.end_date >= day.day and
main_p.end_date > main_p.start_date
"
# ad_return_complaint 1 "<pre>[im_ad_hoc_query $workload_sql]</pre>"
db_foreach workload $workload_sql {
# Fix issues with duration in order to avoid errors...
if {"" == $project_duration_days || $project_duration_days < 1} { set project_duration_days 1 }
# Get the double hash (months -> (project_id -> work))
set v ""
if {[info exists hash($month)]} { set v $hash($month) }
# ps is a hash table project_id -> days of work (of the specific day)
array unset ps
array set ps $v
set p_days 0
if {[info exists ps($project_id)]} { set p_days $ps($project_id) }
set p_days [expr $p_days + $estimated_days / $project_duration_days]
set ps($project_id) $p_days
set hash($month) [array get ps]
# Sum up the work per project
set v 0
if {[info exists project_work_hash($project_id)]} { set v $project_work_hash($project_id) }
set v [expr $v + $estimated_days / $project_duration_days]
set project_work_hash($project_id) $v
# Project Names
set project_name_hash($project_id) $project_name
}
# ad_return_complaint 1 "<pre>[join [array get hash] "\n"]</pre>"
# The list of day
set days [lsort [array names hash]]
set pids [list]
foreach pid [array names project_work_hash] {
set v $project_work_hash($pid)
if {$v > 0} { lappend pids $pid }
}
set pids [lsort $pids]
set project_count [llength $pids]
set data_list [list]
foreach day $days {
array unset ps
array set ps $hash($day)
set data_line "{date: '$day'"
foreach pid $pids {
set v 0.0
if {[info exists ps($pid)]} { set v $ps($pid) }
set v [expr round(1000.0 * $v) / 1000.0]
append data_line ", '$project_name_hash($pid)': $v"
}
append data_line "}"
lappend data_list $data_line
}
set data_json "\[\n"
append data_json [join $data_list ",\n"]
append data_json "\n\]\n"
set project_list [list]
foreach pid $pids {
lappend project_list "'$project_name_hash($pid)'"
}
set project_json [join $project_list ", "]
# ad_return_complaint 1 "<pre>$data_json</pre>"
......@@ -93,3 +93,22 @@ SELECT im_component_plugin__new (
'sencha_milestone_tracker -project_id $project_id -diagram_caption "Milestones" -diagram_width 300 -diagram_height 300'
);
SELECT im_component_plugin__new (
null, -- plugin_id
'im_component_plugin', -- object_type
now(), -- creation_date
null, -- creation_user
null, -- creation_ip
null, -- context_id
'Project Timeline', -- plugin_name
'sencha-reporting-portfolio', -- package_name
'bottom', -- location
'/intranet/index', -- page_url
null, -- view_name
10, -- sort_order
'sencha_project_timeline' -- Portlet TCL
);
......@@ -82,3 +82,36 @@ ad_proc -public sencha_milestone_tracker {
set result [ad_parse_template -params $params "/packages/sencha-reporting-portfolio/lib/milestone-tracker"]
return [string trim $result]
}
ad_proc -public sencha_project_timeline {
{-diagram_width 1000 }
{-diagram_height 400 }
{-diagram_caption "Project Timeline" }
{-diagram_start_date ""}
{-diagram_end_date ""}
} {
Returns a HTML code with a Sencha project timelinediagram.
The timeline shows the resource requirements over time.
} {
# Choose the version and type of the sencha libs
set version "v407"
set ext "ext-all-debug-w-comments.js"
# Make sure the Sencha library is loaded
template::head::add_css -href "/sencha-$version/ext-all.css" -media "screen" -order 1
template::head::add_javascript -src "/sencha-$version/$ext" -order 2
set params [list \
[list diagram_width $diagram_width] \
[list diagram_height $diagram_height] \
[list diagram_caption $diagram_caption] \
[list diagram_start_date $diagram_start_date] \
[list diagram_end_date $diagram_end_date] \
]
set result [ad_parse_template -params $params "/packages/sencha-reporting-portfolio/lib/project-timeline"]
return [string trim $result]
}
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