Skip to content

Commit

Permalink
Fix for OctoPrint#1001 connection tab not unfolding
Browse files Browse the repository at this point in the history
Defer collapsing the connection element until the whole wrapper part is
visible (it's hidden for non-admins).
  • Loading branch information
markwal committed Jul 30, 2015
1 parent 94625c4 commit af67d8b
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/octoprint/static/js/app/viewmodels/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ $(function() {
self._processStateData(data.state);
};

self.openOrCloseOnStateChange = function() {
var connectionTab = $("#connection");
if (self.isOperational() && connectionTab.hasClass("in")) {
connectionTab.collapse("hide");
} else if (!self.isOperational() && !connectionTab.hasClass("in")) {
connectionTab.collapse("show");
}
}

self._processStateData = function(data) {
self.previousIsOperational = self.isOperational();

Expand All @@ -97,15 +106,10 @@ $(function() {
self.isReady(data.flags.ready);
self.isLoading(data.flags.loading);

var connectionTab = $("#connection");
if (self.previousIsOperational != self.isOperational()) {
if (self.isOperational() && connectionTab.hasClass("in")) {
// connection just got established, close connection tab for now
connectionTab.collapse("hide");
} else if (!connectionTab.hasClass("in")) {
// connection just dropped, make sure connection tab is open
connectionTab.collapse("show");
}
if (self.loginState.isAdmin() && self.previousIsOperational != self.isOperational()) {
// only open or close if the panel is visible (for admins) and
// the state just changed to avoid thwarting manual open/close
self.openOrCloseOnStateChange();
}
};

Expand Down Expand Up @@ -147,6 +151,16 @@ $(function() {

self.onStartup = function() {
self.requestData();

// when isAdmin becomes true the first time, set the panel open or
// closed based on the connection state
var subscription = self.loginState.isAdmin.subscribe(function(newValue) {
if (newValue) {
// wait until after the isAdmin state has run through all subscriptions
setTimeout(self.openOrCloseOnStateChange, 0);
subscription.dispose();
}
});
};
}

Expand Down

0 comments on commit af67d8b

Please sign in to comment.