Skip to content

Commit 104756b

Browse files
committed
New Version 1.13.1
- B #145, #143: Issues with manuell added print jobs (e.g. missing username, lastDate and total)
1 parent b360fa2 commit 104756b

File tree

7 files changed

+124
-30
lines changed

7 files changed

+124
-30
lines changed

octoprint_PrintJobHistory/DatabaseManager.py

+67-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
FORCE_CREATE_TABLES = False
2222
SQL_LOGGING = True
2323

24-
CURRENT_DATABASE_SCHEME_VERSION = 5
24+
CURRENT_DATABASE_SCHEME_VERSION = 6
2525

2626
# List all Models
2727
MODELS = [PluginMetaDataModel, PrintJobModel, FilamentModel, TemperatureModel]
@@ -73,14 +73,73 @@ def _createOrUpgradeSchemeIfNecessary(self):
7373

7474
def _upgradeDatabase(self,currentDatabaseSchemeVersion, targetDatabaseSchemeVersion):
7575

76-
migrationFunctions = [self._upgradeFrom1To2, self._upgradeFrom2To3, self._upgradeFrom3To4, self._upgradeFrom4To5]
76+
migrationFunctions = [self._upgradeFrom1To2,
77+
self._upgradeFrom2To3,
78+
self._upgradeFrom3To4,
79+
self._upgradeFrom4To5,
80+
self._upgradeFrom5To6,
81+
self._upgradeFrom6To7,
82+
self._upgradeFrom7To8,
83+
self._upgradeFrom8To9,
84+
self._upgradeFrom9To10
85+
]
7786

7887
for migrationMethodIndex in range(currentDatabaseSchemeVersion -1, targetDatabaseSchemeVersion -1):
7988
self._logger.info("Database migration from '" + str(migrationMethodIndex + 1) + "' to '" + str(migrationMethodIndex + 2) + "'")
8089
migrationFunctions[migrationMethodIndex]()
8190
pass
8291
pass
8392

93+
def _upgradeFrom9To10(self):
94+
self._logger.info(" Starting 9 -> 10")
95+
self._logger.info(" Successfully 9 -> 10")
96+
pass
97+
98+
def _upgradeFrom8To9(self):
99+
self._logger.info(" Starting 8 -> 9")
100+
self._logger.info(" Successfully 8 -> 9")
101+
pass
102+
103+
def _upgradeFrom7To8(self):
104+
self._logger.info(" Starting 7 -> 8")
105+
self._logger.info(" Successfully 7 -> 8")
106+
pass
107+
108+
def _upgradeFrom6To7(self):
109+
self._logger.info(" Starting 6 -> 7")
110+
self._logger.info(" Successfully 6 -> 7")
111+
pass
112+
113+
def _upgradeFrom5To6(self):
114+
self._logger.info(" Starting 5 -> 6")
115+
# What is changed:
116+
# - FilamentModel:
117+
# - renameing:
118+
# profileVendor -> vendor
119+
# spoolWeight -> weight
120+
# (ALTER TABLE spo_spoolmodel RENAME COLUMN encloserTemperature to enclosureTemperature; not working SQLite did not support the ALTER TABLE RENAME COLUMN syntax before version 3.25.0.
121+
# see https://www.sqlitetutorial.net/sqlite-rename-column/#:~:text=SQLite%20did%20not%20support%20the,the%20version%20lower%20than%203.25.)
122+
123+
connection = sqlite3.connect(self._databaseFileLocation)
124+
cursor = connection.cursor()
125+
126+
sql = """
127+
PRAGMA foreign_keys=off;
128+
BEGIN TRANSACTION;
129+
130+
UPDATE 'pjh_filamentmodel' SET toolId='total' where toolId is NULL;
131+
132+
UPDATE 'pjh_pluginmetadatamodel' SET value=6 WHERE key='databaseSchemeVersion';
133+
COMMIT;
134+
PRAGMA foreign_keys=on;
135+
"""
136+
cursor.executescript(sql)
137+
138+
connection.close()
139+
self._logger.info(" Successfully 5 -> 6")
140+
pass
141+
142+
84143
def _upgradeFrom4To5(self):
85144
self._logger.info(" Starting 4 -> 5")
86145
# What is changed:
@@ -477,7 +536,8 @@ def calculatePrintJobsStatisticByQuery(self, tableQuery):
477536
printJobCount = printJobCount + 1
478537
if (firstDate == None):
479538
firstDate = job.printStartDateTime
480-
lastDate = job.printEndDateTime
539+
if (job.printEndDateTime != None):
540+
lastDate = job.printEndDateTime
481541
tempJobFileSize = job.fileSize
482542
if (tempJobFileSize == None):
483543
tempJobFileSize = 0
@@ -520,7 +580,10 @@ def calculatePrintJobsStatisticByQuery(self, tableQuery):
520580

