');
- });
-
- 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 @@