From f8e04a5c48652295f2711af6816a8dc2182d07c7 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 5 Mar 2013 18:14:51 -0500 Subject: [PATCH] Version check gets how many versions behind you are, and shows judgemental faces on the dashboard --- .../javascripts/admin/models/version_check.js | 8 +++++-- .../admin/templates/dashboard.js.handlebars | 10 +++++++-- app/assets/stylesheets/admin/admin_base.scss | 14 ++++++------- app/models/discourse_version_check.rb | 2 +- .../discourse_version_check_serializer.rb | 2 +- lib/discourse_updates.rb | 21 ++++++++++++------- lib/jobs/version_check.rb | 1 + 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/admin/models/version_check.js b/app/assets/javascripts/admin/models/version_check.js index 8ef1d79c89a..958bef4564c 100644 --- a/app/assets/javascripts/admin/models/version_check.js +++ b/app/assets/javascripts/admin/models/version_check.js @@ -8,8 +8,12 @@ **/ Discourse.VersionCheck = Discourse.Model.extend({ upToDate: function() { - return this.get('latest_version') === this.get('installed_version'); - }.property('latest_version', 'installed_version'), + return this.get('missing_versions_count') === 0; + }.property('missing_versions_count'), + + behindByOneVersion: function() { + return this.get('missing_versions_count') === 1; + }.property('missing_versions_count'), gitLink: function() { return "https://github.com/discourse/discourse/tree/" + this.get('installed_sha'); diff --git a/app/assets/javascripts/admin/templates/dashboard.js.handlebars b/app/assets/javascripts/admin/templates/dashboard.js.handlebars index c91c5350bab..0e97ac0e777 100644 --- a/app/assets/javascripts/admin/templates/dashboard.js.handlebars +++ b/app/assets/javascripts/admin/templates/dashboard.js.handlebars @@ -14,9 +14,15 @@

{{i18n admin.dashboard.latest_version}}: {{ versionCheck.latest_version }} {{#if versionCheck.upToDate }} - {{i18n admin.dashboard.up_to_date}} + {{i18n admin.dashboard.up_to_date}} {{else}} - + + {{#if versionCheck.behindByOneVersion}} + ☺ + {{else}} + ☹ + {{/if}} + {{i18n admin.dashboard.critical_available}} {{i18n admin.dashboard.updates_available}} {{i18n admin.dashboard.please_upgrade}} diff --git a/app/assets/stylesheets/admin/admin_base.scss b/app/assets/stylesheets/admin/admin_base.scss index c15f906f27e..98602f9ef51 100644 --- a/app/assets/stylesheets/admin/admin_base.scss +++ b/app/assets/stylesheets/admin/admin_base.scss @@ -93,7 +93,7 @@ font-weight: bold } - .version-notes i.icon { + .version-notes .icon { margin-left: 20px; } @@ -104,17 +104,17 @@ display: none; } - i.icon { - font-size: 20px; + .icon { + font-size: 26px; } - i.update-to-date { + .update-to-date { color: green; } - i.updates-available { - color: orange; + .updates-available { + color: #FF9500; } - i.critical-updates-available { + .critical-updates-available { color: red; } } diff --git a/app/models/discourse_version_check.rb b/app/models/discourse_version_check.rb index 144ffdbf345..803e7cee3d6 100644 --- a/app/models/discourse_version_check.rb +++ b/app/models/discourse_version_check.rb @@ -5,7 +5,7 @@ class DiscourseVersionCheck include ActiveAttr::MassAssignment include ActiveModel::Serialization - attr_accessor :latest_version, :critical_updates, :installed_version, :installed_sha + attr_accessor :latest_version, :critical_updates, :installed_version, :installed_sha, :missing_versions_count def active_model_serializer DiscourseVersionCheckSerializer diff --git a/app/serializers/discourse_version_check_serializer.rb b/app/serializers/discourse_version_check_serializer.rb index a13ca3c70b9..91adad35397 100644 --- a/app/serializers/discourse_version_check_serializer.rb +++ b/app/serializers/discourse_version_check_serializer.rb @@ -1,5 +1,5 @@ class DiscourseVersionCheckSerializer < ApplicationSerializer - attributes :latest_version, :critical_updates, :installed_version, :installed_sha + attributes :latest_version, :critical_updates, :installed_version, :installed_sha, :missing_versions_count self.root = false end \ No newline at end of file diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb index c5c793b11de..00682e5119d 100644 --- a/lib/discourse_updates.rb +++ b/lib/discourse_updates.rb @@ -7,27 +7,30 @@ module DiscourseUpdates latest_version: latest_version || Discourse::VERSION::STRING, critical_updates: critical_update_available?, installed_version: Discourse::VERSION::STRING, - installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version) + installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version), + missing_versions_count: missing_versions_count || nil # TODO: more info, like links and release messages ) end - def latest_version=(arg) - $redis.set latest_version_key, arg - end - def latest_version $redis.get latest_version_key end - def critical_update_available=(arg) - $redis.set critical_updates_available_key, arg + def missing_versions_count + $redis.get(missing_versions_count_key).try(:to_i) end def critical_update_available? ($redis.get(critical_updates_available_key) || false) == 'true' end + ['latest_version', 'missing_versions_count', 'critical_update_available'].each do |name| + eval "define_method :#{name}= do |arg| + $redis.set #{name}_key, arg + end" + end + private @@ -38,5 +41,9 @@ module DiscourseUpdates def critical_updates_available_key 'critical_updates_available' end + + def missing_versions_count_key + 'missing_versions_count' + end end end \ No newline at end of file diff --git a/lib/jobs/version_check.rb b/lib/jobs/version_check.rb index d5652f5566f..b2ef87b1fff 100644 --- a/lib/jobs/version_check.rb +++ b/lib/jobs/version_check.rb @@ -9,6 +9,7 @@ module Jobs json = DiscourseHub.discourse_version_check DiscourseUpdates.latest_version = json['latestVersion'] DiscourseUpdates.critical_update_available = json['criticalUpdates'] + DiscourseUpdates.missing_versions_count = json['missingVersionsCount'] end true end