[Codestriker-commits] CVS update: codestriker/lib/Codestriker/Action Search.pm ViewTopicComments.pm
Brought to you by:
sits
From: <si...@us...> - 2008-08-31 11:45:07
|
User: sits Date: 08/08/31 04:45:05 Modified: t/Http/Method view-topic-comments.t view-topic-metrics.t lib/Codestriker/Http Dispatcher.pm UrlBuilder.pm lib/Codestriker/Http/Method AddProjectMethod.pm DownloadTopicTextMethod.pm ListProjectsMethod.pm ViewTopicMetricsMethod.pm UpdateTopicMetricsMethod.pm SearchTopicsMethod.pm SubmitSearchTopicsMethod.pm DownloadMetricsMethod.pm ViewMetricsMethod.pm CreateProjectMethod.pm ViewTopicCommentsMethod.pm template/en/default viewtopiccomments.html.tmpl search.html.tmpl lib/Codestriker/Action Search.pm ViewTopicComments.pm Added: t/Http/Method update-comment-metrics.t lib/Codestriker/Http/Method UpdateCommentMetricsMethod.pm Log: A lot of the system now works with the new URL style. Index: view-topic-comments.t =================================================================== RCS file: /cvsroot/codestriker/codestriker/t/Http/Method/view-topic-comments.t,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view-topic-comments.t 10 Aug 2008 12:18:42 -0000 1.1 +++ view-topic-comments.t 31 Aug 2008 11:45:02 -0000 1.2 @@ -22,7 +22,7 @@ "View comments URL CGI syntax"); is($url_nice->url(topicid => 1234, projectid => 10), - $mock_query->url() . '/project/10/topic/1234/comments', + $mock_query->url() . '/project/10/topic/1234/comments/list', "View comments URL nice syntax"); # Check that the parameters extracted correctly. @@ -30,7 +30,7 @@ $mock_http_input->{query} = $mock_query; $mock_query->mock('path_info', sub { - return $mock_query->url() . '/project/10/topic/1234/comments'; + return $mock_query->url() . '/project/10/topic/1234/comments/list'; }); $mock_query->mock('param', sub { return undef; }); $url_nice->extract_parameters($mock_http_input); Index: view-topic-metrics.t =================================================================== RCS file: /cvsroot/codestriker/codestriker/t/Http/Method/view-topic-metrics.t,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- view-topic-metrics.t 10 Aug 2008 12:18:42 -0000 1.1 +++ view-topic-metrics.t 31 Aug 2008 11:45:02 -0000 1.2 @@ -22,7 +22,7 @@ "View topic metrics URL CGI syntax"); is($url_nice->url(topicid => 1234, projectid => 10), - $mock_query->url() . '/project/10/topic/1234/metrics', + $mock_query->url() . '/project/10/topic/1234/metrics/view', "View topic metrics URL nice syntax"); # Check that the parameters extracted correctly. @@ -30,7 +30,7 @@ $mock_http_input->{query} = $mock_query; $mock_query->mock('path_info', sub { - return $mock_query->url() . '/project/10/topic/1234/metrics'; + return $mock_query->url() . '/project/10/topic/1234/metrics/view'; }); $mock_query->mock('param', sub { return undef; }); $url_nice->extract_parameters($mock_http_input); Index: update-comment-metrics.t =================================================================== RCS file: update-comment-metrics.t diff -N update-comment-metrics.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ update-comment-metrics.t 31 Aug 2008 11:45:02 -0000 1.1 @@ -0,0 +1,40 @@ +# Tests for the UpdateCommentMetrics method. + +use strict; +use Test::More tests => 4; + +use lib '../../../lib'; +use Test::MockObject; +use Codestriker; +use Codestriker::Http::Method::UpdateCommentMetricsMethod; + +# Create a CGI mock object for these tests. +my $mock_query = Test::MockObject->new(); +$mock_query->mock('url', + sub { 'http://localhost.localdomain/codestriker/codestriker.pl' } ); + +# Create two method objects to test each URL scheme. +my $url_cgi = Codestriker::Http::Method::UpdateCommentMetricsMethod->new($mock_query, 1); +my $url_nice = Codestriker::Http::Method::UpdateCommentMetricsMethod->new($mock_query, 0); + +is($url_cgi->url(topicid => 1234, projectid => 10), + $mock_query->url() . '?action=change_comments_state', + "Update comment metrics URL CGI syntax"); + +is($url_nice->url(topicid => 1234, projectid => 10), + $mock_query->url() . '/project/10/topic/1234/comments/update', + "Update comment metrics URL nice syntax"); + +# Check that the parameters extracted correctly. +my $mock_http_input = Test::MockObject->new(); +$mock_http_input->{query} = $mock_query; +$mock_query->mock('path_info', + sub { + return $mock_query->url() . '/project/10/topic/1234/comments/update'; + }); +$mock_query->mock('param', sub { return undef; }); +$url_nice->extract_parameters($mock_http_input); +is ($mock_http_input->{projectid}, "10", "project nice URL parameter extraction"); +is ($mock_http_input->{topicid}, "1234", "topicid nice URL parameter extraction"); + + \ No newline at end of file Index: Dispatcher.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Dispatcher.pm,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Dispatcher.pm 29 Aug 2008 10:49:02 -0000 1.8 +++ Dispatcher.pm 31 Aug 2008 11:45:03 -0000 1.9 @@ -23,6 +23,7 @@ use Codestriker::Http::Method::DownloadTopicTextMethod; use Codestriker::Http::Method::UpdateTopicPropertiesMethod; use Codestriker::Http::Method::UpdateTopicMetricsMethod; +use Codestriker::Http::Method::UpdateCommentMetricsMethod; use Codestriker::Http::Method::AddCommentMethod; use Codestriker::Http::Method::CreateCommentMethod; use Codestriker::Http::Method::AddTopicMethod; @@ -50,6 +51,7 @@ Codestriker::Http::Method::CreateTopicMethod->new($query); my @methods = (); + push @methods, Codestriker::Http::Method::SearchTopicsMethod->new($query); push @methods, Codestriker::Http::Method::ViewTopicTextMethod->new($query); push @methods, Codestriker::Http::Method::ViewTopicCommentsMethod->new($query); push @methods, Codestriker::Http::Method::ViewTopicFileMethod->new($query); @@ -57,6 +59,7 @@ push @methods, Codestriker::Http::Method::ViewTopicPropertiesMethod->new($query); push @methods, Codestriker::Http::Method::UpdateTopicPropertiesMethod->new($query); push @methods, Codestriker::Http::Method::UpdateTopicMetricsMethod->new($query); + push @methods, Codestriker::Http::Method::UpdateCommentMetricsMethod->new($query); push @methods, $self->{list_topics_method}; push @methods, Codestriker::Http::Method::CreateCommentMethod->new($query); push @methods, Codestriker::Http::Method::AddCommentMethod->new($query); @@ -68,7 +71,6 @@ push @methods, Codestriker::Http::Method::EditProjectMethod->new($query); push @methods, Codestriker::Http::Method::UpdateProjectMethod->new($query); push @methods, Codestriker::Http::Method::ListProjectsMethod->new($query); - push @methods, Codestriker::Http::Method::SearchTopicsMethod->new($query); push @methods, Codestriker::Http::Method::SubmitSearchTopicsMethod->new($query); push @methods, Codestriker::Http::Method::StaticResourcesMethod->new($query); push @methods, Codestriker::Http::Method::ViewMetricsMethod->new($query); Index: UrlBuilder.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/UrlBuilder.pm,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- UrlBuilder.pm 29 Aug 2008 10:49:02 -0000 1.45 +++ UrlBuilder.pm 31 Aug 2008 11:45:03 -0000 1.46 @@ -7,25 +7,6 @@ # Collection of routines for building codestriker URLs. -# TODO, handle URL scheme such as: -# UrlBuilder needs to be smart and know how to handle the old and new scheme. -# Config variable could disable old scheme, then perhaps way to set security -# on location. - -# Need a populate parameters method to set http_input hash. -# map new anchor -> a and filenumber -> fn. - -# TODO: fix javascript eo method. -# - -# For eahc method, need object to generate_url(%args), and another that takes query object and sets -# parameters to $http_input. These could be unit tested as well. Object called Action. -# When processing input, each object could check query, and return false if can't handle it? -# For CGI case, can always handle it. Could call it Method? Might fit better into REST later. -# Process method could return associated action object? better than large dispatch method currently -# present. -# process -> (%args, %http_input). - package Codestriker::Http::UrlBuilder; use strict; @@ -52,6 +33,7 @@ use Codestriker::Http::Method::ViewMetricsMethod; use Codestriker::Http::Method::UpdateTopicPropertiesMethod; use Codestriker::Http::Method::UpdateTopicMetricsMethod; +use Codestriker::Http::Method::UpdateCommentMetricsMethod; # Constructor for this class. sub new { @@ -195,7 +177,7 @@ # Create the URL for updating comments. sub update_comments_url { my ($self, %args) = @_; -# return Codestriker::Http::Method::UpdateTopicCommentsMethod->new($self->{query})->url(%args); + return Codestriker::Http::Method::UpdateCommentMetricsMethod->new($self->{query})->url(%args); } # Create the URL for viewing the topic properties. Index: AddProjectMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/AddProjectMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AddProjectMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ AddProjectMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -34,6 +34,7 @@ $http_input->extract_cgi_parameters(); return 1; } elsif ($path_info =~ m{^/admin/projects/add}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: DownloadTopicTextMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/DownloadTopicTextMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DownloadTopicTextMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ DownloadTopicTextMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -40,7 +40,7 @@ return 1; } elsif ($path_info =~ m{^/project/\d+/topic/\d+/download}) { $self->_extract_nice_parameters($http_input, - project => 'projectid', topic => 'topicid'); + project => 'projectid', topic => 'topic'); return 1; } else { return 0; Index: ListProjectsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ListProjectsMethod.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ListProjectsMethod.pm 29 Aug 2008 10:48:57 -0000 1.3 +++ ListProjectsMethod.pm 31 Aug 2008 11:45:03 -0000 1.4 @@ -34,6 +34,7 @@ $http_input->extract_cgi_parameters(); return 1; } elsif ($path_info =~ m{^/admin/projects/list$}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: ViewTopicMetricsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ViewTopicMetricsMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ViewTopicMetricsMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ ViewTopicMetricsMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -24,7 +24,7 @@ if ($self->{cgi_style}) { return $self->{url_prefix} . "?action=viewinfo&topic=$args{topicid}"; } else { - return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/metrics"; + return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/metrics/view"; } } @@ -36,7 +36,7 @@ if ($self->{cgi_style} && defined $action && $action eq "viewinfo") { $http_input->extract_cgi_parameters(); return 1; - } elsif ($path_info =~ m{^/project/\d+/topic/\d+/metrics}) { + } elsif ($path_info =~ m{^/project/\d+/topic/\d+/metrics/view}) { $self->_extract_nice_parameters($http_input, project => 'projectid', topic => 'topic'); return 1; Index: UpdateTopicMetricsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/UpdateTopicMetricsMethod.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- UpdateTopicMetricsMethod.pm 29 Aug 2008 10:48:57 -0000 1.1 +++ UpdateTopicMetricsMethod.pm 31 Aug 2008 11:45:03 -0000 1.2 @@ -36,7 +36,7 @@ if ($self->{cgi_style} && defined $action && $action eq "edit_topic_metrics") { $http_input->extract_cgi_parameters(); return 1; - } elsif ($path_info =~ m{^/project/\d+/topic/\d+/properties}) { + } elsif ($path_info =~ m{^/project/\d+/topic/\d+/metrics/update}) { $self->_extract_nice_parameters($http_input, project => 'projectid', topic => 'topicid'); return 1; Index: SearchTopicsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/SearchTopicsMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SearchTopicsMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ SearchTopicsMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -33,7 +33,8 @@ if ($self->{cgi_style} && defined $action && $action eq "search") { $http_input->extract_cgi_parameters(); return 1; - } elsif ($path_info =~ m{^/topics/search/}) { + } elsif ($path_info =~ m{^/topics/search}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: SubmitSearchTopicsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/SubmitSearchTopicsMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SubmitSearchTopicsMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ SubmitSearchTopicsMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -33,7 +33,8 @@ if ($self->{cgi_style} && defined $action && $action eq "submit_search") { $http_input->extract_cgi_parameters(); return 1; - } elsif ($path_info =~ m{^/topics/submitsearch/}) { + } elsif ($path_info =~ m{^/topics/submitsearch}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: DownloadMetricsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/DownloadMetricsMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DownloadMetricsMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ DownloadMetricsMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -34,6 +34,7 @@ $http_input->extract_cgi_parameters(); return 1; } elsif ($path_info =~ m{^/metrics/download$}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: ViewMetricsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ViewMetricsMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ViewMetricsMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ ViewMetricsMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -34,6 +34,7 @@ $http_input->extract_cgi_parameters(); return 1; } elsif ($path_info =~ m{^/metrics/view$}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: CreateProjectMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/CreateProjectMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CreateProjectMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ CreateProjectMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -34,6 +34,7 @@ $http_input->extract_cgi_parameters(); return 1; } elsif ($path_info =~ m{^/admin/projects/create$}) { + $self->_extract_nice_parameters($http_input); return 1; } else { return 0; Index: ViewTopicCommentsMethod.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Http/Method/ViewTopicCommentsMethod.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ViewTopicCommentsMethod.pm 29 Aug 2008 10:48:57 -0000 1.2 +++ ViewTopicCommentsMethod.pm 31 Aug 2008 11:45:03 -0000 1.3 @@ -24,7 +24,7 @@ if ($self->{cgi_style}) { return $self->{url_prefix} . "?action=list_comments&topic=$args{topicid}"; } else { - return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/comments"; + return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/comments/list"; } } @@ -36,7 +36,7 @@ if ($self->{cgi_style} && defined $action && $action eq "list_comments") { $http_input->extract_cgi_parameters(); return 1; - } elsif ($path_info =~ m{^/project/\d+/topic/\d+/comments}) { + } elsif ($path_info =~ m{^/project/\d+/topic/\d+/comments/list}) { $self->_extract_nice_parameters($http_input, project => 'projectid', topic => 'topic'); return 1; Index: UpdateCommentMetricsMethod.pm =================================================================== RCS file: UpdateCommentMetricsMethod.pm diff -N UpdateCommentMetricsMethod.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ UpdateCommentMetricsMethod.pm 31 Aug 2008 11:45:03 -0000 1.1 @@ -0,0 +1,54 @@ +############################################################################### +# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved. +# si...@us... +# +# This program is free software; you can redistribute it and modify it under +# the terms of the GPL. + +# Method for updating the metrics associated with comments. + +package Codestriker::Http::Method::UpdateCommentMetricsMethod; + +use strict; +use Carp; +use Codestriker::Http::Method; + +@Codestriker::Http::Method::UpdateCommentMetricsMethod::ISA = ("Codestriker::Http::Method"); + +# Generate a URL for this method. +sub url() { + my ($self, %args) = @_; + + if ($self->{cgi_style}) { + return $self->{url_prefix} . "?action=change_comments_state"; + } else { + confess "Parameter topicid missing" unless defined $args{topicid}; + confess "Parameter projectid missing" unless defined $args{projectid}; + return $self->{url_prefix} . "/project/$args{projectid}/topic/$args{topicid}/comments/update"; + } +} + +sub extract_parameters { + my ($self, $http_input) = @_; + + my $action = $http_input->{query}->param('action'); + my $path_info = $http_input->{query}->path_info(); + if ($self->{cgi_style} && defined $action && $action eq "change_comments_state") { + $http_input->extract_cgi_parameters(); + return 1; + } elsif ($path_info =~ m{^/project/\d+/topic/\d+/comments/update}) { + $self->_extract_nice_parameters($http_input, + project => 'projectid', topic => 'topic'); + return 1; + } else { + return 0; + } +} + +sub execute { + my ($self, $http_input, $http_output) = @_; + + Codestriker::Action::SubmitEditCommentsState->process($http_input, $http_output); +} + +1; Index: viewtopiccomments.html.tmpl =================================================================== RCS file: /cvsroot/codestriker/codestriker/template/en/default/viewtopiccomments.html.tmpl,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- viewtopiccomments.html.tmpl 8 Aug 2008 07:02:08 -0000 1.30 +++ viewtopiccomments.html.tmpl 31 Aug 2008 11:45:04 -0000 1.31 @@ -48,7 +48,7 @@ // --> </SCRIPT> -<FORM METHOD="post" ENCTYPE="multipart/form-data" name="form"> +<FORM METHOD="post" ENCTYPE="multipart/form-data" name="form" action="[% action_url %]"> <INPUT TYPE="hidden" NAME="action" VALUE="change_comments_state" /> <INPUT TYPE="hidden" NAME="topic" VALUE="[% topic %]" /> Index: search.html.tmpl =================================================================== RCS file: /cvsroot/codestriker/codestriker/template/en/default/search.html.tmpl,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- search.html.tmpl 8 Aug 2008 07:02:08 -0000 1.36 +++ search.html.tmpl 31 Aug 2008 11:45:04 -0000 1.37 @@ -3,7 +3,7 @@ [% PROCESS header.html.tmpl version = version displaymenu = 1 closehead = 1 help = "x671.html" subtitle = "Find Topics" %] -<FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded"> +<FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded" ACTION="[% action_url %]"> <INPUT TYPE="hidden" NAME="action" VALUE="submit_search" /> Index: Search.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/Search.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Search.pm 17 Aug 2008 22:25:36 -0000 1.7 +++ Search.pm 31 Aug 2008 11:45:05 -0000 1.8 @@ -74,7 +74,7 @@ } # Target URL to divert the post to. - $vars->{'submit_search_url'} = $url_builder->submit_search_url(); + $vars->{'action_url'} = $url_builder->submit_search_url(); my $template = Codestriker::Http::Template->new("search"); $template->process($vars); Index: ViewTopicComments.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/lib/Codestriker/Action/ViewTopicComments.pm,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ViewTopicComments.pm 18 Aug 2008 11:11:29 -0000 1.20 +++ ViewTopicComments.pm 31 Aug 2008 11:45:05 -0000 1.21 @@ -158,7 +158,11 @@ # Store the topic status $vars->{'default_state'} = $topic->{topic_state}; - $vars->{'topic_states'} = \@Codestriker::topic_states; + $vars->{'topic_states'} = \@Codestriker::topic_states; + + # Set the action URL for the form. + $vars->{'action_url'} = $url_builder->update_comments_url(topicid => $topicid, + projectid => $projectid); # Send the data to the template for rendering. my $template = Codestriker::Http::Template->new("viewtopiccomments"); |