Skip to content

Commit

Permalink
API Rename getActiveJob to getPendingJob, add last updated date to re…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
robbieaverill committed May 31, 2018
1 parent 409319f commit 3fc275c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 30 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 36 additions & 10 deletions client/src/bundles/CheckForUpdates.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
/* global window */

window.jQuery.entwine('ss', ($) => {
// p tag that holds button
/**
* p tag that holds button
*/
$('#checkForUpdates').entwine({
// Magically set by the magic get/set{thisMemberProperty} (see poll function below)
/**
* Magically set by the magic get/set{thisMemberProperty} (see poll function below)
*/
PollTimeout: null,

/**
* Start the loading process
*/
onclick() {
this.setLoading();
},

/**
* Poll the current job and update the frontend status
*/
onmatch() {
// Poll the current job and update the front end status
if (this.getButton(true).length) {
this.setLoading();
}
},

/**
* Add warning message (set as data attribute on GridFieldRefreshButton) before
* and has finished
Expand All @@ -22,19 +34,21 @@ window.jQuery.entwine('ss', ($) => {
const message = this.getButton().data('message');
$('.ss-gridfield-buttonrow')
.first()
.prepend(`<p class="message warning">${message}</p>`);
.prepend(`<p class="alert alert-info">${message}</p>`);
this.poll();
},

/**
* Poll the provided "check" endpoint to determine whether the job has been processed
* and has finished.
*/
poll() {
const self = this;
$.ajax({
url: this.getButton().data('check'),
url: self.getButton().data('check'),
async: true,
success: (data) => {
this.clearLoading(JSON.parse(data));
self.clearLoading(JSON.parse(data));
},
error: (error) => {
if (typeof console !== 'undefined') {
Expand All @@ -43,15 +57,27 @@ window.jQuery.entwine('ss', ($) => {
}
});
},

/**
* Returns the "Check for updates" button
*
* @param {boolean} disabled
*/
getButton(disabled) {
let button = 'button';
if (disabled) {
button += ':disabled';
button += ':disabled';
}
return this.children(button).first();
},
clearLoading(hasRunningJob) {
if (hasRunningJob === false) {

/**
* Cleanup timers and reload the GridField
* @param {String|boolean} checkResult
*/
clearLoading(checkResult) {
if (checkResult !== true) {
// Reload the report
this.closest('fieldset.ss-gridfield').reload();
return;
}
Expand All @@ -63,6 +89,6 @@ window.jQuery.entwine('ss', ($) => {
this.setPollTimeout(setTimeout(() => {
$('#checkForUpdates').poll();
}, 5000));
}
},
});
});
Empty file added lang/_manifest_exclude
Empty file.
29 changes: 29 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
en:
BringYourOwnIdeas\Maintenance\Forms\GridFieldDropdownFilter:
AllResults: 'All results'
BringYourOwnIdeas\Maintenance\Model\Package:
PLURALNAME: Packages
PLURALS:
one: 'A Package'
other: '{count} Packages'
SINGULARNAME: Package
BringYourOwnIdeas\Maintenance\Reports\SiteSummary:
FilterSupported: 'Supported modules'
FilterUnsupported: 'Unsupported modules'
LAST_UPDATED: 'Last updated {updated}'
LINK_TO_ADDONS: 'Explore Addons'
ShowAllModules: 'Show all modules'
TITLE: 'Installed modules'
VERSION: Version
VersionUnknown: Unknown
BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask:
DESCRIPTION: 'Repopulates installation summary, listing installed modules and information associated with each.'
TITLE: 'Refresh installed package info'
CheckForUpdates:
TITLE: 'Check for updates'
GridFieldRefreshButton:
MESSAGE: 'Updating this list may take 2-3 minutes. You can continue to use the CMS while we run the update.'
REFRESH: 'Check for updates'
UPDATE: Updating...
SiteSummary:
AddonsLinkTitle: 'View {package} on addons.silverstripe.org'
20 changes: 11 additions & 9 deletions src/Forms/GridFieldRefreshButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace BringYourOwnIdeas\Maintenance\Forms;

use BringYourOwnIdeas\Maintenance\Reports\SiteSummary;
use SilverStripe\ORM\DataList;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\View\ArrayData;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use Symbiote\QueuedJobs\Services\QueuedJob;
use BringYourOwnIdeas\Maintenance\Jobs\CheckForUpdatesJob;
Expand Down Expand Up @@ -72,7 +74,7 @@ public function getHTMLFragments($gridField)
)
);

if ($this->hasActiveJob()) {
if ($this->hasPendingJob()) {
$button->setTitle(_t('GridFieldRefreshButton.UPDATE', 'Updating...'));
$button->setDisabled(true);
}
Expand Down Expand Up @@ -126,12 +128,12 @@ public function getURLHandlers($gridField)
}

/**
* @see hasActiveJob
* @return string JSON boolean
* @see hasPendingJob
* @return string JSON encoded value for whether there is a job pending or in process to update the report
*/
public function handleCheck()
{
$isRunning = $this->hasActiveJob();
$isRunning = $this->hasPendingJob();
return Convert::raw2json($isRunning);
}

Expand All @@ -141,10 +143,10 @@ public function handleCheck()
*
* @return boolean
*/
public function hasActiveJob()
public function hasPendingJob()
{
/** @var DataList $jobList */
$jobList = Injector::inst()
/** @var QueuedJobDescriptor $job */
$job = Injector::inst()
->get(QueuedJobService::class)
->getJobList(QueuedJob::QUEUED)
->filter([
Expand All @@ -158,15 +160,15 @@ public function hasActiveJob()
]
]);

return $jobList->exists();
return $job->exists();
}

/**
* Handle the refresh, for both the action button and the URL
*/
public function handleRefresh()
{
if (!$this->hasActiveJob()) {
if (!$this->hasPendingJob()) {
$injector = Injector::inst();
$injector->get(QueuedJobService::class)->queueJob($injector->create(CheckForUpdatesJob::class));
}
Expand Down
32 changes: 24 additions & 8 deletions src/Reports/SiteSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace BringYourOwnIdeas\Maintenance\Reports;

use BringYourOwnIdeas\Maintenance\Forms\GridFieldDropdownFilter;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldHtmlFragment;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldLinkButton;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldRefreshButton;
use BringYourOwnIdeas\Maintenance\Model\Package;
use SilverStripe\Core\Config\Config;
use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\View\Requirements;
use SilverStripe\Forms\GridField\GridFieldExportButton;
use SilverStripe\View\ArrayData;
use SilverStripe\Core\Injector\Injector;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldDropdownFilter;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldRefreshButton;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldLinkButton;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldHtmlFragment;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Reports\Report;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;

/**
* A report listing all installed modules used in this site (from a cache).
Expand Down Expand Up @@ -86,6 +86,7 @@ public function getReportField()
$versionHtml = ArrayData::create([
'Title' => _t(__CLASS__ . '.VERSION', 'Version'),
'Version' => $this->resolveCmsVersion(),
'LastUpdated' => $this->getLastUpdated(),
])->renderWith('SiteSummary_VersionHeader');

/** @var GridFieldDropdownFilter $dropdownFilter */
Expand Down Expand Up @@ -158,4 +159,19 @@ protected function resolveCmsVersion()

return implode(', ', $versionParts);
}

/**
* Get the "last updated" date for the report. This is based on the modified date of any of the records, since
* they are regenerated when the report is generated.
*
* @return string
*/
public function getLastUpdated()
{
$packages = Package::get()->limit(1);
if (!$packages->count()) {
return '';
}
return $packages->first()->dbObject('LastEdited')->Nice();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<span class="grid-refresh-button" id="checkForUpdates">
<span class="grid-refresh-button site-summary__check-for-updates" id="checkForUpdates">
$Button
</span>
5 changes: 4 additions & 1 deletion templates/SiteSummary_VersionHeader.ss
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<div class="site-summary__clearfix"></div>
<h3>{$Title.XML}: {$Version.XML}</h3>
<h3>{$Title}: {$Version}</h3>
<p class="site-summary__last-updated">
<%t BringYourOwnIdeas\\Maintenance\\Reports\\SiteSummary.LAST_UPDATED "Last updated {updated}" updated=$LastUpdated %>
</p>

0 comments on commit 3fc275c

Please sign in to comment.