@@ -14,7 +14,8 @@ module.exports = app => app.component('chat-message-script', {
1414 showCreateDashboardModal : false ,
1515 newDashboardTitle : '' ,
1616 dashboardCode : '' ,
17- createErrors : [ ]
17+ createErrors : [ ] ,
18+ dashboardEditor : null
1819 } ;
1920 } ,
2021 computed : {
@@ -39,8 +40,22 @@ module.exports = app => app.component('chat-message-script', {
3940 this . dashboardCode = this . script ;
4041 this . createErrors = [ ] ;
4142 this . showCreateDashboardModal = true ;
43+ this . $nextTick ( ( ) => {
44+ if ( this . dashboardEditor ) {
45+ this . dashboardEditor . toTextArea ( ) ;
46+ }
47+ this . $refs . dashboardCodeEditor . value = this . dashboardCode ;
48+ this . dashboardEditor = CodeMirror . fromTextArea ( this . $refs . dashboardCodeEditor , {
49+ mode : 'javascript' ,
50+ lineNumbers : true
51+ } ) ;
52+ this . dashboardEditor . on ( 'change' , ( ) => {
53+ this . dashboardCode = this . dashboardEditor . getValue ( ) ;
54+ } ) ;
55+ } ) ;
4256 } ,
4357 async createDashboardFromScript ( ) {
58+ this . dashboardCode = this . dashboardEditor . getValue ( ) ;
4459 const { dashboard } = await api . Dashboard . createDashboard ( {
4560 code : this . dashboardCode ,
4661 title : this . newDashboardTitle
@@ -70,6 +85,14 @@ module.exports = app => app.component('chat-message-script', {
7085 } ) ;
7186 }
7287 } ,
88+ watch : {
89+ showCreateDashboardModal ( val ) {
90+ if ( ! val && this . dashboardEditor ) {
91+ this . dashboardEditor . toTextArea ( ) ;
92+ this . dashboardEditor = null ;
93+ }
94+ }
95+ } ,
7396 mounted ( ) {
7497 Prism . highlightElement ( this . $refs . code ) ;
7598 if ( this . message . executionResult ?. output ) {
0 commit comments