Skip to content

Commit 07af240

Browse files
committed
Cleanup
1 parent 0bc0676 commit 07af240

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

octoprint_gcodethumbs/static/js/gcode-preview-viewmodel.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
$(function() {
22
function GCodePreviewViewModel(parameters) {
3-
console.log("initializing GCodePreviewViewModel");
3+
// console.log("initializing GCodePreviewViewModel");
44

5-
var self = this;
6-
var downloading = false;
7-
var errors = {};
5+
const self = this;
6+
let downloading = false;
7+
const errors = {};
8+
const previews = {}; // maps filenames to GCodePreview instances
89

910
self.filesViewModel = parameters[0];
10-
console.log(self.filesViewModel);
11-
const previews = {}; // maps filenames to GCodePreview instances
11+
// console.log(self.filesViewModel);
1212

1313
/*
1414
HACK! unfortunately there seems to be no way to enrich the files section in a clean way
@@ -27,9 +27,10 @@ $(function() {
2727
const elements = getElements()
2828
.filter( isVisible )
2929
.filter( elementNeedsPreview )
30-
.filter( hasNotErrored) ;
30+
.filter( hasNotErrored );
3131

32-
console.log('[monitor] ', elements.length, ' elements queued');
32+
// if (elements.length > 0)
33+
// console.log('[GCodePreview] ', elements.length, ' elements queued');
3334

3435
if (elements.length)
3536
enrichWithPreview(elements[0]);
@@ -56,7 +57,7 @@ $(function() {
5657
return !errors[filename];
5758
}
5859

59-
// TODO: include device and parent folder(s) to ensure uniqueness
60+
// TODO: include device and parent folder(s) to ensure uniqueness?
6061
function extractKey(element) {
6162
const internal = element.querySelector('.internal');
6263
if (internal)
@@ -65,8 +66,8 @@ $(function() {
6566
}
6667

6768
// renders a preview unattached to the dom
68-
// TODO: cache
69-
function renderPreview(element, gcode) {
69+
// TODO: cache?
70+
function renderPreview(element, gcode, filename) {
7071
// create canvas
7172
const canvas = document.createElement('canvas');
7273

@@ -75,33 +76,37 @@ $(function() {
7576
canvas : canvas,
7677
});
7778

79+
previews[filename] = preview;
80+
7881
// resize to container
7982
canvas.width = element.offsetWidth;
8083

8184
// render while still detached from the DOM
8285
preview.processGCode(gcode);
83-
86+
8487
return canvas;
8588
}
8689

8790
function enrichWithPreview(element) {
8891
const filename = extractKey(element);
8992
downloading = true;
9093

94+
console.log('[GCodePreview] downloading ' + filename);
95+
9196
// TODO: show spinner while downloading
9297
OctoPrint.files.download("local", filename)
9398
.done(function(response, rstatus) {
9499
downloading = false;
95100
if(rstatus === 'success') {
96101

97-
const canvas = renderPreview(element, response);
102+
const canvas = renderPreview(element, response, filename);
98103

99104
// attach to DOM
100-
insertAfter(canvas, element.querySelector('.title'))
105+
insertAfter(canvas, element.querySelector('.title'));
101106
}
102107
})
103108
.catch(function(e) {
104-
console.warn('error while getting file', e)
109+
console.warn('error while getting file', e);
105110
downloading = false;
106111
errors[filename] = e;
107112
});
@@ -115,4 +120,4 @@ $(function() {
115120
}
116121

117122
OCTOPRINT_VIEWMODELS.push([GCodePreviewViewModel, ["filesViewModel"], "#element"]);
118-
})
123+
});

0 commit comments

Comments
 (0)