Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from David-Maisonave/patch-1
Browse files Browse the repository at this point in the history
Fixed Issue#17 by hooking into the Terminal Tab
  • Loading branch information
mike1pol authored Jan 9, 2022
2 parents b4de876 + d91f767 commit ff907b4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions octoprint_macro/static/js/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $(function () {
self.settings = parameters[0];
self.loginState = parameters[1];
self.connectionState = parameters[2];
self.terminal = parameters[3]; //Hooks into the Terminal Tab
self.isActive = function (data) {
const dop = data.dop();
if (dop && self.connectionState.isPrinting()) {
Expand All @@ -18,29 +19,26 @@ $(function () {
return self.connectionState.isOperational() && self.loginState.isUser();
}
function executeCommands(commands) {
if (commands.length > 0) {
const command = commands.shift();
OctoPrint.control
.sendGcode(command)
.then(() => executeCommands(commands))
.catch(e => console.error(e))
}
var splitCommands = commands.split("\n'");
var len = splitCommands.length;
for(var i=0;i<len;i++){
self.terminal.command(splitCommands[i]);
self.terminal.sendCommand();
}
}
self.executeMacro = function () {
const macro = this.macro();
const commands = macro.split('\n');
const executeCommand = [];
for (let i = 0; i < commands.length; i += 1) {
const command = commands[i];
if (!command.includes(';;')) {
executeCommand.push(command.toUpperCase());
executeCommands(command);
} else if (!command.startsWith(';;')) {
const idx = command.indexOf(';;');
const newCommand = command.slice(0, idx);
executeCommand.push(newCommand.toUpperCase());
executeCommands(newCommand);
}
}
executeCommands(executeCommand);
}
self.getClass = function () {
var columns = this.settings.settings.plugins.macro.column();
Expand All @@ -52,7 +50,7 @@ $(function () {
}
OCTOPRINT_VIEWMODELS.push({
construct: MacroViewModel,
dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel"],
dependencies: ["settingsViewModel", "loginStateViewModel", "connectionViewModel", "terminalViewModel"],
elements: ["#sidebar_plugin_macro"]
});
});

0 comments on commit ff907b4

Please sign in to comment.