diff --git a/src/app/github-int/github-int.js b/src/app/github-int/github-int.js index cad0050c..ae8adc8b 100644 --- a/src/app/github-int/github-int.js +++ b/src/app/github-int/github-int.js @@ -31,7 +31,7 @@ class GithubInt { * Note: unauthenticated users are limited to 60 github api calls per hour * and each file is an api call. */ - cloneRepo(repoUrl) { + cloneRepo(repoUrl, destPath) { var tokens = repoUrl.split('/', 2); if(tokens.length<2) @@ -57,7 +57,9 @@ class GithubInt { return; } - fs.makeDirectory(reponame); + var parentPath = destPath + '/' + reponame; + + fs.makeDirectory(parentPath); var loaded = 0; var showErrors = true; @@ -82,7 +84,7 @@ class GithubInt { return; } - fs.writeFile(reponame+'/'+tree[this].path, new Buffer(data,'binary')); + fs.writeFile(parentPath+'/'+tree[this].path, new Buffer(data,'binary')); loaded += 1; @@ -94,7 +96,7 @@ class GithubInt { if(tree[i].type == 'tree'){ loaded += 1; - fs.makeDirectory(reponame+'/'+tree[i].path); + fs.makeDirectory(parentPath+'/'+tree[i].path); } } }.bind(this)); @@ -105,14 +107,16 @@ class GithubInt { * If the repo already exists, it deletes it and creates a new repo. * If needed this can be extended to modify current existing repo rather than deleting, but this is non-trivial. */ - saveAll() { + saveAll(saveRepoName, srcPath) { var fs = SysFileSystem; + this.saveRepoName = saveRepoName; + this.sourcePath = srcPath; if(!this.authenticated) { notify('Must be authenticated...', 'red'); } - var repo = this.hub.getRepo(this.username, 'saved-jor1k-workspace'); + var repo = this.hub.getRepo(this.username, saveRepoName); repo.show(function(err, repo_info){ if(err){ if(err.error==404) @@ -138,7 +142,7 @@ class GithubInt { * Helper for saveAll. */ createSaveRepo(err, res) { - this.user.createRepo({'name': 'saved-jor1k-workspace'}, function(err, res) { + this.user.createRepo({'name': this.saveRepoName}, function(err, res) { if(err) { @@ -150,8 +154,8 @@ class GithubInt { return; } - var repo = this.hub.getRepo(this.username, 'saved-jor1k-workspace'); - this.pushToRepo(repo); + var repo = this.hub.getRepo(this.username, this.saveRepoName); + this.pushToRepo(repo, this.sourcePath); }.bind(this)); } @@ -160,9 +164,22 @@ class GithubInt { * * This is very hacky... the api is very limited and doesn't allow parallel writes */ - pushToRepo(repo) { + pushToRepo(repo, sourcePath) { var fs = SysFileSystem; - var tree = fs.getDirectoryTree(); + + var tree = []; + if(sourcePath === ''){ + tree = fs.getDirectoryTreeOfDir('/'); + } + else{ + tree = fs.getDirectoryTreeOfDir(sourcePath); + } + + //trim source path from tree + var pathLength = sourcePath.length; + var trimPath = function(fullPath){ + return fullPath.substring(pathLength, fullPath.length); + }; var readFile = function(err){ @@ -206,7 +223,7 @@ class GithubInt { var i = this; tree[this].path = tree[this].path.substring(1,tree[this].path.length); - repo.write('master', tree[i].path, buf.toString('binary'), 'save', readFile.bind(i+1)); + repo.write('master', trimPath(tree[i].path), buf.toString('binary'), 'save', readFile.bind(i+1)); }; readFile(); diff --git a/src/app/sys-filesystem.js b/src/app/sys-filesystem.js index 6e84e124..7da875c1 100644 --- a/src/app/sys-filesystem.js +++ b/src/app/sys-filesystem.js @@ -167,13 +167,13 @@ class SysFileSystem { * of all nodes within /home/user. Partially ordered from root -> leafs */ getDirectoryTree(){ - return this.getDirectoryTreeHelper('/'); + return this.getDirectoryTreeOfDir('/'); } /* * Helper for getDirectoryTree */ - getDirectoryTreeHelper(path){ + getDirectoryTreeOfDir(path){ var children = this.localFS.readdirSync(path); if(path=='/') @@ -200,7 +200,7 @@ class SysFileSystem { for(var a=0; a {}); export var runCode = ko.observable((gccOptions) => {}); -export var githubUsername = ko.observable(''); -export var githubPassword = ko.observable(''); -export var githubRepo = ko.observable(''); - export var buildCmd = ko.observable(''); export var execCmd = ko.observable(''); diff --git a/src/components/file-browser/file-browser.html b/src/components/file-browser/file-browser.html index db7bb620..0e44cafb 100644 --- a/src/components/file-browser/file-browser.html +++ b/src/components/file-browser/file-browser.html @@ -4,43 +4,4 @@
Loading...
-
-
-
-
- -
- -
- -
- -
-
-
- -
- -
-
-
-
- - -
-
-
\ No newline at end of file diff --git a/src/components/file-browser/file-browser.js b/src/components/file-browser/file-browser.js index 6fc09fa0..ef772ff2 100644 --- a/src/components/file-browser/file-browser.js +++ b/src/components/file-browser/file-browser.js @@ -30,65 +30,6 @@ var confirmNotific8Options = { class Filebrowser { constructor() { - this.githubUsername = SysGlobalObservables.githubUsername; - this.githubPassword = SysGlobalObservables.githubPassword; - this.githubRepo = SysGlobalObservables.githubRepo; - this.compileBtnEnable = SysGlobalObservables.compileBtnEnable; - - var githubOptsContainer = $('#github-opts-container'); - $('span:contains("File Browser")').click(() => { - githubOptsContainer.show(); - }); - - $('span:contains("Code")').click(() => { - githubOptsContainer.hide(); - }); - - $('span:contains("Video Search")').click(() => { - githubOptsContainer.hide(); - }); - - $('span:contains("Man page search")').click(() => { - githubOptsContainer.hide(); - }); - - githubOptsContainer.css('width', $('#code-container').width() + 'px'); - - const $saveReop = $('#save-workspace-btn'); - $saveReop.click(() => { - var username = this.githubUsername(); - var password = this.githubPassword(); - console.log('Save Repo'); - this.githubPassword(''); - - if (!username || !password) - return; - - var github = new GithubInt(username, password); - github.saveAll(); - }); - - const $cloneRepo = $('#clone-repo-btn'); - $cloneRepo.click(() => { - var username = this.githubUsername(); - var password = this.githubPassword(); - var repo = this.githubRepo(); - console.log('Clone Repo'); - if (!repo) - return; - - this.githubPassword(''); - - var github; - - if(username && password) - github = new GithubInt(username, password); - else - github = new GithubInt(); - - github.cloneRepo(repo); - }); - var readyCallback = () => { this.id = '#file-browser-body'; var fs = this.fs = SysFileSystem; @@ -169,6 +110,10 @@ class Filebrowser { } menuHtml += '
  • Rename
  • '; menuHtml += '
  • Delete
  • '; + if (self.metaData[itemId].isDirectory) { + menuHtml += '
  • Clone a repo into \'' + self.metaData[itemId].name + '\'...
  • '; + menuHtml += '
  • Push \''+ self.metaData[itemId].name + '\' to a repo...
  • '; + } menuContainer.html(menuHtml); }, @@ -182,7 +127,7 @@ class Filebrowser { var index; if (action === 'delete') { - bootbox.confirm('Are you sure you want to delete "' + itemName + '" ?', function (result) { + bootbox.confirm('Are you sure you want to delete the directory \'' + itemName + '\'?', function (result) { if (result) { if (self.metaData[itemId].isDirectory) { self.fs.removeDirectory(itemPath); @@ -235,6 +180,98 @@ class Filebrowser { } }); } + else if (action === 'clone') { + bootbox.dialog({ + title: 'Clone a GitHub repo into \'' + itemName + '\'...', + message: '
    ' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '
    ' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '
    ' + +'
    ', + buttons: { + success: { + label: 'Clone', + className: 'btn-clone', + callback: function () { + var username = $('#githubUsername').val(); + var password = $('#githubPassword').val(); + var repoName = $('#githubRepo').val(); + + console.log('Clone Repo'); + + if (repoName.trim().length === 0) + return; + + var github; + + if((username.trim().length !== 0) && (password.trim().length !== 0)) + github = new GithubInt(username, password); + else + github = new GithubInt(); + + github.cloneRepo(repoName, itemPath); + } + } + } + }); + } + else if (action === 'push') { + bootbox.dialog({ + title: 'Push \''+ itemName + '\' to a GitHub repo...', + message: '
    ' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '
    ' + + '
    ' + + '' + + '
    ' + + '' + + '
    ' + + '
    ' + +'
    ', + buttons: { + success: { + label: 'Push', + className: 'btn-push', + callback: function () { + var username = $('#githubUsername').val(); + var password = $('#githubPassword').val(); + var saveRepoName = $('#githubSaveRepo').val(); + + console.log('Save Repo'); + + if ((username.trim().length === 0) || (password.trim().length === 0) + || (saveRepoName.trim().length === 0)) + return; + + var github = new GithubInt(username, password); + + github.saveAll(saveRepoName, itemPath); + } + } + } + }); + } } }); diff --git a/src/styles/_file-browser.scss b/src/styles/_file-browser.scss index 1f23a75f..f3be2a60 100644 --- a/src/styles/_file-browser.scss +++ b/src/styles/_file-browser.scss @@ -7,6 +7,7 @@ user-select: none; width: 100%; height: 100%; + overflow: auto; .loading { font-size: 16px;