How to use ScriptBrowser method in Karma

Best JavaScript code snippet using karma

Scripts.js

Source:Scripts.js Github

copy

Full Screen

1function openScript(path,lineNumber){2 var tab = Ext.ComponentQuery.query("#mainTabPanel")[0];3 tab.setActiveTab(tab.down("#ScriptBrowser"));4 if(path.charAt(0) != "/") path = "/"+path;5 Ext.getCmp("ScriptBrowser").fireEvent('scriptEdit',path,parseInt(lineNumber,10));6 //scriptController.onScriptEdit(path,lineNumber);7 if(Ext.isChrome){8 return false;9 }10}11Ext.define("Redwood.controller.Scripts", {12 extend: 'Ext.app.Controller',13 stores: ['Scripts'],14 models: ['Scripts'],15 views: ['ScriptBrowser','ImageView','CommitView','FindTextView'],16 clipBoard: [],17 lastFocused: "",18 init: function () {19 this.control({20 'scriptBrowser': {21 newScript: this.onNewScript,22 scriptVersionDiff: this.onScriptVersionDiff,23 syncDiffs: this.onSyncDiffs,24 loadVersionHistory: this.loadVersionHistory,25 clearVersionHistory: this.clearVersionHistory,26 scriptEdit: this.onScriptEdit,27 render: this.onScriptRender,28 saveAll: this.onScriptSave,29 deleteScript: this.onDelete,30 newFolder: this.onNewFolder,31 rename: this.onRename,32 findText: this.onFindText,33 copy: this.onCopy,34 focused: this.onFocus,35 paste: this.onPaste,36 terminal: this.onTerminal,37 find: this.onFind,38 findNext: this.onFindNext,39 clearSearch: this.onClearSearch,40 findPrev: this.onFindPrev,41 replace: this.onReplace,42 replaceAll: this.onReplaceAll,43 uploadFile: this.onUpload,44 compile: this.onCompile,45 pushChanges: this.onPushChanges,46 pullChanges: this.onPullChanges,47 recordImage: this.onRecordImage,48 recordSteps: this.onRecordSteps,49 imageEdit:this.onImageEdit,50 uploadFiles:this.onUploadFiles,51 runPip:this.onRunPip52 },53 'scriptBrowser button': {54 }55 });56 },57 compileEventAttached: false,58 onFindText: function(path){59 var selection = this.treePanel.getSelectionModel().getSelection()[0];60 var path = selection.get("fullpath");61 var win = Ext.create('Redwood.view.FindTextView',{62 path:path63 });64 win.show();65 },66 onFindTextResults: function(foundTextResults){67 this.scriptBrowser.down("#findText").store.loadData(foundTextResults);68 var panel = this.scriptBrowser.down("#outputPanel");69 panel.expand();70 panel.down("tabpanel").setActiveTab(2);71 },72 onSyncDiffs: function(sourceTab){73 var allScripts = Ext.ComponentQuery.query('codeeditorpanel');74 allScripts = allScripts.concat(Ext.ComponentQuery.query('diffpanel'));75 Ext.each(allScripts,function(script){76 if(script != sourceTab && script.path == sourceTab.path){77 script.fireSyncEvent = false;78 script.setValue(sourceTab.getValue());79 script.fireSyncEvent = true;80 script.refreshNeeded = true;81 }82 })83 },84 onScriptVersionDiff: function(record,version){85 var me = this;86 if(me.tabPanel.down("#"+version)){87 me.tabPanel.setActiveTab(me.tabPanel.down("#"+version));88 return;89 }90 var foundTab = null;91 me.tabPanel.items.each(function(tab){92 if (tab.title === "["+version+"]"+record.get("text")){93 foundTab = tab;94 }95 });96 if(foundTab){97 me.tabPanel.setActiveTab(foundTab);98 return;99 }100 var editorType = me.getEditorType(record.get("fullpath"));101 var tab = this.tabPanel.add({102 inConflict:false,103 path:record.get("fullpath"),104 editorType:editorType,105 title:"["+version+"]"+record.get("text"),106 closable:true,107 xtype:"diffpanel",108 itemId:version+record.get("fullpath"),109 node:record,110 listeners:{111 focus: function(mel){112 me.up('scriptBrowser').fireEvent('focused',me.down("mergepanel").editor);113 }114 }115 });116 me.tabPanel.setActiveTab(tab);117 Ext.Ajax.request({118 url:"/versioncontrolhistory/diff",119 method:"POST",120 jsonData : {path:record.get("fullpath"),version:version},121 success: function(response, action) {122 var obj = Ext.decode(response.responseText);123 tab.setCurrentVersion(obj.currentVersion);124 tab.sePrevVersion(obj.prevVersion);125 tab.clearDirty();126 }127 });128 },129 onRunPip: function(){130 var panel = this.scriptBrowser.down("#outputPanel");131 panel.expand();132 var output = this.scriptBrowser.down("#compileOutput");133 var elem = output.getEl();134 while (elem.dom.hasChildNodes()) {135 elem.dom.removeChild(elem.dom.lastChild);136 }137 Ext.Ajax.request({138 url:"/runpip",139 method:"GET",140 success: function(response) {141 var obj = Ext.decode(response.responseText);142 if(obj.error){143 Ext.Msg.alert('Error', obj.error);144 if (callback) callback();145 }146 }147 });148 },149 onStopTC: function(){150 Ext.Ajax.request({151 url:"/stopunittest",152 method:"POST",153 jsonData : {},154 success: function(response) {155 //Ext.MessageBox.hide();156 //Ext.Msg.alert('Success', "Code was successfully pushed to the main branch.");157 }158 });159 Ext.getCmp('runUnitTest').setIcon('images/play.png');160 },161 onRunTC: function(){162 var tab = this.tabPanel.getActiveTab();163 if(!tab){164 Ext.Msg.show({title: "Error",msg:"Please open script containing JUnit/TestNG you want to run.",buttons : Ext.MessageBox.OK});165 return166 }167 Ext.MessageBox.show({168 msg: 'Scanning opened file for test cases, please wait...',169 progressText: 'Scanning...',170 width:300,171 wait:true,172 waitConfig: {interval:200}173 });174 Ext.Ajax.request({175 url:"/getallunittcs",176 method:"POST",177 jsonData : {import:false,path:tab.path},178 success: function(response) {179 //Ext.MessageBox.hide();180 //Ext.Msg.alert('Success', "Code was successfully pushed to the main branch.");181 }182 });183 },184 onImportAllTCs: function(){185 Ext.MessageBox.show({186 msg: 'Scanning files for test cases, please wait...',187 progressText: 'Scanning...',188 width:300,189 wait:true,190 waitConfig: {interval:200}191 });192 Ext.Ajax.request({193 url:"/getallunittcs",194 method:"POST",195 jsonData : {import:true},196 success: function(response) {197 //Ext.MessageBox.hide();198 //Ext.Msg.alert('Success', "Code was successfully pushed to the main branch.");199 }200 });201 },202 onImportAllPythonTCs: function(){203 Ext.MessageBox.show({204 msg: 'Scanning files for test cases, please wait...',205 progressText: 'Scanning...',206 width:300,207 wait:true,208 waitConfig: {interval:200}209 });210 Ext.Ajax.request({211 url:"/getallpythonunittcs",212 method:"POST",213 jsonData : {import:true},214 success: function(response) {215 //Ext.MessageBox.hide();216 //Ext.Msg.alert('Success', "Code was successfully pushed to the main branch.");217 }218 });219 },220 onRecordImage: function(){221 Ext.Ajax.request({222 url:"/recordimage",223 method:"POST",224 jsonData : {},225 success: function(response) {226 //Ext.MessageBox.hide();227 //Ext.Msg.alert('Success', "Code was successfully pushed to the main branch.");228 }229 });230 },231 onUploadFiles: function(){232 var path = "";233 var selection = this.treePanel.getSelectionModel().getSelection()[0];234 if ((selection.get("fileType") != "folder")&&(selection.get("fileType") != "libs")){235 selection = selection.parentNode;236 path = selection.get("fullpath");237 }238 else{239 path = selection.get("fullpath");240 }241 Ext.Ajax.request({242 url:"/uploadfiles",243 method:"POST",244 jsonData : {path:path},245 success: function(response) {246 var obj = Ext.decode(response.responseText);247 if(obj.error) Ext.Msg.alert('Error', obj.error);248 }249 });250 Ext.MessageBox.show({251 msg: 'Uploading files, please wait...',252 progressText: 'Uploading...',253 width:300,254 wait:true,255 waitConfig: {interval:200}256 });257 },258 onRecordSteps: function(){259 Ext.Ajax.request({260 url:"/record",261 method:"POST",262 jsonData : {},263 success: function(response) {264 var obj = Ext.decode(response.responseText);265 if(obj.error) Ext.Msg.alert('Error', obj.error);266 }267 });268 },269 onImageRecorded: function(id){270 var tab = this.tabPanel.add({271 title:"[New Image]*",272 dirty: true,273 closable:true,274 xtype:"imageview",275 _id:id276 });277 this.tabPanel.setActiveTab(tab);278 },279 onImageEdit: function(record){280 var tab = this.tabPanel.add({281 title:record.get("name"),282 closable:true,283 xtype:"imageview",284 dataRecord:record,285 _id:record.get("_id")286 });287 this.tabPanel.setActiveTab(tab);288 },289 onPushChanges: function(){290 var me = this;291 var allScripts = Ext.ComponentQuery.query('codeeditorpanel');292 allScripts = allScripts.concat(Ext.ComponentQuery.query('mergepanel'));293 var foundDirty = false;294 Ext.each(allScripts, function(script, index) {295 if(script.dirty == true){296 foundDirty = true;297 }298 });299 var doPush = function(){300 var commitWindow = new Redwood.view.CommitView({});301 commitWindow.show();302 return;303 Ext.MessageBox.show({304 msg: 'Pushing changes to master branch, please wait...',305 progressText: 'Pushing...',306 width:300,307 wait:true,308 waitConfig: {interval:200}309 });310 Ext.Ajax.request({311 url:"/scripts/push",312 method:"POST",313 timeout: 400000,314 jsonData : {},315 success: function(response) {316 me.treePanel.getRootNode().cascadeBy(function(node) {317 if(node.get("text").indexOf("<span") != -1){318 node.set("text",node.get("name"));319 node.set("qtip","");320 }321 });322 Ext.MessageBox.hide();323 var obj = Ext.decode(response.responseText);324 if(obj.error){325 Ext.Msg.alert('Error', obj.error);326 }327 else{328 Ext.Msg.alert('Success', "Code was successfully pushed to the main branch.");329 }330 }331 });332 };333 if (foundDirty == true){334 Ext.Msg.show({335 title:'Save Confirmation',336 msg: "It appears you have unsaved changes. Would you like to save them first?",337 buttons: Ext.Msg.YESNO,338 icon: Ext.Msg.QUESTION,339 fn: function(id){340 if (id == "yes"){341 me.onScriptSave(function(){342 doPush()343 })344 }345 else{346 Ext.Msg.alert('Warning', "The code was not pushed due to changes not being saved.")347 }348 }349 });350 }351 else{352 var foundConflict = false;353 me.treePanel.getRootNode().cascadeBy(function(node) {354 var openInConflict = false;355 if(node.get("inConflict") == true){356 if ((foundConflict == true) &&(openInConflict == false)) return false;357 if (openInConflict == true){358 me.onScriptEdit(node);359 return;360 }361 foundConflict = true;362 Ext.Msg.show({363 title:'Error',364 msg: "It appears you have files in conflict. Would you like to resolve them now?",365 buttons: Ext.Msg.YESNO,366 icon: Ext.Msg.QUESTION,367 fn: function(id){368 if (id == "yes"){369 openInConflict = true;370 me.onScriptEdit(node);371 }372 }373 });374 }375 });376 if(foundConflict == false) doPush();377 }378 },379 onPullChanges: function(){380 Ext.MessageBox.show({381 msg: 'Pulling changes from master branch, please wait...',382 progressText: 'Pulling...',383 width:300,384 wait:true,385 waitConfig: {interval:200}386 });387 var me = this;388 var allScripts = Ext.ComponentQuery.query('codeeditorpanel');389 allScripts = allScripts.concat(Ext.ComponentQuery.query('mergepanel'));390 var expandedNodes = me.getExpandedNodes(me.treePanel.getRootNode());391 var foundDirty = false;392 Ext.each(allScripts, function(script, index) {393 if(script.dirty == true){394 foundDirty = true;395 }396 });397 var doPull = function(){398 Ext.Ajax.request({399 url:"/scripts/pull",400 method:"POST",401 timeout: 600000,402 jsonData : {},403 success: function(response) {404 var obj = Ext.decode(response.responseText);405 var message = "";406 var title = "Success";407 if (obj.conflicts.length > 0){408 message = "Code was pulled but the following files are in conflict:<br>";409 Ext.each(obj.conflicts,function(conflict){410 message = message + "<b color='red'>"+conflict+"</b><br>";411 });412 }413 else if(obj.error){414 title = "Error";415 message = obj.error;416 }417 else{418 message = "Code was successfully pulled from the main branch.";419 }420 me.getStore('Scripts').reload({callback:function(){421 me.expandNodes(expandedNodes);422 Ext.each(allScripts,function(script){423 var foundIt = false;424 me.treePanel.getRootNode().cascadeBy(function(node) {425 if (node.get("fullpath").indexOf(script.path) != -1){426 foundIt = true;427 //script.close();428 //node.parentNode.expand();429 if (node.get("inConflict") == true){430 script.close();431 //me.onScriptEdit(node);432 node.parentNode.expand();433 }434 else{435 script.node = node;436 //me.onScriptEdit(node);437 Ext.Ajax.request({438 url:"/script/get",439 method:"POST",440 jsonData : {path:script.path},441 success: function(response, action) {442 var obj = Ext.decode(response.responseText);443 script.setValue(obj.text);444 script.clearDirty();445 script.refreshNeeded = true;446 }447 });448 }449 }450 });451 if (foundIt == false) script.close();452 });453 me.treePanel.getRootNode().cascadeBy(function(node) {454 if (node.get("inConflict") == true){455 me.onScriptEdit(node);456 }457 });458 }});459 Ext.MessageBox.hide();460 Ext.Msg.alert(title, message);461 me.loadVersionHistory(me.tabPanel.getActiveTab());462 }463 });464 };465 if (foundDirty == true){466 Ext.Msg.show({467 title:'Save Confirmation',468 msg: "It appears you have unsaved changes. Would you like to save them first?",469 buttons: Ext.Msg.YESNO,470 icon: Ext.Msg.QUESTION,471 fn: function(id){472 if (id == "yes"){473 me.onScriptSave(function(){474 doPull()475 })476 }477 else{478 Ext.Msg.alert('Warning', "The code was not pulled due to changes not being saved.")479 }480 }481 });482 }483 else{484 doPull();485 }486 },487 onCompile: function(){488 Ext.socket.emit('compile', {project:Ext.util.Cookies.get("project"),username:Ext.util.Cookies.get("username")});489 var me = this;490 var output = me.scriptBrowser.down("#compileOutput");491 var elem = output.getEl();492 //elem.dom.innerHTML = "";493 while (elem.dom.hasChildNodes()) {494 elem.dom.removeChild(elem.dom.lastChild);495 }496 var panel = me.scriptBrowser.down("#outputPanel");497 panel.expand();498 panel.down("tabpanel").setActiveTab(0);499 if (me.compileEventAttached == false){500 //handle compile messages501 Ext.socket.on('compile',function(msg){502 var output = me.scriptBrowser.down("#compileOutput");503 var elem = output.getEl();504 var lines = msg.split("\n");505 lines.forEach(function(line,index){506 //add green color for BUILD SUCCESSFUL507 if(line.indexOf("BUILD SUCCESSFUL") != -1){508 line = "<b style='color:green'>BUILD SUCCESSFUL</b>"509 }510 else if(line.indexOf("BUILD FAILED") != -1){511 line = "<b style='color:red'>BUILD FAILED</b>"512 }513 //see if we get our file to show up514 var srcIndex = line.lastIndexOf("\\src\\");515 if(srcIndex != -1){516 var endOfPath = line.indexOf(":",srcIndex);517 if (endOfPath == -1){518 srcIndex = line.indexOf("\\src\\");519 endOfPath = line.indexOf(":",srcIndex);520 }521 var path = line.slice(srcIndex,endOfPath);522 //var lineNumber = line.substr(endOfPath+2,1);523 var lineNumber = line.slice(endOfPath+1,line.indexOf(":",endOfPath+1));524 lineNumber = parseInt(lineNumber,10) -1;525 normalisedPath = path;526 while(normalisedPath.indexOf("\\") != -1){527 var normalisedPath = normalisedPath.replace("\\","/");528 }529 var linkHmtl = "<a href='javascript:openScript(&quot;"+ normalisedPath +"&quot;,"+lineNumber+")'>"+ path +"</a>";530 var newMsg = line.replace(path,linkHmtl);531 //var newMsg = line.replace(path,"<a href='javascript:function(){return false;}'>"+ path +"</a>");532 Ext.DomHelper.append(elem, {tag: 'div',html:newMsg});533 }534 //see if it's python535 else if(line.indexOf(" File ") == 0 && line.indexOf(".py\"") != -1){536 var pythonPath = line.split('"')[1];537 var pythonLineNumber = line.split('line ')[1];538 pythonLineNumber = parseInt(pythonLineNumber,10) -1;539 var pythonLinkHmtl = "<a href='javascript:openScript(&quot;/"+ pythonPath.replace(/\\/g,"/") +"&quot;,"+pythonLineNumber+")'>"+ pythonPath +"</a>";540 var pythonNewMsg = line.replace(pythonPath,pythonLinkHmtl);541 Ext.DomHelper.append(elem, {tag: 'div',html:pythonNewMsg});542 }else if((line.indexOf("Sorry: ") == 0 || line.indexOf("SyntaxError: ") == 0) && line.indexOf(".py,") != -1){543 var pythonPath = lines[index-1].split('Compiling ')[1];544 pythonPath = pythonPath.split(' ...')[0];545 var pythonFileName = line.split('(')[1];546 var pythonFileName = pythonFileName.split(',')[0];547 var pythonLineNumber = line.split('line ')[1];548 pythonLineNumber = pythonLineNumber.split(')')[0];549 pythonLineNumber = parseInt(pythonLineNumber,10) -1;550 var pythonLinkHmtl = "<a href='javascript:openScript(&quot;/"+ pythonPath.replace(/\\/g,"/") +"&quot;,"+pythonLineNumber+")'>"+ pythonPath +"</a>";551 var pythonNewMsg = line.replace(pythonFileName,pythonLinkHmtl);552 Ext.DomHelper.append(elem, {tag: 'div',html:pythonNewMsg});553 }else if(line.indexOf("Sorry: ") == 0 && line.indexOf(".py',") != -1){554 var pythonPath = lines[index-1].split('Compiling ')[1];555 pythonPath = pythonPath.split(' ...')[0];556 var pythonFileName = line.split('(')[2];557 pythonFileName = pythonFileName.split("'")[1];558 var pythonLineNumber = line.split('(')[2];559 pythonLineNumber = pythonLineNumber.split("'")[2];560 pythonLineNumber = pythonLineNumber.split(",")[1].trim();561 pythonLineNumber = parseInt(pythonLineNumber,10) -1;562 var pythonLinkHmtl = "<a href='javascript:openScript(&quot;/"+ pythonPath.replace(/\\/g,"/") +"&quot;,"+pythonLineNumber+")'>"+ pythonPath +"</a>";563 var pythonNewMsg = line.replace(pythonFileName,pythonLinkHmtl);564 Ext.DomHelper.append(elem, {tag: 'div',html:pythonNewMsg});565 }566 //if c#567 else if(line.indexOf(": error ") != -1 && line.indexOf(".cs(") != -1){568 var csharpPath = line.split('(')[0];569 var csharpLineNumber = line.split('(')[1].split(',')[0];570 csharpLineNumber = parseInt(csharpLineNumber,10) -1;571 var csharpLinkHmtl = "<a href='javascript:openScript(&quot;/"+ csharpPath.replace(/\\/g,"/").trim() +"&quot;,"+csharpLineNumber+")'>"+ csharpPath +"</a>";572 var csharpNewMsg = line.replace(csharpPath,csharpLinkHmtl);573 Ext.DomHelper.append(elem, {tag: 'div',html:csharpNewMsg});574 }575 else{576 Ext.DomHelper.append(elem, {tag: 'div',html:line});577 }578 });579 //scroll to bottom580 elem.dom.scrollTop = elem.dom.scrollHeight;581 //elem.dom.parentNode.scrollTop = elem.dom.parentNode.scrollHeight;582 });583 me.compileEventAttached = true;584 }585 },586 getIconType: function(fileName){587 var icon;588 if (fileName.slice(-6) == "groovy"){589 icon = "images/fileTypeGroovy.png";590 }else if (fileName.slice(-4) == "java"){591 icon = "images/fileTypeJava.png";592 }else if (fileName.slice(-2) == "js"){593 icon = "images/fileTypeJavascript.png";594 }else if (fileName.slice(-2) == "py"){595 icon = "images/python.png";596 }else if (fileName.slice(-2) == "cs"){597 icon = "images/csharp.png";598 }599 return icon;600 },601 onUpload: function(form){602 if(this.treePanel.getSelectionModel().getSelection().length == 1){603 var me = this;604 var path = "";605 var selection = this.treePanel.getSelectionModel().getSelection()[0];606 if ((selection.get("fileType") != "folder")&&(selection.get("fileType") != "libs")){607 selection = selection.parentNode;608 path = selection.get("fullpath");609 }610 else{611 path = selection.get("fullpath");612 }613 var fileName = form.down("#uploadFileName").getValue();614 fileName = fileName.replace(/^.*[\\\/]/, '');615 form.down("#destDir").setValue(path);616 form.submit({617 url: '/fileupload',618 waitMsg: 'Uploading...',619 success: function(fp, o) {620 Ext.Msg.alert('Success', 'cool').hide();621 var newNode = selection.appendChild({name:fileName,text:fileName,fileType:"file",leaf:true,icon:me.getIconType(fileName),fullpath:path+"/"+fileName});622 me.getStore('Scripts').sort();623 newNode.parentNode.expand();624 me.treePanel.getSelectionModel().select(newNode);625 },626 //don't know why but failed actually means success627 failure: function(form,info){628 var obj = Ext.decode(info.response.responseText);629 if(obj.error != null){630 Ext.Msg.alert('Error', obj.error);631 return;632 }633 var newNode = selection.appendChild({name:fileName,text:fileName,fileType:"file",leaf:true,icon:me.getIconType(fileName),fullpath:path+"/"+fileName});634 me.treePanel.getStore().sort();635 newNode.parentNode.expand();636 me.treePanel.getSelectionModel().select(newNode);637 }638 });639 }640 },641 GetOpenedEditor: function(){642 var tab = this.tabPanel.getActiveTab();643 if (tab == null) return null;644 if (tab.down("codeeditorfield") != null){645 return tab.down("codeeditorfield").editor;646 }647 else{648 return tab.editor.edit;649 }650 },651 onFindPrev: function(){652 if (this.GetOpenedEditor() != null){653 Ext.editorCommands.search(this.GetOpenedEditor(),true);654 }655 },656 onClearSearch: function(){657 if (this.GetOpenedEditor() != null){658 Ext.editorCommands.clearSearch(this.GetOpenedEditor());659 }660 },661 onFindNext: function(){662 if (this.GetOpenedEditor() != null){663 Ext.editorCommands.search(this.GetOpenedEditor());664 }665 },666 onFind: function(){667 if (this.GetOpenedEditor() != null){668 Ext.editorCommands.clearSearch(this.GetOpenedEditor());669 Ext.editorCommands.search(this.GetOpenedEditor());670 }671 },672 onReplace: function(){673 if (this.GetOpenedEditor() != null){674 Ext.editorCommands.replace(this.GetOpenedEditor());675 }676 },677 onReplaceAll: function(){678 if (this.GetOpenedEditor() != null){679 Ext.editorCommands.replace(this.GetOpenedEditor(),true);680 }681 },682 onTerminal: function(){683 var terminalWin = Ext.create('Redwood.ux.TerminalWindow',{684 });685 terminalWin.show();686 },687 getExpandedNodes: function(root){688 var expandedNodes = [];689 var isExpanded = function(node){690 if (node.isExpanded()){691 if (!node.isRoot()){692 expandedNodes.push(node.get("fullpath"));693 }694 node.eachChild(function(child){695 isExpanded(child);696 });697 }698 };699 isExpanded(root);700 return expandedNodes.reverse();701 },702 expandNodes: function(nodes,callback){703 var me = this;704 nodes.forEach(function(node,index,array){705 var toExpand = me.treePanel.getRootNode().findChild("fullpath",node,true);706 if (toExpand){707 me.treePanel.getRootNode().findChild("fullpath",node,true).expand();708 }709 if (array.length-1 == index){710 if(callback) callback();711 }712 });713 },714 onPaste: function(){715 if(this.treePanel.getSelectionModel().getSelection().length == 1){716 var me = this;717 var selection = this.treePanel.getSelectionModel().getSelection()[0];718 var path = me.getPathFromNode(selection);719 var allScripts = [];720 this.clipBoard.forEach(function(node){721 if(!node.parentNode.isRoot()){722 allScripts.push(node.get("fullpath"));723 }724 });725 var expandedNodes = me.getExpandedNodes(this.treePanel.getRootNode());726 Ext.Ajax.request({727 url:"/scripts/copy",728 method:"POST",729 jsonData : {scripts:allScripts,destDir:path},730 success: function(response, action) {731 var obj = Ext.decode(response.responseText);732 if(obj.error != null){733 Ext.Msg.alert('Error', obj.error);734 }735 else{736 /*737 var expandAll = function(store){738 expandedNodes.forEach(function(node,index,array){739 var toExpand = me.treePanel.getRootNode().findChild("fullpath",node,true);740 if (toExpand){741 me.treePanel.getRootNode().findChild("fullpath",node,true).expand();742 }743 if (array.length-1 == index){744 var destNode = me.treePanel.getRootNode().findChild("fullpath",path,true);745 if (destNode){746 me.treePanel.getSelectionModel().select(destNode);747 destNode.expand();748 }749 store.removeListener("load",expandAll);750 }751 });752 };753 me.getStore('Scripts').on("load",expandAll);754 */755 var expandAll = function(store){756 me.expandNodes(expandedNodes,function(){757 var destNode = me.treePanel.getRootNode().findChild("fullpath",path,true);758 if (destNode){759 me.treePanel.getSelectionModel().select(destNode);760 destNode.expand();761 }762 store.removeListener("load",expandAll);763 });764 };765 me.getStore('Scripts').on("load",expandAll);766 me.getStore('Scripts').load();767 }768 }769 });770 }771 },772 onFocus: function(object){773 this.lastFocused = object;774 },775 onCopy: function(){776 this.clipBoard = this.treePanel.getSelectionModel().getSelection();777 },778 onRename: function(){779 if(this.treePanel.getSelectionModel().getSelection().length == 1){780 var selection = this.treePanel.getSelectionModel().getSelection()[0];781 var path = "";782 var objectType;783 var me = this;784 path = selection.get("fullpath");785 if (selection.get("cls") != "folder"){786 objectType = "script";787 }788 else{789 objectType = "folder";790 }791 var win = Ext.create('Redwood.view.FileName',{792 path:path,793 objectType:objectType,794 title: "Rename",795 operationType:"rename",796 defaultName:selection.get("name"),797 //defaultName:selection.get("text"),798 fn: function(newName){799 //new path800 var newPath = path.substring(0,path.lastIndexOf("/")+1)+newName;801 selection.set({name:newName,text:newName,fullpath:newPath,icon:me.getIconType(newName)});802 selection.dirty = false;803 me.getStore('Scripts').sort();804 me.treePanel.getSelectionModel().select(selection);805 me.tabPanel.items.each(function(tab){806 if(tab.path === path){807 //tab.itemId = newPath;808 tab.path = newPath;809 tab.tooltip = newPath;810 tab.setTitle(newName);811 }812 });813 //var foundTab = me.tabPanel.down("#"+path);814 }815 });816 win.show();817 }818 },819 onNewFolder: function(){820 if(this.treePanel.getSelectionModel().getSelection().length > 0){821 var me = this;822 var selection = this.treePanel.getSelectionModel().getSelection()[0];823 var path = me.getPathFromNode(selection);824 var win = Ext.create('Redwood.view.FileName',{825 path:path,826 title: "New Folder",827 objectType: "folder",828 fn: function(folderName){829 var newNode = selection.appendChild({name:folderName,text:folderName,cls:"folder",fileType:"folder",fullpath:path+"/"+folderName,children: []});830 me.getStore('Scripts').sort();831 newNode.parentNode.expand();832 me.treePanel.getSelectionModel().select(newNode);833 }834 });835 win.show();836 }837 },838 onDelete: function(){839 if(Ext.util.Cookies.get('role') == "Test Designer") return;840 var me = this;841 var selection = this.treePanel.getSelectionModel().getSelection();842 if(selection.length > 0){843 var message = 'Are you sure you want to delete selected files/folders?';844 if (selection.length == 1){845 message = 'Are you sure you want to delete: <b>'+selection[0].get("name")+'</b> ?';846 }847 Ext.Msg.show({848 title:'Delete Confirmation',849 msg: message,850 buttons: Ext.Msg.YESNO,851 icon: Ext.Msg.QUESTION,852 fn: function(id){853 if (id == "yes"){854 var scripts = [];855 for (var i=0;selection.length > i;i++){856 //if (selection[i].get("fullpath") == "public/automationscripts/src"){857 if (selection[i].parentNode.isRoot()==true){858 //see if src dir is about to be deleted859 Ext.Msg.alert('Error', 'Can not delete this src/libs/build.xml items.');860 return;861 }862 scripts.push({fullpath:selection[i].get("fullpath"),cls:selection[i].get("cls")})863 }864 Ext.Ajax.request({865 url:"/scripts/delete",866 method:"POST",867 jsonData : scripts,868 success: function(response, action) {869 for (var i=0;selection.length > i;i++){870 if (selection[i].hasChildNodes()){871 selection[i].cascadeBy(function(node){872 if (!node.hasChildNodes()){873 me.tabPanel.remove(node.get("fullpath"));874 }875 });876 }877 else{878 me.tabPanel.remove(selection[i].get("fullpath"));879 }880 selection[i].remove();881 }882 }883 });884 }885 }886 });887 }888 },889 getPathFromNode: function(node){890 var path;891 if (node.get("fileType") != "folder"){892 node = node.parentNode;893 path = node.get("fullpath");894 }895 else{896 path = node.get("fullpath");897 }898 return path;899 },900 onNewScript: function(type){901 if(this.treePanel.getSelectionModel().getSelection().length > 0){902 var me = this;903 var selection = this.treePanel.getSelectionModel().getSelection()[0];904 if(selection.get("fileType") != "folder"){905 selection = selection.parentNode;906 }907 var path = me.getPathFromNode(selection);908 var win = Ext.create('Redwood.view.FileName',{909 path:path,910 objectType:type,911 fn: function(fileName){912 var newNode = selection.appendChild({qtip:'This file is not yet pushed.',name:fileName,text:'<span style="color:blue">' + fileName + '</span>',fileType:"file",leaf:true,icon:me.getIconType(fileName),fullpath:path+"/"+fileName});913 me.onScriptEdit(newNode);914 me.getStore('Scripts').sort();915 newNode.parentNode.expand();916 me.treePanel.getSelectionModel().select(newNode);917 }918 });919 win.show();920 }921 },922 onScriptSave: function(callback){923 if(Ext.util.Cookies.get('role') == "Test Designer") return;924 var me = this;925 var allScripts = Ext.ComponentQuery.query('codeeditorpanel');926 allScripts = allScripts.concat(Ext.ComponentQuery.query('mergepanel'));927 var total = 0;928 if (allScripts.length == 0){929 if (callback) callback();930 return;931 }932 Ext.each(allScripts, function(script, index) {933 if (script.dirty == true){934 if (script.inConflict == false){935 var sendSaveRequest = function(){936 //if we are saving pip requirements937 Ext.Ajax.request({938 url:"/script",939 method:"PUT",940 jsonData : {path:script.path,text:script.getValue()},941 success: function(response, action) {942 var obj = Ext.decode(response.responseText);943 if(obj.error){944 Ext.Msg.alert('Error', obj.error);945 if (callback) callback();946 return;947 }948 if(script.path.indexOf(pipReqFilePath) == script.path.length -pipReqFilePath.length){949 var panel = me.scriptBrowser.down("#outputPanel");950 panel.expand();951 var output = me.scriptBrowser.down("#compileOutput");952 var elem = output.getEl();953 while (elem.dom.hasChildNodes()) {954 elem.dom.removeChild(elem.dom.lastChild);955 }956 }957 script.clearDirty();958 if(script.closeAfterSave == true){959 script.close();960 }961 script.node.set("text",'<span style="color:blue">' + script.node.get("name") + '</span>');962 script.node.set("qtip",'This file is not yet pushed.');963 total++;964 if (total == allScripts.length){965 if (callback) callback();966 }967 me.loadVersionHistory(me.tabPanel.getActiveTab())968 },969 failure: function (response) {970 var obj = Ext.decode(response.responseText);971 if(obj.error){972 Ext.Msg.alert('Error', obj.error);973 }974 else{975 Ext.Msg.alert('Error', "Unable to save file.");976 }977 }978 });979 };980 var pipReqFilePath = "/"+Ext.util.Cookies.get("username")+"/PipRequirements";981 if(script.path.indexOf(pipReqFilePath) == script.path.length -pipReqFilePath.length){982 if(!script.getValue().match(/[^\W_]/)){983 Ext.Msg.show({984 title:'Save Confirmation',985 msg: "It appears you have an empty pip requirement file. This would cause all libraries to be uninstalled. Do you want to proceed?",986 buttons: Ext.Msg.YESNO,987 icon: Ext.Msg.QUESTION,988 fn: function(id){989 if (id == "yes"){990 sendSaveRequest()991 }992 }993 });994 }995 else{996 sendSaveRequest()997 }998 }999 else{1000 sendSaveRequest()1001 }1002 }1003 else{1004 Ext.Ajax.request({1005 url:"/script/resolveconflict",1006 method:"POST",1007 jsonData : {path:script.path,text:script.getValue()},1008 success: function(response, action) {1009 var obj = Ext.decode(response.responseText);1010 script.clearDirty();1011 total++;1012 if (total == allScripts.length){1013 script.close();1014 script.node.set("inConflict",false);1015 script.node.set("text",script.node.get("name"));1016 if (callback) callback();1017 }1018 me.treePanel.getRootNode().cascadeBy(function(node) {1019 if ((node.get("fullpath") && (node.get("fullpath").indexOf(obj.filesInConflict[0]) != -1))){1020 node.set("inConflict",true);1021 node.set("text",'<span style="color:red">' + node.get("name") + '</span>');1022 me.tabPanel.items.each(function(tab){1023 if (tab.path === node.get("fullpath")){1024 tab.close();1025 }1026 });1027 me.onScriptEdit(node);1028 }1029 });1030 }1031 });1032 }1033 }1034 else{1035 total++;1036 if (total == allScripts.length){1037 if (callback) callback();1038 }1039 }1040 });1041 },1042 loadVersionHistory: function(tab){1043 if(tab){1044 this.scriptBrowser.down("#versionControl").store.load({params:{path:tab.path}});1045 this.scriptBrowser.down("#versionControl").lastTab = tab;1046 }1047 },1048 clearVersionHistory: function(){1049 this.scriptBrowser.down("#versionControl").store.removeAll();1050 },1051 getEditorType: function(path){1052 var editorType = "text";1053 if (path.slice(-6) == "groovy"){1054 editorType = "text/x-groovy";1055 }else if (path.slice(-4) == "java"){1056 editorType = "text/x-java";1057 }else if (path.slice(-3) == "xml"){1058 editorType = "application/xml";1059 }else if (path.slice(-2) == "js"){1060 editorType = "text/javascript";1061 }else if (path.slice(-2) == "py"){1062 editorType = "text/x-python";1063 }else if (path.slice(-2) == "cs"){1064 editorType = "text/x-csharp";1065 }1066 return editorType;1067 },1068 onScriptEdit: function(record,lineNumber){1069 var me = this;1070 //if string search for1071 if (typeof(record) == "string"){1072 this.treePanel.getRootNode().cascadeBy(function(node) {1073 //if ((node.get("fullpath") && (node.get("fullpath").indexOf(record) != -1))){1074 if ((node.get("fullpath") && ("/src/"+node.get("fullpath").split("/src/")[1] == record))){1075 node.parentNode.expand();1076 me.treePanel.getSelectionModel().select(node);1077 record = node;1078 }1079 });1080 }1081 //if still a string node was not found1082 if (typeof(record) == "string"){1083 return;1084 }1085 var foundTab = null;1086 this.tabPanel.items.each(function(tab){1087 if (tab.path === record.get("fullpath")){1088 foundTab = tab;1089 }1090 });1091 if (foundTab == null){1092 var editorType = me.getEditorType(record.get("fullpath"));1093 var tab;1094 if (record.get("inConflict") == false){1095 tab = this.tabPanel.add({1096 inCollab:false,1097 inConflict:false,1098 path:record.get("fullpath"),1099 editorType:editorType,1100 title:record.get("name"),1101 closable:true,1102 xtype:"codeeditorpanel",1103 itemId:record.get("fullpath"),1104 tooltip:record.get("fullpath"),1105 node:record,1106 listeners:{1107 focus: function(me){1108 me.up('scriptBrowser').fireEvent('focused',me.down("codeeditorfield").editor);1109 },1110 close: function(){1111 //close all diff panels1112 var allScripts = Ext.ComponentQuery.query('diffpanel');1113 Ext.each(allScripts,function(script){1114 if (tab.path == script.path){1115 script.close();1116 }1117 });1118 me.clearVersionHistory();1119 me.tabPanel.setActiveTab(0);1120 }1121 }1122 });1123 Ext.Ajax.request({1124 url:"/script/get",1125 method:"POST",1126 jsonData : {path:record.get("fullpath")},1127 success: function(response, action) {1128 var obj = Ext.decode(response.responseText);1129 tab.setValue(obj.text);1130 if (lineNumber && typeof(lineNumber) == "number"){1131 tab.setCursor({line:lineNumber,ch:0});1132 }1133 tab.clearHistory();1134 tab.clearDirty();1135 }1136 });1137 }1138 else{1139 tab = this.tabPanel.add({1140 inConflict:true,1141 path:record.get("fullpath"),1142 editorType:editorType,1143 title:record.get("text"),1144 closable:true,1145 xtype:"mergepanel",1146 itemId:record.get("fullpath"),1147 tooltip:record.get("fullpath"),1148 node:record,1149 listeners:{1150 focus: function(me){1151 me.up('scriptBrowser').fireEvent('focused',me.down("mergepanel").editor);1152 }1153 }1154 });1155 Ext.Ajax.request({1156 url:"/script/mergeinfo",1157 method:"POST",1158 jsonData : {path:record.get("fullpath")},1159 success: function(response, action) {1160 var obj = Ext.decode(response.responseText);1161 tab.setMine(obj.mine);1162 tab.setTheirs(obj.theirs);1163 }1164 });1165 }1166 foundTab = tab;1167 }1168 me.tabPanel.setActiveTab(foundTab);1169 if (typeof(lineNumber) == "number"){1170 me.tabPanel.getActiveTab().setCursor({line:lineNumber,ch:0});1171 foundTab.focus();1172 }1173 me.loadVersionHistory(foundTab);1174 },1175 onScriptRender: function(){1176 var me = this;1177 this.scriptBrowser = Ext.ComponentQuery.query('scriptBrowser')[0];1178 //this.tabPanel = Ext.ComponentQuery.query('tabpanel',this.scriptBrowser)[0];1179 this.tabPanel = this.scriptBrowser.down("#scriptstab");1180 this.treePanel = Ext.ComponentQuery.query('treepanel',this.scriptBrowser)[0];1181 this.searchField = Ext.ComponentQuery.query('#findTextField',this.scriptBrowser);1182 this.treePanel.on("afterrender",function(tree){1183 new Ext.util.KeyMap({1184 target: me.treePanel.getEl(),1185 binding: [{1186 key: "c",1187 ctrl:true,1188 fn: function(){1189 tree.up('scriptBrowser').fireEvent('copy');}1190 },1191 {1192 key: "v",1193 ctrl:true,1194 fn: function(){1195 tree.up('scriptBrowser').fireEvent('paste');}1196 },1197 {1198 key: Ext.EventObject.DELETE,1199 fn: function(){1200 tree.up('scriptBrowser').fireEvent('delete');}1201 }1202 ]1203 });1204 });1205 }...

Full Screen

Full Screen

ScriptBrowser.js

Source:ScriptBrowser.js Github

copy

Full Screen

1var pushAction = Ext.create('Ext.Action', {2 icon: 'images/install.png',3 tooltip: "Push Changes to Master Branch",4 margin: "0 3 0 3",5 handler: function(widget, event) {6 this.up('scriptBrowser').fireEvent('pushChanges');7 }8});9var recordImageAction = Ext.create('Ext.Action', {10 icon: 'images/media_record.png',11 tooltip: "Record Image From Desktop",12 margin: "0 3 0 3",13 handler: function(widget, event) {14 this.up('scriptBrowser').fireEvent('recordImage');15 }16});17var uploadFiles = Ext.create('Ext.Action', {18 icon: 'images/uploadFolders.png',19 tooltip: "Upload multiple directories and files.",20 //margin: "0 3 0 3",21 text:"Upload Directories",22 handler: function(widget, event) {23 var editor = this.up('scriptBrowser');24 if (editor == undefined){25 editor = this.up('#treeContext').scriptEditor;26 }27 editor.fireEvent('uploadFiles');28 }29});30var runPip = Ext.create('Ext.Action', {31 icon: 'images/python.png',32 tooltip: "Run pip install against current requirement file.",33 text:"Run Pip Install",34 itemId: "runPip",35 visible: false,36 handler: function(widget, event) {37 var editor = this.up('scriptBrowser');38 if (editor == undefined){39 editor = this.up('#treeContext').scriptEditor;40 }41 editor.fireEvent('runPip');42 }43});44var recordStepsAction = Ext.create('Ext.Action', {45 icon: 'images/media_record.png',46 tooltip: "Start Looking Glass Utility",47 margin: "0 3 0 3",48 handler: function(widget, event) {49 this.up('scriptBrowser').fireEvent('recordSteps');50 }51});52var shareScriptAction = Ext.create('Ext.Action', {53 icon: 'images/share.png',54 tooltip: "Collaborate with another user.",55 margin: "0 3 0 3",56 handler: function(widget, event) {57 var tab = this.up('scriptBrowser').down("#scriptstab").getActiveTab();58 if(tab){59 Redwood.app.getController("Collaboration").onShareScript(tab);60 }61 else{62 Ext.Msg.alert('Error', "Please open script you want to share.");63 }64 }65});66var pullAction = Ext.create('Ext.Action', {67 icon: 'images/uninstall.png',68 tooltip: "Pull Latest Changes From Master Branch",69 margin: "0 3 0 3",70 handler: function(widget, event) {71 this.up('scriptBrowser').fireEvent('pullChanges');72 }73});74var copyAction = Ext.create('Ext.Action', {75 icon: 'images/page_copy.png',76 tooltip: "Copy File/Folder",77 margin: "0 3 0 3",78 handler: function(widget, event) {79 this.up('scriptBrowser').fireEvent('copy');80 }81});82var uploadActionHidden = Ext.create('Ext.form.field.File', {83 name:"file",84 itemId:"uploadFileName",85 listeners: {86 change: function(me,value){87 Ext.getCmp("ScriptBrowser").fireEvent("uploadFile",me.up("form"));88 }89 }90});91var uploadForm = Ext.create('Ext.form.Panel', {92 renderTo: Ext.getBody(),93 standardSubmit : false,94 hidden: true,95 items: [uploadActionHidden,96 {xtype:"textfield",97 name:"destDir",98 itemId:"destDir"}99 ]100});101var uploadAction = Ext.create('Ext.Action', {102 icon: 'images/upload.png',103 tooltip: "Upload File",104 text:"Upload",105 handler: function(widget, event) {106 //uploadActionHidden.handler.call(uploadActionHidden.scope, uploadActionHidden, Ext.EventObject)107 uploadActionHidden.fileInputEl.dom.click();108 }109});110var importAllTCsAction = Ext.create('Ext.Action', {111 tooltip: "Import TestNG/Junit Test Cases.",112 text:"Import Test Cases",113 icon: 'images/import.png',114 handler: function(widget, event) {115 Redwood.app.getController("Scripts").onImportAllTCs();116 }117});118var runTCAction = Ext.create('Ext.Action', {119 tooltip: "Run TestNG/Junit Test Case in opened script.",120 icon: 'images/play.png',121 id:"runUnitTest",122 //hidden:true,123 handler: function(widget, event) {124 if(widget.icon == 'images/play.png'){125 Redwood.app.getController("Scripts").onRunTC();126 }127 else{128 Redwood.app.getController("Scripts").onStopTC();129 widget.setIcon('images/play.png');130 }131 }132});133var findPrev = Ext.create('Ext.Action', {134 icon: 'images/arrow_up.png',135 tooltip: "Find Previous",136 margin: "0 3 0 3",137 handler: function(widget, event) {138 this.up('scriptBrowser').fireEvent('findPrev');139 }140});141var findNext = Ext.create('Ext.Action', {142 icon: 'images/arrow_down.png',143 tooltip: "Find Next",144 margin: "0 3 0 3",145 handler: function(widget, event) {146 this.up('scriptBrowser').fireEvent('findNext');147 }148});149var findText = Ext.create('Ext.form.field.Trigger', {150 id:"findTextField",151 width: 240,152 margin: "0 3 0 3",153 emptyText: 'find text',154 trigger1Cls: Ext.baseCSSPrefix + 'form-clear-trigger',155 onTrigger1Click: function(){156 this.setValue("");157 this.focus();158 },159 listeners: {160 afterrender: function(me){161 me.triggerCell.item(0).setDisplayed(false);162 },163 change: function(me,newVal,oldVal){164 if (me.getValue() == ""){165 me.triggerCell.item(0).setDisplayed(false);166 }167 else{168 me.triggerCell.item(0).setDisplayed(true);169 }170 this.up('scriptBrowser').fireEvent('find');171 },172 specialkey: function(field, e){173 if (e.getKey() == e.ENTER) {174 if (this.getValue() != ""){175 this.up('scriptBrowser').fireEvent('findNext');176 }177 }178 }179 }180});181var regExpression = Ext.create('Ext.form.field.Checkbox', {182 id:"searchRegex",183 boxLabel: "Regex",184 style: "font-size: 11px;",185 listeners:{186 change: function(){187 this.up('scriptBrowser').fireEvent('find');188 }189 }190});191var caseSensitive = Ext.create('Ext.form.field.Checkbox', {192 id:"searchCase",193 boxLabel: "Case",194 style: "font-size: 11px;",195 listeners:{196 change: function(){197 this.up('scriptBrowser').fireEvent('find');198 }199 }200});201var replaceText = Ext.create('Ext.form.field.Text', {202 id:"replaceTextField",203 margin: "0 3 0 0",204 width:"240px",205 emptyText:"replace text"206});207var replaceAction = Ext.create('Ext.Button', {208 text: "Replace",209 margin: "0 3 0 3",210 handler: function(widget, event) {211 this.up('scriptBrowser').fireEvent('replace');212 }213});214var replaceAllAction = Ext.create('Ext.Button', {215 text: "Replace All",216 margin: "0 3 0 0",217 style: "border-style:solid;border-width:1px;",218 handler: function(widget, event) {219 this.up('scriptBrowser').fireEvent('replaceAll');220 }221});222var terminalAction = Ext.create('Ext.Action', {223 icon: 'images/terminal.png',224 tooltip: "Open terminal",225 margin: "0 3 0 3",226 handler: function(widget, event) {227 this.up('scriptBrowser').fireEvent('terminal');228 }229});230var pasteAction = Ext.create('Ext.Action', {231 icon: 'images/paste_plain.png',232 itemId: "pasteBar",233 tooltip: "Paste File/Folder",234 margin: "0 3 0 3",235 handler: function(widget, event) {236 this.up('scriptBrowser').fireEvent('paste');237 }238});239var newScriptAction = Ext.create('Ext.Action', {240 icon: 'images/page_add.png',241 text: 'File',242 itemId: "newScript",243 tooltip: "New File",244 handler: function(widget, event) {245 var editor = this.up('scriptBrowser');246 if (editor == undefined){247 editor = this.up('#treeContext').scriptEditor;248 }249 editor.fireEvent('newScript',"script");250 }251});252var newGroovyScriptAction = Ext.create('Ext.Action', {253 icon: 'images/fileTypeGroovy.png',254 text: 'Groovy Action',255 tooltip: "New Groovy Action",256 handler: function(widget, event) {257 var editor = this.up('scriptBrowser');258 if (editor == undefined){259 editor = this.up('#treeContext').scriptEditor;260 }261 editor.fireEvent('newScript',"groovyAction");262 }263});264var newPythonScriptAction = Ext.create('Ext.Action', {265 icon: 'images/python.png',266 text: 'Python Action',267 tooltip: "New Python Action",268 handler: function(widget, event) {269 var editor = this.up('scriptBrowser');270 if (editor == undefined){271 editor = this.up('#treeContext').scriptEditor;272 }273 editor.fireEvent('newScript',"pythonAction");274 }275});276var newCSharpScriptAction = Ext.create('Ext.Action', {277 icon: 'images/csharp.png',278 text: 'C# Action',279 tooltip: "New C# Action",280 handler: function(widget, event) {281 var editor = this.up('scriptBrowser');282 if (editor == undefined){283 editor = this.up('#treeContext').scriptEditor;284 }285 editor.fireEvent('newScript',"csharpAction");286 }287});288var newJavaScriptAction = Ext.create('Ext.Action', {289 icon: 'images/fileTypeJava.png',290 text: 'Java Action',291 tooltip: "New Java Action",292 handler: function(widget, event) {293 var editor = this.up('scriptBrowser');294 if (editor == undefined){295 editor = this.up('#treeContext').scriptEditor;296 }297 editor.fireEvent('newScript',"javaAction");298 }299});300var newFolderAction = Ext.create('Ext.Action', {301 icon: 'images/folder.gif',302 text: 'Folder',303 itemId: "newFolder",304 tooltip: "New Folder",305 handler: function(widget, event) {306 var editor = this.up('scriptBrowser');307 if (editor == undefined){308 editor = this.up('#treeContext').scriptEditor;309 }310 editor.fireEvent('newFolder');311 }312});313var saveScriptAction = Ext.create('Ext.Action', {314 icon: 'images/saveAll.png',315 //text: '',316 disabled: false,317 tooltip: "Save All",318 margin: "0 3 0 3",319 handler: function(widget, event) {320 this.setDisabled(true);321 var me = this;322 this.up('scriptBrowser').fireEvent('saveAll',function(){323 me.setDisabled(false);324 });325 }326});327var deleteMenuAction = Ext.create('Ext.Action', {328 icon: 'images/delete.png',329 text: 'Delete',330 itemId: "deleteMenu",331 //tooltip: "Delete",332 handler: function(widget, event) {333 this.up('menu').scriptEditor.fireEvent('deleteScript');334 }335});336var copyMenuAction = Ext.create('Ext.Action', {337 icon: 'images/page_copy.png',338 itemId: "copyMenu",339 text: 'Copy',340 handler: function(widget, event) {341 this.up('menu').scriptEditor.fireEvent('copy');342 }343});344var pasteMenuAction = Ext.create('Ext.Action', {345 icon: 'images/paste_plain.png',346 itemId: "pasteMenu",347 text: 'Paste',348 handler: function(widget, event) {349 this.up('menu').scriptEditor.fireEvent('paste');350 }351});352var deleteScriptAction = Ext.create('Ext.Action', {353 icon: 'images/delete.png',354 //text: 'Delete',355 itemId: "deleteBar",356 tooltip: "Delete",357 margin: "0 3 0 3",358 handler: function(widget, event) {359 this.up('scriptBrowser').fireEvent('deleteScript');360 }361});362var compileAction = Ext.create('Ext.Action', {363 icon: 'images/compile.png',364 //text: 'Delete',365 itemId: "compileBar",366 tooltip: "Build Scripts",367 margin: "0 3 0 3",368 handler: function(widget, event) {369 var me = this;370 this.up('scriptBrowser').fireEvent('saveAll',function(){371 me.up('scriptBrowser').fireEvent('compile');372 });373 }374});375var newMenuItem = Ext.create('Ext.Action', {376 itemId:"newItemsBar",377 text: "New",378 iconCls: 'icon-add',379 menu: new Ext.menu.Menu({380 items: [381 newJavaScriptAction,382 newGroovyScriptAction,383 newPythonScriptAction,384 newCSharpScriptAction,385 newScriptAction,386 newFolderAction,387 uploadAction,388 uploadFiles389 ]390 })391});392var newItemButton = Ext.create('Ext.button.Split',{393 text: "New",394 itemId:"newItemsMenu",395 iconCls: 'icon-add',396 handler: function(){397 this.showMenu();398 },399 menu: new Ext.menu.Menu({400 items: [401 newJavaScriptAction,402 newGroovyScriptAction,403 newPythonScriptAction,404 newScriptAction,405 newFolderAction,406 uploadAction,407 uploadFiles408 ]409 })410});411var importTCButton = Ext.create('Ext.button.Split',{412 text: "Import Test Cases",413 itemId:"importTCMenu",414 icon: 'images/import.png',415 handler: function(){416 this.showMenu();417 },418 menu: new Ext.menu.Menu({419 items: [420 importAllTCsAction421 ]422 })423});424var renameMenuAction = Ext.create('Ext.Action', {425 text: "Rename",426 itemId: "renameMenu",427 handler: function(widget, event) {428 this.up('menu').scriptEditor.fireEvent('rename');429 }430});431var contextMenu = Ext.create('Ext.menu.Menu', {432 itemId:"treeContext",433 items: [434 //runPip,435 newMenuItem,436 {xtype: 'menuseparator'},437 deleteMenuAction,438 renameMenuAction,439 {xtype: 'menuseparator'},440 copyMenuAction,441 pasteMenuAction442 ],443 listeners:{444 beforeshow: function(me){445 var selection = me.treePanel.getSelectionModel().getSelection();446 if (me.treePanel.getSelectionModel().getSelection().length == 1){447 me.down("#renameMenu").setDisabled(false);448 }449 else{450 me.down("#renameMenu").setDisabled(true);451 }452 var foundRootItem = false;453 selection.forEach(function(node){454 if (node.parentNode.isRoot() == true){455 me.down("#renameMenu").setDisabled(true);456 me.down("#deleteMenu").setDisabled(true);457 me.down("#copyMenu").setDisabled(true);458 if (node.get("fileType")=="libs"){459 me.down("#newFolder").setDisabled(true);460 me.down("#newScript").setDisabled(true);461 }462 var pipReqFilePath = "/"+Ext.util.Cookies.get("username")+"/PipRequirements";463 if(node.get("fullpath").indexOf(pipReqFilePath) == node.get("fullpath").length -pipReqFilePath.length){464 //me.down("#runPip").setVisible(true);465 }466 else{467 //me.down("#runPip").setVisible(false);468 }469 foundRootItem = true;470 }471 });472 if (foundRootItem == false){473 me.down("#newFolder").setDisabled(false);474 me.down("#newScript").setDisabled(false);475 me.down("#renameMenu").setDisabled(false);476 me.down("#deleteMenu").setDisabled(false);477 me.down("#copyMenu").setDisabled(false);478 }479 //480 }481 }482});483Ext.define('Redwood.view.ScriptBrowser', {484 extend: 'Ext.panel.Panel',485 alias: 'widget.scriptBrowser',486 id: "ScriptBrowser",487 title: "Scripts",488 layout: 'fit',489 listeners:{490 show: function(panel){491 var tab = panel.down("#scriptstab").getActiveTab();492 if(tab) {493 setTimeout(function(){tab.focus();},100);494 }495 },496 afterrender:function(){497 this.setHeight(this.findParentByType('viewport').getHeight()-27);498 }499 },500 initComponent: function () {501 var scriptEditor = this;502 var scriptView = Ext.create('Ext.Panel', {503 layout: 'border',504 items: [505 {506 region: "south",507 split: true,508 itemId: "outputPanel",509 id: "scriptOutputPanel",510 xtype: "panel",511 height: 200,512 collapseDirection:"down",513 collapsible: true,514 readOnly: true,515 title: "Output",516 collapsed: true,517 layout: 'fit',518 autoScroll:true,519 items:{520 xtype: "box",521 itemId: "compileOutput",522 anchor: '100%',523 listeners:{524 added: function(){525 //console.log("tes")526 }527 }528 //readOnly: true,529 //grow: true,530 //bodyPadding: 0,531 //border: false,532 //labelStyle: 'white-space: nowrap;',533 //fieldStyle:"border:none 0px black;background-image:none"534 }535 },536 {537 region: 'west',538 split:true,539 xtype: 'treepanel',540 collapseDirection: "left",541 collapsible: true,542 title: 'Scripts',543 multiSelect: true,544 rootVisible: false,545 id:"scriptsTree",546 store: Ext.data.StoreManager.lookup('Scripts'),547 width: 150,548 focused: false,549 viewConfig: {550 markDirty: false,551 stripeRows: true,552 preserveScrollOnRefresh:true,553 onRowDeselect: function(rowIdx){554 this.removeRowCls(rowIdx,"x-redwood-tree-unfocused");555 this.removeRowCls(rowIdx, this.selectedItemCls);556 this.removeRowCls(rowIdx, this.focusedItemCls);557 },558 listeners: {559 itemcontextmenu: function(view, rec, node, index, e) {560 e.stopEvent();561 view.getSelectionModel().select(rec);562 contextMenu.treePanel = view;563 contextMenu.scriptEditor = scriptEditor;564 contextMenu.showAt(e.getXY());565 return false;566 }567 }568 },569 listeners: {570 afterrender: function(me){571 me.el.on("click",function(){572 me.getView().focus();573 });574 },575 itemdblclick: function(me,record,item,index,evt,eOpts){576 if (record.get("fileType") === "file"){577 scriptEditor.fireEvent('scriptEdit', record);578 }579 else if(record.get("fileType") === "image"){580 scriptEditor.fireEvent('imageEdit', record);581 }582 },583 load: function(){584 this.getSelectionModel().select(this.getRootNode().getChildAt(0));585 },586 itemclick: function(me,record,item,index,evt,eOpts){587 //console.log(evt)588 },589 selectionchange: function(model,selected,eOpts){590 if ((selected.length === 0)||(selected.length > 1)){591 newItemButton.setDisabled(true);592 }else{593 newItemButton.setDisabled(false);594 }595 var foundRootItem = false;596 selected.forEach(function(node){597 if (node.parentNode.isRoot()){598 copyAction.setDisabled(true);599 deleteScriptAction.setDisabled(true);600 if (node.get("fileType") === "libs"){601 newScriptAction.setDisabled(true);602 newGroovyScriptAction.setDisabled(true);603 newJavaScriptAction.setDisabled(true);604 newPythonScriptAction.setDisabled(true);605 newFolderAction.setDisabled(true);606 }607 foundRootItem = true;608 }609 });610 if (foundRootItem === false){611 newScriptAction.setDisabled(false);612 newGroovyScriptAction.setDisabled(false);613 newJavaScriptAction.setDisabled(false);614 newPythonScriptAction.setDisabled(false);615 newFolderAction.setDisabled(false);616 deleteScriptAction.setDisabled(false);617 copyAction.setDisabled(false);618 }619 }620 }621 },622 {623 xtype:'tabpanel',624 itemId: 'scriptstab',625 id:'scriptstab',626 ui: "orange-tab",627 region: 'center',628 defaults:{ autoScroll:true },629 plugins: [630 Ext.create('Ext.ux.TabCloseMenu', {631 }),632 Ext.create('Ext.ux.TabReorderer', {633 })634 ],635 listeners: {636 tabchange: function(tabPanel,newCard,oldCard,eOpts){637 if(newCard.path){638 setTimeout(function(){newCard.focus();},100);639 if(newCard.refreshNeeded == true) {640 newCard.focusArea();641 newCard.refreshNeeded = false;642 }643 var username = Ext.util.Cookies.get('username');644 var project = Ext.util.Cookies.get('project');645 var loc = newCard.path.indexOf(project+"/"+username);646 var urlPath = newCard.path.substring(loc+username.length+project.length+1,newCard.path.length);647 window.history.replaceState("", "", '/index.html?script='+urlPath+"&project="+Ext.util.Cookies.get('project'));648 }649 },650 render: function(me){651 me.el.on("click",function(){652 if ((me.getActiveTab() != null)&&(me.path)){653 me.getActiveTab().focus();654 }655 });656 me.items.on("remove",function(){657 if(me.items.length == 0){658 window.history.replaceState("", "", '/index.html');659 }660 })661 }662 }663 }664 ]665 });666 this.items = [scriptView];667 this.tbar = {668 xtype: 'toolbar',669 dock: 'top',670 items:[newItemButton,saveScriptAction,deleteScriptAction,'-',671 copyAction,pasteAction,'-',terminalAction,672 //recordImageAction,673 "-",674 compileAction,675 "-",676 pushAction,677 pullAction,678 recordStepsAction,679 "-",680 runTCAction,681 //importTCButton,682 "->",683 importAllTCsAction,684 "-",685 findText,686 findPrev,687 findNext,688 caseSensitive,689 regExpression,690 ' ',691 replaceText,692 replaceAction,693 replaceAllAction694 ]695 };696 this.callParent(arguments);697 }...

Full Screen

Full Screen

controllers.js

Source:controllers.js Github

copy

Full Screen

1(function () {2 'use strict';3 var module = angular.module('ScriptBrowser.controllers', [4 'ScriptBrowser.services',5 'angularSpinner',6 'ng-code-mirror',7 'angularResizable',8 'angucomplete-alt'9 ]);10 module.config(['$interpolateProvider', function ($interpolateProvider) {11 $interpolateProvider.startSymbol('{$');12 $interpolateProvider.endSymbol('$}');13 }]);14 module.config(['usSpinnerConfigProvider', function (usSpinnerConfigProvider) {15 usSpinnerConfigProvider.setDefaults({16 color: '#111'17 });18 }]);19 var DatasetController = function ($scope, Dataset) {20 $scope.Dataset = Dataset;21 };22 DatasetController.$inject = [23 '$scope',24 'ScriptBrowser.services.Dataset'25 ];26 module.controller('ScriptBrowser.controllers.DatasetController', DatasetController);27 var ViewController = function ($scope, Dataset, SimilarityGraph, Script, usSpinnerService) {28 $scope.spinnerOptions = {29 radius: 20,30 width: 6,31 length: 10,32 color: "#000000"33 };34 $scope.similarity_graph_data = undefined;35 $scope.script = undefined;36 $scope.focus_node = undefined;37 $scope.load = function(){38 var request = SimilarityGraph.load(Dataset.id);39 if (request) {40 usSpinnerService.spin('vis-spinner');41 request.then(function() {42 usSpinnerService.stop('vis-spinner');43 $scope.similarity_graph_data = SimilarityGraph.data;44 });45 }46 };47 $scope.highlight = function(call){48 var call_name = call.name.replace('.', '-');49 $('.' + call_name).addClass('highlight');50 };51 $scope.remove_highlight = function(){52 $('.highlight').removeClass('highlight');53 };54 $scope.click_node = function(script){55 console.log(script);56 if ($scope.focus_node){57 SimilarityGraph.defocus_node($scope.focus_node);58 }59 $scope.focus_node = script;60 SimilarityGraph.focus_node($scope.focus_node);61 var request = Script.load(script.id);62 if (request) {63 usSpinnerService.spin('code-spinner');64 request.then(function() {65 usSpinnerService.stop('code-spinner');66 $scope.script = Script.data;67 PR.prettyPrint();68 });69 }70 };71 // load the similarity graph72 $scope.load();73 };74 ViewController.$inject = [75 '$scope',76 'ScriptBrowser.services.Dataset',77 'ScriptBrowser.services.SimilarityGraph',78 'ScriptBrowser.services.Script',79 'usSpinnerService'80 ];81 module.controller('ScriptBrowser.controllers.ViewController', ViewController);82 var RelationGraphController = function ($scope, Dataset, RelationGraph, Script, usSpinnerService) {83 $scope.spinnerOptions = {84 radius: 20,85 width: 6,86 length: 10,87 color: "#000000"88 };89 $scope.relation_graph_data = undefined;90 $scope.script = undefined;91 $scope.focus_node = undefined;92 $scope.load = function(){93 var request = RelationGraph.load(Dataset.id);94 if (request) {95 usSpinnerService.spin('vis-spinner');96 request.then(function() {97 usSpinnerService.stop('vis-spinner');98 $scope.relation_graph_data = RelationGraph.data;99 });100 }101 };102 $scope.click_node = function(script){103 console.log(script);104 $scope.focus_node = script;105 var request = Script.load(script.original_id);106 if (request) {107 usSpinnerService.spin('code-spinner');108 request.then(function() {109 usSpinnerService.stop('code-spinner');110 $scope.script = Script.data;111 PR.prettyPrint();112 });113 }114 };115 // load the similarity graph116 $scope.load();117 };118 RelationGraphController.$inject = [119 '$scope',120 'ScriptBrowser.services.Dataset',121 'ScriptBrowser.services.RelationGraph',122 'ScriptBrowser.services.Script',123 'usSpinnerService'124 ];125 module.controller('ScriptBrowser.controllers.RelationGraphController', RelationGraphController);126 var ComparatorController = function ($scope, Dataset, SimilarityPairs, Comparator, usSpinnerService) {127 $scope.spinnerOptions = {128 radius: 20,129 width: 6,130 length: 10,131 color: "#000000"132 };133 $scope.similarity_pairs = undefined;134 $scope.source = undefined;135 $scope.target = undefined;136 $scope.diff = undefined;137 $scope.relative_relation = "U";138 $scope.options = [139 {value: "<", text: "<"},140 {value: "=", text: "="},141 {value: ">", text: ">"},142 {value: "?", text: "?"},143 {value: "U", text: "Undefined"},144 ];145 $scope.load = function(){146 var request = SimilarityPairs.load(Dataset.id, 'cosine', 0.8);147 if (request) {148 usSpinnerService.spin('vis-spinner');149 request.then(function() {150 usSpinnerService.stop('vis-spinner');151 $scope.similarity_pairs = SimilarityPairs.data;152 });153 }154 };155 $scope.option_btn_class = function(option){156 return (option.value == $scope.relative_relation) ? "btn-selected" : "";157 };158 $scope.change_option = function(option){159 $scope.relative_relation = option.value;160 $scope.update_note();161 };162 // load the similarity pairs163 $scope.load();164 $scope.current_pair = undefined;165 $scope.click_pair = function(pair){166 var request = Comparator.load(Dataset.id, pair.source.id, pair.target.id);167 if (request) {168 usSpinnerService.spin('code-spinner');169 request.then(function() {170 usSpinnerService.stop('code-spinner');171 $scope.source = Comparator.data.source;172 $scope.target = Comparator.data.target;173 $scope.diff = Comparator.data.diff;174 $scope.note = Comparator.data.note;175 $scope.relative_relation = Comparator.data.relative_relation;176 $scope.current_pair = pair;177 PR.prettyPrint();178 });179 }180 };181 $scope.highlight_row = function(pair){182 return ($scope.current_pair == pair) ? "highlight-row" : "";183 };184 $scope.update_note = function(){185 var request = Comparator.update_note($scope.source.id, $scope.target.id, $scope.relative_relation, $scope.note);186 if (request) {187 usSpinnerService.spin('note-spinner');188 request.then(function() {189 usSpinnerService.stop('note-spinner');190 });191 }192 };193 };194 ComparatorController.$inject = [195 '$scope',196 'ScriptBrowser.services.Dataset',197 'ScriptBrowser.services.SimilarityPairs',198 'ScriptBrowser.services.Comparator',199 'usSpinnerService'200 ];201 module.controller('ScriptBrowser.controllers.ComparatorController', ComparatorController);202 module.directive('datetimeFormat', function() {203 return {204 require: 'ngModel',205 link: function(scope, element, attrs, ngModelController) {206 ngModelController.$parsers.push(function(data) {207 //convert data from view format to model format208 data = moment.utc(data, "YYYY-MM-DD HH:mm:ss");209 if (data.isValid()) return data.toDate();210 else return undefined;211 });212 ngModelController.$formatters.push(function(data) {213 //convert data from model format to view format214 if (data !== undefined) return moment.utc(data).format("YYYY-MM-DD HH:mm:ss"); //converted215 return data;216 });217 }218 }219 });220 module.directive('whenScrolled', function() {221 return function(scope, element, attr) {222 var raw = element[0];223 var checkBounds = function(evt) {224 if (Math.abs(raw.scrollTop + $(raw).height() - raw.scrollHeight) < 10) {225 scope.$apply(attr.whenScrolled);226 }227 };228 element.bind('scroll load', checkBounds);229 };230 });231 module.directive('ngEnter', function () {232 return function (scope, element, attrs) {233 element.bind("keydown keypress", function (event) {234 if(event.which === 13) {235 scope.$apply(function (){236 scope.$eval(attrs.ngEnter);237 });238 event.preventDefault();239 }240 });241 };242 });...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1Ext.application({2//var APP = newExt.app.Application({3 name: "Redwood",4 appFolder: ".",5 autoCreateViewport: true,6 applyPermissions: function(){7 var mainTab = Ext.ComponentQuery.query('#mainTabPanel')[0];8 if(Ext.util.Cookies.get('role') == "Test Designer"){9 mainTab.remove(mainTab.down("#adminTab"));10 mainTab.down("scriptBrowser").down("#compileBar").hide();11 mainTab.down("scriptBrowser").down("#saveAll").hide();12 mainTab.down("scriptBrowser").down("#push").hide();13 mainTab.down("scriptBrowser").down("#runUnitTest").hide();14 mainTab.down("scriptBrowser").down("#importAllTCs").hide();15 mainTab.down("scriptBrowser").down("#newItemsMenu").hide();16 mainTab.down("scriptBrowser").down("#deleteBar").hide();17 mainTab.down("scriptBrowser").down("#pasteBar").hide();18 mainTab.down("scriptBrowser").down("#copyBar").hide();19 mainTab.down("scriptBrowser").down("#terminal").hide();20 mainTab.down("actions").down("#saveAction").hide();21 mainTab.down("actions").down("#deleteAction").hide();22 mainTab.down("actions").down("#cloneAction").hide();23 mainTab.down("actions").down("#newAction").hide();24 }25 },26 controllers: [27 'Machines','Variables','Users','Scripts','Actions','Projects','RealTimeEvents','TestCases','TestSets','Executions','License','EmailSettings','Hosts','Templates'],28 launch: function(){29 Redwood.app = this;30 Ext.clipboard = {};31 Ext.Ajax.timeout = 300000;32 Ext.override(Ext.data.proxy.Ajax, { timeout: 300000 });33 Ext.data.proxy.JsonP.timeout = 300000;34 this.applyPermissions();35 Ext.uniqueId = function()36 {37 var newDate = new Date;38 var partOne = newDate.getTime();39 var partTwo = 1 + Math.floor((Math.random()*32767));40 var partThree = 1 + Math.floor((Math.random()*32767));41 var id = partOne + '-' + partTwo + '-' + partThree;42 return id;43 };44 Ext.arraysEqual = function(a,b){45 if (a.length != b.length) {46 return false;47 }48 for (var i=0; i<a.length; i++) {49 if (a[i] != b[i]) {50 return false;51 }52 }53 return true;54 };55 Ext.tip.QuickTipManager.init();56 Ext.socket = io.connect('http://'+ document.location.host,{'reconnection delay': 5000});57 Ext.socket.on("reconnecting",function(data){58 Ext.MessageBox.show({59 msg: 'Connection to server lost, attempting to reconnect...',60 progressText: 'Connecting...',61 width:300,62 wait:true,63 waitConfig: {interval:200}64 });65 return;66 //update execution status of TCs that are running67 Ext.data.StoreManager.each(function(store){68 if (store.storeId.indexOf("ExecutionTCs") == -1) return;69 var records = store.query("_id",testCase._id).getAt(0);70 var executionID = store.storeId.replace("ExecutionTCs","");71 records.forEach(function(record){72 for(var propt in testCase){73 if ((propt != "_id")&&(propt != "name")){74 record.set(propt.toString(),Ext.util.Format.htmlEncode(testCase[propt]));75 }76 }77 store.fireEvent("beforesync",{update:[record]});78 })79 });80 });81 Ext.socket.on('connect', function(){82 if (Ext.MessageBox.isVisible()){83 Ext.MessageBox.hide();84 }85 Ext.socket.emit("userConnected",{username:Ext.util.Cookies.get('username')});86 });87 this.getController("RealTimeEvents").startEvents();88 var uri = Ext.Object.fromQueryString(location.search);89 var mainTab = Ext.ComponentQuery.query('#mainTabPanel')[0];90 var event;91 if(uri.project){92 if (Ext.util.Cookies.get('project') != uri.project){93 Ext.util.Cookies.set('project',uri.project);94 window.location.reload(true);95 }96 }97 if(uri.testcase){98 event = Ext.data.StoreManager.lookup('TestCases').on("load",function(store){99 mainTab.setActiveTab(mainTab.down("#testcasesBrowser"));100 var record = store.findRecord("_id",uri.testcase);101 if(record != null){102 Redwood.app.getController("TestCases").onEditTestCase(record);103 store.un(event);104 }105 });106 }107 else if(uri.action){108 event = Ext.data.StoreManager.lookup('Actions').on("load",function(store){109 mainTab.setActiveTab(mainTab.down("#actionsBrowser"));110 var record = store.findRecord("_id",uri.action);111 if(record != null){112 Redwood.app.getController("Actions").onEditAction(record);113 store.un(event);114 }115 });116 }117 else if(uri.execution){118 mainTab.setActiveTab(mainTab.down("#executionsBrowser"));119 event = Ext.data.StoreManager.lookup('Executions').on("load",function(store){120 var record = store.query("_id",uri.execution);121 if(record.length > 0){122 Redwood.app.getController("Executions").onExecutionEdit(uri.execution);123 store.un(event);124 }125 });126 }else if(uri.result){127 mainTab.setActiveTab(mainTab.down("#executionsBrowser"));128 Redwood.app.getController("Executions").openExecutionDetails(uri.result);129 }else if(uri.aggregate){130 mainTab.setActiveTab(mainTab.down("#executionsBrowser"));131 event = Ext.data.StoreManager.lookup('Executions').on("load",function(store){132 Redwood.app.getController("Executions").aggregateReport(uri.aggregate.split(","));133 store.un(event);134 });135 }else if(uri.script){136 mainTab.setActiveTab(mainTab.down("#ScriptBrowser"));137 event = Ext.data.StoreManager.lookup('Scripts').on("load",function(store){138 if(uri.line){139 Redwood.app.getController("Scripts").onScriptEdit(uri.script,parseInt(uri.line)-1);140 }141 else{142 Redwood.app.getController("Scripts").onScriptEdit(uri.script);143 }144 store.un(event);145 });146 }147 window.onbeforeunload = function(){148 console.log("SCRIPT");149 var allScripts = Ext.ComponentQuery.query('codeeditorpanel');150 for (var i=0;i<allScripts.length;i++){151 if (allScripts[i].dirty == true){152 return "You have unsaved changes in one of your scripts.";153 }154 }155 var allActions = Ext.ComponentQuery.query('actionview');156 for (var i=0;i<allActions.length;i++){157 if (allActions[i].dirty == true){158 return "You have unsaved changes in one of your actions.";159 }160 }161 var allTestCases = Ext.ComponentQuery.query('testcaseview');162 for (var i=0;i<allTestCases.length;i++){163 if (allTestCases[i].dirty == true){164 return "You have unsaved changes in one of your test cases.";165 }166 }167 var allExecutions = Ext.ComponentQuery.query('executionview');168 for (var i=0;i<allExecutions.length;i++){169 if (allExecutions[i].dirty == true){170 return "You have unsaved changes in one of your executions.";171 }172 }173 var allTestSets = Ext.ComponentQuery.query('testsetEdit');174 for (var i=0;i<allTestSets.length;i++){175 if (allTestSets[i].dirty == true){176 return "You have unsaved changes in one of your test sets.";177 }178 }179 };180 //Ext.FocusManager.enable();181 }182});183/*184Ext.application({185 name: "Redwood",186 appFolder: "app",187 launch: function () {188 Ext.create('Ext.container.Viewport', {189 layout: 'fit',190 items: [{191 xtype: 'panel',192 title: 'Redwood Automation Framework',193 html: ''194 }]195 });196 }197});...

Full Screen

Full Screen

services.js

Source:services.js Github

copy

Full Screen

1(function () {2 'use strict';3 var module = angular.module('ScriptBrowser.services', [4 'ng.django.urls',5 'ScriptBrowser.bootstrap',6 'ngSanitize'7 ]);8 module.factory('ScriptBrowser.services.Dataset', [9 '$http', 'djangoUrl',10 'ScriptBrowser.bootstrap.dataset',11 function datasetFactory($http, djangoUrl, datasetId) {12 var apiUrl = djangoUrl.reverse('dataset');13 var Dataset = function () {14 this.id = datasetId15 };16 var request = {17 params: {18 id: datasetId19 }20 };21 $http.get(apiUrl, request)22 .success(function (data) {23 angular.extend(Dataset.prototype, data);24 });25 return new Dataset();26 }27 ]);28 //A service for loading similarity graph.29 module.factory('ScriptBrowser.services.SimilarityGraph', [30 '$rootScope', '$http', 'djangoUrl',31 function similarityGraphFactory($rootScope, $http, djangoUrl) {32 var apiUrl = djangoUrl.reverse('similarity-graph');33 var SimilarityGraph = function () {34 var self = this;35 self.data = undefined;36 };37 angular.extend(SimilarityGraph.prototype, {38 focus_node: function(node){39 node.neighbors = node.links;40 },41 defocus_node: function(node){42 if (node.neighbors) node.neighbors = undefined;43 if (node.children) node.children = undefined;44 },45 construct_node_links: function(data){46 var self = this;47 data.nodes.forEach(function(d){48 d.links = [];49 });50 data.links.forEach(function(d){51 var src_node = data.nodes[d.source];52 var tar_node = data.nodes[d.target];53 src_node.links.push(tar_node);54 tar_node.links.push(src_node);55 });56 return data;57 },58 load: function (dataset) {59 var self = this;60 var request = {61 params: {62 id: dataset63 }64 };65 return $http.get(apiUrl, request)66 .success(function (data) {67 self.data = self.construct_node_links(data);68 });69 }70 });71 return new SimilarityGraph();72 }73 ]);74 //A service for loading relation graph.75 module.factory('ScriptBrowser.services.RelationGraph', [76 '$rootScope', '$http', 'djangoUrl',77 function relationGraphFactory($rootScope, $http, djangoUrl) {78 var RelationGraph = function () {79 var self = this;80 self.data = undefined;81 };82 angular.extend(RelationGraph.prototype, {83 construct_node_links: function(data){84 var self = this;85 /*data.nodes.forEach(function(d){86 // d.links = [];87 //d.id = "node_" + d.id;88 });89 data.links.forEach(function(d){90 var src_node = data.nodes[d.source];91 var tar_node = data.nodes[d.target];92 src_node.links.push(tar_node);93 tar_node.links.push(src_node);(94 // d.source = "node_" + d.src_script;95 // d.target = "node_" + d.tar_script;96 });*/97 return data;98 },99 load: function (dataset) {100 var self = this;101 var apiUrl = djangoUrl.reverse('relation-graph', {dataset_id: dataset});102 return $http.get(apiUrl)103 .success(function (data) {104 self.data = self.construct_node_links(data);105 });106 }107 });108 return new RelationGraph();109 }110 ]);111 //A service for loading similarity pairs.112 module.factory('ScriptBrowser.services.SimilarityPairs', [113 '$rootScope', '$http', 'djangoUrl',114 function similarityGraphFactory($rootScope, $http, djangoUrl) {115 var apiUrl = djangoUrl.reverse('similarity-graph');116 var SimilarityPairs = function () {117 var self = this;118 self.data = undefined;119 };120 angular.extend(SimilarityPairs.prototype, {121 convert_links: function(data){122 var self = this;123 data.links.forEach(function(d){124 d.source = data.nodes[d.source];125 d.target = data.nodes[d.target];126 });127 return data.links;128 },129 load: function (dataset, metric, threshold) {130 var self = this;131 var request = {132 params: {133 id: dataset134 }135 };136 if (metric) request.params.metric = metric;137 if (threshold) request.params.threshold = threshold;138 return $http.get(apiUrl, request)139 .success(function (data) {140 self.data = self.convert_links(data);141 });142 }143 });144 return new SimilarityPairs();145 }146 ]);147 //A service for loading script contents.148 module.factory('ScriptBrowser.services.Script', [149 '$http', 'djangoUrl',150 function scriptFactory($http, djangoUrl) {151 var apiUrl = djangoUrl.reverse('script');152 var Script = function () {153 var self = this;154 self.data = undefined;155 };156 angular.extend(Script.prototype, {157 load: function (script_id) {158 var self = this;159 var request = {160 params: {161 id: script_id162 }163 };164 return $http.get(apiUrl, request)165 .success(function (data) {166 self.data = data;167 });168 }169 });170 return new Script();171 }172 ]);173 //A service for loading script comparator.174 module.factory('ScriptBrowser.services.Comparator', [175 '$http', 'djangoUrl',176 function scriptFactory($http, djangoUrl) {177 var apiUrl = djangoUrl.reverse('comparator');178 var Comparator = function () {179 var self = this;180 self.data = undefined;181 };182 angular.extend(Comparator.prototype, {183 load: function (dataset_id, src_id, tar_id) {184 var self = this;185 var request = {186 params: {187 id: dataset_id,188 src_id: src_id,189 tar_id: tar_id190 }191 };192 return $http.get(apiUrl, request)193 .success(function (data) {194 self.data = data;195 });196 },197 update_note: function(src_id, tar_id, relative_relation, note){198 var self = this;199 var request = {200 src_script: src_id,201 tar_script: tar_id,202 relative_relation: relative_relation,203 note: note204 };205 if (self.relative_relation == relative_relation && note == self.note) {206 return false;207 }208 else {209 return $http.post(apiUrl, request)210 .success(function (data) {211 self.note = data.note;212 });213 }214 }215 });216 return new Comparator();217 }218 ]);...

Full Screen

Full Screen

launcher.spec.js

Source:launcher.spec.js Github

copy

Full Screen

1'use strict'2const di = require('di')3const events = require('../../lib/events')4const launcher = require('../../lib/launcher')5const createMockTimer = require('./mocks/timer')6// promise mock7const stubPromise = (obj, method, stubAction) => {8 const promise = new Promise((resolve) => {9 obj[method].resolve = resolve10 })11 sinon.stub(obj, method).callsFake(() => {12 if (stubAction) stubAction()13 return promise14 })15}16function FakeBrowser (id, name, baseBrowserDecorator) {17 this.id = id18 this.name = name19 this.DEFAULT_CMD = {20 linux: '/script',21 darwin: '/script',22 win32: 'script.exe'23 }24 this.ENV_CMD = 'SCRIPT_BIN'25 baseBrowserDecorator(this)26 FakeBrowser._instances.push(this)27 sinon.stub(this, 'start').callsFake(() => {28 this.state = this.STATE_BEING_CAPTURED29 this._done()30 })31 stubPromise(this, 'forceKill')32 sinon.stub(this, 'restart')33}34function ScriptBrowser (id, name, baseBrowserDecorator) {35 this.id = id36 this.name = name37 this.DEFAULT_CMD = {38 linux: '/script',39 darwin: '/script',40 win32: 'script.exe'41 }42 this.ENV_CMD = 'SCRIPT_BIN'43 baseBrowserDecorator(this)44 ScriptBrowser._instances.push(this)45 sinon.stub(this, 'start').callsFake(() => {46 this.state = this.STATE_BEING_CAPTURED47 this._done()48 })49 stubPromise(this, 'forceKill')50 sinon.stub(this, 'restart')51}52describe('launcher', () => {53 // mock out id generator54 let lastGeneratedId = null55 launcher.Launcher.generateId = () => ++lastGeneratedId56 beforeEach(() => {57 lastGeneratedId = 058 FakeBrowser._instances = []59 ScriptBrowser._instances = []60 })61 describe('Launcher', () => {62 let emitter63 let server64 let config65 let l66 beforeEach(() => {67 emitter = new events.EventEmitter()68 server = { loadErrors: [] }69 config = {70 captureTimeout: 0,71 protocol: 'http:',72 hostname: 'localhost',73 port: 1234,74 urlRoot: '/root/'75 }76 const injector = new di.Injector([{77 'launcher:Fake': ['type', FakeBrowser],78 'launcher:Script': ['type', ScriptBrowser],79 server: ['value', server],80 emitter: ['value', emitter],81 config: ['value', config],82 timer: ['factory', createMockTimer]83 }])84 l = new launcher.Launcher(server, emitter, injector)85 })86 describe('launch', () => {87 it('should inject and start all browsers', (done) => {88 l.launch(['Fake'], 1)89 const browser = FakeBrowser._instances.pop()90 l.jobs.on('end', () => {91 expect(browser.start).to.have.been.calledWith('http://localhost:1234/root/')92 expect(browser.id).to.equal(lastGeneratedId)93 expect(browser.name).to.equal('Fake')94 done()95 })96 })97 describe('with upstream proxy settings', () => {98 beforeEach(() => {99 emitter = new events.EventEmitter()100 server = { loadErrors: [] }101 config = {102 captureTimeout: 0,103 protocol: 'http:',104 hostname: 'localhost',105 port: 1234,106 urlRoot: '/root/',107 upstreamProxy: {108 path: '/__proxy__/',109 hostname: 'proxy',110 port: '5678',111 protocol: 'https:'112 }113 }114 const injector = new di.Injector([{115 'launcher:Fake': ['type', FakeBrowser],116 'launcher:Script': ['type', ScriptBrowser],117 server: ['value', server],118 emitter: ['value', emitter],119 config: ['value', config],120 timer: ['factory', createMockTimer]121 }])122 l = new launcher.Launcher(server, emitter, injector)123 })124 it('should inject and start all browsers', (done) => {125 l.launch(['Fake'], 1)126 const browser = FakeBrowser._instances.pop()127 l.jobs.on('end', () => {128 expect(browser.start).to.have.been.calledWith('https://proxy:5678/__proxy__/root/')129 expect(browser.id).to.equal(lastGeneratedId)130 expect(browser.name).to.equal('Fake')131 done()132 })133 })134 })135 it('should not start when server has load errors', (done) => {136 server.loadErrors = ['error']137 l.launch(['Fake'], 1)138 l.jobs.on('end', () => {139 expect(FakeBrowser._instances).to.be.empty140 done()141 })142 })143 it('should allow launching a script', (done) => {144 l.launch(['/usr/local/bin/special-browser'], 1)145 const script = ScriptBrowser._instances.pop()146 l.jobs.on('end', () => {147 expect(script.start).to.have.been.calledWith('http://localhost:1234/root/')148 expect(script.name).to.equal('/usr/local/bin/special-browser')149 done()150 })151 })152 it('should use the non default host', (done) => {153 config.hostname = 'whatever'154 l.launch(['Fake'], 1)155 const browser = FakeBrowser._instances.pop()156 l.jobs.on('end', () => {157 expect(browser.start).to.have.been.calledWith('http://whatever:1234/root/')158 done()159 })160 })161 })162 describe('restart', () => {163 it('should restart the browser', () => {164 l.launch(['Fake'], 1)165 const browser = FakeBrowser._instances.pop()166 expect(l.restart(lastGeneratedId)).to.equal(true)167 expect(browser.restart).to.have.been.called168 })169 it('should return false if the browser was not launched by launcher (manual)', () => {170 l.launch([], 1)171 expect(l.restart('manual-id')).to.equal(false)172 })173 })174 describe('kill', () => {175 it('should kill browser with given id', (done) => {176 l.launch(['Fake'], 1)177 const browser = FakeBrowser._instances.pop()178 l.kill(browser.id, done)179 expect(browser.forceKill).to.have.been.called180 browser.forceKill.resolve()181 })182 it('should return false if browser does not exist, but still resolve the callback', (done) => {183 l.launch(['Fake'], 1)184 const browser = FakeBrowser._instances.pop()185 expect(l.kill('weird-id', done)).to.equal(false)186 expect(browser.forceKill).not.to.have.been.called187 })188 it('should not require a callback', (done) => {189 l.launch(['Fake'], 1)190 FakeBrowser._instances.pop()191 l.kill('weird-id')192 process.nextTick(done)193 })194 })195 describe('killAll', () => {196 it('should kill all running processe', () => {197 l.launch(['Fake', 'Fake'], 1)198 l.killAll()199 let browser = FakeBrowser._instances.pop()200 expect(browser.forceKill).to.have.been.called201 browser = FakeBrowser._instances.pop()202 expect(browser.forceKill).to.have.been.called203 })204 it('should call callback when all processes killed', (done) => {205 const exitSpy = sinon.spy()206 l.launch(['Fake', 'Fake'], 1)207 l.killAll(exitSpy)208 expect(exitSpy).not.to.have.been.called209 // finish the first browser210 let browser = FakeBrowser._instances.pop()211 browser.forceKill.resolve()212 setImmediate(() => {213 expect(exitSpy).not.to.have.been.called214 // finish the second browser215 browser = FakeBrowser._instances.pop()216 browser.forceKill.resolve()217 setImmediate(() => {218 expect(exitSpy).to.have.been.called219 done()220 })221 })222 })223 it('should call callback even if no browsers lanunched', (done) => {224 l.killAll(done)225 })226 })227 describe('areAllCaptured', () => {228 it('should return true if only if all browsers captured', () => {229 l._browsers = [{230 isCaptured: () => true231 }, {232 isCaptured: () => false233 }]234 expect(l.areAllCaptured()).to.be.equal(false)235 l._browsers = [{236 isCaptured: () => true237 }, {238 isCaptured: () => true239 }]240 expect(l.areAllCaptured()).to.be.equal(true)241 })242 })243 describe('markCaptured', () => {244 it('should not fail if an un-launched browser attaches', () => {245 expect(() => l.markCaptured('not-a-thing')).to.not.throw()246 })247 })248 describe('onExit', () => {249 it('should kill all browsers', (done) => {250 l.launch(['Fake', 'Fake'], 1)251 emitter.emitAsync('exit').then(done)252 let browser = FakeBrowser._instances.pop()253 browser.forceKill.resolve()254 browser = FakeBrowser._instances.pop()255 browser.forceKill.resolve()256 })257 })258 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1var ScriptBrowser = function(baseBrowserDecorator, script) {2 baseBrowserDecorator(this);3 this.name = script;4 this._getCommand = function() {5 return script;6 };7};8ScriptBrowser.$inject = ['baseBrowserDecorator', 'name'];9// PUBLISH DI MODULE10module.exports = {11 'launcher:Script': ['type', ScriptBrowser]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var allTestFiles = [];2var TEST_REGEXP = /(spec|test)\.js$/i;3Object.keys(window.__karma__.files).forEach(function(file) {4 if (TEST_REGEXP.test(file)) {5 var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');6 allTestFiles.push(normalizedTestModule);7 }8});9require.config({10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var ScriptBrowser = require('script-browser');2var ScriptBrowser = require('script-browser');3var ScriptBrowser = require('script-browser');4var ScriptBrowser = require('script-browser');5var ScriptBrowser = require('script-browser');6var ScriptBrowser = require('script-browser');7var ScriptBrowser = require('script-browser');8var ScriptBrowser = require('script-browser');9var ScriptBrowser = require('script-browser');10var ScriptBrowser = require('script-browser');11var ScriptBrowser = require('script-browser');12var ScriptBrowser = require('script-browser');13var ScriptBrowser = require('script-browser');14var ScriptBrowser = require('script-browser');15var scriptBrowser = new ScriptBrowser(__dirname

Full Screen

Using AI Code Generation

copy

Full Screen

1var scriptBrowser = new ScriptBrowser([2]);3scriptBrowser.loadScripts();4var scriptBrowser = new ScriptBrowser([5]);6scriptBrowser.loadScripts();7var scriptLoader = new ScriptLoader([8]);9scriptLoader.loadScripts();10var scriptLoader = new ScriptLoader([11]);12scriptLoader.loadScripts();13var scriptLoader = new ScriptLoader([14]);15scriptLoader.loadScripts();16var scriptBrowser = new ScriptBrowser([17]);18scriptBrowser.loadScripts();19var scriptLoader = new ScriptLoader([20]);21scriptLoader.loadScripts();

Full Screen

Using AI Code Generation

copy

Full Screen

1var scriptBrowser = new ScriptBrowser();2scriptBrowser.loadScript('var a = 1;');3scriptBrowser.loadScript(function () {4 var a = 1;5});6scriptBrowser.loadScript([7 'var a = 1;',8 function () {9 var a = 1;10 }11]);12});13});14scriptBrowser.loadScript('var a = 1;', function () {15});16scriptBrowser.loadScript(function () {17 var a = 1;18}, function () {19});20scriptBrowser.loadScript([21 'var a = 1;',22 function () {23 var a = 1;24 }25], function () {26});27}, function (error) {28});29}, function (error) {30});31scriptBrowser.loadScript('var

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Karma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful