Skip to content

Commit

Permalink
Item12952: extensions installer brought back - largely untested, but …
Browse files Browse the repository at this point in the history
…it's the old code
  • Loading branch information
crawford committed Sep 2, 2014
1 parent cc42a89 commit ece2721
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use warnings;
use Error qw(:try);
use Assert;
use Foswiki::Configure::Dependency;
use Foswiki::Configure::Util;
use File::stat;

my $depwarn = ''; # Pass back warnings from untaint validation routine
Expand Down
252 changes: 94 additions & 158 deletions core/lib/Foswiki/Configure/Wizards/ExploreExtensions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use Assert;
---+ package Foswiki::Configure::Wizards:ExploreExtensions
Specialised UI; an implementation of the "Find more extensions" UI screen.
When this screen is visited, the remote extensions repositories are visited
to pull down details of available extensions. These are then presented
in custom tabular form.
Visits remote extensions repositories to pull down details of
available extensions. These are then presented to the reporter
in tabular form.
=cut

Expand All @@ -27,8 +26,10 @@ use Foswiki::Func ();
# They describe the format of an extension topic.

# Ordered list of field names to column headings
my @tableHeads =
qw( image description compatibility release installedRelease install );
my %tableHeads = (
installed => [ 'description', 'release', 'installedRelease', 'install' ],
uninstalled => [ 'description', 'release', 'install' ]
);