521581
# do formatting
522582
queryString = self._buildQueryString(tableQuery)
523-
fromToString = firstDate.strftime('%d.%m.%Y %H:%M') + " - " + lastDate.strftime('%d.%m.%Y %H:%M')
583+
lastDateString = ""
584+
if (lastDate != None):
585+
lastDateString = lastDate.strftime('%d.%m.%Y %H:%M')
586+
fromToString = firstDate.strftime('%d.%m.%Y %H:%M') + " - " + lastDateString
524587
durationString = StringUtils.secondsToText(duration)
525588
lengthString = self._buildLengthString(length)
526589
weightString = self._buildWeightString(weight)

octoprint_PrintJobHistory/api/PrintJobHistoryAPI.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class PrintJobHistoryAPI(octoprint.plugin.BlueprintPlugin):
4040

4141
def _updatePrintJobFromJson(self, printJobModel, jsonData):
4242
# transfer header values
43+
printJobModel.userName = self._getValueFromJSONOrNone("userName", jsonData)
4344
printJobModel.fileName = self._getValueFromJSONOrNone("fileName", jsonData)
4445
# printJobModel.filePathName = self._getValueFromJSONOrNone("fileName", jsonData) # pech
4546
printJobModel.printStartDateTime = StringUtils.transformToDateTimeOrNone(self._getValueFromJSONOrNone("printStartDateTimeFormatted", jsonData))

octoprint_PrintJobHistory/models/PrintJobModel.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ def getFilamentModels(self, withoutTotal = False):
5959
self._loadFilamentModels()
6060
allFilamentModels = self.filamentModelsByToolId.values()
6161
if (withoutTotal):
62-
allFilamentModels[:] = [filamentModel for filamentModel in allFilamentModels if filamentModel.toolId != "total"]
62+
newAllFilamentModels = []
63+
for filamentModel in allFilamentModels:
64+
if filamentModel.toolId != "total":
65+
newAllFilamentModels.append(filamentModel)
66+
allFilamentModels = newAllFilamentModels
6367
pass
64-
6568
return allFilamentModels
6669

6770

