Skip to content

Commit

Permalink
Remove two-column rights array refactor for a later effort.
Browse files Browse the repository at this point in the history
  • Loading branch information
moseshll committed Mar 13, 2024
1 parent 3858196 commit 9e050db
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 63 deletions.
27 changes: 6 additions & 21 deletions cgi/CRMS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7347,8 +7347,6 @@ sub Categories

# Get the rights combinations appropriate to the project
# in an order appropriate for a two-column layout unless $order.
# TODO: remove the $order parameter and just have views call
# ArrayToTwoColumns when needed.
sub Rights
{
my $self = shift;
Expand All @@ -7358,9 +7356,7 @@ sub Rights
my $proj = $self->SimpleSqlGet('SELECT project FROM queue WHERE id=?', $id);
$proj = 1 unless defined $proj;
my @all = ();
my $sql = 'SELECT r.id,CONCAT(a.name,"/",rs.name),'.
'COALESCE(r.description,CONCAT(a.dscr,"/",rs.dscr))'.
',a.name,rs.name FROM rights r'.
my $sql = 'SELECT r.id,CONCAT(a.name,"/",rs.name),r.description,a.name,rs.name FROM rights r'.
' INNER JOIN attributes a ON r.attr=a.id'.
' INNER JOIN reasons rs ON r.reason=rs.id'.
' INNER JOIN projectrights pr ON r.id=pr.rights'.
Expand All @@ -7378,25 +7374,14 @@ sub Rights
$n++;
}
return \@all if $order;
return $self->ArrayToTwoColumns(\@all);
}

# Interleave the first half of an array with the second half,
# making it amenable to top-to-bottom scanning in two columns.
# Used in the various review forms to lay out the list of rights
# into an HTML table.
# If there is an odd number of elements, the first column gets the extra.
sub ArrayToTwoColumns {
my $self = shift;
my $array = shift;

my @inorder;
my $of = scalar @$array;
my $of = scalar @all;
my $middle = int($of / 2);
$middle += 1 if $of % 2 == 1;
foreach my $n (0 .. $middle - 1) {
push @inorder, $array->[$n];
push @inorder, $array->[$n + $middle] if $n + $middle < $of;
foreach my $n (0 .. $middle - 1)
{
push @inorder, $all[$n];
push @inorder, $all[$n + $middle] if $n + $middle < $of;
}
return \@inorder;
}
Expand Down
19 changes: 16 additions & 3 deletions cgi/partial/ADDForm.tt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,22 @@
[% rights = crms.Rights(htid, 1) %]
<div id="RightsCont" class="subpartial">
<div id="RightsReason" style="position:relative;">
[% # TODO: use rights_help.tt in other project forms %]
[% INCLUDE partial/rights_help.tt rights = rights %]
[% rights = crms.ArrayToTwoColumns(rights) %]
<div id="rightsHelp" style="position:absolute;top:0px;right:1em;">
<a class="tip" href="#">
<img width="16" height="16" alt="Rights/Reason Help" src="[% crms.WebPath('web', 'help.png') %]"/>
<span>
[% asterisk = 0 %]
[% FOR right IN rights %]
<strong>[% right.rights %]</strong> - [% right.description %]<br/>
[% IF right.description.search('\*') %][% asterisk = 1 %][% END %]
[% END %]
[% IF asterisk %]
<br/>* if no publication date listed on piece, use copyright date
[% END %]
</span>
</a>
</div>
[% rights = crms.Rights(htid) %]
[% of = rights.size() %]
[% n = 0 %]
<div style="display:none" id="UNDNFI" title="[% crms.SimpleSqlGet('SELECT id FROM rights WHERE attr=5 AND reason=8') %]"></div>
Expand Down
15 changes: 0 additions & 15 deletions cgi/partial/rights_help.tt

This file was deleted.

26 changes: 2 additions & 24 deletions t/CRMS.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,11 @@ subtest 'CRMS::WriteRightsFile' => sub {

subtest 'CRMS::CanExportVolume' => sub {
subtest 'CRMS::CanExportVolume und/nfi' => sub {
is($crms->CanExportVolume('mdp.001', 'und', 'nfi', 1), 0);
is(0, $crms->CanExportVolume('mdp.001', 'und', 'nfi', 1));
};

subtest 'CRMS::CanExportVolume und/crms' => sub {
is($crms->CanExportVolume('mdp.001', 'und', 'crms', 1), 0);
};
};

subtest '#ArrayToTwoColumns' => sub {
subtest 'no items' => sub {
is_deeply($crms->ArrayToTwoColumns([]), []);
};

subtest 'one item' => sub {
is_deeply($crms->ArrayToTwoColumns([1]), [1]);
};

subtest 'two items' => sub {
is_deeply($crms->ArrayToTwoColumns([1, 2]), [1, 2]);
};

subtest 'three items' => sub {
is_deeply($crms->ArrayToTwoColumns([1, 2, 3]), [1, 3, 2]);
};

subtest 'four items' => sub {
is_deeply($crms->ArrayToTwoColumns([1, 2, 3, 4]), [1, 3, 2, 4]);
is(0, $crms->CanExportVolume('mdp.001', 'und', 'crms', 1));
};
};

Expand Down

0 comments on commit 9e050db

Please sign in to comment.