Skip to content
44 changes: 42 additions & 2 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,55 @@ sub listCourses {

=item listArchivedCourses($ce)

Lists the courses which have been archived (end in .tar.gz).
Lists the courses which have been archived (end in .tar.gz). The courses found
are returned as a hash whose keys are the course ids and the values are
references to hashes containing the C<filename> (the basename of the file
including the .tar.gz extension) and file C<size>. For example,

{
myTestCourse => {
filename => 'myTestCourse.tar.gz',
size => '605 KB'
}
}

=cut

sub listArchivedCourses {
my ($ce) = @_;
my $archivesDir = path("$ce->{webworkDirs}{courses}/$ce->{admin_course_id}/archives");
surePathToFile($ce->{webworkDirs}{courses}, "$archivesDir/test"); # Ensure archives directory exists.
return @{ $archivesDir->list->grep(qr/\.tar\.gz$/)->map('basename') };

my $archives = $archivesDir->list->grep(qr/\.tar\.gz$/i);

my %return;
for (@$archives) {
my $size = $_->stat->size;
my @units = qw(B KB MB GB);
my $unit_idx = 0;
while ($size >= 1024 && $unit_idx < $#units) {
$size /= 1024;
++$unit_idx;
}
my $basename = $_->basename;
my $arch = Archive::Tar->new($_);
my %top_level;
for my $file ($arch->get_files) {
(my $first = $file->full_path) =~ s{/.*}{}s;
$top_level{$first} = 1 if length $first;
}
unless (keys %top_level == 1) {
warn "The archive $basename does not contain a single top-level course directory.\n";
next;
}
my ($currCourseID) = keys %top_level;
my $round = 10**($unit_idx > 0 ? $unit_idx - 1 : 0);
$return{$currCourseID} = {
filename => $basename,
size => sprintf("%s %s", int($size * $round) / $round, $units[$unit_idx])
};
}
return %return;
}

################################################################################
Expand Down
5 changes: 3 additions & 2 deletions templates/ContentGenerator/CourseAdmin.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
) =%>
</p>
<ol>
% for (sort { lc($a) cmp lc($b) } listArchivedCourses($ce)) {
<li><%= $_ %></li>
% my %courseArchives = listArchivedCourses($ce);
% for (sort { lc($a) cmp lc($b) } keys %courseArchives) {
<li><%= "$_ ($courseArchives{$_}{size})" %></li>
% }
</ol>
% }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= maketext(
'Courses are listed either alphabetically or in order by the time of most recent login activity, oldest '
. 'first. To change the listing order check the mode you want and click "Refresh Listing". The '
. 'listing format is: Course_Name (status :: date/time of most recent login) where status is "hidden" '
. 'listing format is: Course_ID (status :: date/time of most recent login) where status is "hidden" '
. 'or "visible".'
) =%>
</p>
Expand Down Expand Up @@ -35,7 +35,7 @@
<%= $c->hidden_fields('subDisplay') =%>
<div class="mb-2"><%= maketext('Select course(s) to archive.') %></div>
<div class="row mb-2">
<%= label_for archive_courseIDs => maketext('Course Name:'), class => 'col-auto col-form-label fw-bold' =%>
<%= label_for archive_courseIDs => maketext('Course ID:'), class => 'col-auto col-form-label fw-bold' =%>
<div class="col-auto">
<%= select_field archive_courseIDs => [ map { [ $courseLabels->{$_} => $_ ] } @$courseIDs ],
id => 'archive_courseIDs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= maketext(
'Courses are listed either alphabetically or in order by the time of most recent login activity, '
. 'oldest first. To change the listing order check the mode you want and click "Refresh Listing". '
. 'The listing format is: Course_Name (status :: date/time of most recent login) where status is '
. 'The listing format is: Course_ID (status :: date/time of most recent login) where status is '
. '"hidden" or "visible".'
) =%>
</p>
Expand Down Expand Up @@ -35,7 +35,7 @@
<%= $c->hidden_fields('subDisplay') =%>
<div class="mb-2"><%= maketext('Select a course to delete.') %></div>
<div class="row mb-2">
<%= label_for delete_courseID => maketext('Course Name:'), class => 'col-auto col-form-label fw-bold' =%>
<%= label_for delete_courseID => maketext('Course ID:'), class => 'col-auto col-form-label fw-bold' =%>
<div class="col-auto">
<%= select_field delete_courseID => [ map { [ $courseLabels->{$_} => $_ ] } @$courseIDs ],
id => 'delete_courseID',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= maketext(
'Courses are listed either alphabetically or in order by the time of most recent login activity, '
. 'oldest first. To change the listing order check the mode you want and click "Refresh Listing". '
. 'The listing format is: Course_Name (status :: date/time of most recent login) where status is "hidden" '
. 'The listing format is: Course_ID (status :: date/time of most recent login) where status is "hidden" '
. 'or "visible".'
) =%>
</p>
Expand Down Expand Up @@ -43,7 +43,7 @@
%
<div class="mb-2"><%= maketext('Select course(s) to hide or unhide.') %></div>
<div class="row mb-2">
<%= label_for hide_courseIDs => maketext('Course Name:'), class => 'col-auto col-form-label fw-bold' =%>
<%= label_for hide_courseIDs => maketext('Course ID:'), class => 'col-auto col-form-label fw-bold' =%>
<div class="col-auto">
<%= select_field hide_courseIDs => [ map { [ $courseLabels->{$_} => $_ ] } @$hideCourseIDs ],
id => 'hide_courseIDs',
Expand Down
24 changes: 12 additions & 12 deletions templates/ContentGenerator/CourseAdmin/rename_course_form.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,55 @@
. 'string.'
) =%>
</p>
<div class="col-lg-7 col-md-8">
<div class="col-lg-9 col-md-11">
<div class="row mb-2">
<%= label_for rename_oldCourseID => maketext('Course ID:'),
class => 'col-sm-6 col-form-label fw-bold' =%>
<div class="col-sm-6">
class => 'col-lg-3 col-md-4 pe-0 col-form-label fw-bold' =%>
<div class="col-lg-9 col-md-8">
<%= select_field rename_oldCourseID => [ map { [ $_ => $_ ] } @courseIDs ],
class => 'form-select',
size => 10,
id => 'rename_oldCourseID' =%>
</div>
</div>
<div class="row mb-2 align-items-center">
<div class="col-sm-6">
<div class="col-lg-3 col-md-4 pe-0">
<div class="form-check">
<label class="form-check-label" id="rename_newCourseID_label">
<%= maketext('Change CourseID to:') %>
<%= maketext('New ID:') %>
<%= check_box rename_newCourseID_checkbox => 'on', class => 'form-check-input' %>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="col-lg-9 col-md-8">
<%= text_field rename_newCourseID => '',
class => 'form-control', 'aria-labelledby' => 'rename_newCourseID_label' =%>
</div>
</div>
<div class="row mb-2 align-items-center">
<div class="col-sm-6">
<div class="col-lg-3 col-md-4 pe-0">
<div class="form-check">
<label class="form-check-label" id="rename_newCourseTitle_label">
<%= maketext('Change Course Title to:') %>
<%= maketext('New Title:') %>
<%= check_box rename_newCourseTitle_checkbox => 'on', class => 'form-check-input' %>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="col-lg-9 col-md-8">
<%= text_field rename_newCourseTitle => '',
class => 'form-control', 'aria-labelledby' => 'rename_newCourseTitle_label' =%>
</div>
</div>
<div class="row mb-2 align-items-center">
<div class="col-sm-6">
<div class="col-lg-3 col-md-4 pe-0">
<div class="form-check">
<label class="form-check-label" id="rename_newCourseInstitution_label">
<%= maketext('Change Institution to:') %>
<%= maketext('New Institution:') %>
<%= check_box rename_newCourseInstitution_checkbox => 'on', class => 'form-check-input' %>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="col-lg-9 col-md-8">
<%= text_field rename_newCourseInstitution => '',
class => 'form-control', 'aria-labelledby' => 'rename_newCourseInstitution_label' =%>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<h2><%= maketext('Unarchive Course') %> <%= $c->helpMacro('AdminUnarchiveCourse') %></h2>
%
% # Find courses which have been archived.
% my @courseIDs = sort { lc($a) cmp lc($b) } listArchivedCourses($ce);
% my %courseArchives = listArchivedCourses($ce);
% my @courseIDs = sort { lc($a) cmp lc($b) } keys %courseArchives;
%
% if (@courseIDs) {
<%= form_for current_route, method => 'POST', begin =%>
Expand All @@ -12,20 +13,25 @@
%
<div class="mb-2"><%= maketext('Select a course to unarchive.') =%></div>
%
<div class="col-lg-7 col-md-8">
<div class="col-lg-9 col-md-11">
<div class="row mb-2">
<%= label_for 'unarchive_courseID' => maketext('Course Name:'), class => 'col-sm-4 col-form-label' =%>
<div class="col-sm-8">
<%= select_field unarchive_courseID => \@courseIDs,
id => 'unarchive_courseID',
class => 'form-select',
size => 10
<%= label_for 'unarchive_courseID' => maketext('Course ID:'),
class => 'col-md-2 pe-0 col-form-label fw-bold' =%>
<div class="col-lg-9 col-md-8">
<%= select_field
unarchive_courseID => [
map { [ "$_ ($courseArchives{$_}{size})" => $courseArchives{$_}{filename} ] } @courseIDs
],
id => 'unarchive_courseID',
class => 'form-select',
size => 10
=%>
</div>
</div>
<div class="row mb-2 align-items-center">
<%= label_for new_courseID => maketext('New Name:'), class => 'col-sm-4 col-form-label' =%>
<div class="col-sm-8">
<%= label_for new_courseID => maketext('New ID:'),
class => 'col-md-2 pe-0 col-form-label fw-bold' =%>
<div class="col-lg-9 col-md-8">
<%= text_field new_courseID => '',
id => 'new_courseID',
size => 25,
Expand Down