@@ -11,18 +11,18 @@ let msgbox = document.getElementById('outputMsg')
11
11
let ssabox = document . getElementById ( 'ssa' )
12
12
ssabox . addEventListener ( 'load' , ( ) => {
13
13
// inject ssa style
14
- let head = $ ( "iframe" ) . contents ( ) . find ( "head" ) ;
15
- head . append ( $ ( "<link/>" , { rel : 'stylesheet' , href : '/gossa/scrollbar.css' , type : 'text/css' } ) ) ;
14
+ $ ( "iframe" ) . contents ( ) . find ( "head" ) . append ( $ ( "<link/>" , { rel : 'stylesheet' , href : '/gossa/scrollbar.css' , type : 'text/css' } ) ) ;
16
15
setMessageBox ( '' , true )
17
16
} ) ;
18
17
19
- let lastFuncName , lastCode ;
18
+ let lastFuncName , lastCode , lastGcflags ;
20
19
function build ( ) {
21
20
let funcname = document . getElementById ( 'funcname' ) . value ;
22
21
let code = document . getElementById ( 'code' ) . value ;
22
+ let gcflags = document . getElementById ( 'gcflags' ) . value ;
23
23
24
24
// several early checks
25
- if ( funcname === lastFuncName && code == lastCode ) {
25
+ if ( funcname === lastFuncName && code === lastCode && gcflags === lastGcflags ) {
26
26
console . log ( 'no changes, do not submit' )
27
27
return
28
28
}
@@ -33,6 +33,7 @@ function build() {
33
33
34
34
lastFuncName = funcname
35
35
lastCode = code
36
+ lastGcflags = gcflags
36
37
setMessageBox ( 'Waiting for response...' , false )
37
38
38
39
fetch ( '/api/v1/buildssa' , {
@@ -41,6 +42,7 @@ function build() {
41
42
body : JSON . stringify ( {
42
43
'funcname' : funcname ,
43
44
'code' : code ,
45
+ 'gcflags' : gcflags ,
44
46
} ) ,
45
47
} )
46
48
. then ( ( response ) => {
@@ -53,8 +55,12 @@ function build() {
53
55
} )
54
56
. then ( res => {
55
57
ssabox . src = `/gossa/buildbox/${ res . data . build_id } /ssa.html`
58
+
59
+ // update url
60
+ const param = 'id=' + res . data . build_id
61
+ history . pushState ( null , null , document . location . href . split ( '?' ) [ 0 ] + '?' + param )
56
62
} )
57
- . catch ( res => setMessageBox ( res . data . msg , true ) ) ;
63
+ . catch ( res => setMessageBox ( res . data . msg , false ) ) ;
58
64
}
59
65
60
66
function setMessageBox ( msg , hide ) {
@@ -95,8 +101,8 @@ $('#code').linedtextarea();
95
101
$ ( '#code' ) . keydown ( function ( event ) {
96
102
if ( event . keyCode == 9 ) {
97
103
event . preventDefault ( ) ;
98
- var start = this . selectionStart ;
99
- var end = this . selectionEnd ;
104
+ let start = this . selectionStart ;
105
+ let end = this . selectionEnd ;
100
106
// set textarea value to: text before caret + tab + text after caret
101
107
$ ( this ) . val ( $ ( this ) . val ( ) . substring ( 0 , start )
102
108
+ "\t"
@@ -107,6 +113,35 @@ $('#code').keydown(function(event){
107
113
}
108
114
} ) ;
109
115
116
+ function loadCode ( ) {
117
+ const params = new URLSearchParams ( window . location . search ) ;
118
+ const id = params . get ( 'id' ) ;
119
+ if ( id === null || id === undefined || id === '' ) { return ; }
120
+ ssabox . src = `/gossa/buildbox/${ id } /ssa.html`
121
+ // load code
122
+ fetch ( `/gossa/buildbox/${ id } /main.go` )
123
+ . then ( ( response ) => {
124
+ return new Promise ( ( resolve , reject ) => {
125
+ let func ; response . status < 400 ? func = resolve : func = reject ;
126
+ response . text ( ) . then ( data => func ( { 'status' : response . status , 'data' : data } ) ) ;
127
+ } ) ;
128
+ } )
129
+ . then ( res => {
130
+ console . log ( res )
131
+ document . getElementById ( 'code' ) . textContent = res . data
132
+ } )
133
+ . catch ( res => {
134
+ fetch ( `/gossa/buildbox/${ id } /main_test.go` )
135
+ . then ( res => res . text ( ) )
136
+ . then ( res => {
137
+ console . log ( res )
138
+ document . getElementById ( 'code' ) . textContent = res
139
+ } )
140
+ // if still fail? don't handle anything
141
+ } ) ;
142
+ }
143
+ loadCode ( ) // load content if access with id
144
+
110
145
// TODO: dragable scroll
111
146
// let wholePage = document.querySelector('body');
112
147
// let el = document.querySelector("#ssa").contentDocument.querySelector('body');
0 commit comments