From 2d1bbf22e95c266643a68141fe1a1e2218f4099b Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 21 Feb 2013 15:03:43 -0500 Subject: [PATCH] Refactor functions out of the dashboard controller --- .../controllers/admin_dashboard_controller.js | 34 +------------------ .../javascripts/admin/models/version_check.js | 18 ++++++++-- .../admin/templates/dashboard.js.handlebars | 8 ++--- .../admin/views/admin_dashboard_view.js | 24 +++++++++++-- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js b/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js index efc3243d94d..5c00923dcb9 100644 --- a/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_dashboard_controller.js @@ -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); diff --git a/app/assets/javascripts/admin/models/version_check.js b/app/assets/javascripts/admin/models/version_check.js index 687f08cdd80..5692b7d2885 100644 --- a/app/assets/javascripts/admin/models/version_check.js +++ b/app/assets/javascripts/admin/models/version_check.js @@ -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() { diff --git a/app/assets/javascripts/admin/templates/dashboard.js.handlebars b/app/assets/javascripts/admin/templates/dashboard.js.handlebars index 9ee62a1e25f..316621c7d97 100644 --- a/app/assets/javascripts/admin/templates/dashboard.js.handlebars +++ b/app/assets/javascripts/admin/templates/dashboard.js.handlebars @@ -1,21 +1,21 @@

{{i18n admin.dashboard.welcome}}

{{#if Discourse.SiteSettings.version_checks}} -

+

{{#if loading }} {{i18n loading}} {{else}} {{i18n admin.dashboard.version}}: {{ versionCheck.installed_version }} {{#if versionCheck.installed_sha}} - ({{shortSha}}) + ({{versionCheck.shortSha}}) {{/if}} - {{#if upToDate }} + {{#if versionCheck.upToDate }} {{i18n admin.dashboard.up_to_date}} {{else}} - + {{i18n admin.dashboard.critical_available}} {{i18n admin.dashboard.updates_available}} {{i18n admin.dashboard.please_upgrade}} diff --git a/app/assets/javascripts/admin/views/admin_dashboard_view.js b/app/assets/javascripts/admin/views/admin_dashboard_view.js index 9ab4bf42383..55cbbbc8894 100644 --- a/app/assets/javascripts/admin/views/admin_dashboard_view.js +++ b/app/assets/javascripts/admin/views/admin_dashboard_view.js @@ -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);