@@ -73,20 +73,17 @@ FilamentManager.prototype.core.bridge = function pluginBridge() {
73
73
self . core . bridge = {
74
74
allViewModels : { } ,
75
75
76
- REQUIRED_VIEWMODELS : [ 'settingsViewModel' , 'printerStateViewModel' , 'loginStateViewModel' , 'temperatureViewModel' ] ,
76
+ REQUIRED_VIEWMODELS : [ 'settingsViewModel' , 'printerStateViewModel' , 'loginStateViewModel' , 'temperatureViewModel' , 'filesViewModel' ] ,
77
77
78
78
BINDINGS : [ '#settings_plugin_filamentmanager' , '#settings_plugin_filamentmanager_profiledialog' , '#settings_plugin_filamentmanager_spooldialog' , '#settings_plugin_filamentmanager_configurationdialog' , '#sidebar_plugin_filamentmanager_wrapper' , '#plugin_filamentmanager_confirmationdialog' ] ,
79
79
80
80
viewModel : function FilamentManagerViewModel ( viewModels ) {
81
81
self . core . bridge . allViewModels = _ . object ( self . core . bridge . REQUIRED_VIEWMODELS , viewModels ) ;
82
82
self . core . callbacks . call ( self ) ;
83
83
84
- self . viewModels . profiles . call ( self ) ;
85
- self . viewModels . spools . call ( self ) ;
86
- self . viewModels . selections . call ( self ) ;
87
- self . viewModels . config . call ( self ) ;
88
- self . viewModels . import . call ( self ) ;
89
- self . viewModels . confirmation . call ( self ) ;
84
+ Object . values ( self . viewModels ) . forEach ( function ( viewModel ) {
85
+ return viewModel . call ( self ) ;
86
+ } ) ;
90
87
91
88
self . viewModels . profiles . updateCallbacks . push ( self . viewModels . spools . requestSpools ) ;
92
89
self . viewModels . profiles . updateCallbacks . push ( self . viewModels . selections . requestSelectedSpools ) ;
@@ -95,7 +92,6 @@ FilamentManager.prototype.core.bridge = function pluginBridge() {
95
92
self . viewModels . import . afterImportCallbacks . push ( self . viewModels . spools . requestSpools ) ;
96
93
self . viewModels . import . afterImportCallbacks . push ( self . viewModels . selections . requestSelectedSpools ) ;
97
94
98
- self . viewModels . warning . call ( self ) ;
99
95
self . selectedSpools = self . viewModels . selections . selectedSpools ; // for backwards compatibility
100
96
return self ;
101
97
}
@@ -110,8 +106,6 @@ FilamentManager.prototype.core.callbacks = function octoprintCallbacks() {
110
106
111
107
self . onStartup = function onStartupCallback ( ) {
112
108
self . viewModels . warning . replaceFilamentView ( ) ;
113
- self . viewModels . confirmation . replacePrintStart ( ) ;
114
- self . viewModels . confirmation . replacePrintResume ( ) ;
115
109
} ;
116
110
117
111
self . onBeforeBinding = function onBeforeBindingCallback ( ) {
@@ -220,11 +214,20 @@ FilamentManager.prototype.core.client = function apiClient() {
220
214
return OctoPrint . patchJson ( selectionUrl ( id ) , data , opts ) ;
221
215
}
222
216
} ;
217
+
218
+ self . database = {
219
+ test : function test ( config , opts ) {
220
+ var url = pluginUrl + '/database/test' ;
221
+ var data = { config : config } ;
222
+ return OctoPrint . postJson ( url , data , opts ) ;
223
+ }
224
+ } ;
223
225
} ;
224
226
/* global FilamentManager ko $ */
225
227
226
228
FilamentManager . prototype . viewModels . config = function configurationViewModel ( ) {
227
229
var self = this . viewModels . config ;
230
+ var api = this . core . client ;
228
231
var settingsViewModel = this . core . bridge . allViewModels . settingsViewModel ;
229
232
230
233
@@ -267,14 +270,33 @@ FilamentManager.prototype.viewModels.config = function configurationViewModel()
267
270
var pluginSettings = settingsViewModel . settings . plugins . filamentmanager ;
268
271
ko . mapping . fromJS ( ko . toJS ( pluginSettings ) , self . config ) ;
269
272
} ;
273
+
274
+ self . connectionTest = function runExternalDatabaseConnectionTest ( viewModel , event ) {
275
+ var target = $ ( event . target ) ;
276
+ target . removeClass ( 'btn-success btn-danger' ) ;
277
+ target . prepend ( '<i class="fa fa-spinner fa-spin"></i> ' ) ;
278
+ target . prop ( 'disabled' , true ) ;
279
+
280
+ var data = ko . mapping . toJS ( self . config . database ) ;
281
+
282
+ api . database . test ( data ) . done ( function ( ) {
283
+ target . addClass ( 'btn-success' ) ;
284
+ } ) . fail ( function ( ) {
285
+ target . addClass ( 'btn-danger' ) ;
286
+ } ) . always ( function ( ) {
287
+ $ ( 'i.fa-spinner' , target ) . remove ( ) ;
288
+ target . prop ( 'disabled' , false ) ;
289
+ } ) ;
290
+ } ;
270
291
} ;
271
- /* global FilamentManager gettext $ ko Utils */
292
+ /* global FilamentManager gettext $ ko Utils OctoPrint */
272
293
273
294
FilamentManager . prototype . viewModels . confirmation = function spoolSelectionConfirmationViewModel ( ) {
274
295
var self = this . viewModels . confirmation ;
275
296
var _core$bridge$allViewM = this . core . bridge . allViewModels ,
276
297
printerStateViewModel = _core$bridge$allViewM . printerStateViewModel ,
277
- settingsViewModel = _core$bridge$allViewM . settingsViewModel ;
298
+ settingsViewModel = _core$bridge$allViewM . settingsViewModel ,
299
+ filesViewModel = _core$bridge$allViewM . filesViewModel ;
278
300
var selections = this . viewModels . selections ;
279
301
280
302
@@ -304,46 +326,53 @@ FilamentManager.prototype.viewModels.confirmation = function spoolSelectionConfi
304
326
dialog . modal ( 'show' ) ;
305
327
} ;
306
328
307
- printerStateViewModel . fmPrint = function confirmSpoolSelectionBeforeStartPrint ( ) {
329
+ var startPrint = printerStateViewModel . print ;
330
+
331
+ printerStateViewModel . print = function confirmSpoolSelectionBeforeStartPrint ( ) {
308
332
if ( settingsViewModel . settings . plugins . filamentmanager . confirmSpoolSelection ( ) ) {
309
333
showDialog ( ) ;
310
334
button . html ( gettext ( 'Start Print' ) ) ;
311
- self . print = function startPrint ( ) {
335
+ self . print = function continueToStartPrint ( ) {
312
336
dialog . modal ( 'hide' ) ;
313
- printerStateViewModel . print ( ) ;
337
+ startPrint ( ) ;
314
338
} ;
315
339
} else {
316
- printerStateViewModel . print ( ) ;
340
+ startPrint ( ) ;
317
341
}
318
342
} ;
319
343
320
- printerStateViewModel . fmResume = function confirmSpoolSelectionBeforeResumePrint ( ) {
344
+ var resumePrint = printerStateViewModel . resume ;
345
+
346
+ printerStateViewModel . resume = function confirmSpoolSelectionBeforeResumePrint ( ) {
321
347
if ( settingsViewModel . settings . plugins . filamentmanager . confirmSpoolSelection ( ) ) {
322
348
showDialog ( ) ;
323
349
button . html ( gettext ( 'Resume Print' ) ) ;
324
- self . print = function resumePrint ( ) {
350
+ self . print = function continueToResumePrint ( ) {
325
351
dialog . modal ( 'hide' ) ;
326
- printerStateViewModel . onlyResume ( ) ;
352
+ resumePrint ( ) ;
327
353
} ;
328
354
} else {
329
- printerStateViewModel . onlyResume ( ) ;
355
+ resumePrint ( ) ;
330
356
}
331
357
} ;
332
358
333
- self . replacePrintStart = function replacePrintStartButtonBehavior ( ) {
334
- // Modifying print button action to invoke 'fmPrint'
335
- var element = $ ( '#job_print' ) ;
336
- var dataBind = element . attr ( 'data-bind' ) ;
337
- dataBind = dataBind . replace ( / c l i c k : ( .* ?) (? = , | $ ) / , 'click: fmPrint' ) ;
338
- element . attr ( 'data-bind' , dataBind ) ;
339
- } ;
359
+ filesViewModel . loadFile = function confirmSpoolSelectionOnLoadAndPrint ( data , printAfterLoad ) {
360
+ if ( ! data ) {
361
+ return ;
362
+ }
363
+
364
+ if ( printAfterLoad && filesViewModel . listHelper . isSelected ( data ) && filesViewModel . enablePrint ( data ) ) {
365
+ // file was already selected, just start the print job
366
+ printerStateViewModel . print ( ) ;
367
+ } else {
368
+ // select file, start print job (if requested and within dimensions)
369
+ var withinPrintDimensions = filesViewModel . evaluatePrintDimensions ( data , true ) ;
370
+ var print = printAfterLoad && withinPrintDimensions ;
340
371
341
- self . replacePrintResume = function replacePrintResumeButtonBehavior ( ) {
342
- // Modifying resume button action to invoke 'fmResume'
343
- var element = $ ( '#job_pause' ) ;
344
- var dataBind = element . attr ( 'data-bind' ) ;
345
- dataBind = dataBind . replace ( / c l i c k : ( .* ?) (? = , | $ ) / , 'click: function() { isPaused() ? fmResume() : onlyPause(); }' ) ;
346
- element . attr ( 'data-bind' , dataBind ) ;
372
+ OctoPrint . files . select ( data . origin , data . path , false ) . done ( function ( ) {
373
+ if ( print ) printerStateViewModel . print ( ) ;
374
+ } ) ;
375
+ }
347
376
} ;
348
377
} ;
349
378
/* global FilamentManager ko $ PNotify gettext */
0 commit comments