-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathjs.tmpl
1226 lines (955 loc) · 38.4 KB
/
js.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- jQuery first, then Bootstrap JS. -->
<!-- Modal -->
<div class="modal fade" id="accountJoin" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="exampleModalLabel"></h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Welcome to the Strukture! To get started enter a username that will be used for chat.</p>
<hr>
<p><input type="text" class="form-control username-input" name="" placeholder="username"></p>
</div>
<div class="modal-footer">
<button type="button" onclick="saveProfile()" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
<script src="/dist/jquery.js"></script>
<script src="/dist/bootstrap.js" ></script>
<script type="text/javascript" src="/dist/havok.js"></script>
<script src="/dist/jstree.min.js"></script>
<script src="/dist/jquery.toolbar.js"></script>
<script src="/ajax-loading.js"></script>
<script type="text/javascript">
var __loading = $.loading()
</script>
<script type="text/javascript" src="dist/jquery.terminal-0.10.8.min.js"></script>
<script type="text/javascript" src="dist/unix_formatting.js"></script>
<script src="/dist/src/ace.js"></script>
<script src="/dist/src/ext-language_tools.js"></script>
<script src="dist/sweetalert.min.js"></script>
<script type="text/javascript" src="/dist/hotkeys.js"></script>
<script type="text/javascript" src="/dist/jquery.ui.position.js"></script>
<script type="text/javascript" src="/dist/jquery.contextMenu.js"></script>
<script type="text/javascript">
var working = false;
var editors = {};
var kanbanBoards = {};
var editorPaths = {};
var termsize = 0;
var dirHandle;
async function uploadDirectory(project){
dirHandle = await window.showDirectoryPicker();
iterateOver(dirHandle, project)
}
const headers = {
"accept": "*/*",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
}
async function iterateOver(dirHandle, project, path = "/"){
var it = dirHandle.entries()
var next = await it.next()
while(!next.done){
const [name, handler] = next.value
if (handler.kind === 'directory') {
// run directory code
let newPath = path == "/" ? path + name : path + "/" + name
//mkdir
await fetch("http://localhost:8884/api/act", {
headers,
"referrer": "http://localhost:8884/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `type=60&pkg=${project}&prefix=${path}&path=${name}&basesix=&fmode=dir`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
await iterateOver(handler, project, newPath)
} else {
// write file
await fetch("http://localhost:8884/api/act", {
headers,
"referrer": "http://localhost:8884/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `type=60&pkg=${project}&prefix=${path}&path=${name}&basesix=&fmode=touch`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
fileData = await handler.getFile();
let text = await fileData.text()
await fetch("http://localhost:8884/api/put", {
headers,
"referrer": "http://localhost:8884/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `type=30&target=${path}/${name}&pkg=${project}&data=${encodeURIComponent(text)}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
}
next = await it.next()
}
$(".modal .close").click()
updateTree()
}
window.debugFn = (cmd) => {
socketTerminal.send(cmd + " \n");
}
try {
if(!window.localStorage["chatName"]){
$("#accountJoin").modal('show');
}
if(!window.localStorage["struktureid"]){
window.localStorage.struktureid = `${makeid()}-${makeid()}-${(new Date()).getTime()}`;
}
} catch(e) {
}
/*
Plugin format :
name : "Name"
show: function(code)
exec : function(code,editor)
*/
$trukture = {
addPlugin:function(plugin){
$trukture.plugins.push(plugin)
},
exec: function(cmd,callback){
//console call here
$.ajax({url:"/api/console",type:"POST",data:{command:cmd},success:function(html){
if (html.includes("Error::")){
callback(false, html)
} else {
callback(html)
}
},error:function(e){
callback(false, e.responseText);
}})
},
FindPlugin : function(name){
for (var i = $trukture.plugins.length - 1; i >= 0; i--) {
var plugin = $trukture.plugins[i];
if ( plugin.name == name ) {
return plugin;
}
}
},
plugins:[]
}
function addBubble(message){
//chatroom-thread
let styles = "margin-bottom:5px;max-width:240px;";
if(message.name == window.localStorage["chatName"]){
styles += "margin-left:auto;";
}
$(".chat-thread").append(`<div class='list-group-item' style='${styles}'><h6>${message.name}<h6>
<hr>
<div>${message.message}</div><br>${ (new Date()).toLocaleString() }</div>` );
var d = $('.chat-thread');
d.scrollTop(d.prop("scrollHeight"));
}
function toggleChat(){
if($(".chat-window").css("display") == "none" ){
$(".chat-window").css("display", "block");
return;
}
$(".chat-window").css("display", "none");
}
function saveProfile(){
let name = $(".username-input").val();
window.localStorage["chatName"] = name;
$("#accountJoin").modal('hide');
sendMessage({message : window.localStorage["chatName"] + " has joined the chatroom." })
}
function sendMessage(obj){
let payload = Object.assign(obj, { name : window.localStorage["chatName"] });
socket.send(JSON.stringify(payload));
}
function sendChat(){
//chat-input
if($(".chat-input").val() == "" )
return;
sendMessage({message : $(".chat-input").val() });
$(".chat-input").val("");
}
$(".chat-input").keyup(function(e) {
var code = e.keyCode ? e.keyCode : e.which;
if (code == 13) { // Enter keycode
sendChat();
}
});
function connectSocket(){
window.socket = new WebSocket("ws://" + window.location.host + "/api/socket");
socket.onclose = function(event) {
console.log("WebSocket is closed now.");
swal("Connection closed!", "Realtime functionality will not currently work, to restore it, please refresh the page.", "warning");
};
// Connection opened
socket.addEventListener('open', function (event) {
if(window.localStorage["chatName"])
sendMessage({message : window.localStorage["chatName"] + " has joined the chatroom." })
});
// Listen for messages
socket.addEventListener('message', function (event) {
processMessage(JSON.parse(event.data) );
});
}
function processMessage(data){
//editor change
if(data.editor && data.name != window.localStorage["chatName"]){
if(editorPaths[data.path]){
if( editorPaths[data.path].getValue() != data.editor){
let currentCursor = editorPaths[data.path].getCursorPosition();
editorPaths[data.path].setValue(data.editor);
editorPaths[data.path].moveCursorToPosition(currentCursor);
}
}
}
//chat message
if(data.message){
addBubble(data);
}
//kanban change
if(data.board && data.name){
if(!kanbanBoards[data.board])
return;
console.log("Updating board");
kanbanBoards[data.board]();
data.message = data.name + " has updated " + data.board;
addBubble(data);
}
}
connectSocket();
function handleClickStruk(plugin,txt,editorid,pkg){
//console.log(plugin,txt,editorid)
$trukture.exec("cd " + pkg,function(dud){})
var plugin = $trukture.FindPlugin(plugin)
var edt = editors[editorid];
var execution = plugin.exec(txt,edt)
if (typeof(execution) == "string") {
edt.insert( execution)
}
}
function getItems(code){
var codeedit = {
"sep1": "---------"
}
for (var i = $trukture.plugins.length - 1; i >= 0; i--) {
var plugin = $trukture.plugins[i];
if ( plugin.show(code) ) {
codeedit[plugin.name] = {name: plugin.name}
}
}
return codeedit
}
//add plugin go get github dep
function addtermwidth(){
if (termsize != 2){
//below limit
if(termsize == 0){
termsize = 1;
$(".terminal-side").css("width","50" + percentagetext)
}
else if(termsize == 1){
termsize = 2;
$(".terminal-side").css("width","95" + percentagetext)
}
}
}
function removePlugin(path){
//
$.ajax({url:"/api/delete", type:"POST", data:{type: "101",pkg:path} ,success:function(html){
$("[data-plugin='" + path +"']").remove()
},error:function(e){
$(".plugin-list").html(e.responseText)
} })
}
function GetPlugins(){
//plugin-list
$.ajax({url:"/api/new", type:"POST", data:{type: "101"} ,error:function(e){
$(".plugin-list").html(e.responseText)
} })
}
function CollapseGloj(){
if($(".panel-k-left").css('display') == "none"){
$(".right-bay").removeClass("side-bay")
$(".left-bay").addClass("side-bay")
$(".panel-k-left").css('display',"block");
$(".panel-k-right").addClass("col-sm-9");
$(".panel-k-right").removeClass("col-sm-12");
$(".cps-side").html('<i class="fa fa-compress"></i> Hide')
// $(".recop").css("display","none");
} else {
$(".left-bay").removeClass("side-bay")
$(".right-bay").addClass("side-bay")
$(".panel-k-left").css('display',"none");
$(".panel-k-right").removeClass("col-sm-9");
$(".panel-k-right").addClass("col-sm-12");
// $(".recop").css("display","block");
$(".cps-side").html('<i class="fa fa-arrow-right"></i> Show')
}
}
function redtermwidth(){
if (termsize != 0){
//below limit
if(termsize == 1){
termsize = 0;
$(".terminal-side").css("width","320px")
}
else if(termsize == 2){
termsize = 1;
$(".terminal-side").css("width","50" + percentagetext)
}
}
}
var langTools = ace.require("ace/ext/language_tools");
var autoCompleter = {
identifierRegexps: [/[a-zA-Z_0-9]\.\s/],
getCompletions: function(editor, session, pos, prefix, callback) {
let pkg = $(".tabview.active").attr("pkg"),
id = $(".tabview.active").attr("id");
//console.log(session, pos, prefix)
if(editor.custom){
let latest = editor.getValue();
let index = editor.session.doc.positionToIndex(editor.selection.getCursor()) ;
let lastEntry;
$.ajax(
{
url : "/api/complete",
type : "POST",
data : {
content : latest,
pref : index,
pkg,
gocode : "true",
id
},
success : function(html){
let completions = html ? html[1] : false;
if(completions && completions.length > 0){
callback(null, completions.map(function(ea) {
if(prefix[prefix.length - 1] === ".")
ea.package = prefix;
let ret = {caption: ea.name, value:prefix[prefix.length - 1] === "." ? ea.package + ea.name : ea.name, score: 0, meta: ea.type + " " + ea.class, trigger : true}
return ret
}));
} else {
callback(null, [])
}
}
}
)
}
}
}
langTools.addCompleter(autoCompleter);
function vetAndLint(id,pkg, path){
resetVetter(id)
let file = path
let errors = []
$.ajax({type : "POST", data : {
pkg
} ,url: "/api/govet", success:function(html){
let cText = html.Text.split("\n")
for(var i = 1; i < cText.length;i++){
let line = cText[i]
if ( line.includes(file) ){
let lineParts = line.split(":")
if( lineParts[2] ){
let lastBit = lineParts[ lineParts.length - 1]
errors.push({
row: parseInt(lineParts[1]) - 1,
column: 0,
text: lastBit,
type: "warning" //This would give a red x on the gutter
})
}
}
}
editors[id].getSession().setAnnotations(errors)
} });
$.ajax({type : "POST", data : {
pkg,
path
},url: "/api/golint", success:function(html){
let cText = html.Text.split("\n")
for(var i = 0; i < cText.length;i++){
let line = cText[i]
if ( line.includes(file) ){
let lineParts = line.split(":")
if( lineParts[1] ){
let lastBit = lineParts[ lineParts.length - 1]
errors.push({
row: parseInt(lineParts[1]) - 1,
column: 0,
text: lastBit,
type: "warning" //This would give a red x on the gutter
})
}
}
}
editors[id].getSession().setAnnotations(errors)
} });
}
function resetVetter(id){
editors[id].getSession().clearAnnotations()
}
function ClearSideBay(){
$(".side-bay").html("");
}
$('.side-bay').bind("DOMSubtreeModified",function(){
if ($(".side-bay").height() == 0){
$(".dimisser-btn").css('display','none')
} else $(".dimisser-btn").css('display','block');
if($(".pop-box").css("display") != "none" ){
$(".pop-box").scrollTop(1)
}
return false;
});
function toggleTerm(){
if($(".terminal-side").hasClass('active')){
$(".terminal-side").removeClass('active');
$(".terminal-side").css('display','none');
} else {
$(".terminal-side").addClass('active');
$(".terminal-side").css('display','block');
}
}
$(document).bind("ajaxSend", function(){
if($(".terminal-side").hasClass('active') && termx != null){
termx("[[b;#00FF00;]Request sent > ]",{flush:false})
}
});
$(document).bind('keydown', 'ctrl+s', function(){});
$(document).bind('keydown', 'ctrl+i', toggleTerm);
$(document).bind('keydown', 'ctrl+m', CollapseGloj);
$(document).bind('keydown', 'ctrl+n', function(){
$(".footer-bay .modal").modal("hide")
$(".new-package").click();
});
var working = false;
var termx = null;
let winDir;
let comRan = 0
let prevBuff = "";
window.socketTerminal = new WebSocket("ws://" + window.location.host + "/api/terminal_realtime");
function reset(){
if(socketTerminal.readyState === 2 || socketTerminal.readyState === 3){
window.socketTerminal = new WebSocket("ws://" + window.location.host + "/api/terminal_realtime");
working = false;
prevBuff = "";
comRan = 0
winDir = null
$('#terminaldefault').terminal().set_prompt('user@Strutkure $')
socketTerminal.addEventListener('message', handleMsg);
}
}
// Listen for messages
socketTerminal.addEventListener('error', function (event) {
reset()
})
function handleMsg(event) {
let term = $('#terminaldefault').terminal();
if(winDir == "await"){
if(prevBuff == event.data) return
let path = event.data.split("\n")
winDir = path[path.length - 1]
}
if(!comRan && event.data.includes("globals.Windows user.")){
winDir = "await"
let path = event.data.split("\n")
if(path.length > 2){
winDir = path[path.length - 1]
}
}
if (winDir && event.data.includes(winDir.replace(">", ""))){
working = false;
prevBuff = "";
$(".next-dlv").css("display", "none")
term.set_prompt(winDir)
return
}
comRan++
if(event.data.includes("bash") && event.data.includes("$") && event.data.length < 50){
working = false;
prevBuff = "";
$(".next-dlv").css("display", "none")
term.set_prompt('user@Strutkure $')
return;
}
if(event.data != prevBuff){
term.echo(event.data);
prevBuff = event.data;
}
if(working)
term.set_prompt('>')
if(event.data.includes("(dlv)") || (event.data.includes("Type 'help' for list of commands.") && window.$awaitDelve ) ){
window.$startMap = true;
term.set_prompt('>')
}
if(window.$awaitDelve && window.$startMap){
var br = window.$breakpoints[ window.$arrayIndex ];
term.echo(event.data);
if(!br){
$(".next-dlv").css("display", "block")
delete window.$awaitDelve
window.socketTerminal.send("continue \n");
}
else {
window.socketTerminal.send(br + "\n");
window.$arrayIndex++;
}
return
}
}
socketTerminal.addEventListener('message', handleMsg);
$(".next-dlv").click(() => {
socketTerminal.send("continue \n")
})
$(".next-dlv").css("display", "none")
jQuery(function($, undefined) {
$('#terminaldefault').terminal(function(command, term) {
termx = term.echo;
if(winDir && command == "killnow") return reset()
if (command !== '') {
working = true;
let cmC = command.trim()
if(winDir){
if(cmC[0] == "c" && cmC[1] == "d"){
winDir = "await"
prevBuff = command
}
}
setTimeout(()=> {
prevBuff = ""
window.socketTerminal.send(command + "\n");
}, 400)
}
if(winDir){
term.set_prompt(( working ? "": winDir ) )
return
}
term.set_prompt(( working ? "":'user@Strutkure $' ) )
}, {
greetings: 'Welcome to the Strukture v1.1\nA few notes :\nMake use of the kill command to stop a process.\n2.Command killnow will stop the current process.',
name: 'struk_term',
height: ($(".terminal-side").height() - 55),
prompt: (working ? "":'user@Strutkure $'),
completion : function (string, callback){
console.log(string);
return ["test", "foo","tt"];
}
});
});
function SaveFile(editor, link,pkv){
var payload = {type:"1",target:link,pkg:pkv};
if ( link.includes("gosforceasapi/") ) {
link_final = link.split("++()/")
payload.target = link_final[0].replace("gosforceasapi/", "")
payload.type = "13r";
}
payload["data"] = editors[editor].getValue();
$.ajax({url:"/api/put", data: payload ,type:"POST",success:function(html){
$(".side-bay").html(html);
},error:function(e){
$(".side-bay").html(e.responseText);
}
});
}
function resetTerminal(){
let term = $('#terminaldefault').terminal();
term.exec([`killnow`]);
}
function SavePKG(typ, pkv,editor){
var payload = {type:typ,pkg:pkv};
payload["data"] = editors[editor].getValue();
$.ajax({url:"/api/put", data: payload ,type:"POST",success:function(html){
$(".side-bay").html(html);
},error:function(e){
$(".side-bay").html(e.responseText);
}
});
}
function BuildPKG( pkv){
$(".side-bay").html("<h1 style='text-align:center;'><i class='fa fa-cog fa-spin'/></h1>")
$(".side-bay").load("/api/build?pkg=" + pkv);
}
function ClearLogs( pkv){
$(".side-bay").html("<h1 style='text-align:center;'><i class='fa fa-cog fa-spin'/></h1>")
$(".side-bay").load("/api/empty?pkg=" + pkv);
}
function StartServer( pkv){
$(".side-bay").html("<h1 style='text-align:center;'><i class='fa fa-cog fa-spin'/></h1>")
$(".side-bay").load("/api/start?pkg=" + pkv);
}
function StopServer( pkv){
$(".side-bay").html("<h1 style='text-align:center;'><i class='fa fa-cog fa-spin'/></h1>")
$(".side-bay").load("/api/stop?pkg=" + pkv);
}
function SavePKGAndBuild(typ, pkv,editor){
var payload = {type:typ,pkg:pkv};
payload["data"] = editors[editor].getValue();
$.ajax({url:"/api/put", data: payload ,type:"POST",success:function(html){
$(".side-bay").load("/api/build?pkg=" + pkv);
},error:function(e){
$(".side-bay").load("/api/build?pkg=" + pkv);
}
});
}
function removeWelcome(){
$.ajax({url:"/api/saw"})
$(".welcome-card").remove();
}
function SearchEditor(editor){
editors[editor].find("name=\"" + $(".sti[editor='" + editor + "']").val() + "\"",{
backwards: true,
wrap: false,
caseSensitive: false,
wholeWord: false,
regExp: false
});
editors[editor].findNext();
}
function AddtoEd(typ, editor){
if (typ == "struct"){
editors[editor].gotoLine(editors[editor].session.getLength() );
editors[editor].insert("<struct name=\"" + $(".sti[editor='" + editor + "']").val() + "\" >\n//Add some attrs\n\n</struct>\n\n");
$(".sti[editor='" + editor + "']").val("");
} else if (typ == "object") {
editors[editor].gotoLine(editors[editor].session.getLength() );
editors[editor].insert("<object name=\"" + $(".sti[editor='" + editor + "']").val() + "\" struct=\"\" >\n\n</object>\n\n");
$(".sti[editor='" + editor + "']").val("");
} else {
editors[editor].gotoLine(editors[editor].session.getLength() );
editors[editor].insert("<method name=\"" + $(".sti[editor='" + editor + "']").val() + "\" var=\"\" return=\"\" >\n\n</method>\n\n");
$(".sti[editor='" + editor + "']").val("");
}
}
function buildFunction(package, name){
swal("Hijacking terminal", "Building function. Please be patient, this will take some time.", "warning");
if(!$(".terminal-side").hasClass('active')){
$(".terminal-side").addClass('active');
$(".terminal-side").css('display','block');
}
let term = $('#terminaldefault').terminal();
term.exec([`cd $GOPATH/src/${package}`]);
setTimeout(function(){
term.exec([`cd ${name} && dep init -gopath && rm ./Gopkg.* && cd ../ && faas-cli build -f ${name}.yml && rm -rf ./${name}/vendor`]);
}, 1100);
}
function deployFunction(package, name){
swal("Hijacking terminal", "Deploying function. Please be patient, this will take some time.", "warning");
if(!$(".terminal-side").hasClass('active')){
$(".terminal-side").addClass('active');
$(".terminal-side").css('display','block');
}
let term = $('#terminaldefault').terminal();
term.exec([`cd $GOPATH/src/${package}`]);
setTimeout(function(){
term.exec([`faas-cli deploy -f ${name}.yml`]);
}, 1100);
}
function SaveFileWeb(editor, link,pkv){
var payload = {type:"3",target:link,pkg:pkv};
payload["data"] = editors[editor].getValue();
$.ajax({url:"/api/put", data: payload ,type:"POST",success:function(html){
$(".side-bay").html(html);
},error:function(e){
$(".side-bay").html(e.responseText);
}
});
}
function SaveFileSrc(editor, link,pkv, custom_data = null){
var payload = {type:"30",target:link,pkg:pkv};
payload["data"] = custom_data ? custom_data : editors[editor].getValue();
$.ajax({url:"/api/put", data: payload ,type:"POST",success:function(html){
if(!custom_data)
$(".side-bay").html(html);
vetAndLint(editor, pkv, link)
},error:function(e){
if(!custom_data)
$(".side-bay").html(e.responseText);
vetAndLint(editor, pkv, link)
}
});
}
$(function () {
$('#jstree').on('changed.jstree', function (e, data) {
var node = data.instance.get_node(data.selected[0]).original;
if(node){
if(node.project)
return;
if(!working && node.type != "" ){
working = true;
$(".loader-prog").css("display","block");
$.ajax({url:"/api/get",type:"POST",data:{space:node.appid,type:node.type,id:node.id}, error:function(e){
working = false;
$(".loader-prog").css("display","none");
$(".ready-three").append($(e.responseText) );
}
});
}
//attempt request
}
}).jstree({
'core' : {
'data' : {
'url' : function (node) {
return '/api/get';
},
'type' : 'POST'
,
'data' : function (node) {
return node.id == "#" ? {'type' : '0'} : { 'id' : node.id, 'type' : node.type };
}
}
},
"plugins" : [ "contextmenu","state" ],
"contextmenu": {
"select_node" : false ,
"items": function ($node) {
var menu = {};
if ($node.original.ctype){
menu["Create"] = {
"label": "Create",
"action": function (obj) {
havop("/api/create?type=" + $node.original.ctype + "&pkg=" + $node.original.appid,".side-bay");
}
};
}
if ($node.original.dtype.includes("isDir=Yes")){
menu["Run"] = {
"label": "Open in terminal",
"action": function (obj) {
// isDirTerm
let parts = $node.original.dtype.split("path=")
if( winDir ){
winDir = ('src/' + $node.original.appid + "/" + parts[1]).split("/").join("\\") + ">"
}
socketTerminal.send('cd $GOPATH/src/' + $node.original.appid + "/" + parts[1] + "\n");
setTimeout(() => {
if(!$(".terminal-side").hasClass('active')){
$(".terminal-side").addClass('active');
$(".terminal-side").css('display','block');
}
}, 3000)
}
};
menu["Search"] = {
"label": "Search in folder",
"action": function (obj) {
// isDirTerm
let parts = $node.original.dtype.split("path=")
let id = $node.original.appid
if(working) return;
working = true;
$(".loader-prog").css("display","block");
$.ajax({url:"/api/get",type:"POST",data:{pkg:id,type:"5505",path:parts[1]}, error:function(e){
working = false;
$(".loader-prog").css("display","none");
$(".ready-three").append($(e.responseText) );
}
});
}
};
}
if ($node.original.btype){
menu["Build"] = {
"label": "Build",
"action": function (obj) {
BuildPKG($node.original.appid);
}
};
menu["Start"] = {
"label": "Start/Reset",
"action": function (obj) {
StartServer($node.original.appid);
}
};
menu["Stop"] = {