From 3dbd15c429d4853f79a7eae2686ea71b6c300cae Mon Sep 17 00:00:00 2001 From: OllisGit Date: Mon, 24 May 2021 18:24:10 +0200 Subject: [PATCH] New Version 1.4.0 - PR #161, #117, #133, #134, #153 multi tool support. Big thanks goes to @codingcatgirl - PR #61, #59 temperature offset. Thanks a lot @WyattNielsen - E/B #118 use newodometer.py - E add "implementation-api" - B #150, #116 CSV import fixed ..other tickets - #102, #132, #135, #140, #142 --- octoprint_SpoolManager/DatabaseManager.py | 2 +- octoprint_SpoolManager/__init__.py | 1 - octoprint_SpoolManager/api/SpoolManagerAPI.py | 4 ++ .../common/CSVExportImporter.py | 9 ++-- .../static/js/SpoolManager.js | 49 ++++++++++++++++--- .../templates/SpoolManager_tab_dialogs.jinja2 | 14 +++--- setup.py | 2 +- 7 files changed, 59 insertions(+), 22 deletions(-) diff --git a/octoprint_SpoolManager/DatabaseManager.py b/octoprint_SpoolManager/DatabaseManager.py index 95605d59..e0c433a2 100644 --- a/octoprint_SpoolManager/DatabaseManager.py +++ b/octoprint_SpoolManager/DatabaseManager.py @@ -642,7 +642,7 @@ def backupDatabaseFile(self): else: self._logger.info("No database backup needed, because there is no databasefile '"+str(self._databaseSettings.fileLocation)+"'") - def reCreateDatabase(self, databaseSettings): + def reCreateDatabase(self, databaseSettings = None): self._currentErrorMessageDict = None self._logger.info("ReCreating Database") diff --git a/octoprint_SpoolManager/__init__.py b/octoprint_SpoolManager/__init__.py index afb9ac12..588a1230 100644 --- a/octoprint_SpoolManager/__init__.py +++ b/octoprint_SpoolManager/__init__.py @@ -186,7 +186,6 @@ def _sendDataToClient(self, payloadDict): def _sendMessageToClient(self, type, title, message): self._logger.warning("SendToClient: " + type + "#" + title + "#" + message) - title = "SPM:" + title self._sendDataToClient(dict(action="showPopUp", type=type, title= title, diff --git a/octoprint_SpoolManager/api/SpoolManagerAPI.py b/octoprint_SpoolManager/api/SpoolManagerAPI.py index 10de9702..c29ceafc 100644 --- a/octoprint_SpoolManager/api/SpoolManagerAPI.py +++ b/octoprint_SpoolManager/api/SpoolManagerAPI.py @@ -320,6 +320,8 @@ def allowed_to_print(self): infoData = { "toolIndex": toolIndex, "spoolName": spoolModel.displayName if spoolModel else '(no spool selected)', + "material": spoolModel.material if spoolModel else '', + "remainingWeight": spoolModel.remainingWeight if spoolModel else '', "toolOffset": spoolModel.offsetTemperature if spoolModel.offsetTemperature is not None else 0, "bedOffset": spoolModel.offsetBedTemperature if spoolModel.offsetBedTemperature is not None else 0, "enclosureOffset": spoolModel.offsetEnclosureTemperature if spoolModel.offsetEnclosureTemperature is not None else 0 @@ -535,6 +537,8 @@ def updateParsingStatus(lineNumber): spool.remainingWeight = remainingWeight # spool.save() + spool.isActive = True + databaseManager.saveSpool(spool) pass else: diff --git a/octoprint_SpoolManager/common/CSVExportImporter.py b/octoprint_SpoolManager/common/CSVExportImporter.py index d4a7e18f..4454f15c 100644 --- a/octoprint_SpoolManager/common/CSVExportImporter.py +++ b/octoprint_SpoolManager/common/CSVExportImporter.py @@ -9,6 +9,7 @@ from octoprint_SpoolManager.models.SpoolModel import SpoolModel FORMAT_DATETIME = "%d.%m.%Y %H:%M" +FORMAT_DATE = "%d.%m.%Y" COLUMN_DISPLAY_NAME = "Spool Name" COLUMN_COLOR_NAME = "Color Name" @@ -115,7 +116,7 @@ def parseAndAssignFieldValue(self, fieldLabel, fieldName, fieldValue, printJobMo setattr(printJobModel, fieldName, fieldDateTime) pass else: - fieldDateTime = datetime.datetime.fromtimestamp(float(fieldValue)) + fieldDateTime = datetime.datetime.strptime(fieldValue, FORMAT_DATE) setattr(printJobModel, fieldName, fieldDateTime) pass pass @@ -327,7 +328,7 @@ def parseCSV(csvFile4Import, updateParsingStatus, errorCollection, logger, delet errorCollection.append("Mandatory column is missing!
'" + "".join(mandatoryFieldMissing) + "'
") break else: - printJobModel = SpoolModel() + spoolModel = SpoolModel() # parse line with header defined order columnIndex = 0 for columnValue in row: @@ -342,13 +343,13 @@ def parseCSV(csvFile4Import, updateParsingStatus, errorCollection, logger, delet errorCollection.append("["+str(lineNumber)+"] Mandatory value for column '" + columnName + "' is missing!") pass else: - csvColumn.parseAndAssignFieldValue(columnValue, printJobModel, errorCollection, lineNumber) + csvColumn.parseAndAssignFieldValue(columnValue, spoolModel, errorCollection, lineNumber) pass columnIndex += 1 if (len(errorCollection) != 0): logger.error("Reading error line '" + str(lineNumber) + "' in Column '" + column + "' ") else: - result.append(printJobModel) + result.append(spoolModel) pass except Exception as e: errorMessage = "CSV Parsing error. Line:'" + str(lineNumber) + "' Error:'" + str(e) + "' File:'" + csvFile4Import + "'" diff --git a/octoprint_SpoolManager/static/js/SpoolManager.js b/octoprint_SpoolManager/static/js/SpoolManager.js index ff43aecb..1d17d48a 100644 --- a/octoprint_SpoolManager/static/js/SpoolManager.js +++ b/octoprint_SpoolManager/static/js/SpoolManager.js @@ -82,13 +82,35 @@ $(function() { ////////////////////////////////////////////////////////////////////////////////////////////////HELPER FUNCTION + + loadSettingsFromBrowserStore = function(){ + // TODO maybe in a separate js-file + // load all settings from browser storage + if (!Modernizr.localstorage) { + // damn!!! + return false; + } + // Table visibility + self.initTableVisibilities(); + + var storageKey = "spoolmanager.table.selectedPageSize"; + if (localStorage[storageKey] == null){ + localStorage[storageKey] = "25"; // default page size + } else { + self.spoolItemTableHelper.selectedPageSize(localStorage[storageKey]); + } + self.spoolItemTableHelper.selectedPageSize.subscribe(function(newValue){ + localStorage[storageKey] = newValue; + }); + } + // Typs: error self.showPopUp = function(popupType, popupTitle, message){ var title = popupType.toUpperCase() + ": " + popupTitle; var popupId = (title+message).replace(/([^a-z0-9]+)/gi, '-'); if($("."+popupId).length <1) { new PNotify({ - title: title, + title: "SPM:" + title, text: message, type: popupType, hide: false, @@ -98,7 +120,6 @@ $(function() { }; - // found here: https://stackoverflow.com/questions/19491336/how-to-get-url-parameter-using-jquery-or-plain-javascript?rq=1 var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), @@ -646,10 +667,22 @@ $('.dropdown-menu.keep-open').click(function(e) { } } + buildSpoolLabel = function(item){ + var label = item.toolIndex+": '" + item.material + " - " + item.spoolName; + + if (item.remainingWeight != null && typeof item.remainingWeight === 'number'){ + label = label + " ("+item.remainingWeight.toFixed(2) +"g)"; + } + label = label + "'"; + return label; + } + if (result.filamentNotEnough.length) { itemList = []; for (item of result.filamentNotEnough) { - itemList.push("'" + item.spoolName + "' (tool "+item.toolIndex+")"); + var spoolLabel = buildSpoolLabel(item); + // itemList.push("'" + item.spoolName + "' (tool "+item.toolIndex+")"); + itemList.push(spoolLabel); } if (itemList.length === 1) { check = confirm( @@ -685,7 +718,7 @@ $('.dropdown-menu.keep-open').click(function(e) { // } // build message for each tool for (item of result.reminderSpoolSelection) { - var toolMessage = item.toolIndex+": '" + item.spoolName + "'"; + var toolMessage = buildSpoolLabel(item); if (responseData.toolOffsetEnabled) toolMessage += "\n-- Tool Offset: "+item.toolOffset+'\u00B0'; if (responseData.bedOffsetEnabled) toolMessage += "\n-- Bed Offset: "+item.bedOffset+'\u00B0'; if (responseData.enclosureOffsetEnabled) toolMessage += "\n-- Enclosure Offset: "+item.enclosureOffset+'\u00B0'; @@ -693,7 +726,7 @@ $('.dropdown-menu.keep-open').click(function(e) { } check = confirm( "Do you want to start the print with following selected spools?\n" + - '- '+ itemList.join('\n- ') + "- "+ itemList.join("\n- ") ); if (!check) { @@ -782,8 +815,10 @@ $('.dropdown-menu.keep-open').click(function(e) { self.onBeforeBinding = function() { // assign current pluginSettings self.pluginSettings = self.settingsViewModel.settings.plugins[PLUGIN_ID]; - // Table visibility - self. initTableVisibilities(); + + // load browser stored settings (includs TabelVisibility and pageSize, ...) + loadSettingsFromBrowserStore(); + // resetSettings-Stuff new ResetSettingsUtilV3(self.pluginSettings).assignResetSettingsFeature(PLUGIN_ID, function(data){ // no additional reset function needed in V2 diff --git a/octoprint_SpoolManager/templates/SpoolManager_tab_dialogs.jinja2 b/octoprint_SpoolManager/templates/SpoolManager_tab_dialogs.jinja2 index ee9290fa..f7e02748 100644 --- a/octoprint_SpoolManager/templates/SpoolManager_tab_dialogs.jinja2 +++ b/octoprint_SpoolManager/templates/SpoolManager_tab_dialogs.jinja2 @@ -155,16 +155,14 @@ - - - - +