Version check gets how many versions behind you are, and shows judgemental faces on the dashboard

This commit is contained in:
Neil Lalonde 2013-03-05 18:14:51 -05:00
parent 3c1388bbd7
commit f8e04a5c48
7 changed files with 38 additions and 20 deletions

View File

@ -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');

View File

@ -14,9 +14,15 @@
<p class="version-notes">
{{i18n admin.dashboard.latest_version}}: <span class="version-number">{{ versionCheck.latest_version }}</span>
{{#if versionCheck.upToDate }}
<i class='icon icon-ok update-to-date'></i> {{i18n admin.dashboard.up_to_date}}
<span class='icon update-to-date'>☻</span> {{i18n admin.dashboard.up_to_date}}
{{else}}
<i {{bindAttr class=":icon :icon-warning-sign versionCheck.critical_updates:critical-updates-available:updates-available"}}></i>
<span {{bindAttr class=":icon versionCheck.critical_updates:critical-updates-available:updates-available"}}>
{{#if versionCheck.behindByOneVersion}}
{{else}}
{{/if}}
</span>
<span class="critical-note">{{i18n admin.dashboard.critical_available}}</span>
<span class="normal-note">{{i18n admin.dashboard.updates_available}}</span>
{{i18n admin.dashboard.please_upgrade}}

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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