| 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 displaying a list of comments.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::ViewTopicComments;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
use Codestriker::Http::Template;
|
|
|
15 |
use Codestriker::Http::Render;
|
|
|
16 |
use Codestriker::Model::Comment;
|
|
|
17 |
use Codestriker::Model::File;
|
|
|
18 |
|
|
|
19 |
# If the input is valid, list the appropriate comments for a topic.
|
|
|
20 |
sub process($$$) {
|
|
|
21 |
my ($type, $http_input, $http_response) = @_;
|
|
|
22 |
|
|
|
23 |
my $query = $http_response->get_query();
|
|
|
24 |
|
|
|
25 |
# Check that the appropriate fields have been filled in.
|
|
|
26 |
my $topicid = $http_input->get('topic');
|
|
|
27 |
my $email = $http_input->get('email');
|
|
|
28 |
my $mode = $http_input->get('mode');
|
|
|
29 |
my $fview = $http_input->get('fview');
|
|
|
30 |
my $tabwidth = $http_input->get('tabwidth');
|
|
|
31 |
my $feedback = $http_input->get('feedback');
|
|
|
32 |
my $show_context = $http_input->get('scontext');
|
|
|
33 |
my $show_comments_from_user = $http_input->get('sauthor');
|
|
|
34 |
|
|
|
35 |
# Retrieve the filter parameters from the metrics, if any.
|
|
|
36 |
my %metric_filter = ();
|
|
|
37 |
foreach my $comment_state_metric (@{$Codestriker::comment_state_metrics}) {
|
|
|
38 |
my $name = "comment_state_metric_" . $comment_state_metric->{name};
|
|
|
39 |
my $value = $http_input->get($name);
|
|
|
40 |
if (defined $value && $value ne "__any__") {
|
|
|
41 |
$metric_filter{$comment_state_metric->{name}} = $value;
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
# Retrieve the comment details for this topic.
|
|
|
46 |
my @comments =
|
|
|
47 |
Codestriker::Model::Comment->read_filtered($topicid,
|
|
|
48 |
$show_comments_from_user,
|
|
|
49 |
\%metric_filter);
|
|
|
50 |
|
|
|
51 |
# Retrieve the appropriate topic details.
|
|
|
52 |
my $topic = Codestriker::Model::Topic->new($topicid);
|
|
|
53 |
|
|
|
54 |
# Display the data, with each topic title linked to the view topic screen.
|
|
|
55 |
$http_response->generate_header(topic=>$topic,
|
|
|
56 |
comments=>\@comments,
|
|
|
57 |
topic_title=>"Topic Comments: $topic->{title}",
|
|
|
58 |
email=>$email, fview=>$fview,
|
|
|
59 |
tabwidth=>$tabwidth,
|
|
|
60 |
reload=>0, cache=>0);
|
|
|
61 |
|
|
|
62 |
# Create the hash for the template variables.
|
|
|
63 |
my $vars = {};
|
|
|
64 |
$vars->{'feedback'} = $feedback;
|
|
|
65 |
|
|
|
66 |
# Obtain a new URL builder object.
|
|
|
67 |
my $url_builder = Codestriker::Http::UrlBuilder->new($query);
|
|
|
68 |
|
|
|
69 |
Codestriker::Action::ViewTopic::ProcessTopicHeader($vars, $topic,
|
|
|
70 |
$url_builder);
|
|
|
71 |
|
|
|
72 |
# Get the list of users that have put comments in against the
|
|
|
73 |
# comment, and filter if needed.
|
|
|
74 |
my @usersThatHaveComments =
|
|
|
75 |
Codestriker::Model::Comment->read_authors($topicid);
|
|
|
76 |
@usersThatHaveComments = map
|
|
|
77 |
{ Codestriker->filter_email($_) }
|
|
|
78 |
@usersThatHaveComments;
|
|
|
79 |
|
|
|
80 |
# Filter the email address out, in the object.
|
|
|
81 |
foreach my $comment (@comments) {
|
|
|
82 |
$comment->{author} = Codestriker->filter_email($comment->{author});
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
# Go through all the comments and make them into an appropriate form for
|
|
|
86 |
# displaying.
|
|
|
87 |
my $last_filenumber = -999;
|
|
|
88 |
my $last_fileline = -999;
|
|
|
89 |
my $index = 0;
|
|
|
90 |
for (my $i = 0; $i <= $#comments; $i++) {
|
|
|
91 |
my $comment = $comments[$i];
|
|
|
92 |
|
|
|
93 |
if ($comment->{fileline} != $last_fileline ||
|
|
|
94 |
$comment->{filenumber} != $last_filenumber) {
|
|
|
95 |
my $new_file =
|
|
|
96 |
$url_builder->view_file_url($topicid, $comment->{filenumber},
|
|
|
97 |
$comment->{filenew},
|
|
|
98 |
$comment->{fileline}, $mode, 0);
|
|
|
99 |
|
|
|
100 |
$comment->{view_file} = "javascript: myOpen('$new_file','CVS')";
|
|
|
101 |
my $parallel =
|
|
|
102 |
$url_builder->view_file_url($topicid, $comment->{filenumber},
|
|
|
103 |
$comment->{filenew},
|
|
|
104 |
$comment->{fileline}, $mode, 1);
|
|
|
105 |
$comment->{view_parallel} =
|
|
|
106 |
"javascript: myOpen('$parallel','CVS')";
|
|
|
107 |
$comment->{edit_url} =
|
|
|
108 |
"javascript: eo('" . $comment->{filenumber} . "','" .
|
|
|
109 |
$comment->{fileline} . "','" . $comment->{filenew} . "')";
|
|
|
110 |
$comment->{anchor} = $comment->{filenumber} . "|" .
|
|
|
111 |
$comment->{fileline} . "|" . $comment->{filenew};
|
|
|
112 |
|
|
|
113 |
$last_fileline = $comment->{fileline};
|
|
|
114 |
$last_filenumber = $comment->{filenumber};
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
if ($show_context ne "" && $show_context > 0 &&
|
|
|
118 |
$comment->{filenumber} != -1 && $comment->{fileline} != -1) {
|
|
|
119 |
my $delta = Codestriker::Model::Delta->get_delta($topicid,
|
|
|
120 |
$comment->{filenumber},
|
|
|
121 |
$comment->{fileline} ,
|
|
|
122 |
$comment->{filenew});
|
|
|
123 |
|
|
|
124 |
$comment->{context} = Codestriker::Http::Render->get_context(
|
|
|
125 |
$comment->{fileline} ,
|
|
|
126 |
$show_context, 1,
|
|
|
127 |
$delta->{old_linenumber},
|
|
|
128 |
$delta->{new_linenumber},
|
|
|
129 |
$delta->{text},
|
|
|
130 |
$comment->{filenew});
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
# Store the parameters to the template.
|
|
|
135 |
$vars->{'email'} = $email;
|
|
|
136 |
$vars->{'comments'} = \@comments;
|
|
|
137 |
$vars->{'users'} = \@usersThatHaveComments;
|
|
|
138 |
$vars->{'tabwidth'} = $tabwidth;
|
|
|
139 |
|
|
|
140 |
# Push in the current filter combo box selections so the window remembers
|
|
|
141 |
# what the user has currently set.
|
|
|
142 |
$vars->{'scontext'} = $show_context;
|
|
|
143 |
$vars->{'sauthor'} = $http_input->get('sauthor');
|
|
|
144 |
$vars->{'metrics_selection'} = \%metric_filter;
|
|
|
145 |
|
|
|
146 |
# Store the metrics configuration into the template so it knows
|
|
|
147 |
# how to render the dropdowns.
|
|
|
148 |
my @metrics = ();
|
|
|
149 |
foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) {
|
|
|
150 |
my $metric_data = {};
|
|
|
151 |
$metric_data->{name} = $metric_config->{name};
|
|
|
152 |
$metric_data->{values} = $metric_config->{values};
|
|
|
153 |
push @metrics, $metric_data;
|
|
|
154 |
}
|
|
|
155 |
$vars->{'metrics'} = \@metrics;
|
|
|
156 |
|
|
|
157 |
# Store the topic status
|
|
|
158 |
$vars->{'default_state'} = $topic->{topic_state};
|
|
|
159 |
$vars->{'topic_states'} = \@Codestriker::topic_states;
|
|
|
160 |
|
|
|
161 |
# Send the data to the template for rendering.
|
|
|
162 |
my $template = Codestriker::Http::Template->new("viewtopiccomments");
|
|
|
163 |
$template->process($vars);
|
|
|
164 |
|
|
|
165 |
$http_response->generate_footer();
|
|
|
166 |
|
|
|
167 |
# Fire the topic listener to indicate that the user has viewed the topic.
|
|
|
168 |
Codestriker::TopicListeners::Manager::topic_viewed($email, $topic);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
1;
|