Skip to content

Commit

Permalink
Merge pull request #55 from creative-commoners/pulls/1.0/show-version…
Browse files Browse the repository at this point in the history
…-on-module-report

NEW Showing framework/CMS version on module report
  • Loading branch information
robbieaverill authored May 23, 2018
2 parents 8e12261 + f338089 commit 1ccf490
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 20 deletions.
6 changes: 6 additions & 0 deletions css/sitesummary.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
display:block;
}

/* Due to a rule applied to `.cms .ss-gridfield > div` we have to be specific here */
.cms .ss-gridfield > div.site-summary__clearfix {
margin: 0;
clear: both;
}

.gridfield-button-link {
margin-bottom: 12px;
}
42 changes: 42 additions & 0 deletions src/Forms/GridFieldHtmlFragment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Facilitates adding arbitrary HTML to grid fields
*
* @package forms
* @subpackage fields-gridfield
*/

class GridFieldHtmlFragment implements GridField_HTMLProvider
{
/**
* Fragment to write the html fragment to.
* @var string
*/
protected $targetFragment;

/**
* An HTML fragment to render
* @var string
*/
protected $htmlFragment;

/**
* @param string $targetFragment Fragment to write the html fragment to.
* @param string $htmlFragment An HTML fragment to render
*/
public function __construct($targetFragment, $htmlFragment)
{
$this->targetFragment = $targetFragment;
$this->htmlFragment = $htmlFragment;
}

/**
* @param GridField $gridField
* @return array
*/
public function getHTMLFragments($gridField)
{
return [$this->targetFragment => $this->htmlFragment];
}
}
68 changes: 48 additions & 20 deletions src/Reports/SiteSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ public function title()
return _t(__CLASS__ . '.TITLE', 'Installed modules');
}

public function description()
{
return _t(
__CLASS__ . '.DESCRIPTION',
<<<DESC
Provides information about what SilverStripe modules are installed,
giving an insight to project statistics such as how big the installation is,
what it would take to upgrade it, and what functionality is available
to both editors and users.
DESC
);
}

public function sourceRecords($params)
public function sourceRecords()
{
$packageList = Package::get();
$typeFilters = Config::inst()->get(UpdatePackageInfo::class, 'allowed_types');
Expand Down Expand Up @@ -68,20 +55,61 @@ public function getReportField()
{
Requirements::css('silverstripe-maintenance/css/sitesummary.css');

/** @var GridField $gridField */
$gridField = parent::getReportField();
/** @var GridField $grid */
$grid = parent::getReportField();

$config = $gridField->getConfig();
/** @var GridFieldConfig $config */
$config = $grid->getConfig();

/** @var GridFieldExportButton $exportButton */
$exportButton = $config->getComponentByType(GridFieldExportButton::class);
$exportButton->setExportColumns(Package::create()->summaryFields());

$versionHtml = ArrayData::create([
'Title' => _t(__CLASS__ . '.VERSION', 'Version'),
'Version' => $this->resolveCmsVersion(),
])->renderWith('SiteSummary_VersionHeader');

$config->addComponents(
Injector::inst()->create('GridFieldButtonRow', 'before'),
Injector::inst()->create('GridFieldLinkButton', 'https://addons.silverstripe.org', 'buttons-before-left')
Injector::inst()->create(GridFieldButtonRow::class, 'before'),
Injector::inst()->create(
GridFieldLinkButton::class,
'https://addons.silverstripe.org',
'buttons-before-left'
),
Injector::inst()->create(GridFieldHtmlFragment::class, 'header', $versionHtml)
);

return $gridField;
return $grid;
}

/**
* Extract CMS and Framework version details from the records in the report
*
* @return string
*/
protected function resolveCmsVersion()
{
$versionModules = [
'silverstripe/framework' => 'Framework',
'silverstripe/cms' => 'CMS',
];
$this->extend('updateVersionModules', $versionModules);

$records = $this->sourceRecords()->filter('Name', array_keys($versionModules));
$versionParts = [];

foreach ($versionModules as $name => $label) {
$record = $records->find('Name', $name);
if (!$record) {
$version = _t(__CLASS__.'.VersionUnknown', 'Unknown');
} else {
$version = $record->Version;
}

$versionParts[] = "$label $version";
}

return implode(', ', $versionParts);
}
}
2 changes: 2 additions & 0 deletions templates/SiteSummary_VersionHeader.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="site-summary__clearfix"></div>
<h3>{$Title.XML}: {$Version.XML}</h3>

0 comments on commit 1ccf490

Please sign in to comment.