Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cydrobolt/polr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaoyi Zha <summermontreal@gmail.com>2017-04-22 00:32:30 +0300
committerChaoyi Zha <summermontreal@gmail.com>2017-04-22 00:32:30 +0300
commita90618f406f0336e5888f9835bae1d8b4fa847dd (patch)
treec7889083a2aba5e5b97bfd4887153cf893dc51c0
parent21e465e149282004840d0e9fe9c1ad1b0b41974b (diff)
Check for updates using GitHub rreleases API on the client sidefeature/update_checking
-rw-r--r--docs/user-guide/upgrading.md8
-rw-r--r--public/css/admin.css4
-rw-r--r--public/js/AdminCtrl.js57
-rw-r--r--resources/views/admin.blade.php15
-rw-r--r--resources/views/layouts/base.blade.php3
5 files changed, 82 insertions, 5 deletions
diff --git a/docs/user-guide/upgrading.md b/docs/user-guide/upgrading.md
index e55f288..ac3133f 100644
--- a/docs/user-guide/upgrading.md
+++ b/docs/user-guide/upgrading.md
@@ -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.
diff --git a/public/css/admin.css b/public/css/admin.css
index b718f20..9f2275d 100644
--- a/public/css/admin.css
+++ b/public/css/admin.css
@@ -23,6 +23,10 @@
display: none;
}
+.update-status {
+ margin-left: 0.3em;
+}
+
.api-quota {
display: inline;
}
diff --git a/public/js/AdminCtrl.js b/public/js/AdminCtrl.js
index cd0c606..432cc52 100644
--- a/public/js/AdminCtrl.js
+++ b/public/js/AdminCtrl.js
@@ -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();
diff --git a/resources/views/admin.blade.php b/resources/views/admin.blade.php
index 1940187..64be9ba 100644
--- a/resources/views/admin.blade.php
+++ b/resources/views/admin.blade.php
@@ -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)
diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php
index 85d0ea2..c3a90c6 100644
--- a/resources/views/layouts/base.blade.php
+++ b/resources/views/layouts/base.blade.php
@@ -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')