more cleanup from recent changes

This commit is contained in:
myk%mozilla.org 2004-05-05 01:32:14 +00:00
parent 576e2a2776
commit 6336a2d677
9 changed files with 124 additions and 115 deletions

View File

@ -54,29 +54,6 @@ sub version {
return $self->{_version};
}
sub tempdir {
my $self = shift;
$self->{_tempdir} ||=
File::Temp->tempdir("doctor-XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
return $self->{_tempdir};
}
sub line_endings {
my $self = shift;
if (!$self->content) { return undef }
elsif ($self->content =~ /\r\n/s) { return "windows" }
elsif ($self->content =~ /\r[^\n]/s) { return "mac" }
else { return "unix" }
}
sub linebreak {
my $self = shift;
if (!$self->content) { return undef; }
elsif ($self->content =~ /\r\n/s) { return "\r\n" }
elsif ($self->content =~ /\r[^\n]/s) { return "\r" }
else { return "\n" }
}
sub spec {
my $self = shift;
# The spec can only be set once.
@ -125,6 +102,29 @@ sub spec {
return $self->{_spec};
}
sub tempdir {
my $self = shift;
$self->{_tempdir} ||=
File::Temp->tempdir("doctor-XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
return $self->{_tempdir};
}
sub line_endings {
my $self = shift;
if (!$self->content) { return undef }
elsif ($self->content =~ /\r\n/s) { return "windows" }
elsif ($self->content =~ /\r[^\n]/s) { return "mac" }
else { return "unix" }
}
sub linebreak {
my $self = shift;
if (!$self->content) { return undef; }
elsif ($self->content =~ /\r\n/s) { return "\r\n" }
elsif ($self->content =~ /\r[^\n]/s) { return "\r" }
else { return "\n" }
}
sub url {
my $self = shift;
# Construct a URL to the file if possible.

View File

@ -133,12 +133,10 @@ sub retrieve {
my $disposition = $action eq "download" ? "attachment" : "inline";
my $length = length($file->content);
print $request->header(
-type => qq|text/html; name="$file->name"|,
-content_disposition => qq|$disposition; filename="$file->name"|,
-content_length => $length );
-type => "text/html; name=\"" . $file->name . "\"",
-content_disposition => "$disposition; filename=\"" . $file->name . "\"",
-content_length => length($file->content) );
print $file->content;
}
@ -146,7 +144,7 @@ sub retrieve {
sub diff {
my $file = Doctor::File->new($request->param('file'));
ValidateVersions($request->param('version'), $file->version);
my $diff = $file->diff($request->param('content'))
my $diff = $file->diff(GetContent())
|| "There are no differences between the version in CVS and your revision.";
print $request->header(-type=>"text/plain");
@ -236,6 +234,8 @@ sub queue {
ThrowCodeError($@, "Mail Failure");
}
$vars->{file} = $file;
print $request->header;
$template->process("queued.tmpl", $vars)
|| ThrowCodeError($template->error(), "Template Processing Failed");
@ -251,21 +251,22 @@ sub commit {
if ($action eq "commit") {
ValidateVersions($request->param('version'), $file->version);
$file->patch($request->param('content'));
$file->patch(GetContent());
}
else {
$file->add($request->param("content"));
$file->add(GetContent());
}
my ($rv, $output, $errors) = $file->commit($username, $password, $comment);
if ($rv != 0) {
ThrowUserError("An error occurred while committing the file.",
ThrowUserError("An error occurred while committing the file: $output $errors",
undef,
$output,
$rv,
$errors);
}
$vars->{file} = $file;
$vars->{output} = $output;
$vars->{errors} = $errors;
@ -306,21 +307,20 @@ sub ValidateComment {
return $request->param('comment');
}
sub ValidateVersions()
{
# Throws an error if the version of the file that was edited
# does not match the version in the repository. In the future
# we should try to merge the user's changes if possible.
my ($oldversion, $newversion) = @_;
if ($oldversion && $newversion && $oldversion != $newversion) {
ThrowCodeError("You edited version <em>$oldversion</em> of the file,
but version <em>$newversion</em> is in the repository. Reload the edit
page and make your changes again (and bother the authors of this script
to implement change merging
(<a href=\"http://bugzilla.mozilla.org/show_bug.cgi?id=164342\">bug 164342</a>).");
}
sub ValidateVersions() {
# Throws an error if the version of the file that was edited
# does not match the version in the repository. In the future
# we should try to merge the user's changes if possible.
my ($oldversion, $newversion) = @_;
if ($oldversion && $newversion && $oldversion != $newversion) {
ThrowCodeError("You edited version <em>$oldversion</em> of the file,
but version <em>$newversion</em> is in the repository. Reload the edit
page and make your changes again (and bother the authors of this script
to implement change merging
(<a href=\"http://bugzilla.mozilla.org/show_bug.cgi?id=164342\">bug 164342</a>).");
}
}
@ -328,58 +328,56 @@ sub ValidateVersions()
# Error Handling
################################################################################
sub ThrowUserError
{
# Throw an error about a problem with the user's request. This function
# should avoid mentioning system problems displaying the error message, since
# the user isn't going to care about them and probably doesn't need to deal
# with them after fixing their own mistake. Errors should be gentle on
# the user, since many "user" errors are caused by bad UI that trip them up.
# !!! Mail code errors to the system administrator!
($vars->{'message'},
$vars->{'title'},
$vars->{'cvs_command'},
$vars->{'cvs_error_code'},
$vars->{'cvs_error_message'}) = @_;
chdir($HOME);
print $request->header;
$template->process("user-error.tmpl", $vars)
|| print( ($vars->{'title'} ? "<h1>$vars->{'title'}</h1>" : "") .
"<p>$vars->{'message'}</p><p>Please go back and try again.</p>" );
exit;
sub ThrowUserError {
# Throw an error about a problem with the user's request. This function
# should avoid mentioning system problems displaying the error message, since
# the user isn't going to care about them and probably doesn't need to deal
# with them after fixing their own mistake. Errors should be gentle on
# the user, since many "user" errors are caused by bad UI that trip them up.
# !!! Mail code errors to the system administrator!
($vars->{'message'},
$vars->{'title'},
$vars->{'cvs_command'},
$vars->{'cvs_error_code'},
$vars->{'cvs_error_message'}) = @_;
chdir($HOME);
print $request->header;
$template->process("user-error.tmpl", $vars)
|| print( ($vars->{'title'} ? "<h1>$vars->{'title'}</h1>" : "") .
"<p>$vars->{'message'}</p><p>Please go back and try again.</p>" );
exit;
}
sub ThrowCodeError
{
# Throw error about a problem with the code. This function should be
# apologetic and deferent to the user, since it isn't the user's fault
# the code didn't work.
# !!! Mail code errors to the system administrator!
($vars->{'message'}, $vars->{'title'}) = @_;
chdir($HOME);
print $request->header;
$template->process("code-error.tmpl", $vars)
|| print("
<p>
Unfortunately Doctor has experienced an internal error from which
it was unable to recover. More information about the error is
provided below. Please forward this information along with any
other information that would help diagnose and fix this problem
to the system administrator at
<a href=\"mailto:$CONFIG{ADMIN_EMAIL}\">$CONFIG{ADMIN_EMAIL}</a>.
</p>
<p>
couldn't process error.tmpl template: " . $template->error() .
"; error occurred while trying to display error message: " .
($vars->{'title'} ? "$vars->{'title'}: ": "") . $vars->{'message'} .
"</p>");
exit;
sub ThrowCodeError {
# Throw error about a problem with the code. This function should be
# apologetic and deferent to the user, since it isn't the user's fault
# the code didn't work.
# !!! Mail code errors to the system administrator!
($vars->{'message'}, $vars->{'title'}) = @_;
chdir($HOME);
print $request->header;
$template->process("code-error.tmpl", $vars)
|| print("
<p>
Unfortunately Doctor has experienced an internal error from which
it was unable to recover. More information about the error is
provided below. Please forward this information along with any
other information that would help diagnose and fix this problem
to the system administrator at
<a href=\"mailto:$CONFIG{ADMIN_EMAIL}\">$CONFIG{ADMIN_EMAIL}</a>.
</p>
<p>
couldn't process error.tmpl template: " . $template->error() .
"; error occurred while trying to display error message: " .
($vars->{'title'} ? "$vars->{'title'}: ": "") . $vars->{'message'} .
"</p>");
exit;
}
################################################################################

View File

@ -2,11 +2,16 @@
* Banner and Navigation Bar
*/
#bannernav {
h1 {
margin-top: 0px;
margin-bottom: 5px;
font-size: 24px;
font-weight: bold;
}
h2 {
font-size: 18px;
}
/*
* Tabs

View File

@ -28,6 +28,7 @@
<head>
<title>Doctor - [% title %]</title>
<link rel="stylesheet" href="doctor.css" type="text/css"></link>
</head>
<body>

View File

@ -25,24 +25,23 @@
<head>
<title>Doctor - [% is_new ? "created" : "committed" %] [%+ file.relative_spec FILTER html %]</title>
<link rel="stylesheet" href="doctor.css" type="text/css"></link>
</head>
<body bgcolor="white" color="black">
<big><b>Doctor - [% is_new ? "created" : "committed" %] <em>
[% IF file.url %]
<h1>
Doctor - [% is_new ? "created" : "committed" %]
[%+ IF file.url %]
<a href="[% file.url FILTER html %]">[% file.relative_spec FILTER html %]</a>
[% ELSE %]
[% file.relative_spec FILTER html %]
[% END %]
</em></b></big>
</h1>
<p>
[% IF is_new %]
The new file has been committed to the repository.
[% ELSE %]
Your changes have been committed to the repository.
[% END %]
[% IF is_new %] The new file has [% ELSE %] Your changes have [% END %]
been committed to the repository.
</p>
<h2>Results</h2>

View File

@ -51,7 +51,7 @@
<input id="file" type="hidden" name="file" value="[% file.spec FILTER html %]">
<input id="version" type="hidden" name="version" value="[% version %]">
<div id="bannernav">
<h1>
Doctor - [% is_new ? "create" : "edit" %]
[%+ IF file.url %]
<a href="[% file.url FILTER html %]">[% file.relative_spec FILTER html %]</a>
@ -64,7 +64,7 @@
[% END %]
| <label for="content_file">upload:</label>
<input id="content_file" type="file" name="content_file">
</div>
</h1>
<div id="tabs">
<button id="editTab" class="tab [% "wysiwyg" IF wysiwyg %]"

View File

@ -19,21 +19,25 @@
# Contributor(s): Myk Melez <myk@mozilla.org>
# %]
[% is_new = (file.version == "new" ? 1 : 0) %]
<html>
<head>
<title>Doctor - changes submitted for review - [% (file_url ? file_url : file) FILTER html %]</title>
<title>Doctor - changes submitted for review - [%+ file.relative_spec FILTER html %]</title>
<link rel="stylesheet" href="doctor.css" type="text/css"></link>
</head>
<body bgcolor="white" color="black">
<big><b>Doctor - changes submitted for review - <em>
[% IF file_url %]
<a href="[% file_url FILTER html %]">[% file_url FILTER html %]</a>
<h1>
Doctor - changes submitted for review
[%+ IF file.url %]
<a href="[% file.url FILTER html %]">[% file.relative_spec FILTER html %]</a>
[% ELSE %]
[% file FILTER html %]
[% file.relative_spec FILTER html %]
[% END %]
</em></b></big>
</h1>
<p>
Your changes have been submitted for review.

View File

@ -23,11 +23,12 @@
<head>
<title>Doctor - select file to edit</title>
<link rel="stylesheet" href="doctor.css" type="text/css"></link>
</head>
<body bgcolor="white" color="black">
<big><b>Doctor - select file to edit</b></big>
<h1>Doctor - select file to edit</h1>
<br><br>

View File

@ -28,6 +28,7 @@
<head>
<title>Doctor - [% title %]</title>
<link rel="stylesheet" href="doctor.css" type="text/css"></link>
</head>
<body>