Skip to content

Commit

Permalink
Merge branch 'translations' into dlpreplacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Willmac16 committed Jul 27, 2021
2 parents be29a3b + f1a754d commit 7ef72fc
Show file tree
Hide file tree
Showing 13 changed files with 2,921 additions and 232 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

A dashboard tab for Octoprint that displays the most relevant info regarding the state of the printer and any on-going print jobs.

## NOTE

Maintenance of this plugin has been taken over by new maintainers. (as of 27/09/2020)
**NOTE:** This plugin was taken over by new maintainers as of September 2020, see [credits](https://github.com/j7126/OctoPrint-Dashboard#credits) section for details

![Screenshot](https://github.com/j7126/OctoPrint-Dashboard/blob/master/screenshots/screenshot-2.png)

Expand Down Expand Up @@ -44,7 +42,7 @@ For release notes and release history, please visit the [wiki](https://github.co
* The CPU-temp will likely only work on a Raspberry Pi.
* Disk Usage will likely only work on Linux deratives.
* UI testing is limited to latest versions of desktop browsers: Safari, Chrome and Firefox
* Plugin testing is limited to latest verson of OctoPi on RPi3b and 3b+
* Plugin testing is limited to latest verson of OctoPrint

## Dependencies

Expand All @@ -59,7 +57,7 @@ The dashboard uses the time estimates provided by PrintTimeGenius if it is insta
* Chartist chart framework: https://gionkunz.github.io/chartist-js/ [license](https://github.com/gionkunz/chartist-js/blob/master/LICENSE-WTFPL)
* Plugin originally by: StefanCohen
* Currently maintained by: j7126 and Willmac16
* Github Contributors: Andy Harrison (wizard04wsu), Doug Hoyt (doughoyt), Olli (OllisGit), OverLoad (overload08), spiff72, CynanX, Klammerson, 0xz00n, cp2004, clonesht
* Github Contributors: Andy Harrison (wizard04wsu), Doug Hoyt (doughoyt), Olli (OllisGit), OverLoad (overload08), spiff72, CynanX, Klammerson, 0xz00n, cp2004, clonesht, ldursw, martinh2011
* Community support and encouragement: OutsourcedGuru, jneilliii, foosel

## Support OctoPrint
Expand Down
24 changes: 20 additions & 4 deletions octoprint_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
from octoprint.access.permissions import Permissions
except ImportError:
noAccessPermissions = True

from flask_babel import gettext
import logging
from datetime import datetime
from datetime import timedelta
import time, subprocess, json, platform, re, psutil, sys, os


Expand Down Expand Up @@ -128,6 +130,8 @@ class DashboardPlugin(octoprint.plugin.SettingsPlugin,

psutil_worker = 0

jsErrors = []

if noAccessPermissions == False:
def get_additional_permissions(*args, **kwargs):
return [
Expand Down Expand Up @@ -251,7 +255,8 @@ def updateCmds(self):
##~~ SimpleApiPlugin mixin
def get_api_commands(self):
return dict(
testCmdWidget=["cmd"]
testCmdWidget=["cmd"],
jsError=["msg"]
)

def on_api_command(self, command, data):
Expand All @@ -261,6 +266,12 @@ def on_api_command(self, command, data):
self.testCmd(data["cmd"])
else:
self._logger.info("testCmdWidget called, but without proper permissions")
# log frontend js errors
if command == "jsError":
if data["msg"] not in self.jsErrors:
self.jsErrors.append(data["msg"])
self._logger.error("Frontend javascript error detected (this error is not necesarily to do with dashboard):\n{msg}".format(**data))
self._jsLogger.error(data["msg"])

# ~~ StartupPlugin mixin
def on_after_startup(self):
Expand All @@ -284,6 +295,10 @@ def on_after_startup(self):

self.updateCmds()

self._jsLogger = logging.getLogger("octoprint.JsFrontendErrors(Dash)")
self._jsLogger.info("Js Logger (Dash) started")
self._logger.debug("JS Logger started")

self.timelyTimer = RepeatedTimer(1.0, self.timely_notification, run_first=True)
self.timelyTimer.start()

Expand Down Expand Up @@ -594,7 +609,8 @@ def get_settings_defaults(self):
feedrateMax=400,
# time format for eta
ETAUse12HTime=False,
ETAShowSeconds=True
ETAShowSeconds=False,
ETAShowDate=True
)

def get_settings_restricted_paths(self):
Expand Down Expand Up @@ -656,7 +672,7 @@ def get_template_configs(self):
##~~ AssetPlugin mixin
def get_assets(self):
return dict(
js=["js/dashboard.js", "js/chartist.min.js", "js/fitty.min.js"],
js=["js/errorReporter.js", "js/dashboard.js", "js/chartist.min.js", "js/fitty.min.js"],
css=["css/dashboard.css", "css/chartist.min.css"],
less=["less/dashboard.less"]
)
Expand Down
4 changes: 4 additions & 0 deletions octoprint_dashboard/static/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,7 @@ button.dashboardButton#job_cancel>span>span {
.dashboardGridItem.jobControl {
margin-top: 10px;
}

.dashboardGridItem span#eta {
padding-left: 0px;
}
91 changes: 56 additions & 35 deletions octoprint_dashboard/static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ $(function () {

self.admin = ko.observableArray(false);
self.webcam_perm = ko.observable(false);
self.hls_capable = ko.observable(false);


self.fsSystemInfo = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsSystemInfo(), this);
self.fsTempGauges = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsTempGauges(), this);
Expand Down Expand Up @@ -466,26 +468,27 @@ $(function () {
// --- Way to add widget settings 2 ---
// create a modal in the settings page jinja template and set the settingsId attribute below to the id of the modal with a # before it
self.widgetsSettings = ko.observableArray([
{ title: "FullScreen & FullBrowser Mode Buttons", enabled: dashboardSettings.showFullscreen },
{ title: "System Info", enabled: dashboardSettings.showSystemInfo, settingsId: "#dashboardSysInfoSettingsModal", enableInFull: dashboardSettings.fsSystemInfo, printingOnly: dashboardSettings.printingOnly_SystemInfo },
{ title: "Job Control Buttons", enabled: dashboardSettings.showJobControlButtons, enableInFull: dashboardSettings.fsJobControlButtons, printingOnly: dashboardSettings.printingOnly_JobControlButtons },
{ title: "Temperature Gauges", enabled: dashboardSettings.enableTempGauges, settingsId: "#dashboardTempGaugeSettingsModal", enableInFull: dashboardSettings.fsTempGauges, printingOnly: dashboardSettings.printingOnly_TempGauges },
{ title: "Fan Gauge", enabled: dashboardSettings.showFan, enableInFull: dashboardSettings.fsFan, printingOnly: dashboardSettings.printingOnly_Fan },
{ title: gettext("FullScreen & FullBrowser Mode Buttons"), enabled: dashboardSettings.showFullscreen },
{ title: gettext("System Info"), enabled: dashboardSettings.showSystemInfo, settingsId: "#dashboardSysInfoSettingsModal", enableInFull: dashboardSettings.fsSystemInfo, printingOnly: dashboardSettings.printingOnly_SystemInfo },
{ title: gettext("Job Control Buttons"), enabled: dashboardSettings.showJobControlButtons, enableInFull: dashboardSettings.fsJobControlButtons, printingOnly: dashboardSettings.printingOnly_JobControlButtons },
{ title: gettext("Temperature Gauges"), enabled: dashboardSettings.enableTempGauges, settingsId: "#dashboardTempGaugeSettingsModal", enableInFull: dashboardSettings.fsTempGauges, printingOnly: dashboardSettings.printingOnly_TempGauges },
{ title: gettext("Fan Gauge"), enabled: dashboardSettings.showFan, enableInFull: dashboardSettings.fsFan, printingOnly: dashboardSettings.printingOnly_Fan },
{
title: "Enclosure Gauges",
title: gettext("Enclosure Gauges"),
enabled: dashboardSettings.showSensorInfo,
settings: [
{ type: "radio", title: "Enclosure Plugin Gague Style", setting: dashboardSettings.enclosureGaugeStyle, options: [{ name: "Temperature Dial", value: "3/4"}, { name: "Text", value:"text"}] }
{ type: "radio", title: gettext("Enclosure Plugin Gague Style"), setting: dashboardSettings.enclosureGaugeStyle, options: [{ name: gettext("Temperature Dial"), value: "3/4"}, { name: gettext("Text"), value:"text"}] }
],
enableInFull: dashboardSettings.fsSensorInfo,
printingOnly: dashboardSettings.printingOnly_SensorInfo },
{ title: "Command Widgets", enabled: dashboardSettings.showCommandWidgets, settingsId: "#dashboardCommandSettingsModal", enableInFull: dashboardSettings.fsCommandWidgets, printingOnly: dashboardSettings.printingOnly_CommandWidgets },
{ title: "Printer Message (M117)", enabled: dashboardSettings.showPrinterMessage, enableInFull: dashboardSettings.fsPrinterMessage, printingOnly: dashboardSettings.printingOnly_PrinterMessage, clearOn: dashboardSettings.clearOn_PrinterMessage },
{ title: "Print Thumbnail (Slicer Thumbnails)", enabled: dashboardSettings.showPrintThumbnail, enableInFull: dashboardSettings.fsPrintThumbnail, clearOn: dashboardSettings.clearOn_PrintThumbnail },
printingOnly: dashboardSettings.printingOnly_SensorInfo
},
{ title: gettext("Print Thumbnail (Slicer Thumbnails)"), enabled: dashboardSettings.showPrintThumbnail, enableInFull: dashboardSettings.fsPrintThumbnail, clearOn: dashboardSettings.clearOn_PrintThumbnail },
{ title: gettext("Command Widgets"), enabled: dashboardSettings.showCommandWidgets, settingsId: "#dashboardCommandSettingsModal", enableInFull: dashboardSettings.fsCommandWidgets, printingOnly: dashboardSettings.printingOnly_CommandWidgets },
{ title: gettext("Printer Message (M117)"), enabled: dashboardSettings.showPrinterMessage, enableInFull: dashboardSettings.fsPrinterMessage, printingOnly: dashboardSettings.printingOnly_PrinterMessage, clearOn: dashboardSettings.clearOn_PrinterMessage },
{
title: "Progress Gauges",
enabled: function () {
return self.dashboardSettings.showTimeProgress() || self.dashboardSettings.showProgress() || self.dashboardSettings.showLayerProgress() || self.dashboardSettings.showHeightProgress();
title: gettext("Progress Gauges"),
setting: function () {
return dashboardSettings.showTimeProgress() || dashboardSettings.showProgress() || dashboardSettings.showLayerProgress() || dashboardSettings.showHeightProgress();
},
enable: function () {
self.dashboardSettings.showTimeProgress(true);
Expand All @@ -500,28 +503,28 @@ $(function () {
self.dashboardSettings.showHeightProgress(false);
},
settings: [
{ type: "radio", title: "Progress gauge type", setting: self.dashboardSettings.gaugetype, options: [{ name: "Circle", value: "circle" }, { name: "Bar", value: "bar" }] },
{ type: "checkbox", title: "Show Time Progress Gauge", setting: self.dashboardSettings.showTimeProgress },
{ type: "checkbox", title: "Show GCode Progress Gauge", setting: self.dashboardSettings.showProgress },
{ type: "checkbox", title: "Show Layer Progress Gauge", setting: self.dashboardSettings.showLayerProgress },
{ type: "checkbox", title: "Show Height Progress Gauge", setting: self.dashboardSettings.showHeightProgress }
{ type: "radio", title: gettext("Progress gauge type"), enabled: dashboardSettings.gaugetype, options: [{ name: gettext("Circle"), value: "circle" }, { name: gettext("Bar"), value: "bar" }] },
{ type: "checkbox", title: gettext("Show Time Progress Gauge"), enabled: dashboardSettings.showTimeProgress },
{ type: "checkbox", title: gettext("Show GCode Progress Gauge"), enabled: dashboardSettings.showProgress },
{ type: "checkbox", title: gettext("Show Layer Progress Gauge"), enabled: dashboardSettings.showLayerProgress },
{ type: "checkbox", title: gettext("Show Height Progress Gauge"), enabled: dashboardSettings.showHeightProgress }
],
enableInFull: self.dashboardSettings.fsProgressGauges,
printingOnly: self.dashboardSettings.printingOnly_ProgressGauges,
},
{
title: "Layer Duration Graph",
enabled: self.dashboardSettings.showLayerGraph,
title: gettext("Layer Duration Graph"),
setting: dashboardSettings.showLayerGraph,
settings: [
{ type: "radio", title: "Layer graph type", setting: self.dashboardSettings.layerGraphType, options: [{ name: "Normal", value: "normal" }, { name: "Last 40 Layers", value: "last40layers" }, { name: "Scrolling", value: "scrolling" }] }
{ type: "radio", title: gettext("Layer graph type"), enabled: dashboardSettings.layerGraphType, options: [{ name: gettext("Normal"), value: "normal" }, { name: gettext("Last 40 Layers"), value: "last40layers" }, { name: gettext("Scrolling"), value: "scrolling" }] }
],
enableInFull: self.dashboardSettings.fsLayerGraph,
printingOnly: self.dashboardSettings.printingOnly_LayerGraph,
clearOn: self.dashboardSettings.clearOn_LayerGraph
},
{ title: "Filament Widget", enabled: self.dashboardSettings.showFilament, settings: [{ type: "title", title: "The filament widget shows how much filament has been extruded. It can also show the time untill next filament change." }, { type: "checkbox", title: "Show time untill next filament change", setting: self.dashboardSettings.showFilamentChangeTime },], enableInFull: self.dashboardSettings.fsFilament, printingOnly: self.dashboardSettings.printingOnly_Filament, clearOn: self.dashboardSettings.clearOn_Filament },
{ title: "Feedrate", enabled: self.dashboardSettings.showFeedrate, settingsId: "#dashboardFeedrateSettingsModal", enableInFull: self.dashboardSettings.fsFeedrate, printingOnly: self.dashboardSettings.printingOnly_Feedrate, clearOn: self.dashboardSettings.clearOn_Feedrate },
{ title: "Webcam", enabled: self.dashboardSettings.showWebCam, settingsId: "#dashboardWebcamSettingsModal", enableInFull: self.dashboardSettings.fsWebCam, printingOnly: self.dashboardSettings.printingOnly_WebCam },
{ title: gettext("Filament Widget"), enabled: dashboardSettings.showFilament, settings: [{ type: "title", title: gettext("The filament widget shows how much filament has been extruded. It can also show the time untill next filament change.") }, { type: "checkbox", title: gettext("Show time untill next filament change"), enabled: dashboardSettings.showFilamentChangeTime },], enableInFull: dashboardSettings.fsFilament, printingOnly: dashboardSettings.printingOnly_Filament, clearOn: dashboardSettings.clearOn_Filament },
{ title: gettext("Feedrate"), enabled: dashboardSettings.showFeedrate, settingsId: "#dashboardFeedrateSettingsModal", enableInFull: dashboardSettings.fsFeedrate, printingOnly: dashboardSettings.printingOnly_Feedrate, clearOn: dashboardSettings.clearOn_Feedrate },
{ title: gettext("Webcam"), enabled: dashboardSettings.showWebCam, settingsId: "#dashboardWebcamSettingsModal", enableInFull: dashboardSettings.fsWebCam, printingOnly: dashboardSettings.printingOnly_WebCam }
]);

};
Expand Down Expand Up @@ -667,8 +670,12 @@ $(function () {
var url = self.settingsViewModel.settings.webcam.streamUrl();
}

var streamType = determineWebcamStreamType(url);
if (streamType == "mjpg") {
let streamType = "mjpg";
if (self.hls_capable()) {
streamType = determineWebcamStreamType(url);
}

if (streamType === "mjpg") {
self._switchToMjpgWebcam(url, nonce);
} else if (streamType == "hls") {
self._switchToHlsWebcam(url);
Expand Down Expand Up @@ -735,11 +742,16 @@ $(function () {
return str;
}

self.getEta = function(seconds) {
dt = new Date();
self.getEta = function (seconds) {
var dt = new Date();
var today = dt.toString().split(' ').slice(1, 4).join(' ');
dt.setSeconds(dt.getSeconds() + seconds);
//return dt.toTimeString().split(' ')[0];
return formatTime(dt);
var dtDay = dt.toString().split(' ').slice(1, 4).join(' ');
var eta = formatTime(dt);
if (self.settingsViewModel.settings.plugins.dashboard.ETAShowDate() && today != dtDay) {
eta += ' ' + dtDay.split(' ').slice(0, 2).join(' ');
}
return eta;
};

// TODO: move to a js update every second
Expand Down Expand Up @@ -840,8 +852,8 @@ $(function () {

self.formatConnectionstatus = function (currentStatus) {
if (currentStatus) {
return "Connected";
} else return "Disconnected";
return gettext("Connected");
} else return gettext("Disconnected");
};

self.formatPercentage = function (percentage) {
Expand Down Expand Up @@ -968,7 +980,7 @@ $(function () {
}
};

self.updateChartWidth = function() {
self.updateChartWidth = function () {
if (self.bindingDone) {
var options = {
width: `${self.chartWidth}%`
Expand Down Expand Up @@ -1046,6 +1058,15 @@ $(function () {
self.webcam_perm(true);
}


OctoPrint.get("api/version")
.done(function (response) {
verParts = response.server.split('.');
if (Number(verParts[0]) >= 1 && Number(verParts[1]) >= 5) {
self.hls_capable(true);
}
});

if (self.webcam_perm) {
self.switchToDefaultWebcam();
}
Expand Down Expand Up @@ -1153,7 +1174,7 @@ $(function () {
$('button.dashboardButton#job_cancel').addClass('confirm');
var t = 5;
var setText = function () {
$('button.dashboardButton#job_cancel > span').html('Click again to confirm cancel <span>(' + t-- + ')</span>');
$('button.dashboardButton#job_cancel > span').html(gettext('Click again to confirm cancel') + ' <span>(' + t-- + ')</span>');
}
setTimeout(() => {
if (jobCanceling)
Expand Down
28 changes: 28 additions & 0 deletions octoprint_dashboard/static/js/errorReporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// report js errors to the backend to be logged
window.onerror = function (msg, url, lineNo, columnNo, error) {
var message;
if (msg.toLowerCase().indexOf("script error") > -1) {
message = 'Script Error: See Browser Console for Detail';
} else {
var message = [
'Message: ' + msg,
'URL: ' + url,
'Line: ' + lineNo,
'Column: ' + columnNo,
'Error object: ' + JSON.stringify(error)
].join(' - ');
}

$.ajax({
url: API_BASEURL + "plugin/dashboard",
type: "POST",
dataType: "json",
data: JSON.stringify({
command: "jsError",
msg: message
}),
contentType: "application/json; charset=UTF-8"
});

return false;
};
Loading

0 comments on commit 7ef72fc

Please sign in to comment.