Skip to content

Commit

Permalink
show connected endpoint and server in settings
Browse files Browse the repository at this point in the history
change SP panel link based on endpoint
  • Loading branch information
jneilliii committed Dec 11, 2022
1 parent e08efaf commit e27b19a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
1 change: 1 addition & 0 deletions octoprint_simplyprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Events.CONNECTED,
Events.DISCONNECTING,
Events.DISCONNECTED,
Events.CLIENT_AUTHED,

Events.STARTUP,
Events.SHUTDOWN,
Expand Down
50 changes: 31 additions & 19 deletions octoprint_simplyprint/static/js/SimplyPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ $(function () {

self.loading = ko.observable(true);

self.ws_connected_server = ko.observable();
self.current_endpoint = ko.observable();
self.SimplyPrintPanelURL = ko.pureComputed(function(){
return (self.current_endpoint() === "test") ? "https://rewrite.simplyprint.io/panel" : "https://simplyprint.io/panel";
});
self.SimplyPrintEndpoint = ko.pureComputed(function(){
return "SimplyPrint active on " + self.current_endpoint() + " endpoint.";
});

self.onAfterBinding = function () {
// Chose #wizard_plugin_corewizard_onlinecheck because it seemed likely it would be there for all first time
if (!self.settingsViewModel.settings.plugins.SimplyPrint.is_set_up() && !$('#wizard_plugin_corewizard_onlinecheck').length) {
Expand All @@ -78,14 +87,14 @@ $(function () {
}

self.loading(false);
}
};

self.onWizardFinish = function(){
// Show the welcome dialog if corewizard was open
if (!self.settingsViewModel.settings.plugins.SimplyPrint.is_set_up() && $('#wizard_plugin_corewizard_onlinecheck').length) {
$('#SimplyPrintWelcome').modal("show");
}
}
};

function SetupRecommended() {
setTimeout(function () {
Expand All @@ -112,7 +121,7 @@ $(function () {
SetupRecommended();
}
});
}
};

$("body").on("click", "#navbar_systemmenu ul li:nth-child(4)", function () {
if (!self.settingsViewModel.settings.plugins.SimplyPrint.is_set_up()) {
Expand Down Expand Up @@ -240,10 +249,10 @@ $(function () {
/*$("#wizard_dialog .button-finish[name='finish']").on("click", function () {
$("#simplyprint_dialog").modal("show");
});*/
}
};

self.pluginsLoadedCheck = function () {
let pluginSettings = self.settingsViewModel.settings.plugins.SimplyPrint
let pluginSettings = self.settingsViewModel.settings.plugins.SimplyPrint;
if ($("#settings_plugin_pluginmanager_pluginlist tbody").html().length) {
//Plugins have been loaded (being called from the API async, not loaded with the page)
if (typeof pluginSettings.sp_installed_plugins === "undefined" || !Array.isArray(pluginSettings.sp_installed_plugins) || !pluginSettings.sp_installed_plugins.length) {
Expand Down Expand Up @@ -271,14 +280,14 @@ $(function () {
} else {
setTimeout(self.pluginsLoadedCheck, 500);
}
}
};

self.ManagedBySimplyPrintAlert = function (extra = "", onlyPartly = false) {
return `<div class="alert">
<img alt="SimplyPrint logo (all rights reserved)" src="plugin/SimplyPrint/static/img/sp_logo.png" style="margin-left: 10px;width: 19px;">
${onlyPartly ? "Some features here are managed by SimplyPrint" : "This feature is managed by SimplyPrint"}${extra.length ? ". " + extra : ""}
</div>`;
}
};

self.DisableOverwrittenUI = function () {
//Printer profiles
Expand All @@ -301,18 +310,17 @@ $(function () {
$("#settings_gcodeScripts [data-bind=\"value: scripts_gcode_afterPrintCancelled\"]").prop("disabled", true);
$("#settings_gcodeScripts [data-bind=\"value: scripts_gcode_afterPrintPaused\"]").prop("disabled", true);
$("#settings_gcodeScripts [data-bind=\"value: scripts_gcode_beforePrintResumed\"]").prop("disabled", true);
}
};

self.DisableOverwrittenUI();
self.OctoSetupChanges();

// Support for installing and uninstalling the SimplyPrintRpiSoftware (CP)
self.requestInProgress = ko.observable()
self.requestInProgress = ko.observable();
self.doSetup = function () {
console.log("installing")
self.requestInProgress(true);
OctoPrint.simpleApiCommand("SimplyPrint", "setup")
}
OctoPrint.simpleApiCommand("SimplyPrint", "setup");
};

self.onDataUpdaterPluginMessage = function (plugin, data) {
if (plugin !== "SimplyPrint") {
Expand All @@ -333,19 +341,23 @@ $(function () {
"text": "It looks like the dependency has been uninstalled. Please reinstall the plugin or contact us at [email protected]",
"type": "error",
"hide": false,
})
});
} else if (data.message === "sp-rpi_error") {
new PNotify({
"title": "Unknown error enabling the SimplyPrint software",
"text": "Please get in contact so we can resolve this! [email protected]",
"type": "error",
"hide": false,
})
});
} else if (data.message === "sp-ws-connection") {
self.ws_connected_server(data.server);
self.current_endpoint(data.endpoint);
}
}
}
};

