17
17
<div class =" float-right align-items-flex-start align-items-center" >
18
18
<!-- <f7-toggle class="enable-toggle"></f7-toggle> -->
19
19
<f7-link :icon-color =" (rule.status.statusDetail === 'DISABLED') ? 'orange' : 'gray'" icon-ios =" f7:pause_circle" icon-md =" f7:pause_circle" icon-aurora =" f7:pause_circle" icon-size =" 32" color =" orange" @click =" toggleDisabled" ></f7-link >
20
- <f7-link icon-ios =" f7:play_round" icon-md =" f7:play_round" icon-aurora =" f7:play_round" icon-size =" 32" color =" blue" @click =" runNow" ></f7-link >
20
+ <f7-link :tooltip = " 'Run Now' + (($device.desktop) ? ' (Ctrl-R)' : '') " icon-ios =" f7:play_round" icon-md =" f7:play_round" icon-aurora =" f7:play_round" icon-size =" 32" color =" blue" @click =" runNow" ></f7-link >
21
21
</div >
22
22
Status:
23
23
<f7-chip class =" margin-left"
161
161
</f7-page >
162
162
</f7-popup >
163
163
164
- <script-editor-popup v-if =" currentModule" title =" Edit Script" popup-id =" edit-rule-script-direct-popup" :value =" scriptCode" :fullscreen =" false" :opened =" codeEditorOpened" @closed =" codePopupClosed" ></script-editor-popup >
164
+ <script-editor-popup v-if =" currentModule" title =" Edit Script" ref = " codePopup " popup-id =" edit-rule-script-direct-popup" :value =" scriptCode" :fullscreen =" false" :opened =" codeEditorOpened" @closed =" codePopupClosed" ></script-editor-popup >
165
165
<cron-editor popup-id =" edit-rule-cron-popup" :value =" cronExpression" :opened =" cronPopupOpened" @closed =" cronPopupOpened = false" @input =" (value) => updateCronExpression(value)" />
166
166
</f7-page >
167
167
</template >
@@ -310,9 +310,20 @@ export default {
310
310
return
311
311
}
312
312
}
313
- // TODO properly validate rule
314
- if (! this .rule .uid ) return
315
- if (! this .rule .name ) return
313
+ if (! this .rule .uid ) {
314
+ this .$f7 .dialog .alert (' Please give an ID to the rule' )
315
+ return
316
+ }
317
+ if (! this .rule .name ) {
318
+ this .$f7 .dialog .alert (' Please give a name to the rule' )
319
+ return
320
+ }
321
+ if (this .codeEditorOpened ) {
322
+ // save the code currently being edited if the dialog is open
323
+ // this allows to hit ctrl-S to save (and ctrl-R to run the rule) while editing the code
324
+ // without closing the window
325
+ this .currentModule .configuration .script = this .$refs .codePopup .code
326
+ }
316
327
const promise = (this .createMode )
317
328
? this .$oh .api .postPlain (' /rest/rules' , JSON .stringify (this .rule ), ' text/plain' , ' application/json' )
318
329
: this .$oh .api .put (' /rest/rules/' + this .rule .uid , this .rule )
@@ -360,13 +371,12 @@ export default {
360
371
runNow () {
361
372
if (this .createMode ) return
362
373
if (this .rule .status === ' RUNNING' ) return
363
- this .$oh .api .postPlain (' /rest/rules/' + this .rule .uid + ' /runnow' , ' ' ).then ((data ) => {
364
- this .$f7 .toast .create ({
365
- text: ' Running rule' ,
366
- destroyOnClose: true ,
367
- closeTimeout: 2000
368
- }).open ()
369
- }).catch ((err ) => {
374
+ this .$f7 .toast .create ({
375
+ text: ' Running rule' ,
376
+ destroyOnClose: true ,
377
+ closeTimeout: 2000
378
+ }).open ()
379
+ this .$oh .api .postPlain (' /rest/rules/' + this .rule .uid + ' /runnow' , ' ' ).catch ((err ) => {
370
380
this .$f7 .toast .create ({
371
381
text: ' Error while running rule: ' + err,
372
382
destroyOnClose: true ,
@@ -375,7 +385,7 @@ export default {
375
385
})
376
386
},
377
387
startEventSource () {
378
- this .eventSource = this .$oh .sse .connect (' /rest/events?topics=smarthome/rules/* /*' , null , (event ) => {
388
+ this .eventSource = this .$oh .sse .connect (' /rest/events?topics=smarthome/rules/' + this . ruleId + ' /*' , null , (event ) => {
379
389
console .log (event )
380
390
const topicParts = event .topic .split (' /' )
381
391
switch (topicParts[3 ]) {
@@ -390,10 +400,19 @@ export default {
390
400
this .eventSource = null
391
401
},
392
402
keyDown (ev ) {
393
- if (ev .keyCode === 83 && (ev .ctrlKey || ev .metaKey )) {
394
- this .save (! this .createMode )
395
- ev .stopPropagation ()
396
- ev .preventDefault ()
403
+ if (ev .ctrlKey || ev .metakKey ) {
404
+ switch (ev .keyCode ) {
405
+ case 82 :
406
+ this .runNow ()
407
+ ev .stopPropagation ()
408
+ ev .preventDefault ()
409
+ break
410
+ case 83 :
411
+ this .save (! this .createMode )
412
+ ev .stopPropagation ()
413
+ ev .preventDefault ()
414
+ break
415
+ }
397
416
}
398
417
},
399
418
toggleModuleControls () {
@@ -453,7 +472,9 @@ export default {
453
472
this .$refs .modulePopup .f7Popup .open ()
454
473
},
455
474
reorderModule (ev , section ) {
456
- this .rule [section].splice (ev .detail .to , 0 , this .rule [section].splice (ev .detail .from , 1 )[0 ])
475
+ const newSection = [... this .rule [section]]
476
+ newSection .splice (ev .to , 0 , newSection .splice (ev .from , 1 )[0 ])
477
+ this .$set (this .rule , section, newSection)
457
478
},
458
479
saveModule () {
459
480
if (! this .currentModule .type ) return
0 commit comments