mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
added ability to upload file to gists on github thru menu
This commit is contained in:
parent
9c664055be
commit
71919aa206
6 changed files with 116 additions and 83 deletions
|
|
@ -160,6 +160,8 @@ Added dropbox_id option.
|
|||
|
||||
* Added confirmation before (not real) deleting file.
|
||||
|
||||
* Added ability to upload file to gists on github thru menu.
|
||||
|
||||
|
||||
2012.10.01, Version 0.1.7
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ var loadModule = function(pParams){
|
|||
var lSlash = lName.indexOf('/');
|
||||
if(lSlash > 0){
|
||||
var lAfterSlash = lName.substr(lSlash);
|
||||
lName = lName.replace(lAfterSlash, '');
|
||||
lName = Util.removeStr(lName, lAfterSlash);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,11 +103,9 @@ var loadModule = function(pParams){
|
|||
|
||||
return DOM.jsload(cloudcmd.LIBDIRCLIENT + lPath, lFunc ||
|
||||
function(){
|
||||
cloudcmd[lName].init(pArg);
|
||||
Util.exec(cloudcmd[lName].init, pArg);
|
||||
});
|
||||
};
|
||||
else
|
||||
cloudcmd[lName + lPath];
|
||||
};
|
||||
|
||||
CloudClient.GoogleAnalytics = function(){
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ var CloudCommander, Util, DOM, CloudFunc, CodeMirror;
|
|||
lA = lA.href;
|
||||
|
||||
/* убираем адрес хоста*/
|
||||
lA = lA.replace(cloudcmd.HOST, '');
|
||||
lA = Util.removeStr(lA, cloudcmd.HOST);
|
||||
|
||||
/* checking is this link is to directory */
|
||||
var lSize = DOM.getByClass('size', lCurrentFile);
|
||||
|
|
@ -138,15 +138,12 @@ var CloudCommander, Util, DOM, CloudFunc, CodeMirror;
|
|||
* not html data
|
||||
*/
|
||||
if (lSize === '<dir>'){
|
||||
var lIndexOfNOJS = lA.indexOf(CloudFunc.NOJS);
|
||||
if (lIndexOfNOJS === CloudFunc.FS.length){
|
||||
lA = lA.replace(CloudFunc.NOJS, '');
|
||||
/* when folder view
|
||||
* is no need to edit
|
||||
* data
|
||||
*/
|
||||
ReadOnly = true;
|
||||
}
|
||||
lA = Util.removeStr(lA, CloudFunc.NOJS);
|
||||
/* when folder view
|
||||
* is no need to edit
|
||||
* data
|
||||
*/
|
||||
ReadOnly = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,33 @@ var CloudCommander, Util, DOM, CloudFunc, $;
|
|||
items: {
|
||||
'upload_to_gist': {name: 'to Gist',
|
||||
callback: function(key, opt){
|
||||
console.log('Upload To Gist');
|
||||
var lCurrent = DOM.getCurrentFile(),
|
||||
lA = DOM.getCurrentLink(lCurrent).href,
|
||||
lName = DOM.getCurrentName(lCurrent);
|
||||
/* убираем адрес хоста*/
|
||||
lA = Util.removeStr(lA, cloudcmd.HOST);
|
||||
lA = Util.removeStr(lA, CloudFunc.NOJS);
|
||||
|
||||
DOM.ajax({
|
||||
url : lA,
|
||||
error : DOM.Images.showError,
|
||||
success : function(data, textStatus, jqXHR){
|
||||
if( Util.isObject(data) )
|
||||
data = JSON.stringify(data, null, 4);
|
||||
|
||||
var lGitHub = cloudcmd.GitHub;
|
||||
|
||||
if('init' in lGitHub)
|
||||
lGitHub.createGist(data, lName);
|
||||
else
|
||||
Util.exec(cloudcmd.GitHub,
|
||||
function(){
|
||||
lGitHub.createGist(data, lName);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Util.log('Uploading to gist...');
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
@ -159,9 +185,9 @@ var CloudCommander, Util, DOM, CloudFunc, $;
|
|||
.replace('z-index: 1', 'z-index:-1');
|
||||
|
||||
/* get element by point */
|
||||
var lElement = document.elementFromPoint(pEvent.x, pEvent.y);
|
||||
var lTag = lElement.tagName;
|
||||
var lParent;
|
||||
var lElement = document.elementFromPoint(pEvent.x, pEvent.y),
|
||||
lTag = lElement.tagName,
|
||||
lParent;
|
||||
|
||||
if(lTag === 'A' || lTag === 'SPAN'){
|
||||
if (lElement.tagName === 'A')
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
function load(pCallBack){
|
||||
console.time('github load');
|
||||
|
||||
var lDir = './lib/client/storage/github/',
|
||||
var lDir = '/lib/client/storage/github/',
|
||||
lFiles = [
|
||||
lDir + 'github.js',
|
||||
lDir + 'lib/base64.js',
|
||||
|
|
@ -53,35 +53,8 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
});
|
||||
}
|
||||
|
||||
function saveToken(pToken){
|
||||
return Cache.set('token', pToken);
|
||||
}
|
||||
|
||||
function getToken(){
|
||||
return Cache.get('token');
|
||||
}
|
||||
|
||||
|
||||
/* PUBLICK FUNCTIONS */
|
||||
GithubStore.basicLogin = function(pUser, pPasswd){
|
||||
GithubLocal = new Github({
|
||||
username: pUser,
|
||||
password: pPasswd,
|
||||
auth : 'basic'
|
||||
});
|
||||
};
|
||||
|
||||
GithubStore.Login = function(pToken){
|
||||
Github = GithubLocal = new Github({
|
||||
token : pToken,
|
||||
auth : 'oauth'
|
||||
});
|
||||
|
||||
User = GithubLocal.getUser();
|
||||
};
|
||||
|
||||
function init(pCallBack){
|
||||
var lToken = getToken();
|
||||
function init(pCallBack){
|
||||
var lToken = Cache.get('token');
|
||||
if(lToken){
|
||||
GithubStore.Login(lToken);
|
||||
Util.exec(pCallBack);
|
||||
|
|
@ -100,7 +73,7 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
lToken = pData.token;
|
||||
|
||||
GithubStore.Login(lToken);
|
||||
saveToken(lToken);
|
||||
Cache.set('token', lToken);
|
||||
Util.exec(pCallBack);
|
||||
}
|
||||
else
|
||||
|
|
@ -116,58 +89,80 @@ var CloudCommander, Util, DOM, $, Github, cb;
|
|||
}
|
||||
}
|
||||
|
||||
function getUserData(){
|
||||
var lName, lRepoNames,
|
||||
lGetTree = function(pError ,pData){
|
||||
Util.log('Tree of ripository ' + lRepoNames[0].name + ': ');
|
||||
var lTree = pData || [];
|
||||
if(!pError)
|
||||
for(var i = 0, n = lTree.length; i < n ; i++)
|
||||
if( !Util.isContainStr(lTree[i].path, '/') )
|
||||
console.log(lTree[i].path);
|
||||
else
|
||||
Util.log(pError);
|
||||
},
|
||||
|
||||
lShowRepos = function(pError, pRepos){
|
||||
lRepoNames = pRepos || [];
|
||||
Util.log('Repositories: ');
|
||||
if(!pError){
|
||||
for(var i = 0, n = pRepos.length; i < n ; i++)
|
||||
console.log(pRepos[i].name);
|
||||
|
||||
var lRepo = GithubLocal.getRepo(lName, pRepos[0].name);
|
||||
lRepo.getTree('master?recursive=true', lGetTree);
|
||||
}
|
||||
else
|
||||
DOM.Cache.remove('token');
|
||||
},
|
||||
function getUserData(pCallBack){
|
||||
var lName,
|
||||
|
||||
lShowUserInfo = function(pError, pData){
|
||||
if(!pError){
|
||||
lName = pData.name;
|
||||
|
||||
console.log('Hello ' + lName + ' :)!');
|
||||
User.repos(lShowRepos);
|
||||
}
|
||||
else
|
||||
DOM.Cache.remove('token');
|
||||
};
|
||||
|
||||
|
||||
|
||||
User.show(null, lShowUserInfo);
|
||||
|
||||
Util.exec(pCallBack);
|
||||
}
|
||||
|
||||
cloudcmd.GitHub.init = function(){
|
||||
/* PUBLICK FUNCTIONS */
|
||||
GithubStore.basicLogin = function(pUser, pPasswd){
|
||||
GithubLocal = new Github({
|
||||
username: pUser,
|
||||
password: pPasswd,
|
||||
auth : 'basic'
|
||||
});
|
||||
};
|
||||
|
||||
GithubStore.Login = function(pToken){
|
||||
Github = GithubLocal = new Github({
|
||||
token : pToken,
|
||||
auth : 'oauth'
|
||||
});
|
||||
|
||||
User = GithubLocal.getUser();
|
||||
};
|
||||
|
||||
/**
|
||||
* function creates gist
|
||||
*/
|
||||
cloudcmd.GitHub.createGist = function(pContent, pFileName){
|
||||
if(pContent){
|
||||
if(!pFileName)
|
||||
pFileName = Util.getDate();
|
||||
|
||||
var lGist = GithubLocal.getGist(),
|
||||
lFiles = {},
|
||||
lOptions = {
|
||||
description: "uploaded from cloudcmd",
|
||||
public: true
|
||||
};
|
||||
|
||||
lFiles[pFileName] ={
|
||||
content: pContent
|
||||
};
|
||||
|
||||
lOptions.files = lFiles;
|
||||
|
||||
lGist.create(lOptions, cb);
|
||||
}
|
||||
|
||||
return pContent;
|
||||
};
|
||||
|
||||
cloudcmd.GitHub.init = function(pCallBack){
|
||||
Util.loadOnLoad([
|
||||
Util.retExec(pCallBack),
|
||||
getUserData,
|
||||
init,
|
||||
setConfig,
|
||||
load
|
||||
]);
|
||||
|
||||
this.init = null;
|
||||
cloudcmd.GitHub.init = null;
|
||||
};
|
||||
|
||||
cloudcmd.Github = GithubStore;
|
||||
cloudcmd.Github = GithubStore;
|
||||
})();
|
||||
|
|
|
|||
19
lib/util.js
19
lib/util.js
|
|
@ -363,7 +363,8 @@ var Util, exports;
|
|||
* Gets current time in format hh:mm:ss
|
||||
*/
|
||||
Util.getTime = function(){
|
||||
var date = new Date(),
|
||||
var lRet,
|
||||
date = new Date(),
|
||||
hours = date.getHours(),
|
||||
minutes = date.getMinutes(),
|
||||
seconds = date.getSeconds();
|
||||
|
|
@ -371,7 +372,21 @@ var Util, exports;
|
|||
minutes = minutes < 10 ? '0' + minutes : minutes;
|
||||
seconds = seconds < 10 ? '0' + seconds : seconds;
|
||||
|
||||
return hours + ":" + minutes + ":" + seconds;
|
||||
lRet = hours + ":" + minutes + ":" + seconds;
|
||||
|
||||
return lRet;
|
||||
};
|
||||
/**
|
||||
* Gets current date in format yy.mm.dd hh:mm:ss
|
||||
*/
|
||||
Util.getDate = function(){
|
||||
var date = new Date(),
|
||||
day = date.getDate(),
|
||||
month = date.getMonth() + 1,
|
||||
year = date.getFullYear(),
|
||||
lRet = year + "-" + month + "-" + day + " " + Util.getTime();
|
||||
|
||||
return lRet;
|
||||
};
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue