diff --git a/plugins/ice-repo/ice-repo.js b/plugins/ice-repo/ice-repo.js index 360b5a4..7a3c412 100644 --- a/plugins/ice-repo/ice-repo.js +++ b/plugins/ice-repo/ice-repo.js @@ -1 +1,336 @@ -function diffUsingJS(e,t,n,r){var i=difflib.stringAsLines(e),s=difflib.stringAsLines(t),o=new difflib.SequenceMatcher(i,s),u=o.get_opcodes(),a=get("row"+rowID+"Content","parent");while(a.firstChild)a.removeChild(a.firstChild);var f="";f=f?f:null,a.appendChild(diffview.buildView({baseTextLines:i,newTextLines:s,opcodes:u,baseTextName:n,newTextName:r,contextSize:f,viewType:1}))}top.selRowArray=[],top.selRepoDirArray=[],top.selActionArray=[],doRepo=function(e){document.showRepo.repo.value=e,document.showRepo.submit()},updateSelection=function(e,t,n,r){e.checked?(top.selRowArray.push(t),top.selRepoDirArray.push(n),top.selActionArray.push(r)):(arrayIndex=top.selRowArray.indexOf(t),top.selRowArray.splice(arrayIndex,1),top.selRepoDirArray.splice(arrayIndex,1),top.selActionArray.splice(arrayIndex,1))},getContent=function(e,t){if("undefined"==typeof overOption||!overOption){if("undefined"==typeof lastRow||lastRow!=e||get("row"+e+"Content").innerHTML==""){for(i=1;i<=rowID;i++)get("row"+i+"Content").innerHTML="",get("row"+i+"Content").style.display="none";repo=top.repo+"/"+t,dir=top.path+"/"+t,document.fcForm.rowID.value=e,document.fcForm.repo.value=repo,document.fcForm.dir.value=dir,document.fcForm.action.value="view",document.fcForm.submit()}else get("row"+e+"Content").innerHTML="",get("row"+e+"Content").style.display="none";lastRow=e}},commitChanges=function(){if(top.selRowArray.length>0)if(document.fcForm.title.value!="Title..."&&document.fcForm.message.value!="Message..."){get("blackMask","top").style.display="block",top.selRowValue="",top.selDirValue="",top.selRepoValue="",top.selActionValue="";for(i=0;i0?getData():document.fcForm.submit())}):(removeFirstArrayItems(),rowIDArray.length>0?getData():document.fcForm.submit())},sendData=function(e,t){repo.read("master",filePath,function(n,r){dirContent=document.fcForm.fileContents.value,repoContent=r,diffUsingJS(dirContent,repoContent,e,t),get("row"+rowID+"Content","parent").style.display="inline-block"})},removeFirstArrayItems=function(){rowIDArray.splice(0,1),repoArray.splice(0,1),dirArray.splice(0,1),actionArray.splice(0,1)},hideRow=function(e){top.rowCount--,updateInfo("parent"),get("checkbox"+e,"parent").checked=!1,parent.updateSelection(get("checkbox"+e,"parent")),get("row"+e,"parent").style.display=get("row"+e+"Content","parent").style.display="none"},ffAddOrUpdate=function(e,t,n){repo.write("master",t,document.fcForm["fileContents"+e].value,parent.document.fcForm.title.value+"\n\n"+parent.document.fcForm.message.value,function(n){n?alert("Sorry, there was an error adding "+t):(removeFirstArrayItems(),hideRow(e),top.newCount--,rowIDArray.length>0?startProcess():get("blackMask","top").style.display="none")})},ffDelete=function(e,t,n){repo.remove("master",t,function(n){n?alert("Sorry, there was an error deleting "+t):(removeFirstArrayItems(),hideRow(e),top.deletedCount--,rowIDArray.length>0?startProcess():get("blackMask","top").style.display="none")})},startProcess=function(){if(actionArray[0]=="changed"||actionArray[0]=="new")actionArray[0]=="changed"&&(repoLoc=repoArray[0].replace(repoUser+"/"+repoName+"/","")),actionArray[0]=="new"&&(repoLoc=dirArray[0].replace(top.path,"")),ffAddOrUpdate(rowIDArray[0],repoLoc,actionArray[0]);actionArray[0]=="deleted"&&(repoLoc=repoArray[0].replace(repoUser+"/"+repoName+"/",""),ffDelete(rowIDArray[0],repoLoc,actionArray[0]))},get=function(e,t){return t?window[t].document.getElementById(e):document.getElementById(e)},updateInfo=function(e){get("infoPane",e).innerHTML="INFO:

"+top.rowCount+" files

"+top.changedCount+" changed
"+top.newCount+" new
"+top.deletedCount+" deleted"},gitCommand=function(e,t){if(e=="repo.show"){userRepo=t.split("@")[0].split("/"),dir=t.split("@")[1];var n=github.getRepo(userRepo[0],userRepo[1]);rowID=0,n.getTree("master?recursive=true",function(e,t){for(i=0;i",r+="',r+="
"+dirListArray[i],r+="
Delete from server

",r+="",r+="",top.rowCount++,top.newCount++):dirTypeArray[i]=="file"&&dirSHAArray[i]!=repoSHAArray[repoArrayPos]&&(rowID++,sE=ext=="folder"?' style="cursor: default"':"",cE=ext!="folder"?' onClick="getContent('+rowID+",'"+dirListArray[i]+"')\"":"",gE='onClick="pullContent('+rowID+",'"+top.path+"/"+dirListArray[i]+"','"+dirListArray[i]+"','changed')\"",n+="
",n+="',n+="
"+dirListArray[i],n+="
Pull from Github

",n+="
",n+="",top.rowCount++,top.changedCount++);for(i=0;irepoListArray[i].lastIndexOf(".")?"folder":repoListArray[i].substr(repoListArray[i].lastIndexOf(".")+1),dirArrayPos=="-1"&&(rowID++,sE=ext=="folder"?' style="cursor: default"':"",cE=ext!="folder"?' onClick="getContent('+rowID+",'"+repoListArray[i]+"')\"":"",gE='onClick="pullContent('+rowID+",'"+top.path+"/"+repoListArray[i]+"','"+repoListArray[i]+"','deleted')\"",s+="
",s+="',s+="
"+repoListArray[i],s+="
Pull from Github

",s+="
",s+="",top.rowCount++,top.deletedCount++);n="CHANGED FILES:

"+n,r="NEW FILES:

"+r,s="DELETED FILES:

"+s,get("compareList").innerHTML=n+"

"+r+"

"+s,updateInfo(),get("blackMask","top").style.display="none"})}} \ No newline at end of file +top.selRowArray = []; +top.selRepoDirArray = []; +top.selActionArray = []; +top.filetypesArray = ['coffee','css','gif','htm','html','jpg','jpeg','js','less','php','png','rb','rbx','rhtml','ruby','txt','zip']; + +doRepo = function(repo) { + document.showRepo.repo.value = repo; + document.showRepo.submit(); +} + +updateSelection = function(elem,row,repoDir,action) { + if (elem.checked) { + top.selRowArray.push(row); + top.selRepoDirArray.push(repoDir); + top.selActionArray.push(action); + } else { + arrayIndex = top.selRowArray.indexOf(row); + top.selRowArray.splice(arrayIndex,1); + top.selRepoDirArray.splice(arrayIndex,1); + top.selActionArray.splice(arrayIndex,1); + }; +} + +getContent = function(thisRow,path) { + if("undefined" == typeof overOption || !overOption) { + if ("undefined" == typeof lastRow || lastRow!=thisRow || get('row'+thisRow+'Content').innerHTML=="") { + for (i=1;i<=rowID;i++) { + get('row'+i+'Content').innerHTML = ""; + get('row'+i+'Content').style.display = "none"; + } + repo = top.repo + "/" + path; + dir = top.path + "/" + path; + document.fcForm.rowID.value = thisRow; + document.fcForm.repo.value = repo; + document.fcForm.dir.value = dir; + document.fcForm.action.value = "view"; + document.fcForm.submit(); + } else { + get('row'+thisRow+'Content').innerHTML = ""; + get('row'+thisRow+'Content').style.display = "none"; + } + lastRow = thisRow; + } +} + +commitChanges = function() { + if(top.selRowArray.length>0) { + if (document.fcForm.title.value!="Title..." && document.fcForm.message.value!="Message...") { + get('blackMask','top').style.display = "block"; + top.selRowValue = ""; + top.selDirValue = ""; + top.selRepoValue = ""; + top.selActionValue = ""; + for (i=0;i0 ? getData() : document.fcForm.submit(); + } else { + alert('Sorry, there was an error reading '+repoArray[0]); + } + }); + } else { + removeFirstArrayItems(); + rowIDArray.length>0 ? getData() : document.fcForm.submit(); + } +} + +sendData = function(baseTextName,newTextName) { + repo.read('master', filePath, function(err, data) { + dirContent = document.fcForm.fileContents.value; + repoContent = data; + diffUsingJS(dirContent,repoContent,baseTextName,newTextName); + get("row"+rowID+"Content","parent").style.display = "inline-block"; + }); +} + +removeFirstArrayItems = function() { + rowIDArray.splice(0,1); + repoArray.splice(0,1); + dirArray.splice(0,1); + actionArray.splice(0,1); +} + +hideRow = function(row) { + top.rowCount--; + updateInfo('parent'); + get('checkbox'+row,'parent').checked=false; + parent.updateSelection(get('checkbox'+row,'parent')); + get('row'+row,'parent').style.display = get('row'+row+'Content','parent').style.display = "none"; +} + +function diffUsingJS (dirContent,repoContent,baseTextName,newTextName) { + var base = difflib.stringAsLines(dirContent); + var newtxt = difflib.stringAsLines(repoContent); + var sm = new difflib.SequenceMatcher(base, newtxt); + var opcodes = sm.get_opcodes(); + var diffoutputdiv = get("row"+rowID+"Content","parent"); + while (diffoutputdiv.firstChild) diffoutputdiv.removeChild(diffoutputdiv.firstChild); + var contextSize = ""; // optional + contextSize = contextSize ? contextSize : null; + diffoutputdiv.appendChild( + diffview.buildView( + { + baseTextLines:base, + newTextLines:newtxt, + opcodes:opcodes, + baseTextName:baseTextName, + newTextName:newTextName, + contextSize:contextSize, + viewType: 1 // 0 = side by side, 1 = inline + } + ) + ) +} + +// Add or Update files... +ffAddOrUpdate = function(row,gitRepo,action) { + repo.write('master', gitRepo, document.fcForm['fileContents'+row].value,parent.document.fcForm.title.value+ '\n\n'+parent.document.fcForm.message.value, function(err) { + if(!err) { + removeFirstArrayItems(); + hideRow(row); + top.newCount--; + rowIDArray.length>0 ? startProcess() : get('blackMask','top').style.display = "none"; + } else { + alert('Sorry, there was an error adding '+gitRepo); + } + }); +} +// Delete files... +ffDelete = function(row,gitRepo,action) { + repo.remove('master', gitRepo, function(err) { + if(!err) { + removeFirstArrayItems(); + hideRow(row); + top.deletedCount--; + rowIDArray.length>0 ? startProcess() : get('blackMask','top').style.display = "none"; + } else { + alert('Sorry, there was an error deleting '+gitRepo); + } + }); +} + +startProcess = function() { + if(actionArray[0]=="changed"||actionArray[0]=="new") { + if(actionArray[0]=="changed") {repoLoc = repoArray[0].replace(repoUser+"/"+repoName+"/","")} + if(actionArray[0]=="new") {repoLoc = dirArray[0].replace(top.path,'')} + ffAddOrUpdate(rowIDArray[0],repoLoc,actionArray[0]); + } + if(actionArray[0]=="deleted") { + repoLoc = repoArray[0].replace(repoUser+"/"+repoName+"/",""); + ffDelete(rowIDArray[0],repoLoc,actionArray[0]); + } +} + +get = function(elem,context) { + return context ? window[context].document.getElementById(elem) : document.getElementById(elem); +} + +updateInfo = function(context) { + get('infoPane',context).innerHTML = "INFO:

"+top.rowCount+" files

"+top.changedCount+" changed
"+top.newCount+" new
"+top.deletedCount+" deleted"; +} + +gitCommand = function(comm,value) { + if (comm=="repo.show") { + userRepo = value.split("@")[0].split("/"); + dir = value.split("@")[1]; + var repo = github.getRepo(userRepo[0],userRepo[1]); + rowID = 0; + repo.getTree('master?recursive=true', function(err, tree) { + for (i=0;i"; + n += ""; + if (ext != 'folder' && top.filetypesArray.indexOf(ext)==-1) {ext = 'file'}; + n += "
"+dirListArray[i]; + n += "
Delete from server

"; + n += ""; + + n += ""; + top.rowCount++; + top.newCount++; + + } else if (dirTypeArray[i] == "file" && dirSHAArray[i] != repoSHAArray[repoArrayPos]) { + rowID++; + sE = ext == 'folder' ? ' style="cursor: default"' : ''; + cE = ext != 'folder' ? ' onClick="getContent('+rowID+',\''+dirListArray[i]+'\')"' : ''; + gE = 'onClick="pullContent('+rowID+',\''+top.path+'/'+dirListArray[i]+'\',\''+dirListArray[i]+'\',\'changed\')"'; + + c += "
"; + c += ""; + if (ext != 'folder' && top.filetypesArray.indexOf(ext)==-1) {ext = 'file'}; + c += "
"+dirListArray[i]; + c += "
Pull from Github

"; + c += "
"; + + c += ""; + top.rowCount++; + top.changedCount++; + } + } + + for (i=0;i repoListArray[i].lastIndexOf('.') + ? "folder" + : repoListArray[i].substr(repoListArray[i].lastIndexOf('.')+1); + if (dirArrayPos == "-1") { + rowID++; + sE = ext == 'folder' ? ' style="cursor: default"' : ''; + cE = ext != 'folder' ? ' onClick="getContent('+rowID+',\''+repoListArray[i]+'\')"' : ''; + gE = 'onClick="pullContent('+rowID+',\''+top.path+'/'+repoListArray[i]+'\',\''+repoListArray[i]+'\',\'deleted\')"'; + + d += "
"; + d += ""; + if (ext != 'folder' && top.filetypesArray.indexOf(ext)==-1) {ext = 'file'}; + d += "
"+repoListArray[i]; + d += "
Pull from Github

"; + d += "
"; + + d += ""; + top.rowCount++; + top.deletedCount++; + } + } + + c = "CHANGED FILES:

"+c; + n = "NEW FILES:

"+n; + d = "DELETED FILES:

"+d + + get('compareList').innerHTML = c+"

"+n+"

"+d; + updateInfo(); + get('blackMask','top').style.display='none'; + } + ) + } +} \ No newline at end of file