2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2016-08-03 10:13:02 -04:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
|
|
|
2015-11-20 20:27:06 -05:00
|
|
|
const VersionCheck = Discourse.Model.extend({
|
2013-07-03 11:06:07 -04:00
|
|
|
|
2016-08-03 10:13:02 -04:00
|
|
|
@computed('updated_at')
|
|
|
|
noCheckPerformed(updatedAt) {
|
|
|
|
return updatedAt === null;
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('updated_at', 'version_check_pending')
|
|
|
|
dataIsOld(updatedAt, versionCheckPending) {
|
|
|
|
return versionCheckPending || moment().diff(moment(updatedAt), 'hours') >= 48;
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('dataIsOld', 'installed_version', 'latest_version', 'missing_versions_count')
|
|
|
|
staleData(dataIsOld, installedVersion, latestVersion, missingVersionsCount) {
|
|
|
|
return dataIsOld ||
|
|
|
|
(installedVersion !== latestVersion && missingVersionsCount === 0) ||
|
|
|
|
(installedVersion === latestVersion && missingVersionsCount !== 0);
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('missing_versions_count')
|
|
|
|
upToDate(missingVersionsCount) {
|
|
|
|
return missingVersionsCount === 0 || missingVersionsCount === null;
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('missing_versions_count')
|
|
|
|
behindByOneVersion(missingVersionsCount) {
|
|
|
|
return missingVersionsCount === 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('git_branch', 'installed_sha')
|
|
|
|
gitLink(gitBranch, installedSHA) {
|
|
|
|
if (gitBranch) {
|
|
|
|
return `https://github.com/discourse/discourse/compare/${installedSHA}...${gitBranch}`;
|
|
|
|
} else {
|
|
|
|
return `https://github.com/discourse/discourse/tree/${installedSHA}`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed('installed_sha')
|
|
|
|
shortSha(installedSHA) {
|
|
|
|
return installedSHA.substr(0, 10);
|
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
2013-02-21 15:03:43 -05:00
|
|
|
|
2015-11-20 20:27:06 -05:00
|
|
|
VersionCheck.reopenClass({
|
2016-08-03 10:13:02 -04:00
|
|
|
find() {
|
|
|
|
return ajax('/admin/version_check').then(json => VersionCheck.create(json));
|
2013-02-22 15:41:12 -05:00
|
|
|
}
|
2013-03-14 08:01:52 -04:00
|
|
|
});
|
2015-11-20 20:27:06 -05:00
|
|
|
|
|
|
|
export default VersionCheck;
|