diaspora/app/assets/javascripts/app/views/pod_entry_view.js
Florian Staudacher ea397ffdfb Add connection test for pods in the network
* add a class for checking pod connectivity
* extend pod model to handle new functionality
* add an admin frontend to list pods and re-trigger checks manually
* add a daily worker to run through all the pods
* add unit tests for most of the new code
2015-08-24 22:04:53 +02:00

88 lines
2.4 KiB
JavaScript

// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
app.views.PodEntry = app.views.Base.extend({
templateName: "pod_table_entry",
tagName: "tr",
events: {
"click .more": "toggleMore",
"click .recheck": "recheckPod"
},
className: function() {
if( this.model.get("offline") ) { return "bg-danger"; }
if( this.model.get("status")==="version_failed" ) { return "bg-warning"; }
if( this.model.get("status")==="no_errors" ) { return "bg-success"; }
},
initialize: function(opts) {
this.parent = opts.parent;
this.rendered = false;
this.model.on("change", this.render, this);
},
presenter: function() {
return _.extend({}, this.defaultPresenter(), {
/* jshint camelcase: false */
is_unchecked: (this.model.get("status")==="unchecked"),
has_no_errors: (this.model.get("status")==="no_errors"),
has_errors: (this.model.get("status")!=="no_errors"),
status_text: Diaspora.I18n.t("admin.pods.states."+this.model.get("status")),
pod_url: (this.model.get("ssl") ? "https" : "http") + "://" + this.model.get("host"),
response_time_fmt: this._fmtResponseTime()
/* jshint camelcase: true */
});
},
postRenderTemplate: function() {
if( !this.rendered ) {
this.parent.appendChild(this.el);
}
this.rendered = true;
return this;
},
toggleMore: function() {
this.$(".details").toggle();
return false;
},
recheckPod: function() {
var self = this,
flash = new Diaspora.Widgets.FlashMessages();
this.$el.addClass("checking");
this.model.recheck()
.done(function(){
flash.render({
success: true,
notice: Diaspora.I18n.t("admin.pods.recheck.success")
});
})
.fail(function(){
flash.render({
success: false,
notice: Diaspora.I18n.t("admin.pods.recheck.failure")
});
})
.always(function(){
self.$el
.removeClass("bg-danger bg-warning bg-success")
.addClass(_.result(self, "className"))
.removeClass("checking");
});
return false;
},
_fmtResponseTime: function() {
if( this.model.get("response_time")===-1 ) {
return Diaspora.I18n.t("admin.pods.not_available");
}
return Diaspora.I18n.t("admin.pods.ms", {count: this.model.get("response_time")});
}
});
// @license-end