From 57603408dff38f1dc24c5a91e097ab9bba6d2b20 Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Tue, 29 May 2018 13:04:48 +1200 Subject: [PATCH] Add various extension points for security updates In order to display information from `bringyourownideas/silverstripe-composer-security-updates` we need to be able to add various information to the summary, and badges which were previously 'not a thing'. This commit makes badges 'a thing', makes them extensible, and provides a rudimentary way to alter the summary information for the on scren report. Also added were namespaces for the GridFieldComponents, but this should affect nothing (should not affect anything). --- css/sitesummary.css | 36 ++++++++++++++++++---------- src/Forms/GridFieldHtmlFragment.php | 5 +++- src/Forms/GridFieldLinkButton.php | 8 +++++-- src/Forms/GridFieldRefreshButton.php | 17 ++++++++++++- src/Model/Package.php | 29 +++++++++++++++++++++- src/Reports/SiteSummary.php | 28 +++++++++++++++++++++- templates/Package_summary.ss | 11 ++++++++- 7 files changed, 115 insertions(+), 19 deletions(-) diff --git a/css/sitesummary.css b/css/sitesummary.css index 5639861..8979928 100644 --- a/css/sitesummary.css +++ b/css/sitesummary.css @@ -1,21 +1,18 @@ -.package-summary{ +.site-summary { margin-top: 0; } -.package-summary .message { +.site-summary.message, +.site-summary .message { margin-left: 0; margin-right: 0; margin-top: 0; } -.package-summary .grid-refresh-button { +.site-summary .grid-refresh-button { margin-bottom: 0; } -.package-summary__title { - 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; @@ -26,15 +23,12 @@ margin-bottom: 12px; } -.package-summary table.ss-gridfield-table tr td.col-Summary { - padding: 0; -} - a.package-summary__anchor { color: inherit; text-decoration: inherit; display: block; - padding: 8px; + padding: 0 8px; + margin: 0 -8px; } a.package-summary__anchor:hover, @@ -42,3 +36,21 @@ a.package-summary__anchor:active { color: inherit; text-decoration: inherit; } + +.package-summary__badge { + font-size: 0.8em; + padding: 3px 5px; + background: grey; + border-radius: 2px; + color: white; + position: relative; + top: -1px; +} +/* SS4 colours */ +.package-summary__badge--good { background: #3fa142; } +.package-summary__badge--warning {background: #ff7f22;} +.package-summary__badge--bad {background: #d40404;} + +.package-summary__description { + display:block; +} diff --git a/src/Forms/GridFieldHtmlFragment.php b/src/Forms/GridFieldHtmlFragment.php index 4eadc40..4989e12 100644 --- a/src/Forms/GridFieldHtmlFragment.php +++ b/src/Forms/GridFieldHtmlFragment.php @@ -1,12 +1,15 @@ $this->link, 'Caption' => _t('GridFieldLinkButton.LINK_TO_ADDONS', 'Explore Addons') - ])->renderWith(__CLASS__); + ])->renderWith('GridFieldLinkButton'); return [$this->targetFragment => $fragment]; } diff --git a/src/Forms/GridFieldRefreshButton.php b/src/Forms/GridFieldRefreshButton.php index 7f2e329..82034e9 100644 --- a/src/Forms/GridFieldRefreshButton.php +++ b/src/Forms/GridFieldRefreshButton.php @@ -1,11 +1,26 @@ renderWith('Package_summary'); + $summary = $this->renderWith('Package_summary'); + $this->extend('updateSummary', $summary); + return $summary; + } + + /** + * Gives the summary template {@see getSummary()} a list of badges to show against a package + * + * badgeDefinitions are in the format [$title => $type] where: + * title is the unique string to display + * type is an optional class attribute (applied as a BEM modified, by default) + * + * @return ArrayList + */ + public function getBadges() + { + $badgeDefinitions = []; + $this->extend('updageBadges', $badgeDefinitions); + + $badges = ArrayList::create(); + foreach ($badgeDefinitions as $title => $type) { + $badges->push(ArrayData::create([ + 'Title' => $title, + 'Type' => $type, + ])); + } + + return $badges; } /** diff --git a/src/Reports/SiteSummary.php b/src/Reports/SiteSummary.php index 552af53..4816799 100644 --- a/src/Reports/SiteSummary.php +++ b/src/Reports/SiteSummary.php @@ -1,5 +1,9 @@ getConfig(); - $grid->addExtraClass('package-summary'); + $grid->addExtraClass('site-summary'); /** @var GridFieldExportButton $exportButton */ $exportButton = $config->getComponentByType(GridFieldExportButton::class); @@ -84,6 +88,28 @@ public function getReportField() return $grid; } + public function getCMSFields() + { + $fields = parent::getCMSFields(); + $alerts = $this->getAlerts(); + if ($alerts) { + $summaryInfo = '
' . implode("\n", $alerts) . '
'; + $fields->unshift(LiteralField::create('AlertSummary', $summaryInfo)); + } + return $fields; + } + + /** + * Return a list of alerts to display in a message box above the report + * A combination of free text fields - combined alerts as opposed to a message box per alert. + */ + protected function getAlerts() + { + $alerts = []; + $this->extend('updateAlerts', $alerts); + return $alerts; + } + /** * Extract CMS and Framework version details from the records in the report * diff --git a/templates/Package_summary.ss b/templates/Package_summary.ss index 3b18066..8972ac3 100644 --- a/templates/Package_summary.ss +++ b/templates/Package_summary.ss @@ -1,4 +1,13 @@ " class="package-summary__anchor" target="_blank" rel="noopener"> $Title.XML - <% if $Description %>$Description.XML<% end_if %> + + <% if $Badges %> + <% loop $Badges %> + $Title + <% end_loop %> + <% end_if %> + + <% if $Description %> + $Description.XML + <% end_if %>