mirror of
https://github.com/cydrobolt/polr.git
synced 2024-11-09 11:42:28 +01:00
Check for updates using GitHub rreleases API on the client side
This commit is contained in:
parent
21e465e149
commit
a90618f406
@ -5,10 +5,10 @@ To upgrade your Polr instance to the latest `master` or to a new release, you mu
|
||||
## Upgrading from 2.x:
|
||||
|
||||
- Back up your database and files
|
||||
- Update your files by using `git pull` or downloading a release
|
||||
- Run `composer install --no-dev -o` to ensure dependencies are up to date
|
||||
- Migrate database with `php artisan migrate` to ensure database structure is up to date
|
||||
- Update your files using `git pull` or `git checkout <version_tag>` (e.g `git checkout 2.2.0`)
|
||||
- Run `composer install --no-dev -o` to ensure your dependencies are up to date
|
||||
- Migrate your database with `php artisan migrate` to ensure your table structure is up to date
|
||||
|
||||
## Upgrading from 1.x:
|
||||
|
||||
There are breaking changes between 2.x and 1.x; it is not yet possible to automatically upgrade to 2.x.
|
||||
There are breaking changes between 2.x and 1.x, thus it is not yet possible to automatically upgrade from 1.x to 2.x.
|
||||
|
@ -23,6 +23,10 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.update-status {
|
||||
margin-left: 0.3em;
|
||||
}
|
||||
|
||||
.api-quota {
|
||||
display: inline;
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
polr.controller('AdminCtrl', function($scope, $compile) {
|
||||
$scope.state = {
|
||||
showNewUserWell: false
|
||||
showNewUserWell: false,
|
||||
updates: {
|
||||
statusClass: 'fa fa-spin fa-gear',
|
||||
status: 'Checking for updates...',
|
||||
newVersionAvailable: false
|
||||
}
|
||||
};
|
||||
$scope.datatables = {};
|
||||
|
||||
@ -70,6 +75,51 @@ polr.controller('AdminCtrl', function($scope, $compile) {
|
||||
}, datatables_config));
|
||||
};
|
||||
|
||||
$scope.compSemver = function(a, b) {
|
||||
var pa = a.split('.');
|
||||
var pb = b.split('.');
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var na = Number(pa[i]);
|
||||
var nb = Number(pb[i]);
|
||||
if (na > nb) return 1;
|
||||
if (nb > na) return -1;
|
||||
if (!isNaN(na) && isNaN(nb)) return 1;
|
||||
if (isNaN(na) && !isNaN(nb)) return -1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
$scope.checkPolrUpdates = function() {
|
||||
$.ajax({
|
||||
url: 'https://api.github.com/repos/cydrobolt/polr/releases/latest',
|
||||
method: 'GET',
|
||||
dataType: 'json',
|
||||
headers: null
|
||||
}).done(function(data) {
|
||||
console.log(data);
|
||||
// Given the latest release, compare to currently installed release.
|
||||
// Show a notice to admins if a newer version is available.
|
||||
// https://developer.github.com/v3/repos/releases/#get-the-latest-release
|
||||
var remoteVersion = data.tag_name; // e.g 2.2.0
|
||||
var updateDescription = data.body; // detailed changelog
|
||||
|
||||
var compResult = $scope.compSemver(POLR_VERSION, remoteVersion);
|
||||
|
||||
if (compResult == 1) {
|
||||
$scope.state.updates.statusClass = 'fa fa-gears';
|
||||
$scope.state.updates.status = 'A new update is available: ' + data.name;
|
||||
$scope.state.updates.newVersionAvailable = true;
|
||||
}
|
||||
else {
|
||||
$scope.state.updates.statusClass = 'fa fa-check';
|
||||
$scope.state.updates.status = 'You are running the latest version of Polr';
|
||||
}
|
||||
}).fail(function(error) {
|
||||
alert('lmao it no work');
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// Append modals to Angular root
|
||||
$scope.appendModal = function(html, id) {
|
||||
id = esc_selector(id);
|
||||
@ -302,6 +352,11 @@ polr.controller('AdminCtrl', function($scope, $compile) {
|
||||
});
|
||||
|
||||
$scope.initTables();
|
||||
|
||||
if (true) {
|
||||
// FIXME should check if admin
|
||||
$scope.checkPolrUpdates();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
@if ($role == $admin_role)
|
||||
<li role='presentation' class='admin-nav-item'><a href='#admin'>Admin</a></li>
|
||||
<li role='presentation' class='admin-nav-item'><a href='#updates'>Updates <span id="updates-counter"></span></a></li>
|
||||
@endif
|
||||
|
||||
@if ($api_active == 1)
|
||||
@ -85,8 +86,22 @@
|
||||
@include('snippets.user_table', [
|
||||
'table_id' => 'admin_users_table'
|
||||
])
|
||||
</div>
|
||||
|
||||
<div role="tabpanel" class="tab-pane" id="updates">
|
||||
<h3>Updates</h3>
|
||||
<p>
|
||||
<i ng-class="state.updates.statusClass"></i>
|
||||
<span class="text-muted update-status" ng-bind="state.updates.status">Checking for updates...</span>
|
||||
</p>
|
||||
<p ng-if="state.updates.newVersionAvailable">
|
||||
To upgrade Polr, follow the instructions provided in the <a href="//docs.polr.me/en/latest/user-guide/upgrading/">upgrade guide</a>.
|
||||
</p>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@endif
|
||||
|
||||
@if ($api_active == 1)
|
||||
|
@ -78,6 +78,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
toastr["error"](`{{ str_replace('`', '\`', $error) }}`, "Error")
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
// Define Polr version
|
||||
var POLR_VERSION = '{{ env('POLR_VERSION') }}';
|
||||
</script>
|
||||
|
||||
@yield('js')
|
||||
|
Loading…
Reference in New Issue
Block a user