Hello Guys,
I'm currently building my first Octoprint application. The official documentation helped me a lot, but I'm actually stuck. I try to send a simple Gcode to the terminal with a button, but nothing appears in the terminal, or in the logs... Do you have any suggestion ?
Personally, I use Octoprint.control.sendGcode() as opposed to self.termiral.sendCommand(). To be fair, I'm not sure what the best practice is supposed to be, but sendGcode() is working for me. You can provide either a gcode string or an array of gcode strings for it to send.
Pull Request submitted to your repo. It was basically just a binding scope issue. When you inject stuff into other view models you have to make sure that you are also injecting your observables and functions into that view model you're injecting into.
There are other ways to do what you're attempting though, for example using the getAdditionalControls callback in javascript will do the UI injection for you and has a lot of power and flexibility. You may want to take a look at that as an option as well. It follows the same rules as Custom Controls, so parameters, parsing return values, etc.
For an example of the getAddiiontalControls callback you can take a look at my BLTouch plugin. And here is the docs on everything that you can do with custom controls.
Just a warning,.when doing this approach with the viewmodel injection make sure to check the receiving viewmodel and verify you're not overwriting a default functions or observables so it doesn't cause issues with internal functions, hence the rename of the function I did.