self.doUninstall = function () {
self.requestInProgress(true)
self.requestInProgress(true);
OctoPrint.simpleApiCommand("SimplyPrint", "uninstall")
.done(function (response) {
self.requestInProgress(false);
Expand All @@ -362,11 +374,11 @@ $(function () {
"text": "It looks like the dependency has already been uninstalled. Failed to uninstall it again or contact us at [email protected]",
"type": "error",
"hide": false,
})
});
}
}
})
}
});
};
}

OCTOPRINT_VIEWMODELS.push({
Expand Down
2 changes: 1 addition & 1 deletion octoprint_simplyprint/templates/SimplyPrint_navbar.jinja2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div id="simplyprint_plugin_navbar">
<div class="nav navbar-text">
<a href="https://simplyprint.io/panel" target="_blank"><img alt="SimplyPrint logo (all rights reserved)" src="plugin/SimplyPrint/static/img/sp_logo.png" title="SimplyPrint active" style="width: 28px;"></a>
<a data-bind="attr: {href: SimplyPrintPanelURL, title: SimplyPrintEndpoint}" href="https://simplyprint.io/panel" target="_blank"><img alt="SimplyPrint logo (all rights reserved)" src="plugin/SimplyPrint/static/img/sp_logo.png" style="width: 28px;"></a>

<strong>
<span id="simplyprint_version_wrapper">v{{ plugin_SimplyPrint_version }}</span>
Expand Down
3 changes: 2 additions & 1 deletion octoprint_simplyprint/templates/SimplyPrint_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<p>There isn't much to see in here :) All settings are located in the SimplyPrint panel, and everything that needs to be
synced to OctoPrint and your Raspberry Pi, will do so automatically.</p>

<a href="https://simplyprint.io/panel" target="_blank" class="btn btn-primary">Go to the SimplyPrint panel</a>
<p>Currently connected to <span class="label label-info" data-bind="text: current_endpoint"></span> endpoint on server <span class="label label-info" data-bind="text: ws_connected_server"></span>.</p>
<a data-bind="attr: {href: SimplyPrintPanelURL, title: SimplyPrintEndpoint}" href="https://simplyprint.io/panel" target="_blank" class="btn btn-primary">Go to the SimplyPrint panel</a>

{#
<p>
Expand Down
13 changes: 12 additions & 1 deletion octoprint_simplyprint/websocket/simplyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ..comm.monitor import Monitor
import octoprint.server
import octoprint.util
from octoprint.plugin import PluginSettings
from octoprint.plugin import PluginSettings, PluginManager
from octoprint.printer import PrinterInterface
from octoprint.filemanager import FileManager, FileDestinations
from octoprint.events import Events, EventManager
Expand Down Expand Up @@ -88,6 +88,7 @@ def __init__(self, plugin: SimplyPrint) -> None:
self.settings = cast(PluginSettings, plugin._settings)
self.printer = cast(PrinterInterface, plugin._printer)
self.file_manager = cast(FileManager, plugin._file_manager)
self.plugin_manager = cast(PluginManager, plugin._plugin_manager)
self.sys_manager = SystemManager(self)
self._event_bus = cast(EventManager, plugin._event_bus)
if self.settings.get_boolean(["debug_logging"]):
Expand All @@ -98,6 +99,7 @@ def __init__(self, plugin: SimplyPrint) -> None:
self.connected = False
self.is_set_up = self.settings.get(["is_set_up"])
self._set_ws_url()
self.ws_connected_server = ""

self.simplyprint_thread = threading.Thread(
target=self._run_simplyprint_thread
Expand Down Expand Up @@ -274,6 +276,11 @@ def on_event(self, event: str, payload: Dict[str, Any]) -> None:
add_callback(self.send_sp, "power_controller", {"on": True})
elif event == "plugin_simplypowercontroller_power_off":
add_callback(self.send_sp, "power_controller", {"on": False})
elif event == Events.CLIENT_AUTHED:
self.plugin_manager.send_plugin_message(self.plugin._identifier, {"message": "sp-ws-connection",
"server": self.ws_connected_server,
"endpoint": self.settings.get(
["endpoint"])})
if event in [
"plugin_pluginmanager_install_plugin",
"plugin_pluginmanager_uninstall_plugin",
Expand Down Expand Up @@ -431,6 +438,10 @@ def _process_message(self, msg: str) -> None:
name = data.get("name")
if name is not None:
self._save_item("printer_name", name)
self.ws_connected_server = data.get("region", "")
self.plugin_manager.send_plugin_message(self.plugin._identifier, {"message": "sp-ws-connection",
"server": self.ws_connected_server,
"endpoint": self.settings.get(["endpoint"])})
self.reconnect_delay = 1.
self._push_initial_state()
elif event == "error":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
# Remember to bump the version in octoprint_simplyprint/__init__.py as well
plugin_version = "4.0.5dev2"
plugin_version = "4.0.5dev3"

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

0 comments on commit e27b19a

Please sign in to comment.