# Mapping to column heading string
my %headNames = (
Expand All @@ -37,9 +38,9 @@ my %headNames = (
compatibility => 'Compatible with',
installedRelease => 'Installed release',
install => '',
image => '',

# Not used; just here for completeness
image => 'Image',
topic => 'Extension',
classification => 'Classification',
version => 'Most Recent Version',
Expand Down Expand Up @@ -70,9 +71,8 @@ sub _getListOfExtensions {

$this->{list} = {};
$this->{errors} = [];
$this->_findRepositories();

foreach my $place ( @{ $this->{repositories} } ) {
foreach my $place ( findRepositories() ) {
next unless defined $place->{data};
$place->{data} =~ s#/*$#/#;

Expand Down Expand Up @@ -202,77 +202,63 @@ sub _parseRow {
return '';
}

=begin TML
---++ ObjectMethod getExtensions() -> ( $consultedLocations, $table, $errors, $installedCount, $allCount )
Constructs an HTML table of extensions
# Wizard - Constructs an HTML table of installed extensions
sub get_installed_extensions {
my ( $this, $reporter ) = @_;

=cut
$this->_get_extensions( $reporter, 'installed' );
}

sub get_extensions {
# Wizard - Constructs an HTML table of not-installed extensions
sub get_other_extensions {
my ( $this, $reporter ) = @_;

my $table = '';
$this->_get_extensions( $reporter, 'uninstalled' );
}

sub _get_extensions {
my ( $this, $reporter, $set ) = @_;

my $allCount = 0;
my $installed = 0;
my ( $exts, @consultedLocations ) = $this->_getListOfExtensions($reporter);
my $installedExts;
my $installedCount = 0;
my $uninstalledExts;
my $uninstalledCount = 0;

# count
foreach my $key ( keys %$exts ) {
$allCount++;
my $ext = $exts->{$key};
if ( $ext->{installedRelease} ) {
$installed++;
$installedCount++;
$installedExts->{$key} = $ext;
}
else {
$uninstalledCount++;
$uninstalledExts->{$key} = $ext;
}
}
$exts = $set eq 'installed' ? $installedExts : $uninstalledExts;

# Table heads
my $tableHeads = '';
my $colNum = 0;
foreach my $headNameKey (@tableHeads) {
$colNum++;
my $cssClass =
( $colNum == scalar @tableHeads )
? 'action'
: undef;
$tableHeads .=
CGI::th( { class => $cssClass }, $headNames{$headNameKey} );
}

$table .= CGI::Tr(
{ class => 'title' },
CGI::th(
{ colspan => 6 },
"<h3>Installed extensions ($installed out of $allCount)</h3>"
)
);
$table .= CGI::Tr($tableHeads);

$table .= _rawExtensionRows($installedExts);

$table .= CGI::Tr( { class => 'title' },
CGI::th( { colspan => 6 }, "<h3>Uninstalled extensions</h3>" ) );
$table .= CGI::Tr($tableHeads);

$table .= _rawExtensionRows($uninstalledExts);

$reporter->NOTE("<div class=\"extensions_report\">");
$reporter->NOTE( "Looked in " . join( ' ', @consultedLocations ) );
$reporter->NOTE("<table>$table</table>");

# return ( \@consultedLocations, $table, $this->{errors}, $installed,
# $allCount );
}
$reporter->ERROR( @{ $this->{errors} } ) if scalar @{ $this->{errors} };

if ( $set eq 'installed' ) {
$reporter->NOTE(" *Found $installedCount Installed extensions* ");
}
else {
$reporter->NOTE(" *Found $uninstalledCount Uninstalled extensions* ");
}

sub _rawExtensionRows {
my ($exts) = @_;
# Table heads
$reporter->NOTE(
'|'
. join( '|',
map { $headNames{$_} ? " *$headNames{$_}* " : '' }
@{ $tableHeads{$set} } )
. '|'
);

# Each extension has two rows

Expand All @@ -297,162 +283,112 @@ sub _rawExtensionRows {

my $install = 'Install';
my $uninstall = '';
my $trClass = 'configureInstall';

if ( $ext->{installedRelease} ) {

# The module is installed; check the version
if ( $ext->{installedVersion} eq '9999.99_999' ) {

# pseudo-installed
$install = 'pseudo-installed';
$trClass = 'configurePseudoInstalled';
}
elsif ( $ext->compare_versions( '<', $ext->{release} ) ) {

# Installed version is < available version

$install = 'Upgrade';
$uninstall = 'Uninstall';
$trClass = 'configureUpgrade';
}
else {

# Installed version is current version

$install = 'Re-install';
$uninstall = 'Uninstall';
$trClass = 'configureReInstall';
}
}

if ( $install ne 'pseudo-installed' ) {
$install = CGI::checkbox(
-name => 'add',
-value => $ext->{repository} . '/' . $ext->{topic},
-class => 'foswikiCheckbox',
-label => $install,
my %data = (
wizard => 'InstallExtensions',
method => 'add',
args => "$ext->{repository}/$ext->{topic}"
);
my $json = JSON->new->encode( \%data );
$json =~ s/"/&quot;/g;
$install =
"<button class=\"wizard_button\" data-wizard=\"$json\">$install</button>";
}

if ($uninstall) {
$uninstall = '<br />'
. CGI::checkbox(
-name => 'remove',
-value => $ext->{repository} . '/' . $ext->{topic},
-class => 'foswikiCheckbox',
-label => $uninstall,
);
my %data = (
wizard => 'InstallExtensions',
method => 'remove',
args => "$ext->{repository}/$ext->{topic}"
);
my $json = JSON->new->encode( \%data );
$json =~ s/"/&quot;/g;
$uninstall =
"<button class=\"wizard_button\" data-wizard=\"$json\">$uninstall</button>";
}

$trClass .= ' configureAlienExtension'
if ( $ext->{module} && $ext->{module} !~ /^Foswiki::/ );
$trClass .= ' extensionRow';

# Do the title row
# Do the title + actions row
my $thd = $ext->{topic} || 'Unknown';
$thd =~ s/!(\w+)/$1/go; # remove ! escape syntax from text
$thd =
CGI::a( { href => $ext->{data} . $ext->{topic}, -target => '_blank' },
$thd );

# Do the data row
my $row = '';
my $colCount = 0;

my @imgControls = ();
if ( $ext->{image} ) {
$ext->{image} =
'<div title="'
. $ext->{image}
. '" class="foswikiImage loadImage"></div>';
}
"<a href=\"$ext->{data}$ext->{topic}\" target=\"_blank\">$thd</a>";

$out .= CGI::Tr(
{ class => $trClass },
CGI::td(
{
class => "image",
rowspan => 2
},
$ext->{image}
),
CGI::td(
{
colspan => ( $#tableHeads - 1 ),
class => "title"
},
$thd
),
CGI::td(
{
class => "action",
rowspan => 2
},
$install . ' ' . $uninstall
)
);
$reporter->NOTE(
"| $thd" . '|' x scalar( @{ $tableHeads{$set} } ) . " $install |" );

foreach my $f (@tableHeads) {
next if $f eq 'image';
my $tdd = $ext->{$f} || '&nbsp;';
# Do the data row
my @cols;
foreach my $f ( @{ $tableHeads{$set} } ) {
my $tdd = $ext->{$f} || '';
$tdd =~ s/!(\w+)/$1/go; # remove ! escape syntax from text
my $cssClass = "configureExtensionData";
$cssClass .= " $f";
if ( $colCount == scalar @tableHeads - 2 ) {

# nothing (in colspan)
}
else {
$row .= CGI::td( { class => $cssClass }, $tdd );
if ( $f eq 'description' && $ext->{compatibility} ) {
$tdd .= "<br />$ext->{compatibility}";
}
$colCount++;
push( @cols, $tdd );
}
push( @cols, $uninstall );

$out .= CGI::Tr(
{
class => $trClass,
id => $ext->{topic},
@imgControls
},
$row
);

$reporter->NOTE( '|' . join( '|', map { " $_ " } @cols ) . '|' );
}
return $out;
$reporter->NOTE("</div>");
}

# Build descriptive hashes for the repositories listed in
# $Foswiki::cfg{ExtensionsRepositories}
# name=(dataUrl,pubURL[,user,password]) ; ...

sub _findRepositories {
my $this = shift;
unless ( defined( $this->{repositories} ) ) {
my $replist = '';
$replist = $Foswiki::cfg{ExtensionsRepositories}
if defined $Foswiki::cfg{ExtensionsRepositories};

while ( $replist =~ s/^\s*([^=;]+)=\(([^)]*)\)\s*// ) {
my ( $name, $value ) = ( $1, $2 );
if ( $value =~
/^([a-z]+:[^,]+),\s*([a-z]+:[^,]+)(?:,\s*([^,]*),\s*(.*))?$/ )
{
push @{ $this->{repositories} },
{
sub findRepositories {

my $replist = '';
$replist = $Foswiki::cfg{ExtensionsRepositories}
if defined $Foswiki::cfg{ExtensionsRepositories};

my @repositories;
while ( $replist =~ s/^\s*([^=;]+)=\(([^)]*)\)\s*// ) {
my ( $name, $value ) = ( $1, $2 );
if ( $value =~
/^([a-z]+:[^,]+),\s*([a-z]+:[^,]+)(?:,\s*([^,]*),\s*(.*))?$/ )
{
push(
@repositories,
{
name => $name,
data => $1,
pub => $2,
user => $3,
pass => $4
};
}
else {
$this->{_repositoryerror} ||= "$value)$replist";
}
}
);

last unless ( $replist =~ s/^;\s*// );
}
$this->{_repositoryerror} ||= $replist;
}
return @repositories;
}

1;
Expand Down
Loading

0 comments on commit ece2721

Please sign in to comment.