mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
refactor version-check to ES6
This commit is contained in:
parent
35c13bca6c
commit
cb809784df
1 changed files with 38 additions and 30 deletions
|
@ -1,45 +1,53 @@
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
const VersionCheck = Discourse.Model.extend({
|
const VersionCheck = Discourse.Model.extend({
|
||||||
|
|
||||||
noCheckPerformed: function() {
|
@computed('updated_at')
|
||||||
return this.get('updated_at') === null;
|
noCheckPerformed(updatedAt) {
|
||||||
}.property('updated_at'),
|
return updatedAt === null;
|
||||||
|
},
|
||||||
|
|
||||||
dataIsOld: function() {
|
@computed('updated_at', 'version_check_pending')
|
||||||
return this.get('version_check_pending') || moment().diff(moment(this.get('updated_at')), 'hours') >= 48;
|
dataIsOld(updatedAt, versionCheckPending) {
|
||||||
}.property('updated_at'),
|
return versionCheckPending || moment().diff(moment(updatedAt), 'hours') >= 48;
|
||||||
|
},
|
||||||
|
|
||||||
staleData: function() {
|
@computed('dataIsOld', 'installed_version', 'latest_version', 'missing_versions_count')
|
||||||
return ( this.get('dataIsOld') ||
|
staleData(dataIsOld, installedVersion, latestVersion, missingVersionsCount) {
|
||||||
(this.get('installed_version') !== this.get('latest_version') && this.get('missing_versions_count') === 0) ||
|
return dataIsOld ||
|
||||||
(this.get('installed_version') === this.get('latest_version') && this.get('missing_versions_count') !== 0) );
|
(installedVersion !== latestVersion && missingVersionsCount === 0) ||
|
||||||
}.property('dataIsOld', 'missing_versions_count', 'installed_version', 'latest_version'),
|
(installedVersion === latestVersion && missingVersionsCount !== 0);
|
||||||
|
},
|
||||||
|
|
||||||
upToDate: function() {
|
@computed('missing_versions_count')
|
||||||
return this.get('missing_versions_count') === 0 || this.get('missing_versions_count') === null;
|
upToDate(missingVersionsCount) {
|
||||||
}.property('missing_versions_count'),
|
return missingVersionsCount === 0 || missingVersionsCount === null;
|
||||||
|
},
|
||||||
|
|
||||||
behindByOneVersion: function() {
|
@computed('missing_versions_count')
|
||||||
return this.get('missing_versions_count') === 1;
|
behindByOneVersion(missingVersionsCount) {
|
||||||
}.property('missing_versions_count'),
|
return missingVersionsCount === 1;
|
||||||
|
},
|
||||||
|
|
||||||
gitLink: function() {
|
@computed('git_branch', 'installed_sha')
|
||||||
const git_branch = this.get('git_branch');
|
gitLink(gitBranch, installedSHA) {
|
||||||
if (git_branch)
|
if (gitBranch) {
|
||||||
return "https://github.com/discourse/discourse/compare/" + this.get('installed_sha') + "..." + git_branch;
|
return `https://github.com/discourse/discourse/compare/${installedSHA}...${gitBranch}`;
|
||||||
return "https://github.com/discourse/discourse/tree/" + this.get('installed_sha');
|
} else {
|
||||||
}.property('installed_sha', 'git_branch'),
|
return `https://github.com/discourse/discourse/tree/${installedSHA}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
shortSha: function() {
|
@computed('installed_sha')
|
||||||
return this.get('installed_sha').substr(0,10);
|
shortSha(installedSHA) {
|
||||||
}.property('installed_sha')
|
return installedSHA.substr(0, 10);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
VersionCheck.reopenClass({
|
VersionCheck.reopenClass({
|
||||||
find: function() {
|
find() {
|
||||||
return ajax('/admin/version_check').then(function(json) {
|
return ajax('/admin/version_check').then(json => VersionCheck.create(json));
|
||||||
return VersionCheck.create(json);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue