Skip to content

Commit

Permalink
main: add more context menu actions
Browse files Browse the repository at this point in the history
Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine committed Feb 16, 2025
1 parent 8ec0649 commit d44ef9f
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ var api = {
estimate: {
url: "/server/analysis/estimate",
method: "server.analysis.estimate"
},
post_process: {
url: "/server/analysis/process",
method: "server.analysis.process"
},
metascan: {
url: "/server/files/metascan",
method: "server.files.metascan"
}
}

Expand Down Expand Up @@ -779,6 +787,19 @@ function get_metadata(file_name) {
});
}

function scan_metadata(file_name) {
json_rpc.call_method_with_kwargs(
api.metascan.method, {'filename': file_name})
.then((result) => {
// result is an "ok" acknowledgement that the
// print has started
console.log(result);
})
.catch((error) => {
update_error(api.metascan.method, error);
});
}

function estimate_file(file_name) {
json_rpc.call_method_with_kwargs(
api.estimate.method, {'filename': file_name})
Expand All @@ -792,6 +813,19 @@ function estimate_file(file_name) {
});
}

function estimator_post_process_file(file_name, force=false) {
json_rpc.call_method_with_kwargs(
api.post_process.method, {'filename': file_name, 'force': force})
.then((result) => {
// result is an "ok" acknowledgement that the
// print has started
console.log(result);
})
.catch((error) => {
update_error(api.post_process.method, error);
});
}

function make_directory(dir_path) {
json_rpc.call_method_with_kwargs(
api.directory.method.post, {'path': dir_path})
Expand Down Expand Up @@ -1471,6 +1505,19 @@ function jstree_get_metadata() {
}
}

function jstree_scan_metadata() {
let filename = get_selected_item();
if (filename && filename.startsWith("gcodes/")) {
filename = filename.slice(7);
if (api_type == 'http') {
let qs = `?filename=${encode_filename(filename)}`;
form_post_request(api.metascan.url, qs);
} else {
scan_metadata(filename);
}
}
}

function jstree_estimate() {
let filename = get_selected_item();
if (filename && filename.startsWith("gcodes/")) {
Expand All @@ -1484,6 +1531,32 @@ function jstree_estimate() {
}
}

function jstree_post_process() {
let filename = get_selected_item();
if (filename && filename.startsWith("gcodes/")) {
filename = filename.slice(7);
if (api_type == 'http') {
let qs = `?filename=${encode_filename(filename)}`;
form_post_request(api.post_process.url, qs);
} else {
estimator_post_process_file(filename);
}
}
}

function jstree_force_post_process() {
let filename = get_selected_item();
if (filename && filename.startsWith("gcodes/")) {
filename = filename.slice(7);
if (api_type == 'http') {
let qs = `?filename=${encode_filename(filename)}&force=true`;
form_post_request(api.post_process.url, qs);
} else {
estimator_post_process_file(filename, true);
}
}
}

//***********End JSTree Helper Functions***************************/

// A simple reconnecting websocket
Expand Down Expand Up @@ -2069,11 +2142,23 @@ window.onload = () => {
label: "Get Metadata",
action: jstree_get_metadata
}
actions.metascan = {
label: "Scan Metadata",
action: jstree_scan_metadata
}
actions.estimate = {
label: "Estimate",
separator_after: true,
action: jstree_estimate
}
actions.post_process = {
label: "Estimator Post Process",
action: jstree_post_process
}
actions.force_post_process = {
label: "Force Estimator Post Process",
separator_after: true,
action: jstree_force_post_process
}
}
// can delete, cut (move), copy, or rename(move)
actions.rename = {
Expand Down

0 comments on commit d44ef9f

Please sign in to comment.