thestrukture/IDE

View on GitHub
tmpl/ui/user/panel/webtwo.tmpl

Summary

Maintainability
Test Coverage

<div class="tabview" id="{{.ID}}" pkg="{{.PKG}}">
<div  class="row">
    <div class="col-sm-9 clear-btn" style="min-height:32px;">
    
    <button class="btn btn-warning" onclick="SaveFileSrc('{{.ID}}', '{{.SavesTo}}','{{.PKG}}')"><i class="fa fa-save"></i></button>
    <button type="button" class="btn btn-primary" onclick="editors['{{.ID}}c'].wrap = editors['{{.ID}}c'].wrap ? false : true;editors['{{.ID}}'].getSession().setUseWrapMode( editors['{{.ID}}c'].wrap   );" data-toggle="button" aria-pressed="true" autocomplete="off">
 Wrap text
</button>
    {{if .Faas}}
        <button title="Ctrl + ." class="btn  btn-warning" onclick="buildFunction('{{.PKG}}', '{{.PreviewLink}}')">Build</button>
        <button title="Ctrl + U" class="btn  btn-warning" onclick="deployFunction('{{.PKG}}', '{{.PreviewLink}}')"><i class="fa fa-play"></i> Deploy </button>
    {{end}}
    </div>
    
    
</div>
<div id="editor{{.ID}}" class="defed">{{printf "%s" .File}}</div>
<script type="text/javascript">
     editors["{{.ID}}"] = ace.edit("editor{{.ID}}");
     editors["{{.ID}}"].getSession().setMode("ace/mode/" + {{.Type}});
     //editors["{{.ID}}"].setTheme("ace/theme/clouds_midnight");
     editors[{{.ID}} + "c"] = {wrap:false};

     
    editors["{{.ID}}-breakpoints"] = {{printf "%s" .BreakPoints}}

    if(editors["{{.ID}}-breakpoints"] != ""){
        
        (function(){
            var brFinal = [];
            var arr = JSON.parse(editors["{{.ID}}-breakpoints"]);
            for(var i = 0; i < arr.length;i++){
               var row = arr[i];
               if(row){
                    brFinal.push(i); 
               }
            }

            editors["{{.ID}}"].session.setBreakpoints(brFinal);

        })();

    }
     
    

    {{if eq .Type "golang"}}
         editors["{{.ID}}"].custom = true;
     {{end}}
 
        editors["{{.ID}}"].setOptions({
            enableBasicAutocompletion: false,
            enableSnippets: false,
            enableLiveAutocompletion: true,
            highlightSelectedWord : true
        });
    
         editors["{{.ID}}"].commands.addCommand({
        name: 'myCommand',
        bindKey: {win: 'Ctrl-S',  mac: 'Command-S'},
        exec: function(editor) {
            //...
             SaveFileSrc('{{.ID}}', '{{.SavesTo}}','{{.PKG}}');
        },
        readOnly: true // false if this command should not apply in readOnly mode
        });

            editors["{{.ID}}"].commands.addCommand({
        name: 'oterm',
        bindKey: {win: 'Ctrl-I',  mac: 'Ctrl-I'},
        exec: function(editor) {
            //...
            toggleTerm()
        },
        readOnly: true // false if this command should not apply in readOnly mode
        });

                editors["{{.ID}}"].commands.addCommand({
        name: 'collapse',
        bindKey: {win: 'Ctrl-M',  mac: 'Ctrl-M'},
        exec: function(editor) {
            //...
            CollapseGloj()
        },
        readOnly: true // false if this command should not apply in readOnly mode
        });




        editors["{{.ID}}"].on("guttermousedown", function(e) {
            var target = e.domEvent.target; 
            
            if (target.className.indexOf("ace_gutter-cell") == -1)
                return; 

            if (!editors["{{.ID}}"].isFocused()) 
                return; 
          
            if (e.clientX > 25 + target.getBoundingClientRect().left) 
                return; 


            var row = e.getDocumentPosition().row;
            var breakpoints = e.editor.session.getBreakpoints(row, 0);
    
            if(typeof breakpoints[row] === typeof undefined)
                e.editor.session.setBreakpoint(row);
            else
                e.editor.session.clearBreakpoint(row);
                e.stop();

            breakpoints = e.editor.session.getBreakpoints(row, 0);
            console.log(breakpoints);
            
            SaveFileSrc('{{.ID}}', '{{.SavesTo}}-breakpoints','{{.PKG}}', JSON.stringify(breakpoints));
        });


        editors["{{.ID}}"].on('change', function() {

            sendMessage({ 
                path : '{{.PKG}} - {{.SavesTo}}'.replace("\\", "/"),
                editor :  editors["{{.ID}}"].getValue()
            });
            
        });


        editorPaths['{{.PKG}} - {{.SavesTo}}'.replace("\\", "/")] = editors["{{.ID}}"];

    
        setTimeout(function(){


        vetAndLint('{{ .ID }}', '{{ .PKG }}','{{ .SavesTo }}')

     
         $.ajax({url: "/api/pkg-bugs?pkg=" + {{.PKG}}, success:function(html){
             //console.log(html)
             editors["{{.ID}}"].completers = [ editors["{{.ID}}"].completers[3] ]

             if (html.Bugs){
             for (var i = html.Bugs.length - 1; i >= 0; i--) {
                 var bug = html.Bugs[i];
                 
                 var action = bug.Action.split(":")
                 var id = {{.SavesTo}}.split("/")
                 id = id[id.length - 1];
                 if (action[0] == "edit" &&  action[1].includes(id) ){
                                              //find line
                         $(".ace_gutter-cell",  "#" + {{.ID}}).each(function(e,i){
                             if ($(this).html() == action[2]){
                                 $(this).attr("style", "height: 16px;width: 47px;padding-left: 10px;letter-spacing: 3px;")
                                 $(this).html( '<i class="fa fa-warning"></i>' + action[2] )
                             }
                         })
                     
                 }
             }
             }
         } 
     })
     },600)
     addTab('{{.PKG}} - {{.SavesTo}}'.replace("\\", "/") , {{.ID}} );
</script>
</div>