Refactoring and various enhancements
This commit is contained in:
parent
59a829839b
commit
4ee8ccf93c
|
|
@ -49,17 +49,10 @@ module DockerManager
|
|||
|
||||
def progress
|
||||
repo = find_repos(params[:path], upgrading: true)
|
||||
repo = find_repos(params[:path], all: true) if all_repos? && repo.blank?
|
||||
|
||||
raise Discourse::NotFound unless repo.present?
|
||||
return respond_progress if repo.blank?
|
||||
|
||||
upgrader = Upgrader.new(current_user.id, repo, repo_version(repo))
|
||||
render json: {
|
||||
progress: {
|
||||
logs: upgrader.find_logs,
|
||||
percentage: upgrader.last_percentage
|
||||
}
|
||||
}
|
||||
respond_progress(logs: upgrader.find_logs, percentage: upgrader.last_percentage)
|
||||
end
|
||||
|
||||
def latest
|
||||
|
|
@ -119,6 +112,15 @@ module DockerManager
|
|||
|
||||
private
|
||||
|
||||
def respond_progress(logs: nil, percentage: nil)
|
||||
render json: {
|
||||
progress: {
|
||||
logs: logs,
|
||||
percentage: percentage
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def all_repos?
|
||||
params[:path] == "all"
|
||||
end
|
||||
|
|
@ -132,12 +134,16 @@ module DockerManager
|
|||
return repos if all
|
||||
|
||||
repos.select do |repo|
|
||||
(upgrading || !repo.upgrading?) && (repo.latest_local_commit != repo.latest_origin_commit)
|
||||
if upgrading
|
||||
repo.upgrading?
|
||||
else
|
||||
!repo.upgrading? && (repo.latest_local_commit != repo.latest_origin_commit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def repo_version(repo)
|
||||
return repo.is_a?(Array) ? concat_repos_versions(repo) : params[:version]
|
||||
return repo.is_a?(Array) && params[:version].blank? ? concat_repos_versions(repo) : params[:version]
|
||||
end
|
||||
|
||||
def concat_repos_versions(repos)
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -52,13 +52,16 @@ export default Ember.Controller.extend({
|
|||
case "status":
|
||||
this.set('status', msg.value);
|
||||
|
||||
if (msg.value === "complete") {
|
||||
this.get("model").filter(repo => repo.get("upgrading")).forEach(repo => {
|
||||
repo.set("version", repo.get("latest.version"));
|
||||
});
|
||||
}
|
||||
|
||||
if (msg.value === 'complete' || msg.value === 'failed') {
|
||||
this.updateAttribute('upgrading', false);
|
||||
}
|
||||
|
||||
if (msg.value === 'complete') {
|
||||
this.updateAttribute('version', "latest.version", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
@ -72,9 +75,8 @@ export default Ember.Controller.extend({
|
|||
}.property("upgrading"),
|
||||
|
||||
startBus() {
|
||||
const self = this;
|
||||
MessageBus.subscribe("/docker/upgrade", function(msg) {
|
||||
self.messageReceived(msg);
|
||||
MessageBus.subscribe("/docker/upgrade", msg => {
|
||||
this.messageReceived(msg);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -91,7 +93,7 @@ export default Ember.Controller.extend({
|
|||
this.reset();
|
||||
|
||||
if (this.get("multiUpgrade")) {
|
||||
this.updateAttribute("upgrading", true);
|
||||
this.get("model").filter(repo => !repo.get("upToDate")).forEach(repo => repo.set("upgrading", true));
|
||||
return Repo.upgradeAll();
|
||||
}
|
||||
|
||||
|
|
@ -101,21 +103,19 @@ export default Ember.Controller.extend({
|
|||
},
|
||||
|
||||
resetUpgrade() {
|
||||
const self = this;
|
||||
|
||||
bootbox.confirm("WARNING: You should only reset upgrades that have failed and are not running.\n\n"+
|
||||
"This will NOT cancel currently running builds and should only be used as a last resort.", function(result) {
|
||||
"This will NOT cancel currently running builds and should only be used as a last resort.", result => {
|
||||
if (result) {
|
||||
if (self.get("multiUpgrade")) {
|
||||
return Repo.resetAll().finally(() => {
|
||||
self.reset();
|
||||
if (this.get("multiUpgrade")) {
|
||||
return Repo.resetAll(this.get("model").filter(repo => !repo.get("upToDate"))).finally(() => {
|
||||
this.reset();
|
||||
this.updateAttribute("upgrading", false);
|
||||
});
|
||||
}
|
||||
|
||||
const repo = self.get('model')[0];
|
||||
const repo = this.get('model')[0];
|
||||
repo.resetUpgrade().then(function() {
|
||||
self.reset();
|
||||
this.reset();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,9 +3,13 @@
|
|||
import request from 'ember-ajax/request';
|
||||
import Ember from 'ember';
|
||||
|
||||
var loaded = [];
|
||||
let loaded = [];
|
||||
|
||||
var Repo = Ember.Object.extend({
|
||||
function concatVersions(repos) {
|
||||
return repos.map(repo => repo.get("version")).join(", ");
|
||||
}
|
||||
|
||||
const Repo = Ember.Object.extend({
|
||||
unloaded: true,
|
||||
checking: false,
|
||||
|
||||
|
|
@ -35,17 +39,15 @@ var Repo = Ember.Object.extend({
|
|||
},
|
||||
|
||||
findLatest: function() {
|
||||
var self = this;
|
||||
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
if (!self.get('shouldCheck')) {
|
||||
self.set('unloaded', false);
|
||||
return new Ember.RSVP.Promise(resolve => {
|
||||
if (!this.get('shouldCheck')) {
|
||||
this.set('unloaded', false);
|
||||
return resolve();
|
||||
}
|
||||
|
||||
self.set('checking', true);
|
||||
self.repoAjax(Discourse.getURL('/admin/docker/latest')).then(function(result) {
|
||||
self.setProperties({
|
||||
this.set('checking', true);
|
||||
this.repoAjax(Discourse.getURL('/admin/docker/latest')).then(result => {
|
||||
this.setProperties({
|
||||
unloaded: false,
|
||||
checking: false,
|
||||
lastCheckedAt: new Date().getTime(),
|
||||
|
|
@ -57,24 +59,20 @@ var Repo = Ember.Object.extend({
|
|||
},
|
||||
|
||||
findProgress: function() {
|
||||
return this.repoAjax(Discourse.getURL('/admin/docker/progress')).then(function(result) {
|
||||
return result.progress;
|
||||
});
|
||||
return this.repoAjax(Discourse.getURL('/admin/docker/progress')).then(result => result.progress);
|
||||
},
|
||||
|
||||
resetUpgrade: function() {
|
||||
var self = this;
|
||||
return this.repoAjax(Discourse.getURL('/admin/docker/upgrade'), { dataType: 'text', type: 'DELETE' }).then(function() {
|
||||
self.set('upgrading', false);
|
||||
return this.repoAjax(Discourse.getURL('/admin/docker/upgrade'), { dataType: 'text', type: 'DELETE' }).then(() => {
|
||||
this.set('upgrading', false);
|
||||
});
|
||||
},
|
||||
|
||||
startUpgrade: function() {
|
||||
var self = this;
|
||||
this.set('upgrading', true);
|
||||
|
||||
return this.repoAjax(Discourse.getURL('/admin/docker/upgrade'), { dataType: 'text', type: 'POST' }).catch(function() {
|
||||
self.set('upgrading', false);
|
||||
return this.repoAjax(Discourse.getURL('/admin/docker/upgrade'), { dataType: 'text', type: 'POST' }).catch(() => {
|
||||
this.set('upgrading', false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -84,41 +82,35 @@ Repo.reopenClass({
|
|||
return new Ember.RSVP.Promise(function (resolve) {
|
||||
if (loaded.length) { return resolve(loaded); }
|
||||
|
||||
request(Discourse.getURL("/admin/docker/repos")).then(function(result) {
|
||||
loaded = result.repos.map(function(r) {
|
||||
return Repo.create(r);
|
||||
});
|
||||
request(Discourse.getURL("/admin/docker/repos")).then(result => {
|
||||
loaded = result.repos.map(r => Repo.create(r));
|
||||
resolve(loaded);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
findUpgrading: function() {
|
||||
return this.findAll().then(function(result) {
|
||||
return result.findBy('upgrading', true);
|
||||
});
|
||||
return this.findAll().then(result => result.findBy('upgrading', true));
|
||||
},
|
||||
|
||||
find: function(id) {
|
||||
return this.findAll().then(function(result) {
|
||||
return result.findBy('id', id);
|
||||
});
|
||||
return this.findAll().then(result => result.findBy('id', id));
|
||||
},
|
||||
|
||||
upgradeAll() {
|
||||
return request(Discourse.getURL("/admin/docker/upgrade"), { dataType: "text", type: "POST", data: { path: "all" } });
|
||||
},
|
||||
|
||||
resetAll() {
|
||||
return request(Discourse.getURL("/admin/docker/upgrade"), { dataType: "text", type: "DELETE", data: { path: "all" } });
|
||||
resetAll(repos) {
|
||||
return request(Discourse.getURL("/admin/docker/upgrade"), { dataType: "text", type: "DELETE", data: { path: "all", version: concatVersions(repos) } });
|
||||
},
|
||||
|
||||
findLatestAll() {
|
||||
return request(Discourse.getURL("/admin/docker/latest"), { dataType: "text", type: "GET", data: { path: "all" } });
|
||||
},
|
||||
|
||||
findAllProgress() {
|
||||
return request(Discourse.getURL("/admin/docker/progress"), { dataType: "text", type: "GET", data: { path: "all" } });
|
||||
findAllProgress(repos) {
|
||||
return request(Discourse.getURL("/admin/docker/progress"), { dataType: "text", type: "GET", data: { path: "all", version: concatVersions(repos) } });
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export default Ember.Route.extend({
|
|||
repo.set("latest", Ember.Object.create(_repo));
|
||||
});
|
||||
|
||||
return Repo.findAllProgress().then(progress => {
|
||||
return Repo.findAllProgress(model.filter(repo => !repo.get("upToDate"))).then(progress => {
|
||||
this.set("progress", JSON.parse(progress).progress);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue