| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
|
|
|
3 |
# sits@users.sourceforge.net
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and modify it under
|
|
|
6 |
# the terms of the GPL.
|
|
|
7 |
|
|
|
8 |
# Action object for handling the viewing of a topic.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::ViewTopicInfo;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
use Codestriker::Model::Topic;
|
|
|
15 |
use Codestriker::Model::Comment;
|
|
|
16 |
use Codestriker::Http::UrlBuilder;
|
|
|
17 |
use Codestriker::Http::Render;
|
|
|
18 |
use Codestriker::Repository::RepositoryFactory;
|
|
|
19 |
use HTML::Entities ();
|
|
|
20 |
|
|
|
21 |
# If the input is valid, display the topic.
|
|
|
22 |
sub process($$$) {
|
|
|
23 |
my ($type, $http_input, $http_response) = @_;
|
|
|
24 |
|
|
|
25 |
my $query = $http_response->get_query();
|
|
|
26 |
my $topicid = $http_input->get('topic');
|
|
|
27 |
my $mode = $http_input->get('mode');
|
|
|
28 |
my $tabwidth = $http_input->get('tabwidth');
|
|
|
29 |
my $email = $http_input->get('email');
|
|
|
30 |
my $feedback = $http_input->get('feedback');
|
|
|
31 |
|
|
|
32 |
if (Codestriker::Model::Topic::exists($topicid) == 0) {
|
|
|
33 |
# Topic no longer exists, most likely its been deleted.
|
|
|
34 |
$http_response->error("Topic no longer exists.");
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
# Retrieve the appropriate topic details.
|
|
|
38 |
my $topic = Codestriker::Model::Topic->new($topicid);
|
|
|
39 |
|
|
|
40 |
# Retrieve line-by-line versions of the data and description.
|
|
|
41 |
my @document_description = split /\n/, $topic->{description};
|
|
|
42 |
|
|
|
43 |
# Retrieve the comment details for this topic.
|
|
|
44 |
my @topic_comments = $topic->read_comments();
|
|
|
45 |
|
|
|
46 |
$http_response->generate_header(topic=>$topic,
|
|
|
47 |
topic_title=>"Topic Properties: $topic->{title}",
|
|
|
48 |
mode=>$mode, tabwidth=>$tabwidth,
|
|
|
49 |
reload=>0, cache=>1);
|
|
|
50 |
|
|
|
51 |
# Create the hash for the template variables.
|
|
|
52 |
my $vars = {};
|
|
|
53 |
$vars->{'feedback'} = $feedback;
|
|
|
54 |
|
|
|
55 |
# Obtain a new URL builder object.
|
|
|
56 |
my $url_builder = Codestriker::Http::UrlBuilder->new($query);
|
|
|
57 |
|
|
|
58 |
Codestriker::Action::ViewTopic::ProcessTopicHeader($vars, $topic,
|
|
|
59 |
$url_builder);
|
|
|
60 |
|
|
|
61 |
# Get the metrics configuration. Its important to start from the
|
|
|
62 |
# configuration so that the display matches the order of the config
|
|
|
63 |
# file declaration. Any unknown metric names/values will be appended.
|
|
|
64 |
my @comment_metrics = ();
|
|
|
65 |
my %comment_metric_tally = ();
|
|
|
66 |
my $known_metrics;
|
|
|
67 |
foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) {
|
|
|
68 |
my $metric_data = {};
|
|
|
69 |
$metric_data->{name} = $metric_config->{name};
|
|
|
70 |
$metric_data->{values} = $metric_config->{values};
|
|
|
71 |
foreach my $value (@{ $metric_data->{values} }) {
|
|
|
72 |
$known_metrics->{$metric_config->{name}}->{$value} = 1;
|
|
|
73 |
$comment_metric_tally{$metric_config->{name}}->{$value} = 0;
|
|
|
74 |
}
|
|
|
75 |
$known_metrics->{$metric_config->{name}}->{'__array__'} =
|
|
|
76 |
$metric_config->{values};
|
|
|
77 |
push @comment_metrics, $metric_data;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
# Now tally the metric counts. This code is complicated by having to
|
|
|
81 |
# deal with old metric configurations that no longer mirror the current
|
|
|
82 |
# active configuration. The old values should still be reported.
|
|
|
83 |
my $number_comments = 0;
|
|
|
84 |
my $number_comment_threads = 0;
|
|
|
85 |
my %processed_comment_thread = ();
|
|
|
86 |
foreach my $comment (@topic_comments) {
|
|
|
87 |
if (! exists $processed_comment_thread{$comment->{id}}) {
|
|
|
88 |
$processed_comment_thread{$comment->{id}} = 1;
|
|
|
89 |
$number_comment_threads++;
|
|
|
90 |
|
|
|
91 |
# Go through all the metric values stored in this comment thread.
|
|
|
92 |
foreach my $metric (keys %{ $comment->{metrics} }) {
|
|
|
93 |
my $value = $comment->{metrics}->{$metric};
|
|
|
94 |
$comment_metric_tally{$metric}->{$value}++;
|
|
|
95 |
|
|
|
96 |
# If this is an old metric from an old config, make sure it
|
|
|
97 |
# is included in the config for the final display.
|
|
|
98 |
if (! defined $known_metrics->{$metric}) {
|
|
|
99 |
# Old metric name not in the current config.
|
|
|
100 |
my $metric_data = {};
|
|
|
101 |
$metric_data->{name} = $metric;
|
|
|
102 |
$metric_data->{values} = [ $value ];
|
|
|
103 |
$known_metrics->{$metric}->{$value} = 1;
|
|
|
104 |
$known_metrics->{$metric}->{'__array__'} =
|
|
|
105 |
$metric_data->{values};
|
|
|
106 |
push @comment_metrics, $metric_data;
|
|
|
107 |
} elsif (! defined $known_metrics->{$metric}->{$value}) {
|
|
|
108 |
# Known metric name, unknown value.
|
|
|
109 |
push @{ $known_metrics->{$metric}->{'__array__'} },
|
|
|
110 |
$value;
|
|
|
111 |
$known_metrics->{$metric}->{$value} = 1;
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
$number_comments++;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$vars->{'comment_metrics'} = \@comment_metrics;
|
|
|
119 |
$vars->{'comment_metric_tally'} = \%comment_metric_tally;
|
|
|
120 |
$vars->{'number_comments'} = $number_comments;
|
|
|
121 |
$vars->{'number_comment_threads'} = $number_comment_threads;
|
|
|
122 |
|
|
|
123 |
my @projectids = ($topic->{project_id});
|
|
|
124 |
|
|
|
125 |
$vars->{'view_topic_url'} =
|
|
|
126 |
$url_builder->view_url($topicid, -1, $mode);
|
|
|
127 |
|
|
|
128 |
$vars->{'view_topicinfo_url'} = $url_builder->view_topicinfo_url($topicid);
|
|
|
129 |
$vars->{'view_comments_url'} = $url_builder->view_comments_url($topicid);
|
|
|
130 |
$vars->{'list_projects_url'} = $url_builder->list_projects_url();
|
|
|
131 |
|
|
|
132 |
# Display the "update" message if the topic state has been changed.
|
|
|
133 |
$vars->{'updated'} = $http_input->get('updated');
|
|
|
134 |
$vars->{'rc_ok'} = $Codestriker::OK;
|
|
|
135 |
$vars->{'rc_stale_version'} = $Codestriker::STALE_VERSION;
|
|
|
136 |
$vars->{'rc_invalid_topic'} = $Codestriker::INVALID_TOPIC;
|
|
|
137 |
|
|
|
138 |
if ($topic->{bug_ids} ne "") {
|
|
|
139 |
my @bugs = split ', ', $topic->{bug_ids};
|
|
|
140 |
my $bug_string = "";
|
|
|
141 |
for (my $i = 0; $i <= $#bugs; $i++) {
|
|
|
142 |
$bug_string .=
|
|
|
143 |
$query->a({href=>"$Codestriker::bugtracker$bugs[$i]"},
|
|
|
144 |
$bugs[$i]);
|
|
|
145 |
$bug_string .= ', ' unless ($i == $#bugs);
|
|
|
146 |
}
|
|
|
147 |
$vars->{'bug_string'} = $bug_string;
|
|
|
148 |
} else {
|
|
|
149 |
$vars->{'bug_string'} = "";
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
$vars->{'document_reviewers'} =
|
|
|
153 |
Codestriker->filter_email($topic->{reviewers});
|
|
|
154 |
|
|
|
155 |
# Indicate what projects are available, and what the topic's project is.
|
|
|
156 |
my @projects = Codestriker::Model::Project->list();
|
|
|
157 |
$vars->{'projects'} = \@projects;
|
|
|
158 |
$vars->{'topic_projectid'} = $topic->{project_id};
|
|
|
159 |
|
|
|
160 |
$vars->{'number_of_lines'} = $topic->get_topic_size_in_lines();
|
|
|
161 |
|
|
|
162 |
$vars->{'suggested_topic_size_lines'} =
|
|
|
163 |
$Codestriker::suggested_topic_size_lines eq "" ? 0 :
|
|
|
164 |
$Codestriker::suggested_topic_size_lines;
|
|
|
165 |
|
|
|
166 |
# Prepare the data for displaying the state update option.
|
|
|
167 |
# Make sure the old mode setting is no longer used.
|
|
|
168 |
if ((! defined $mode) || $mode == $Codestriker::NORMAL_MODE) {
|
|
|
169 |
$mode = $Codestriker::COLOURED_MODE;
|
|
|
170 |
}
|
|
|
171 |
$vars->{'mode'} = $mode;
|
|
|
172 |
$vars->{'topic_version'} = $topic->{version};
|
|
|
173 |
$vars->{'states'} = \@Codestriker::topic_states;
|
|
|
174 |
$vars->{'default_state'} = $topic->{state};
|
|
|
175 |
|
|
|
176 |
# Obtain the topic description, with "Bug \d\d\d" links rendered to links
|
|
|
177 |
# to the bug tracking system.
|
|
|
178 |
my $data = "";
|
|
|
179 |
for (my $i = 0; $i <= $#document_description; $i++) {
|
|
|
180 |
$data .= $document_description[$i] . "\n";
|
|
|
181 |
}
|
|
|
182 |
$vars->{'description'} = $data;
|
|
|
183 |
|
|
|
184 |
# Get the topic and user metrics.
|
|
|
185 |
my @topic_metrics = $topic->get_metrics()->get_topic_metrics();
|
|
|
186 |
$vars->{topic_metrics} = \@topic_metrics;
|
|
|
187 |
|
|
|
188 |
my @author_metrics =
|
|
|
189 |
$topic->get_metrics()->get_user_metrics($topic->{author});
|
|
|
190 |
$vars->{author_metrics} = \@author_metrics;
|
|
|
191 |
|
|
|
192 |
my @reviewer_list =
|
|
|
193 |
$topic->get_metrics()->get_list_of_topic_participants();
|
|
|
194 |
|
|
|
195 |
# Remove the author from the list just in case somebody put
|
|
|
196 |
# themselves in twice.
|
|
|
197 |
@reviewer_list = grep { $_ ne $topic->{author} } @reviewer_list;
|
|
|
198 |
|
|
|
199 |
my @reviewer_metrics;
|
|
|
200 |
foreach my $reviewer (@reviewer_list)
|
|
|
201 |
{
|
|
|
202 |
my @user_metrics = $topic->get_metrics()->get_user_metrics($reviewer);
|
|
|
203 |
|
|
|
204 |
# Make a copy, we don't want to modify the names in the
|
|
|
205 |
# list. This is just for the consumption of the html
|
|
|
206 |
# templates.
|
|
|
207 |
my $reviewer_ui_name = $reviewer;
|
|
|
208 |
$reviewer_ui_name = "(unknown user)" if ($reviewer eq "");
|
|
|
209 |
|
|
|
210 |
my $metric =
|
|
|
211 |
{
|
|
|
212 |
reviewer => Codestriker->filter_email($reviewer_ui_name),
|
|
|
213 |
user_metrics => \@user_metrics
|
|
|
214 |
};
|
|
|
215 |
|
|
|
216 |
push @reviewer_metrics, $metric;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
$vars->{reviewer_metrics} = \@reviewer_metrics;
|
|
|
220 |
|
|
|
221 |
my @total_metrics = $topic->get_metrics()->get_user_metrics_totals(
|
|
|
222 |
@reviewer_list, $topic->{author});
|
|
|
223 |
$vars->{total_metrics} = \@total_metrics;
|
|
|
224 |
|
|
|
225 |
my @topic_history = $topic->get_metrics()->get_topic_history();
|
|
|
226 |
$vars->{activity_list} = \@topic_history;
|
|
|
227 |
|
|
|
228 |
my $template = Codestriker::Http::Template->new("viewtopicinfo");
|
|
|
229 |
$template->process($vars);
|
|
|
230 |
|
|
|
231 |
$http_response->generate_footer();
|
|
|
232 |
|
|
|
233 |
# Fire the topic listener to indicate that the user has viewed the topic.
|
|
|
234 |
Codestriker::TopicListeners::Manager::topic_viewed($email, $topic);
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
1;
|