Skip to content

Commit

Permalink
Also update the metadata correctly when an analysis finishes
Browse files Browse the repository at this point in the history
Closes OctoPrint#476 for good
(cherry picked from commit 65624ed)
  • Loading branch information
foosel committed Aug 8, 2014
1 parent e9a7cad commit 90e50db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/octoprint/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def __init__(self, gcodeManager):
currentZ=None
)

eventManager().subscribe(Events.METADATA_ANALYSIS_FINISHED, self.onMetadataAnalysisFinished);

#~~ callback handling

def registerCallback(self, callback):
Expand Down Expand Up @@ -153,6 +155,14 @@ def sendUpdateTrigger(self, type):
self._selectedFile["filesize"],
self._selectedFile["sd"])

#~~ callback from metadata analysis event

def onMetadataAnalysisFinished(self, event, data):
if self._selectedFile:
self._setJobData(self._selectedFile["filename"],
self._selectedFile["filesize"],
self._selectedFile["sd"])

#~~ printer commands

def connect(self, port=None, baudrate=None):
Expand Down
31 changes: 16 additions & 15 deletions src/octoprint/static/js/app/viewmodels/printerstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function PrinterStateViewModel(loginStateViewModel) {
if (!self.printTimeLeft())
return "-";
return formatDuration(self.printTimeLeft());
})
});
self.progressString = ko.computed(function() {
if (!self.progress())
return 0;
Expand Down Expand Up @@ -83,22 +83,22 @@ function PrinterStateViewModel(loginStateViewModel) {

self.fromCurrentData = function(data) {
self._fromData(data);
}
};

self.fromHistoryData = function(data) {
self._fromData(data);
}
};

self.fromTimelapseData = function(data) {
self.timelapse(data);
}
};

self._fromData = function(data) {
self._processStateData(data.state)
self._processStateData(data.state);
self._processJobData(data.job);
self._processProgressData(data.progress);
self._processZData(data.currentZ);
}
};

self._processStateData = function(data) {
self.stateString(data.stateString);
Expand All @@ -109,7 +109,7 @@ function PrinterStateViewModel(loginStateViewModel) {
self.isError(data.flags.error);
self.isReady(data.flags.ready);
self.isSdReady(data.flags.sdReady);
}
};

self._processJobData = function(data) {
if (data.file) {
Expand All @@ -121,6 +121,7 @@ function PrinterStateViewModel(loginStateViewModel) {
self.filesize(undefined);
self.sd(undefined);
}

self.estimatedPrintTime(data.estimatedPrintTime);

var result = [];
Expand All @@ -131,12 +132,12 @@ function PrinterStateViewModel(loginStateViewModel) {
result[i] = {
name: ko.observable("Tool " + i),
data: ko.observable(data.filament[key])
}
};
i++;
} while (data.filament.hasOwnProperty("tool" + i));
}
self.filament(result);
}
};

self._processProgressData = function(data) {
if (data.completion) {
Expand All @@ -147,16 +148,16 @@ function PrinterStateViewModel(loginStateViewModel) {
self.filepos(data.filepos);
self.printTime(data.printTime);
self.printTimeLeft(data.printTimeLeft);
}
};

self._processZData = function(data) {
self.currentHeight(data);
}
};

self.print = function() {
var restartCommand = function() {
self._jobCommand("restart");
}
};

if (self.isPaused()) {
$("#confirmation_dialog .confirmation_dialog_message").text("This will restart the print job from the beginning.");
Expand All @@ -167,15 +168,15 @@ function PrinterStateViewModel(loginStateViewModel) {
self._jobCommand("start");
}

}
};

self.pause = function() {
self._jobCommand("pause");
}
};

self.cancel = function() {
self._jobCommand("cancel");
}
};

self._jobCommand = function(command) {
$.ajax({
Expand Down

0 comments on commit 90e50db

Please sign in to comment.