From 5ef196e8ab356709cdca7c159f1c26faf9bd9d04 Mon Sep 17 00:00:00 2001 From: LazeMSS <69049371+LazeMSS@users.noreply.github.com> Date: Sun, 24 Jan 2021 00:43:21 +0100 Subject: [PATCH 1/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc66e7a..1928911 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ or manually using this URL: Install and read the onscreen information - it should be pretty self-explanatory else play with it :) ![](extras/configuration.png)
-## Custom commands special +## Custom commands The custom commands allow you to run any OS command by entering a command into the “Command” field. There is a Test button that will run the command and let you validate the returned data. At the moment the returned data has to be a number (float or integer) and will be fixed If the plugin has detected any known ways of finding interesting data on startup this will be shown in Predefined dropdown button. At the moment it only looks for known CPU temperature, but if you know of any good generic ways to display interesting data then post it here https://github.com/LazeMSS/OctoPrint-TopTemp/issues From 430d1f81c7270bcbceb760fece2eef61513dbe42 Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Sun, 24 Jan 2021 19:08:10 +0100 Subject: [PATCH 2/9] Fixed waiting when not connected. Removed broken file --- octoprint_toptemp/static/js/TopTemp.js | 26 +- .../static/js/TopTemp.js.7E914DEFD1.orig | 873 ------------------ 2 files changed, 19 insertions(+), 880 deletions(-) delete mode 100644 octoprint_toptemp/static/js/TopTemp.js.7E914DEFD1.orig diff --git a/octoprint_toptemp/static/js/TopTemp.js b/octoprint_toptemp/static/js/TopTemp.js index ea18aaf..48954ef 100644 --- a/octoprint_toptemp/static/js/TopTemp.js +++ b/octoprint_toptemp/static/js/TopTemp.js @@ -17,7 +17,9 @@ Settings: - max width for graph/display - Custom option to set as not a temperature (no fahrenheit conversion and check for number) - Custom option postfix label (rpm etc) - - + - thousand seperator option + - Icons: https://github.com/LazeMSS/OctoPrint-TopTemp/issues/5 + - icon color? */ @@ -189,12 +191,7 @@ $(function() { return value; } - // Get updated data from the "feeds" - self.fromCurrentData = function(data){ - if (self.updatePaused){ - return; - } - + self.genericStart = function(){ // Init it all if (!self.started){ self.started = true; @@ -205,6 +202,7 @@ $(function() { if (self.prevOpMode && self.settings.hideInactiveTemps()){ $('#navbar_plugin_toptemp div.TopTempPrinter').hide(); } + $('#navbar_plugin_toptemp div.TopTempPrinter').removeClass('TopTempLoad'); self.prevOpMode = false; }else{ if (!self.prevOpMode && self.settings.hideInactiveTemps()){ @@ -212,6 +210,18 @@ $(function() { } self.prevOpMode = true; } + } + + // Get updated data from the "feeds" + self.fromCurrentData = function(data){ + + if (self.updatePaused){ + return; + } + + // Init it all + self.genericStart(); + // Update temps if any data found and not hidden if (!data.temps.length || (!self.prevOpMode && self.settings.hideInactiveTemps())){ return; @@ -235,6 +245,8 @@ $(function() { if (plugin != "toptemp"){ return; } + // Init it all + self.genericStart(); if (!('success' in data) || data.success == false){ return; } diff --git a/octoprint_toptemp/static/js/TopTemp.js.7E914DEFD1.orig b/octoprint_toptemp/static/js/TopTemp.js.7E914DEFD1.orig deleted file mode 100644 index 5abdadb..0000000 --- a/octoprint_toptemp/static/js/TopTemp.js.7E914DEFD1.orig +++ /dev/null @@ -1,873 +0,0 @@ -/* TopTemp START */ -/* -Notes: -Monitors: - - USE psutil python module : https://plugins.octoprint.org/plugins/resource_monitor/ - Cpu percentage - - Wifi signal - - Disk space - - Fan speed - -- Scroll/cycle view for multiple tools ? - -Settings: - - delete custom - - small fonts options - -- icon color? -*/ - -$(function() { - function TopTempViewModel(parameters) { - var self = this; - - self.settingsViewModel = parameters[0]; - self.tempModel = parameters[1]; - self.settings = {}; - self.newCustMon = {}; - - // Settings window open - self.settingsOpen = false; - self.settingsSaved = false; - self.previewOn = false; - - self.tempNewCust = []; - self.deleteCust = {}; - - // Pause updating of the UI - self.updatePaused = false; - // Was we running - self.prevOpMode = true; - - self.mainTypes = ['bed','chamber']; - - self.cusPrefix = 'cu'; - - self.customHistory = {}; - - // - self.started = false; - - // Process data and format it - self.FormatTempHTML = function(name, data, customType){ - $('#navbar_plugin_toptemp small').remove(); - if (self.updatePaused){ - return; - } - - var iSettings = self.getSettings(name); - - // Do know this or want it shown - if (typeof iSettings == "undefined" || iSettings.show() == false || data.actual == null || data.actual == undefined || (data.target == 0 && iSettings.hideOnNoTarget())){ - $('#navbar_plugin_toptemp_'+name).hide(); - return; - }else{ - $('#navbar_plugin_toptemp_'+name).show(); - } - - // Create if not found - var targetE = $('#navbar_plugin_toptemp_'+name+'_text'); - - // Show a graph - var graphE = $('#TopTempGraph_'+name+'_graph'); - if (!iSettings.graphSettings.show() || graphE.length == 0){ - graphE.hide(); - }else{ - graphE.show(); - - // Update the styles if settings are open - if (self.settingsOpen){ - self.setGraphStyle(name,iSettings.graphSettings); - } - - // Plot the graph - var graphData = null; - if (customType){ - if (name in self.customHistory && self.customHistory[name].length > 0){ - graphData = {'series' : [self.customHistory[name]]}; - } - }else{ - graphData = {'series' : [OctoPrint.coreui.viewmodels.temperatureViewModel.temperatures[name].actual.slice(-50).map(function(val,i){return val[1]})]}; - } - // DO we have what we need - if (graphData != null && typeof Chartist == "object"){ - new Chartist.Line('#TopTempGraph_'+name+'_graph', graphData, - { - axisX:{ - showLabel:false, - showGrid: false, - padding: 0, - offset: 0 - }, - axisY:{ - showLabel:false, - showGrid: false, - low: 0, - padding: 0, - offset: 0 - }, - showPoint: false, - lineSmooth: false, - showGridBackground: false, - chartPadding: 0, - labelOffset: 0 - }); - } - } - - // Start output - var outputstr = '' - if ($.trim(iSettings.label()) != ""){ - outputstr += iSettings.label(); - } - - // Append actual data - outputstr += self.formatTempLabel(name,data.actual,iSettings); - - // Append target if different - if (!customType){ - if (typeof data.target != undefined && data.target != data.actual && data.target > 0){ - // Show arrow - if (iSettings.showTargetArrow()){ - if (data.target > data.actual){ - outputstr += ''; - }else if (data.target < data.actual){ - outputstr += ''; - } - } - // Show target temp - if (iSettings.showTargetTemp()){ - if (!iSettings.showTargetArrow()){ - outputstr += "/"; - } - outputstr += self.formatTempLabel(name,data.target,iSettings); - } - }else if(typeof data.target != undefined && data.target == data.actual && iSettings.showTargetArrow()){ - outputstr += ''; - } - } - - // Should we add an icon - if ($.trim(iSettings.icon()) !== ""){ - iconcolor = ''; - if (iSettings.colorIcons()){ - iconcolor = ' muted'; - if (data.actual >= iSettings.colorChangeLevel()){ - iconcolor = ' text-error'; - } - } - if (iSettings.appendIconNumber != undefined && iSettings.appendIconNumber() === true && typeof data.toolindx !== undefined){ - outputstr = ''+data.toolindx+'' + outputstr; - }else{ - outputstr = '' + outputstr; - } - } - // Now output - targetE.html(outputstr); - } - - // Pretty format a temperature label - self.formatTempLabel = function(name,value,iSettings){ - if (value == null){ - return value; - } - var formatSymbol = "C"; - if (self.settings.fahrenheit()){ - value = (value * 1.8) + 32; - formatSymbol = "F"; - } - value = Number.parseFloat(value).toFixed(iSettings.noDigits()); - value = value.replace(".",iSettings.decSep()); - if (iSettings.showUnit()){ - value += '°'+formatSymbol; - } - return value; - } - - // Get updated data from the "feeds" - self.fromCurrentData = function(data){ - if (self.updatePaused){ - return; - } - - // Init it all - if (!self.started){ - self.started = true; - self.buildContainers(); - } - - if (!self.tempModel.isOperational()){ - if (self.prevOpMode && self.settings.hideInactiveTemps()){ - $('#navbar_plugin_toptemp div.TopTempPrinter').hide(); - } - self.prevOpMode = false; - }else{ - if (!self.prevOpMode && self.settings.hideInactiveTemps()){ - $('#navbar_plugin_toptemp div.TopTempPrinter').show(); - } - self.prevOpMode = true; - } - // Update temps if any data found and not hidden - if (!data.temps.length || (!self.prevOpMode && self.settings.hideInactiveTemps())){ - return; - } - - if (self.tempModel.hasBed() && data.temps[0].bed != undefined){ - self.FormatTempHTML('bed',data.temps[0].bed,false); - } - if (self.tempModel.hasChamber() && data.temps[0].chamber != undefined){ - self.FormatTempHTML('chamber',data.temps[0].chamber,false); - } - if (self.tempModel.hasTools()){ - $.each(self.tempModel.tools(),function(indx,val){ - self.FormatTempHTML('tool'+indx,{'actual' : val.actual(),'target' : val.target(),'name' : val.name(), 'toolindx': indx},false); - }); - } - } - - // CPU Temps - self.onDataUpdaterPluginMessage = function(plugin, data) { - if (plugin != "toptemp"){ - return; - } - if (!('success' in data) || data.success == false){ - return; - } - self.FormatTempHTML(data.key,{'actual' : data.result},true); - } - - self.onSettingsBeforeSave = function(){ - if (self.settingsOpen){ - self.settingsSaved = true; - $('div.modal-backdrop').css('transition',''); - $('div.modal-backdrop').css('top',''); - - // Cleanup - console.log({...self.settings.customMon},1); - self.cleanUpSettings(); - console.log({...self.settings.customMon},2); - self.settings.sortOrder($('#TopTempSortList >div').map(function(){return $(this).data('sortid')}).get()); - // Done saving - self.settingsSaved = false; - } - } - - self.onSettingsHidden = function() { - console.log({...self.settings.customMon},3); - // Remove all custom observers - $('#settings_plugin_toptemp').find('input[data-customMon]').off('change.toptemp'); - $('#settings_plugin_toptemp').find('input[data-settings]').off('change.toptemp'); - // Cleanup preview - $('div.modal-backdrop').css('transition',''); - $('div.modal-backdrop').css('top',''); - $('#TopTempSortList').data('sorter').destroy(); - $('#TopTempSortList').removeData('sorter'); - self.settingsOpen = false; - self.previewOn = false; - - // Force them to be rebuilt on reload of settings - $.each(self.tempNewCust,function(i,v){ - console.log("DELETE CLEANUP TEMP: "+v); - $('#TopTempSortList >div[data-sortid="'+v+'"]').remove(); - $('#settings_toptemp_'+v).remove(); - }); - // Dont delete anything - self.tempNewCust = []; - - // Cleanup - self.cleanUpSettings(); - // Rebuild it all - self.buildContainers(); - } - - // Cleanup the settings - self.cleanUpSettings = function(){ - // Delete - if (self.settingsSaved){ - var tempcust = {...self.settings.customMon}; - // Delete all - $.each(self.deleteCust,function(i,v){ - console.log("DELETE: "+i); - $('#TopTempSortList >div[data-sortid="'+i+'"]').remove(); - $('#settings_toptemp_'+i).remove(); - tempcust[i]['delThis'] = true; - tempcust[i]['show'] = function(){return false;}; - }); - // Fix indexes - var newCustMon = {} - var i = 0; - $.each(tempcust,function(idx,val){ - // Assign to the new - newCustMon['cu'+i] = {...val,...{'updated':new Date().getTime()}}; - i++; - }); - console.log({...newCustMon}); - self.settings.customMon = newCustMon; - console.log({...self.settings.customMon}); - delete newCustMon; - console.log("--- ALL DONE ---"); - - }else{ - // Delete temporay items - $.each(self.tempNewCust,function(i,v){ - console.log("DELETE TEMP: "+v); - $('#TopTempSortList >div[data-sortid="'+v+'"]').remove(); - $('#settings_toptemp_'+v).remove(); - delete self.settings[v]; - delete self.settings.customMon[v]; - }); - } - self.deleteCust = {}; - } - - // Build the sorted list - self.buildIconOrder = function(){ - var allItems = [...self.mainTypes]; - var notools = self.settings.noTools(); - var no = 0; - while (no < notools){ - allItems.push('tool'+no); - no++; - } - // Append all custom tools - $.each(self.settings.customMon,function(idx,val){ - allItems.push(idx); - }); - var finalList = []; - $.each(self.settings.sortOrder(),function(idx,val){ - finalList.push(val); - // Remove from full list if found - var inArray = $.inArray(val,allItems); - if (inArray != -1){ - allItems.splice(inArray,1); - } - }); - finalList.push(...allItems); - return finalList; - } - - // Rebuild custom settings - self.buildCustomSettings = function(){ - // build custom monitors - poor mans dynamic ko - $('#TopTempSettingCustomMenu ul.dropdown-menu > li.TopTempCustMenu').remove(); - var template = $($('#settings_toptemp_customTemplate').wrap('p').parent().clone().html()) - $.each(self.settings.customMon,function(idx,val){ - var newId = 'settings_toptemp_'+idx; - if (!$('#'+newId).length){ - template.attr('id',newId); - template.attr('data-toptempcustomid',idx); - $('#settings_plugin_toptemp div.tab-content').append(template.wrap('p').parent().clone().html()); - } - - $('#'+newId).find('h4:first').text(val.name()+" main settings"); - - // Observer input and set - $('#'+newId).find('input[data-settings]').each(function(){ - var $this = $(this); - var settingID = $this.data('settings'); - // Recursive lookup the value - var curItem = settingID.split('.').reduce((p,c)=>p&&p[c]||null, self.settings.customMon[idx]); - var curVal = curItem(); - - // Handle checkbox vs input - if ($this.is(':checkbox')){ - $this.prop('checked', curVal); - if (curVal){ - $('#'+newId+' div[data-visible="'+settingID+'"]').show(); - }else{ - $('#'+newId+' div[data-visible="'+settingID+'"]').hide(); - } - $this.off('change.toptemp').on('change.toptemp',function(){ - curItem($(this).prop('checked')); - // Hide/show related - if ($(this).prop('checked')){ - $('#'+newId+' div[data-visible="'+settingID+'"]').show(); - }else{ - $('#'+newId+' div[data-visible="'+settingID+'"]').hide(); - } - }); - }else{ - $this.val(curVal); - if (curVal == ""){ - $('#'+newId+' div[data-visible="'+settingID+'"]').hide(); - }else{ - $('#'+newId+' div[data-visible="'+settingID+'"]').show(); - } - // Fix icon selector - if (settingID == "icon"){ - $this.next().find('i').attr('class',curVal); - } - $this.off('change.toptemp').on('change.toptemp',function(){ - curItem($(this).val()); - // Fix icon selector - if (settingID == "icon"){ - $this.next().find('i').attr('class',$(this).val()); - } - // Hide/show related - if ($(this).val() == ""){ - $('#'+newId+' div[data-visible="'+settingID+'"]').hide(); - }else{ - $('#'+newId+' div[data-visible="'+settingID+'"]').show(); - } - }); - } - }) - - // Observe custom mon fields - $('#'+newId).find('input[data-custommon]').each(function(){ - var settingID = $(this).data('custommon'); - // Recursive lookup the value - var curItem = self.settings.customMon[idx][settingID]; - var curVal = curItem(); - if ($(this).is(':checkbox')){ - $(this).prop('checked', curVal); - $(this).off('change.toptemp').on('change.toptemp',function(){ - curItem($(this).prop('checked')); - }); - }else{ - $(this).val(curVal); - $(this).off('change.toptemp').on('change.toptemp',function(){ - // Set namee - if (settingID == "name"){ - var tabPane = $(this).closest('div.tab-pane'); - var tabPID = tabPane.attr('id'); - if ($(this).val() == ""){ - $('#TopTempSettingCustomMenu a[href="#'+tabPID+'"]').text(idx); - tabPane.find('h4:first').text(idx+" main settings"); - }else{ - $('#TopTempSettingCustomMenu a[href="#'+tabPID+'"]').text($(this).val()); - tabPane.find('h4:first').text($(this).val()+" main settings"); - } - } - curItem($(this).val()); - }); - } - }) - // Add menu item - $('#TopTempSettingCustomMenu ul.dropdown-menu').prepend('
  • '+val.name()+'
  • ') - }); - - - // Test a command - $('#settings_plugin_toptemp a.toptempTestCMD').off('click.toptem').on('click.toptem',function(){ - var $this = $(this); - var cmdRun = $this.closest('div.input-append').find('input').val(); - var outputCon = $this.closest('div.tab-pane').find('div.toptempTestCMDOutContainer'); - var output = outputCon.find('div.toptempTestCMDOutput'); - if ($.trim(cmdRun) == ""){ - return; - } - $this.attr( "disabled", true ); - output.html('
    Wait...
    '); - OctoPrint.simpleApiCommand("toptemp", "testCmd", {'cmd':cmdRun}).done(function(response) { - if (!('success' in response) || response.success == false){ - output.html('
    Error
    Error:\n  '+response.error+'\nResult:\n  '+response.result+'\nCode:\n  '+response.returnCode+'\n
    '); - }else{ - output.html('
    Success
    Returned: '+response.result+'
    '); - } - if (outputCon.is(':hidden')){ - outputCon.slideDown(); - } - $this.attr('disabled',false); - }); - }); - - // Get cpu options - OctoPrint.simpleApiCommand("toptemp", "getPredefined", {'reload':true}).done(function(response) { - $('#settings_plugin_toptemp .topTempPreDefCmds li').remove(); - $.each(response,function(idx,val){ - if (val[1] == null){ - return; - } - var item = $('
  • '+val[2]+'
  • '); - item.on('click',function(){ - $(this).closest('div.input-append').find('input').val(val[0]).trigger('change'); - }); - $('#settings_plugin_toptemp .topTempPreDefCmds').append(item); - }) - }); - - // Delete prev sorter - if ($('#TopTempSortList').data('sorter') != null){ - $('#TopTempSortList').data('sorter').destroy(); - } - - // Build sorter - $('#TopTempSortList').html(''); - var allItems = self.buildIconOrder(); - $.each(allItems,function(i,name){ - var settings = self.getSettings(name); - if (self.isCustom(name)){ - var prettyName = settings.name(); - }else{ - var prettyName = name.replace("tool", "Tool "); - prettyName = prettyName.charAt(0).toUpperCase() + prettyName.slice(1); - } - // Skip non active - hackish - var classNameHide = ''; - var iconVis = 'fa-eye'; - if (!settings.show()){ - iconVis = 'fa-eye-slash'; - } - if ((name == "chamber" && !self.tempModel.hasChamber()) || (name == "bed" && !self.tempModel.hasBed()) || (!self.tempModel.hasTools() && name[0] == "t") || (name[0] == "t" && (name.slice(-1)*1) > self.tempModel.tools().length-1) ){ - return true; - // classNameHide = 'muted'; - } - $('#TopTempSortList').append('
    '+prettyName+'
    '); - }); - - var sorter = Sortable.create($('#TopTempSortList')[0],{ - group: 'TopTempSortList', - draggable: 'div.accordion-group', - delay: 200, - delayOnTouchOnly: true, - sort: true, - chosenClass: 'alert-info', - direction: 'vertical', - dragoverBubble: false, - onStart: function(){ - $('#drop_overlay').addClass('UICHideHard'); - }, - onEnd: function(evt){ - $('#drop_overlay').removeClass('UICHideHard in'); - if (self.previewOn){ - var sortlist = $('#TopTempSortList >div').map(function(){return $(this).data('sortid')}).get(); - $.each(sortlist,function(i,val){ - $('#navbar_plugin_toptemp').append($('#navbar_plugin_toptemp_'+val)); - }); - self.fixMargins(); - } - - } - }); - - // Store so we can destroy - $('#TopTempSortList').data('sorter',sorter); - - // Add icon picker from UI Customizer if present - if (typeof OctoPrint.coreui.viewmodels.uICustomizerViewModel != undefined){ - $('#settings_plugin_toptemp .UICShowIconPicker').popover('destroy'); - $('#settings_plugin_toptemp .UICShowIconPicker').each(function(){ - var $this = $(this); - var targetCon = $this.closest('div.tab-pane'); - var targetID = targetCon.attr('id').replace('settings_toptemp_',''); - $(this).popover(OctoPrint.coreui.viewmodels.uICustomizerViewModel.iconSearchPopover($this.find('i'),function(newicon,newcolor){ - // Update using the view - if (newicon !== false){ - OctoPrint.coreui.viewmodels.topTempViewModel.settings[targetID].icon(newicon); - }else{ - OctoPrint.coreui.viewmodels.topTempViewModel.settings[targetID].icon(''); - } - },true,false,false,targetCon,'left')).attr('Title','Click to change icon'); - }); - }else{ - $('#settings_plugin_toptemp .UICShowIconPicker').off('click.TopTempPlugin').on('click.TopTempPlugin',function(event){ - new PNotify({ - title: 'Instal UI Customizer', - text: 'In order to use the icon picker please install my UI Customizer plugin.
    More...', - type: "notice", - hide: false - }); - }); - } - - // Copy settings to all other items - $('button.TopTempCopyToAll,button.TopTempCopyToTools').off('click.TopTempPlugin').on('click.TopTempPlugin',function(event){ - var src = $(this).closest('div.tab-pane').attr('id').replace('settings_toptemp_',''); - // Clone tools only? - if (!$(this).hasClass('TopTempCopyToTools')){ - $.each(self.mainTypes, function(id,target){ - if (target != src){ - self.cloneSettings(src,target); - } - }); - } - var no = self.settings.noTools()-1; - while (no >= 0){ - var target = 'tool'+no; - if (target != src){ - self.cloneSettings(src,target); - } - no--; - } - }); - - $('button.TopTempDelete').off('click.TopTempPlugin').on('click.TopTempPlugin',function(event){ - var tabPane = $(this).closest('div.tab-pane'); - // Toggle - $(this).toggleClass('btn-danger btn-success'); - $(this).find('i').toggleClass('fa-trash fa-undo'); - - // Undo delete - if (!$(this).hasClass('btn-success')){ - tabPane.find('div.alert-danger.toptempWarn').remove(); - $(this).find('span').text('Delete'); - delete self.deleteCust[tabPane.data('toptempcustomid')]; - return; - } - - tabPane.find('h4:first').before('
    Marked for deletion
    Clicking save will delete this custom monitor.
    '); - self.deleteCust[tabPane.data('toptempcustomid')] = true; - $(this).find('span').text('Undo delete'); - }); - } - - // Init show - self.onSettingsShown = function() { - self.settingsSaved = false; - self.settingsOpen = true; - - // Delete temporay items just to make sure - self.tempNewCust = []; - - // Build custom settings - self.buildCustomSettings(); - - // Revert active delete - $('button.TopTempDelete.btn-success').trigger('click'); - $('div.alert.toptempWarn').remove(); - - // Add a new custom settings - $('#settings_plugin_toptemp_newCustom').off('click').on('click',function(){ - var cmindex = Object.keys(self.settings.customMon).length; - OctoPrint.simpleApiCommand("toptemp", "getDefaultSettings", {}).done(function(response) { - self.tempNewCust.push('cu'+cmindex); - self.settings.customMon['cu'+cmindex] = ko.mapping.fromJS({...{ 'cmd' : '' ,'name': 'Custom '+cmindex ,'interval': 25}, ...response }); - // Build it all again - self.buildCustomSettings(); - // Show an alert - $('#settings_toptemp_cu'+cmindex+' h4:first').before('
    Not saved yet!
    Will be deleted if you close settings without saving.
    '); - $('#settings_toptemp_cu'+cmindex+' button.TopTempDelete').parent().remove(); - // Show the new item - $('#TopTempSettingCustomMenu a[href="#settings_toptemp_cu'+cmindex+'"]').trigger('click'); - }); - }); - - // Monitor padding/margin - $('#settings_toptemp_outerm,#settings_toptemp_innerm').off("change.toptemp").on("change.toptemp",function(){ - self.fixMargins(); - }); - - // Preview - $('#TopTempTogglePreview i').removeClass('fa-check-square').addClass('fa-square'); - $('#TopTempTogglePreview').removeClass('active'); - $('#TopTempTogglePreview').off('click.TopTempPlugin').on('click.TopTempPlugin',function(event){ - $(this).find('i').toggleClass('fa-check-square fa-square'); - $(this).toggleClass('active'); - $('div.modal-backdrop').css('transition','top 0.1s linear'); - self.previewOn = !self.previewOn; - if (self.previewOn){ - // Sort them to update preview - var sortlist = $('#TopTempSortList >div').map(function(){return $(this).data('sortid')}).get(); - $.each(sortlist,function(i,val){ - $('#navbar_plugin_toptemp').append($('#navbar_plugin_toptemp_'+val)); - }); - self.fixMargins(); - $('div.modal-backdrop').css('top',$('#navbar').outerHeight()+'px'); - }else{ - // Restore sort order - $.each(self.settings.sortOrder(),function(i,val){ - $('#navbar_plugin_toptemp').append($('#navbar_plugin_toptemp_'+val)); - }); - self.fixMargins(); - $('div.modal-backdrop').css('top','0px'); - } - }); - - - // Settings top icons - $('#TopTempSettingsBar a').not('#TopTempTogglePreview').off('click.TopTempPlugin').on('click.TopTempPlugin',function(event){ - // fix visibily icon - if ($(this).attr('href') == '#settings_toptemp_general'){ - // Update the sorter display of hidden/shown - var allItems = self.buildIconOrder(); - $.each(allItems,function(i,name){ - var settings = self.getSettings(name); - var iconVis = 'fa-eye'; - if (!settings.show()){ - iconVis = 'fa-eye-slash'; - } - $('#TopTempSortList div[data-sortid="'+name+'"] i.TopIconVisSort').removeClass('fa-eye fa-eye-slash').addClass(iconVis); - }); - } - // Hide popover - $('.UICShowIconPicker').popover('hide'); - }); - - // Click general to make sure its always shown - $('#settings_plugin_toptemp a[href="#settings_toptemp_general"]').trigger('click') - - // Cleanup ui and hide unwanted items - if (self.tempModel.hasBed()){ - $('#settings_plugin_toptemp a[href="#settings_toptemp_bed"]').show(); - }else{ - $('#settings_plugin_toptemp a[href="#settings_toptemp_bed"]').hide(); - } - if (self.tempModel.hasChamber()){ - $('#settings_plugin_toptemp a[href="#settings_toptemp_chamber"]').show(); - }else{ - $('#settings_plugin_toptemp a[href="#settings_toptemp_chamber"]').hide(); - } - - // Hide all tools - $('.TopTempHideTool').hide(); - $('#TopTempSettingXtraTools').hide(); - if (self.tempModel.hasTools()){ - // Should we show the drop down for the rest of the tools - if (OctoPrint.coreui.viewmodels.temperatureViewModel.tools().length == 1){ - // Show only tool 0 - $('#settings_plugin_toptemp a[href="#settings_toptemp_tool0"]').show(); - }else{ - // Show the menu anc show each tool - $('#TopTempSettingXtraTools').show(); - $.each(self.tempModel.tools(),function(indx,val){ - $('#settings_plugin_toptemp a[href="#settings_toptemp_tool'+indx+'"]').show(); - }); - } - } - } - - // Clone settings - self.cloneSettings = function(source,target){ - var setClone = function(clonetarget,newVal,lvl1,lvl2){ - // skipe cloning basic - if ($.inArray(lvl1,['label','icon']) != -1){ - return; - } - // Skip unsupported shared settings - if (OctoPrint.coreui.viewmodels.topTempViewModel.settings[clonetarget][lvl1] == undefined){ - return; - } - if (lvl2 != null){ - // Skip unsupported shared settings - if (OctoPrint.coreui.viewmodels.topTempViewModel.settings[clonetarget][lvl1][lvl2] == undefined){ - return - } - OctoPrint.coreui.viewmodels.topTempViewModel.settings[clonetarget][lvl1][lvl2](newVal) - }else{ - OctoPrint.coreui.viewmodels.topTempViewModel.settings[clonetarget][lvl1](newVal) - } - } - // Only two layers deep could not be bother to do a recursive - $.each(OctoPrint.coreui.viewmodels.topTempViewModel.settings[source],function(idx1,val1){ - if (typeof val1 == "object"){ - $.each(val1,function(idx2,val2){ - setClone(target,val2(),idx1,idx2); - }); - }else{ - setClone(target,val1(),idx1,null); - } - }) - - } - - // UI ready - self.onAllBound = function(){ - // Include chartist if not included by others - if (typeof Chartist != "object"){ - $('head').append(''); - $.getScript('/plugin/toptemp/static/js/chartist.min.js'); - } - if (typeof Sortable != "function"){ - $.getScript('/plugin/toptemp/static/js/Sortable.min.js'); - } - - // Get history - OctoPrint.simpleApiCommand("toptemp", "getCustomHistory", {}).done(function(response) { - self.customHistory = response; - }); - } - - // Build containers - self.buildContainers = function(){ - $('#navbar_plugin_toptemp').html('Waiting…'); - var allItems = self.buildIconOrder(); - // Build containers - $.each(allItems, function(id,name){ - // Skip inactive - if ( (name == "chamber" && !self.tempModel.hasChamber()) || (name == "bed" && !self.tempModel.hasBed()) || (name[0] == "t" && (name.slice(-1)*1) > self.tempModel.tools().length-1) ){ - return true; - } - if (self.isCustom(name)){ - self.buildContainer(name,'TopTempCustom'); - }else{ - self.buildContainer(name,'TopTempPrinter'); - } - }); - self.fixMargins(); - } - - self.isCustom = function(string){ - if (string.slice(0,2) == "cu"){ - return true; - }else{ - return false; - } - } - - self.getSettings = function(id){ - if (self.isCustom(id)){ - return self.settings.customMon[id]; - }else{ - return self.settings[id]; - } - } - - self.fixMargins = function(){ - $('#navbar_plugin_toptemp').css({'margin-right' : self.settings.outerMargin()+'px','margin-left' : self.settings.outerMargin()+'px'}); - $('#navbar_plugin_toptemp >div').css('margin-right',self.settings.innerMargin()+'px'); - $('#navbar_plugin_toptemp >div:visible:last').css('margin-right','0px'); - } - - // Build a single container - self.buildContainer = function(name,className){ - var elname = 'navbar_plugin_toptemp_'+name; - var settings = self.getSettings(name); - // Remove old - $('#'+elname).remove(); - // Build new - $('#navbar_plugin_toptemp').append('
    '); - if (!settings.show()){ - $('#'+elname).hide(); - } - self.setGraphStyle(name,settings.graphSettings); - return elname; - } - - // Add CSS for the graphs - self.setGraphStyle = function(name,settings){ - // Remove old - $('#TopTempGraph_'+name+'_style').remove(); - // Build new - $('head').append(''); - // Show the graph? - if (settings.show){ - $('#TopTempGraph_'+name+'_graph').show(); - }else{ - $('#TopTempGraph_'+name+'_graph').hide(); - } - } - - // Bind the settings to an easier variable - self.onBeforeBinding = function () { - self.settings = self.settingsViewModel.settings.plugins.toptemp; - }; - } - - // This is how our plugin registers itself with the application, by adding some configuration information to - // the global variable ADDITIONAL_VIEWMODELS - OCTOPRINT_VIEWMODELS.push([ - // This is the constructor to call for instantiating the plugin - TopTempViewModel, - - // This is a list of dependencies to inject into the plugin, the order which you request here is the order - // in which the dependencies will be injected into your view model upon instantiation via the parameters - // argument - ["settingsViewModel","temperatureViewModel"], - - // Finally, this is the list of all elements we want this view model to be bound to. - [] - ]); -}); - -/* TopTemp END */ From b0fb7156ae7782de680a3148686d774bb87b8c1b Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Sun, 24 Jan 2021 20:14:19 +0100 Subject: [PATCH 3/9] Fixed problem with temperature detection --- octoprint_toptemp/static/js/TopTemp.js | 71 +++++++++++--------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/octoprint_toptemp/static/js/TopTemp.js b/octoprint_toptemp/static/js/TopTemp.js index 48954ef..92f365b 100644 --- a/octoprint_toptemp/static/js/TopTemp.js +++ b/octoprint_toptemp/static/js/TopTemp.js @@ -10,15 +10,18 @@ Monitors: - Scroll/cycle view for multiple tools ? +- Popover with more info + Settings: - - Popover with more info + - Icons: https://github.com/LazeMSS/OctoPrint-TopTemp/issues/5 - small fonts options - Set lowpoint for graph - max width for graph/display + - thousand seperator option + - Custom option to set as not a temperature (no fahrenheit conversion and check for number) - Custom option postfix label (rpm etc) - - thousand seperator option - - Icons: https://github.com/LazeMSS/OctoPrint-TopTemp/issues/5 + - icon color? @@ -42,8 +45,6 @@ $(function() { // Pause updating of the UI self.updatePaused = false; - // Was we running - self.prevOpMode = true; self.mainTypes = ['bed','chamber']; @@ -51,9 +52,6 @@ $(function() { self.customHistory = {}; - // - self.started = false; - // Process data and format it self.FormatTempHTML = function(name, data, customType){ if (self.updatePaused){ @@ -65,7 +63,7 @@ $(function() { var iSettings = self.getSettings(name); // Do know this or want it shown - if (typeof iSettings == "undefined" || iSettings.show() == false || data.actual == null || data.actual == undefined || (data.target == 0 && iSettings.hideOnNoTarget())){ + if (typeof iSettings == "undefined" || iSettings.show() == false || data.actual == null || data.actual == undefined || (data.target == 0 && iSettings.hideOnNoTarget()) || (!customType && self.settings.hideInactiveTemps() && self.tempModel.isOperational() !== true)){ $('#navbar_plugin_toptemp_'+name).hide(); return; }else{ @@ -191,39 +189,13 @@ $(function() { return value; } - self.genericStart = function(){ - // Init it all - if (!self.started){ - self.started = true; - self.buildContainers(); - } - - if (!self.tempModel.isOperational()){ - if (self.prevOpMode && self.settings.hideInactiveTemps()){ - $('#navbar_plugin_toptemp div.TopTempPrinter').hide(); - } - $('#navbar_plugin_toptemp div.TopTempPrinter').removeClass('TopTempLoad'); - self.prevOpMode = false; - }else{ - if (!self.prevOpMode && self.settings.hideInactiveTemps()){ - $('#navbar_plugin_toptemp div.TopTempPrinter').show(); - } - self.prevOpMode = true; - } - } - // Get updated data from the "feeds" self.fromCurrentData = function(data){ - if (self.updatePaused){ return; } - // Init it all - self.genericStart(); - - // Update temps if any data found and not hidden - if (!data.temps.length || (!self.prevOpMode && self.settings.hideInactiveTemps())){ + if (!data.temps.length){ return; } @@ -245,8 +217,7 @@ $(function() { if (plugin != "toptemp"){ return; } - // Init it all - self.genericStart(); + if (!('success' in data) || data.success == false){ return; } @@ -341,7 +312,7 @@ $(function() { // Rebuild it all self.settingsSaved = false; - self.buildContainers(); + self.buildContainers(false); } @@ -822,6 +793,22 @@ $(function() { $.getScript('/plugin/toptemp/static/js/Sortable.min.js'); } + // Wait for the temperature model to be ready + var initSub = self.tempModel.isOperational.subscribe(function(state){ + self.buildContainers(true); + // Remove ourselves + initSub.dispose(); + }) + + // Main sub + self.tempModel.isOperational.subscribe(function(state){ + if (state){ + $('#navbar_plugin_toptemp div.TopTempPrinter').show(); + }else if(self.settings.hideInactiveTemps()){ + $('#navbar_plugin_toptemp div.TopTempPrinter').hide(); + } + }); + // Get history OctoPrint.simpleApiCommand("toptemp", "getCustomHistory", {}).done(function(response) { self.customHistory = response; @@ -829,7 +816,7 @@ $(function() { } // Build containers - self.buildContainers = function(){ + self.buildContainers = function(firstRun){ $('#navbar_plugin_toptemp').html(''); var allItems = self.buildIconOrder(); // Build containers @@ -851,6 +838,10 @@ $(function() { self.FormatTempHTML(k,{'actual' : v[v.length-1]},true); } }); + // Hide all non operationel + if (!firstRun && self.settings.hideInactiveTemps() && self.tempModel.isOperational() !== true){ + $('#navbar_plugin_toptemp div.TopTempPrinter').hide(); + } } self.isCustom = function(string){ From 9863158adbc9a0edb48e5a139849d3116a364a0c Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Sun, 24 Jan 2021 20:17:30 +0100 Subject: [PATCH 4/9] Fixed to large input box --- octoprint_toptemp/templates/toptemp_settings.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_toptemp/templates/toptemp_settings.jinja2 b/octoprint_toptemp/templates/toptemp_settings.jinja2 index e0f5348..26ac500 100644 --- a/octoprint_toptemp/templates/toptemp_settings.jinja2 +++ b/octoprint_toptemp/templates/toptemp_settings.jinja2 @@ -457,7 +457,7 @@
    - +
    Test
    -
    - +
    +
    @@ -295,8 +295,8 @@
    -
    - +
    +
    @@ -427,8 +427,8 @@
    -
    - +
    +
    @@ -572,8 +572,8 @@
    -
    - +
    +
    From a182e4b50704aa104e40bb1896b4e702e7e713c6 Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Mon, 25 Jan 2021 08:20:07 +0100 Subject: [PATCH 7/9] Fixed graph settings not working: #6 --- octoprint_toptemp/static/js/TopTemp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_toptemp/static/js/TopTemp.js b/octoprint_toptemp/static/js/TopTemp.js index 1af965f..e9bbefd 100644 --- a/octoprint_toptemp/static/js/TopTemp.js +++ b/octoprint_toptemp/static/js/TopTemp.js @@ -78,7 +78,7 @@ $(function() { graphE.show(); // Update the styles if settings are open - if (self.settingsOpen){ + if (self.settingsOpen && self.previewOn){ self.setGraphStyle(name,iSettings.graphSettings); } @@ -889,7 +889,7 @@ $(function() { // Remove old $('#TopTempGraph_'+name+'_style').remove(); // Build new - $('head').append(''); + $('head').append('' ); // Show the graph? if (settings.show){ $('#TopTempGraph_'+name+'_graph').show(); From 87cd1a7e37859738fcd7ef8c2fe2875e5429ebdf Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Mon, 25 Jan 2021 08:46:46 +0100 Subject: [PATCH 8/9] Increased the margin for on target temp: #10 --- octoprint_toptemp/static/css/TopTemp.css | 4 +++ octoprint_toptemp/static/js/TopTemp.js | 44 ++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/octoprint_toptemp/static/css/TopTemp.css b/octoprint_toptemp/static/css/TopTemp.css index fefbbc8..cfa95a1 100644 --- a/octoprint_toptemp/static/css/TopTemp.css +++ b/octoprint_toptemp/static/css/TopTemp.css @@ -34,6 +34,10 @@ margin-top: 5px; } +#navbar_plugin_toptemp .leftPad{ + padding-left: 3px; +} + .UICHeaderIcons #navbar_plugin_toptemp{ margin-top: -6px; } diff --git a/octoprint_toptemp/static/js/TopTemp.js b/octoprint_toptemp/static/js/TopTemp.js index e9bbefd..93d018f 100644 --- a/octoprint_toptemp/static/js/TopTemp.js +++ b/octoprint_toptemp/static/js/TopTemp.js @@ -126,27 +126,35 @@ $(function() { // Append actual data outputstr += self.formatTempLabel(name,data.actual,iSettings); - // Append target if different - if (!customType){ - if (typeof data.target != undefined && data.target != data.actual && data.target > 0){ - // Show arrow - if (iSettings.showTargetArrow()){ - if (data.target > data.actual){ - outputstr += ''; - }else if (data.target < data.actual){ - outputstr += ''; - } + // Append target if not custom type, we have a target and told to show it + if (!customType && typeof data.target != undefined && data.target > 0){ + var offsetL = data.target - 0.5; + var offsetU = data.target + 0.5; + var ontarget = false; + + // show arrows between temps + if (iSettings.showTargetArrow()){ + // Inside target margin + if (data.actual >= offsetL && data.actual <= offsetU){ + ontarget = true; + }else if (data.actual < offsetL){ + outputstr += ''; + }else if (data.actual > offsetU){ + outputstr += ''; } - // Show target temp - if (iSettings.showTargetTemp()){ - if (!iSettings.showTargetArrow()){ - outputstr += "/"; - } - outputstr += self.formatTempLabel(name,data.target,iSettings); + } + + // Show checkered if on target + if (ontarget){ + outputstr += ''; + }else if (iSettings.showTargetTemp()){ + // No arrow to seperate then we use text + if (!iSettings.showTargetArrow()){ + outputstr += "/"; } - }else if(typeof data.target != undefined && data.target == data.actual && iSettings.showTargetArrow()){ - outputstr += ''; + outputstr += self.formatTempLabel(name,data.target,iSettings); } + } // Should we add an icon From a5ff645d0ea455f36555d21a26cfa95ee7c90e8a Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Mon, 25 Jan 2021 08:49:39 +0100 Subject: [PATCH 9/9] Next release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 715011c..9989da4 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "Top Temp" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "0.0.0.1" +plugin_version = "0.0.0.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module