| 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 adding a comment to a topic line.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::EditComment;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
use Codestriker::Model::Topic;
|
|
|
14 |
use Codestriker::Http::Render;
|
|
|
15 |
|
|
|
16 |
# Create an appropriate form for adding a comment to a topic.
|
|
|
17 |
sub process($$$) {
|
|
|
18 |
my ($type, $http_input, $http_response) = @_;
|
|
|
19 |
|
|
|
20 |
# Obtain a new URL builder object.
|
|
|
21 |
my $query = $http_response->get_query();
|
|
|
22 |
my $url_builder = Codestriker::Http::UrlBuilder->new($query);
|
|
|
23 |
|
|
|
24 |
# Retrieve the appropriate input fields.
|
|
|
25 |
my $line = $http_input->get('line');
|
|
|
26 |
my $fn = $http_input->get('fn');
|
|
|
27 |
my $new = $http_input->get('new');
|
|
|
28 |
my $topicid = $http_input->get('topic');
|
|
|
29 |
my $context = $http_input->get('context');
|
|
|
30 |
my $email = $http_input->get('email');
|
|
|
31 |
my $mode = $http_input->get('mode');
|
|
|
32 |
my $tabwidth = $http_input->get('tabwidth');
|
|
|
33 |
my $anchor = $http_input->get('a');
|
|
|
34 |
my $fview = $http_input->get('fview');
|
|
|
35 |
|
|
|
36 |
# Retrieve the appropriate topic details.
|
|
|
37 |
my $topic = Codestriker::Model::Topic->new($topicid);
|
|
|
38 |
|
|
|
39 |
# Retrieve the comment details for this topic.
|
|
|
40 |
my @comments = $topic->read_comments();
|
|
|
41 |
|
|
|
42 |
# Retrieve line-by-line versions of the description.
|
|
|
43 |
my @document_description = split /\n/, $topic->{description};
|
|
|
44 |
|
|
|
45 |
# Display the header of this page.
|
|
|
46 |
$http_response->generate_header(topic=>$topic,
|
|
|
47 |
topic_title=>"Edit Comment: $topic->{title}",
|
|
|
48 |
email=>$email,
|
|
|
49 |
mode=>$mode,
|
|
|
50 |
tabwidth=>$tabwidth,
|
|
|
51 |
repository=>$Codestriker::repository_name_map->{$topic->{repository}},
|
|
|
52 |
reload=>0, cache=>0);
|
|
|
53 |
|
|
|
54 |
# Create the hash for the template variables.
|
|
|
55 |
my $vars = {};
|
|
|
56 |
$vars->{'topic_title'} = $topic->{title};
|
|
|
57 |
|
|
|
58 |
Codestriker::Action::ViewTopic::ProcessTopicHeader($vars, $topic,
|
|
|
59 |
$url_builder, $fview,
|
|
|
60 |
$tabwidth, 1, 0);
|
|
|
61 |
|
|
|
62 |
my $view_topic_url = $url_builder->view_url($topicid, $line, $mode);
|
|
|
63 |
my $view_comments_url = $url_builder->view_comments_url($topicid);
|
|
|
64 |
|
|
|
65 |
$vars->{'view_topic_url'} = $view_topic_url;
|
|
|
66 |
$vars->{'view_comments_url'} = $view_comments_url;
|
|
|
67 |
$vars->{'doc_url'} = $url_builder->doc_url();
|
|
|
68 |
|
|
|
69 |
# Retrieve the context in question. Allow the user to increase it
|
|
|
70 |
# or decrease it appropriately.
|
|
|
71 |
my $inc_context = ($context <= 0) ? 1 : $context*2;
|
|
|
72 |
my $dec_context = ($context <= 0) ? 0 : int($context/2);
|
|
|
73 |
my $inc_context_url =
|
|
|
74 |
$url_builder->edit_url($fn, $line, $new, $topicid,
|
|
|
75 |
$inc_context, $anchor, "");
|
|
|
76 |
my $dec_context_url =
|
|
|
77 |
$url_builder->edit_url($fn, $line, $new, $topicid,
|
|
|
78 |
$dec_context, $anchor, "");
|
|
|
79 |
$vars->{'inc_context_url'} = $inc_context_url;
|
|
|
80 |
$vars->{'dec_context_url'} = $dec_context_url;
|
|
|
81 |
$vars->{'context'} = "";
|
|
|
82 |
if ($line != -1) {
|
|
|
83 |
# Retrieve the context for a comment made against a specific line.
|
|
|
84 |
my $delta = Codestriker::Model::Delta->get_delta($topicid, $fn,
|
|
|
85 |
$line, $new);
|
|
|
86 |
|
|
|
87 |
$vars->{'context'} =
|
|
|
88 |
$query->pre(
|
|
|
89 |
Codestriker::Http::Render->get_context($line,
|
|
|
90 |
$context, 1,
|
|
|
91 |
$delta->{old_linenumber},
|
|
|
92 |
$delta->{new_linenumber},
|
|
|
93 |
$delta->{text},
|
|
|
94 |
$new)) .
|
|
|
95 |
$query->p . "\n";
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
# Display the comments which have been made for this line number
|
|
|
99 |
# in chronological order.
|
|
|
100 |
my @display_comments = ();
|
|
|
101 |
for (my $i = 0; $i <= $#comments; $i++) {
|
|
|
102 |
if ($comments[$i]{fileline} == $line &&
|
|
|
103 |
$comments[$i]{filenumber} == $fn &&
|
|
|
104 |
$comments[$i]{filenew} == $new) {
|
|
|
105 |
my $display_comment = {};
|
|
|
106 |
my $author = $comments[$i]{author};
|
|
|
107 |
$display_comment->{author} = Codestriker->filter_email($author);
|
|
|
108 |
$display_comment->{date} = $comments[$i]{date};
|
|
|
109 |
$display_comment->{data} = $comments[$i]{data};
|
|
|
110 |
$display_comment->{metrics} = $comments[$i]{metrics};
|
|
|
111 |
$display_comment->{line} = "";
|
|
|
112 |
$display_comment->{lineurl} = "";
|
|
|
113 |
$display_comment->{linename} = "";
|
|
|
114 |
$display_comment->{line} = "";
|
|
|
115 |
$display_comment->{lineurl} = "";
|
|
|
116 |
$display_comment->{linename} = "";
|
|
|
117 |
push @display_comments, $display_comment;
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
$vars->{'comments'} = \@display_comments;
|
|
|
121 |
|
|
|
122 |
# Store the metrics associated with this comment, if any. Store the
|
|
|
123 |
# metrics configuration, in addition to the current values set for this
|
|
|
124 |
# comment state, if any.
|
|
|
125 |
my @metrics = ();
|
|
|
126 |
my $current_metrics_for_comment;
|
|
|
127 |
if ($#display_comments > -1) {
|
|
|
128 |
$current_metrics_for_comment = $display_comments[0]->{metrics};
|
|
|
129 |
}
|
|
|
130 |
foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) {
|
|
|
131 |
my $metric_data = {};
|
|
|
132 |
$metric_data->{name} = $metric_config->{name};
|
|
|
133 |
$metric_data->{values} = $metric_config->{values};
|
|
|
134 |
$metric_data->{default_value} = $metric_config->{default_value};
|
|
|
135 |
$metric_data->{current_value} =
|
|
|
136 |
$current_metrics_for_comment->{$metric_config->{name}};
|
|
|
137 |
push @metrics, $metric_data;
|
|
|
138 |
}
|
|
|
139 |
$vars->{'metrics'} = \@metrics;
|
|
|
140 |
|
|
|
141 |
# Populate the form values.
|
|
|
142 |
$vars->{'line'} = $line;
|
|
|
143 |
$vars->{'topic'} = $topicid;
|
|
|
144 |
$vars->{'mode'} = $mode;
|
|
|
145 |
$vars->{'anchor'} = $anchor;
|
|
|
146 |
$vars->{'email'} = $email;
|
|
|
147 |
$vars->{'fn'} = $fn;
|
|
|
148 |
$vars->{'new'} = $new;
|
|
|
149 |
|
|
|
150 |
# Add the "other" reviewers, which is all the reviewers without the
|
|
|
151 |
# address set in $email.
|
|
|
152 |
my @reviewers = split ', ', $topic->{reviewers};
|
|
|
153 |
@reviewers = grep !/^$email$/, @reviewers;
|
|
|
154 |
$vars->{'reviewers'} = \@reviewers;
|
|
|
155 |
|
|
|
156 |
# Display the output via the template.
|
|
|
157 |
my $template = Codestriker::Http::Template->new("editcomment");
|
|
|
158 |
$template->process($vars);
|
|
|
159 |
|
|
|
160 |
$http_response->generate_footer();
|
|
|
161 |
|
|
|
162 |
# Fire the topic listener to indicate that the user has viewed the topic.
|
|
|
163 |
Codestriker::TopicListeners::Manager::topic_viewed($email, $topic);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
1;
|