Refactor functions out of the dashboard controller

This commit is contained in:
Neil Lalonde 2013-02-21 15:03:43 -05:00
parent dd6d98f48f
commit 2d1bbf22e9
4 changed files with 41 additions and 43 deletions

View File

@ -10,39 +10,7 @@
**/
window.Discourse.AdminDashboardController = Ember.Controller.extend({
loading: true,
versionCheck: null,
upToDate: function() {
if (this.get('versionCheck')) {
return this.get('versionCheck.latest_version') === this.get('versionCheck.installed_version');
}
return true;
}.property('versionCheck'),
updateIconClasses: function() {
var classes;
classes = "icon icon-warning-sign ";
if (this.get('versionCheck.critical_updates')) {
classes += "critical-updates-available";
} else {
classes += "updates-available";
}
return classes;
}.property('versionCheck.critical_updates'),
priorityClass: function() {
if (this.get('versionCheck.critical_updates')) {
return 'version-check critical';
}
}.property('versionCheck.critical_updates'),
gitLink: function() {
return "https://github.com/discourse/discourse/tree/" + this.get('versionCheck.installed_sha');
}.property('versionCheck.installed_sha'),
shortSha: function() {
return this.get('versionCheck.installed_sha').substr(0,10);
}.property('versionCheck.installed_sha')
versionCheck: null
});
}).call(this);

View File

@ -3,12 +3,24 @@
/**
Our data model for determining whether there's a new version of Discourse
@class VersionCheck
@class VersionCheck
@extends Discourse.Model
@namespace Discourse
@module Discourse
**/
window.Discourse.VersionCheck = Discourse.Model.extend({});
**/
window.Discourse.VersionCheck = Discourse.Model.extend({
upToDate: function() {
return this.get('latest_version') === this.get('installed_version');
}.property('latest_version', 'installed_version'),
gitLink: function() {
return "https://github.com/discourse/discourse/tree/" + this.get('installed_sha');
}.property('installed_sha'),
shortSha: function() {
return this.get('installed_sha').substr(0,10);
}.property('installed_sha')
});
Discourse.VersionCheck.reopenClass({
find: function() {

View File

@ -1,21 +1,21 @@
<h3>{{i18n admin.dashboard.welcome}}</h3>
{{#if Discourse.SiteSettings.version_checks}}
<p {{bindAttr class="priorityClass"}}>
<p {{bindAttr class="view.priorityClass"}}>
{{#if loading }}
{{i18n loading}}
{{else}}
{{i18n admin.dashboard.version}}: <span class="version-number">{{ versionCheck.installed_version }}</span>
{{#if versionCheck.installed_sha}}
<span class="git-version">(<a {{bindAttr href="gitLink"}} target="_blank">{{shortSha}}</a>)</span>
<span class="git-version">(<a {{bindAttr href="versionCheck.gitLink"}} target="_blank">{{versionCheck.shortSha}}</a>)</span>
{{/if}}
<span class="version-notes">
{{#if upToDate }}
{{#if versionCheck.upToDate }}
<i class='icon icon-ok update-to-date'></i> {{i18n admin.dashboard.up_to_date}}
{{else}}
<i {{bindAttr class="updateIconClasses"}}></i>
<i {{bindAttr class="view.updateIconClasses"}}></i>
<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

@ -3,13 +3,31 @@
/**
The default view in the admin section
@class AdminDashboardView
@class AdminDashboardView
@extends Discourse.View
@namespace Discourse
@module Discourse
**/
**/
Discourse.AdminDashboardView = window.Discourse.View.extend({
templateName: 'admin/templates/dashboard'
templateName: 'admin/templates/dashboard',
updateIconClasses: function() {
var classes;
classes = "icon icon-warning-sign ";
if (this.get('controller.versionCheck.critical_updates')) {
classes += "critical-updates-available";
} else {
classes += "updates-available";
}
return classes;
}.property('controller.versionCheck.critical_updates'),
priorityClass: function() {
if (this.get('controller.versionCheck.critical_updates')) {
return 'version-check critical';
}
return 'version-check normal';
}.property('controller.versionCheck.critical_updates')
});
}).call(this);