octoprint_PrintJobHistory/static/js/PrintJobHistory-EditJobDialog.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function PrintJobHistoryEditDialog(){
44
var self = this;
55

66
this.apiClient = null;
7+
this.currentUser = null;
78

89
this.editPrintJobItemDialog = null;
910
this.printJobItemForEdit = null;
@@ -193,6 +194,11 @@ function PrintJobHistoryEditDialog(){
193194
}
194195

195196

197+
/////////////////////////////////////////////////////////////////////////////////////////////////// SETTER
198+
this.setCurrentUser = function(currentUser){
199+
this.currentUser = currentUser;
200+
}
201+
196202
/////////////////////////////////////////////////////////////////////////////////////////////////// SHOW DIALOG
197203
this.showDialog = function(printJobItemForEdit, closeDialogHandler, fullEditMode){
198204

@@ -314,22 +320,28 @@ function PrintJobHistoryEditDialog(){
314320
return;
315321
}
316322

317-
318323
var noteText = self.noteEditor.getText();
319324
var noteDeltaFormat = self.noteEditor.getContents();
320325
var noteHtml = self.noteEditor.getHtml();
321326
self.printJobItemForEdit.noteText(noteText);
322327
self.printJobItemForEdit.noteDeltaFormat(noteDeltaFormat);
323328
self.printJobItemForEdit.noteHtml(noteHtml);
324329

330+
if (self.printJobItemForEdit.userName == null ||
331+
self.printJobItemForEdit.userName() == null ||
332+
self.printJobItemForEdit.userName().trim().length === 0){
333+
if (self.currentUser != null){
334+
self.printJobItemForEdit.userName(self.currentUser.name);
335+
}
336+
}
337+
325338
self.apiClient.callStorePrintJob(self.printJobItemForEdit.databaseId(), self.printJobItemForEdit, function(allPrintJobsResponse){
326339
self.editPrintJobItemDialog.modal('hide');
327340
self.closeDialogHandler(true);
328341
});
329342

330343
}
331344

332-
333345
/////////////////////////////////////////////////////////////////////////////////////////////////// DELETE PRINT JOB
334346
this.deletePrintJobItem = function(){
335347
var result = confirm("Do you really want to delete the print job?");
@@ -341,7 +353,6 @@ function PrintJobHistoryEditDialog(){
341353
}
342354
}
343355

344-
345356
/////////////////////////////////////////////////////////////////////////////////////////////////// DELETE IMAGE
346357
this.deleteImage = function(){
347358

@@ -442,7 +453,6 @@ function PrintJobHistoryEditDialog(){
442453
}
443454
}
444455

445-
446456
this.cancelCaptureImage = function(){
447457
self.imageDisplayMode(IMAGEDISPLAYMODE_SNAPSHOTIMAGE);
448458
self.captureButtonText.text(reCaptureText);

octoprint_PrintJobHistory/static/js/PrintJobHistory.js

+25-15
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,27 @@ $(function() {
139139
// result from backend
140140

141141
this.allFilamentModels = updateData.filamentModels;
142-
this.jsonArray = ko.observable(this.allFilamentModels);
143142
this.allToolKeys = Object.keys(this.allFilamentModels);
144143
this.isMultiToolPrint(Object.keys(this.allFilamentModels).length > 1)
145144

146145
totalFilamentModel = updateData.filamentModels["total"]; // should always be present
147-
this.diameter(totalFilamentModel.diameter);
148-
this.density(totalFilamentModel.density);
149-
this.material(totalFilamentModel.material);
150-
this.vendor(totalFilamentModel.vendor);
151-
this.spoolName(totalFilamentModel.spoolName);
152-
this.spoolCost(totalFilamentModel.spoolCost);
153-
this.spoolCostUnit(totalFilamentModel.spoolCostUnit);
154-
this.weight(totalFilamentModel.weight);
155-
// this.usedLength( formatFilamentLength(updateData.filamentEntity.usedLength) );
156-
// this.calculatedLength( formatFilamentLength(updateData.filamentEntity.calculatedLength) );
157-
this.usedLengthFormatted(totalFilamentModel.usedLengthFormatted );
158-
this.calculatedLengthFormatted(totalFilamentModel.calculatedLengthFormatted );
159-
this.usedWeight(totalFilamentModel.usedWeight );
160-
this.usedCost(totalFilamentModel.usedCost );
146+
// should never happen, but in the past we have some jobs where "total" is missing
147+
if (totalFilamentModel != null){
148+
this.diameter(totalFilamentModel.diameter);
149+
this.density(totalFilamentModel.density);
150+
this.material(totalFilamentModel.material);
151+
this.vendor(totalFilamentModel.vendor);
152+
this.spoolName(totalFilamentModel.spoolName);
153+
this.spoolCost(totalFilamentModel.spoolCost);
154+
this.spoolCostUnit(totalFilamentModel.spoolCostUnit);
155+
this.weight(totalFilamentModel.weight);
156+
// this.usedLength( formatFilamentLength(updateData.filamentEntity.usedLength) );
157+
// this.calculatedLength( formatFilamentLength(updateData.filamentEntity.calculatedLength) );
158+
this.usedLengthFormatted(totalFilamentModel.usedLengthFormatted );
159+
this.calculatedLengthFormatted(totalFilamentModel.calculatedLengthFormatted );
160+
this.usedWeight(totalFilamentModel.usedWeight );
161+
this.usedCost(totalFilamentModel.usedCost );
162+
}
161163
}
162164

163165
this.snapshotFilename(updateData.snapshotFilename);
@@ -497,6 +499,14 @@ $(function() {
497499
}
498500
}
499501

502+
self.onUserLoggedIn = function(currentUser) {
503+
self.printJobEditDialog.setCurrentUser(currentUser);
504+
}
505+
self.onUserLoggedOut = function() {
506+
if (self.printJobEditDialog != null) {
507+
self.printJobEditDialog.setCurrentUser(null);
508+
}
509+
}
500510
// receive data from server
501511
self.onDataUpdaterPluginMessage = function (plugin, data) {
502512

octoprint_PrintJobHistory/test/test_PrintJobService.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def init_database(self):
2626
self.databaseManager = DatabaseManager(testLogger, True)
2727
self.databaseManager.initDatabase(self.databaselocation, self._clientOutput)
2828

29-
30-
31-
def test_createPrintJob(self):
29+
def _test_createPrintJob(self):
3230
self.databaseManager.deletePrintJob(1011)
3331

3432
newPrintJob = self.printJobService.createWithDefaults()
@@ -98,11 +96,20 @@ def test_createPrintJob(self):
9896
# - allTemperatures
9997

10098

101-
10299
# do test-cleanup
103100
for printJobDatabaseId in self.rollBackPrintJobs:
104101
self.databaseManager.deletePrintJob(printJobDatabaseId)
105102

103+
def test_readFilamentModels(self):
104+
# - allFilaments
105+
loadedPrintJobModel = self.printJobService.loadPrintJob(72)
106+
allFilamentModels = loadedPrintJobModel.getFilamentModels()
107+
self.assertEqual(len(allFilamentModels), 2, "'total' and 'tool0' filamentModel expected")
108+
109+
loadedPrintJobModel = self.printJobService.loadPrintJob(72)
110+
allFilamentModels = loadedPrintJobModel.getFilamentModels(withoutTotal=True)
111+
self.assertEqual(len(allFilamentModels), 1, "'total' filamentModel expected")
112+
106113

107114

108115
if __name__ == '__main__':

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "Print Job History"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "1.13.0"
17+
plugin_version = "1.13.1"
1818

1919
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
2020
# module

0 commit comments

Comments
 (0)