diff --git a/wp-trac-client/admin-testing.php b/wp-trac-client/admin-testing.php index e7be6fe..9e1a319 100644 --- a/wp-trac-client/admin-testing.php +++ b/wp-trac-client/admin-testing.php @@ -50,10 +50,15 @@ + + + + + diff --git a/wp-trac-client/js/jquery.masonry.min.js b/wp-trac-client/js/jquery.masonry.min.js new file mode 100644 index 0000000..57c081c --- /dev/null +++ b/wp-trac-client/js/jquery.masonry.min.js @@ -0,0 +1,10 @@ +/** + * jQuery Masonry v2.1.08 + * A dynamic layout plugin for jQuery + * The flip-side of CSS Floats + * http://masonry.desandro.com + * + * Licensed under the MIT license. + * Copyright 2012 David DeSandro + */ +(function(e,t,n){"use strict";var r=t.event,i;r.special.smartresize={setup:function(){t(this).bind("resize",r.special.smartresize.handler)},teardown:function(){t(this).unbind("resize",r.special.smartresize.handler)},handler:function(e,t){var n=this,s=arguments;e.type="smartresize",i&&clearTimeout(i),i=setTimeout(function(){r.dispatch.apply(n,s)},t==="execAsap"?0:100)}},t.fn.smartresize=function(e){return e?this.bind("smartresize",e):this.trigger("smartresize",["execAsap"])},t.Mason=function(e,n){this.element=t(n),this._create(e),this._init()},t.Mason.settings={isResizable:!0,isAnimated:!1,animationOptions:{queue:!1,duration:500},gutterWidth:0,isRTL:!1,isFitWidth:!1,containerStyle:{position:"relative"}},t.Mason.prototype={_filterFindBricks:function(e){var t=this.options.itemSelector;return t?e.filter(t).add(e.find(t)):e},_getBricks:function(e){var t=this._filterFindBricks(e).css({position:"absolute"}).addClass("masonry-brick");return t},_create:function(n){this.options=t.extend(!0,{},t.Mason.settings,n),this.styleQueue=[];var r=this.element[0].style;this.originalStyle={height:r.height||""};var i=this.options.containerStyle;for(var s in i)this.originalStyle[s]=r[s]||"";this.element.css(i),this.horizontalDirection=this.options.isRTL?"right":"left";var o=this.element.css("padding-"+this.horizontalDirection),u=this.element.css("padding-top");this.offset={x:o?parseInt(o,10):0,y:u?parseInt(u,10):0},this.isFluid=this.options.columnWidth&&typeof this.options.columnWidth=="function";var a=this;setTimeout(function(){a.element.addClass("masonry")},0),this.options.isResizable&&t(e).bind("smartresize.masonry",function(){a.resize()}),this.reloadItems()},_init:function(e){this._getColumns(),this._reLayout(e)},option:function(e,n){t.isPlainObject(e)&&(this.options=t.extend(!0,this.options,e))},layout:function(e,t){for(var n=0,r=e.length;ngetProxy('ticket'); + $query = $query . '&max=' . $max . '&page=' . $page; + $ids = $proxy->query($query); + return $ids; +} + +/** + * multicall query tickets. + */ +function wptc_ticket_query_m($querys) { + + // preparing the signature. + $signatures = array(); + foreach ($querys as $query) { + $sign = array( + 'methodName' => 'ticket.query', + 'params' => array($query) + ); + array_push($signatures, $sign); + } + // get the system proxy. + $proxy = get_wptc_client()->getProxy('system'); + $results = $proxy->multicall($signatures); + + return $results; +} + /** * return all details about a ticket. * @@ -217,6 +249,22 @@ function wptc_get_ticket_metas($metaName) { return $metas; } +/** + * return the details attributes for the given meta. + * + * @param $metaType the type of metadata: type, milestone, veraion, + * etc. + * @param $metaName the name of the metadata. + * @return the full attributes for the given metadata. + */ +function wptc_get_ticket_meta($metaType, $metaName) { + + $proxy = get_wptc_client()->getProxy('ticket.' . $metaType); + $attrs = $proxy->get($metaName); + + return $attrs; +} + /** * update a milestone of version, create new one if it is not exist. * @@ -287,6 +335,21 @@ function wptc_get_ticket_priorities() { array_combine($prios, $prios)); } +/** + * return all ticket status names, which are defined in the workflow. + * we assume all projects are using the same workflow. + */ +function wptc_get_ticket_status() { + + $status = wptc_get_ticket_metas('status'); + $ret = array(); + foreach($status as $s) { + $s == 'closed' ? array_unshift($ret, $s) : + array_push($ret, $s); + } + return $ret; +} + /** * return all ticket milestone names. * grouped by due-date: future due-date in group Running @@ -318,6 +381,27 @@ function wptc_get_ticket_milestones($project) { $optgroups); } +/** + * return the ticket summary for the gieven milestone. + */ +function wptc_milestone_ticket_summary($milestone) { + + $queryBase = 'milestone=' . $milestone; + $status = wptc_get_ticket_status(); + + foreach ($status as $s) { + $querys[$s] = $queryBase. '&status=' . $s . '&max=0'; + } + + $ids = wptc_ticket_query_m($querys); + foreach($ids as $id) { + $counts[] = count($id[0]); + } + + return array_combine($status, $counts); + //return round(($counts[0] / array_sum($counts)) * 100); +} + /** * retrun all ticket components. */ diff --git a/wp-trac-client/templates/page-tickets.php b/wp-trac-client/templates/page-tickets.php index 0a4c5f1..8a0644b 100644 --- a/wp-trac-client/templates/page-tickets.php +++ b/wp-trac-client/templates/page-tickets.php @@ -8,14 +8,15 @@
+

Project:

+

Ticket Finder

@@ -40,6 +43,12 @@
+ +

Tickets for Version:

+ +
diff --git a/wp-trac-client/widgets.php b/wp-trac-client/widgets.php index 17a59b1..a4472e3 100644 --- a/wp-trac-client/widgets.php +++ b/wp-trac-client/widgets.php @@ -1168,3 +1168,133 @@ function wptc_widget_ticket_defaults() { return $ticket; } + +/** + * Preparing the summary div html for a milestone. + * + */ +function wptc_widget_milestone_summary($milestone) { + + // get all necessary information. + $attrs = wptc_get_ticket_meta('milestone', $milestone); + $tickets = wptc_milestone_ticket_summary($milestone); + $total = array_sum($tickets); + if($total === 0) { + // skip this milestone. + return ""; + } + $percent = round(($tickets['closed'] / $total) * 100); + + $progressTds = ""; + $progressDts = ""; + // get ready the progress bar. using table. + foreach($tickets as $status => $subtotal) { + + $tdPercent = round(($subtotal / $total) * 100); + $tdStyle = $tdPercent < 1 ? + "display: none" : "width: " . $tdPercent . "%"; + $td = << + +EOT; + $progressTds = $progressTds . $td; + + // the summary label for each status. + $dt = "
" . $status . ":
"; + $dt = $dt . "
" . $subtotal . "
"; + $progressDts = $progressDts . $dt; + } + + // total tickets + $dt = "
Total:
" . $total . "
"; + $progressDts = $progressDts . $dt; + + $html = << +

Milestone: {$attrs['name']}

+
+

Due Date: + {$attrs['due']} +

+ + + {$progressTds} + +
+

{$percent}%

+
+
Number of ticket:
+ {$progressDts} +
+
+
+EOT; + + return $html; +} + +/** + * preparing the div html for the project summary page. + */ +function wptc_widget_project_summary($project) { + + // get running milestone for the given project. + $all = wptc_get_ticket_milestones($project); + if (empty($all)) { + return ""; + } + $running = $all['Running (by Due Date)']; + $milestoneDivs = ""; + foreach(array_keys($running) as $milestone) { + $milestoneDivs = $milestoneDivs . + wptc_widget_milestone_summary($milestone); + } + + $div = << +

Project: {$project}

+ {$milestoneDivs} +
+EOT; + + return $div; +} + +/** + * proeparing hte trac home page. + */ +function wptc_widget_trac_homepage() { + + // get all projects. + $projects = wptc_get_projects(); + $projectDivs = ""; + foreach($projects as $project) { + $projectDivs = $projectDivs . + wptc_widget_project_summary($project['name']); + } + + $div = << + {$projectDivs} + + + +EOT; + + return $div; +} diff --git a/wp-trac-client/wp-trac-client.php b/wp-trac-client/wp-trac-client.php index 9237df9..52cf005 100644 --- a/wp-trac-client/wp-trac-client.php +++ b/wp-trac-client/wp-trac-client.php @@ -112,7 +112,11 @@ function register_resources() { 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css'); // javascript for autocomplete. wp_register_script('wptc-autocomplete', - plugins_url('wt-trac-client/js/wptc-autocomplete.js')); + plugins_url('wp-trac-client/js/wptc-autocomplete.js')); + // js lib for jQuery masonry. + wp_register_script('jquery-masonry', + plugins_url('wp-trac-client/js/jquery.masonry.min.js'), + array('jquery'), '2.1.08'); } function get_wptc_client() {