mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-22 05:31:33 +00:00
list repositories in selector
This commit is contained in:
parent
85f0650bfe
commit
10f89d0c53
@ -141,8 +141,7 @@ TODO:
|
||||
- what to do about included files?
|
||||
- what if files already open in editor
|
||||
- un-bind from repo?
|
||||
- navigate to repo
|
||||
- import 'examples/' retains path?
|
||||
- can published files retain path?
|
||||
- what if import interrupted and partial files?
|
||||
- CORS for some blobs?
|
||||
- confusing when examples load if file not found
|
||||
|
@ -337,18 +337,4 @@ export class CodeProject {
|
||||
return path;
|
||||
}
|
||||
|
||||
migrateToNewFolder(newprefix : string, newstore?) {
|
||||
// TODO: must end with /
|
||||
var newPath = newprefix + this.stripLocalPath(this.mainPath);
|
||||
console.log(this.mainPath + "->" + newPath);
|
||||
var data = this.filedata[this.mainPath];
|
||||
console.log(data.length + " bytes");
|
||||
return (newstore || this.store).setItem(newPath, data).then(() => {
|
||||
//return this.store.removeItem(this.mainPath);
|
||||
console.log("moved " + this.mainPath + " to " + newPath);
|
||||
this.filedata[newPath] = this.filedata[this.mainPath]; //TODO?
|
||||
this.mainPath = newPath;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,14 @@ export function getRepos() : {[key:string]:GHRepoMetadata} {
|
||||
return JSON.parse(localStorage.getItem('__repos') || '{}');
|
||||
}
|
||||
|
||||
export function parseGithubURL(ghurl:string) {
|
||||
var toks = ghurl.split('/');
|
||||
if (toks.length < 5) return null;
|
||||
if (toks[0] != 'https:') return null;
|
||||
if (toks[2] != 'github.com') return null;
|
||||
return {user:toks[3], repo:toks[4], repopath:toks[3]+'/'+toks[4]};
|
||||
}
|
||||
|
||||
export class GithubService {
|
||||
|
||||
githubCons;
|
||||
@ -80,28 +88,20 @@ export class GithubService {
|
||||
return false;
|
||||
}
|
||||
|
||||
parseGithubURL(ghurl:string) {
|
||||
var toks = ghurl.split('/');
|
||||
if (toks.length < 5) return null;
|
||||
if (toks[0] != 'https:') return null;
|
||||
if (toks[2] != 'github.com') return null;
|
||||
return {user:toks[3], repo:toks[4], repopath:toks[3]+'/'+toks[4]};
|
||||
}
|
||||
|
||||
getGithubSession(ghurl:string) : Promise<GHSession> {
|
||||
return new Promise( (yes,no) => {
|
||||
var urlparse = this.parseGithubURL(ghurl);
|
||||
var urlparse = parseGithubURL(ghurl);
|
||||
if (!urlparse) {
|
||||
no("Please enter a valid GitHub URL.");
|
||||
}
|
||||
var sess = {
|
||||
url: ghurl,
|
||||
url: 'https://github.com/' + urlparse.repopath,
|
||||
user: urlparse.user,
|
||||
reponame: urlparse.repo,
|
||||
repopath: urlparse.repopath,
|
||||
prefix: '', //this.getPrefix(urlparse.user, urlparse.repo),
|
||||
repo: this.github.repos(urlparse.user, urlparse.repo),
|
||||
platform_id: this.project.platform_id
|
||||
platform_id: this.project ? this.project.platform_id : null
|
||||
};
|
||||
yes(sess);
|
||||
});
|
||||
@ -124,7 +124,8 @@ export class GithubService {
|
||||
// load README
|
||||
return sess.repo.contents('README.md').read();
|
||||
})
|
||||
.catch( () => {
|
||||
.catch( (e) => {
|
||||
console.log(e);
|
||||
console.log('no README.md found')
|
||||
return ''; // empty README
|
||||
})
|
||||
@ -138,13 +139,14 @@ export class GithubService {
|
||||
sess.mainPath = m[1];
|
||||
}
|
||||
// check README for proper platform
|
||||
// unless we use githubURL=
|
||||
const re8plat = /8bitworkshop.com[^)]+platform=(\w+)/;
|
||||
m = re8plat.exec(readme);
|
||||
if (m) {
|
||||
console.log("platform id: '" + m[1] + "'");
|
||||
sess.platform_id = m[1];
|
||||
if (!this.project.platform_id.startsWith(m[1]))
|
||||
if (sess.platform_id && !sess.platform_id.startsWith(m[1]))
|
||||
throw "Platform mismatch: Repository is " + m[1] + ", you have " + this.project.platform_id + " selected.";
|
||||
sess.platform_id = m[1];
|
||||
}
|
||||
// bind to repository
|
||||
this.bind(sess, true);
|
||||
|
33
src/ui.ts
33
src/ui.ts
@ -14,7 +14,7 @@ import { createNewPersistentStore } from "./store";
|
||||
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG,
|
||||
byteArrayToUTF8, isProbablyBinary, getWithBinary, getBasePlatform } from "./util";
|
||||
import { StateRecorderImpl } from "./recorder";
|
||||
import { GHSession, GithubService, getRepos } from "./services";
|
||||
import { GHSession, GithubService, getRepos, parseGithubURL } from "./services";
|
||||
|
||||
// external libs (TODO)
|
||||
declare var Tour, GIF, saveAs, JSZip, Mousetrap, Split, firebase;
|
||||
@ -253,6 +253,11 @@ function reloadProject(id:string) {
|
||||
// leave repository == '..'
|
||||
if (id == '..') {
|
||||
qs = {};
|
||||
} else if (id.indexOf('://') >= 0) {
|
||||
var urlparse = parseGithubURL(id);
|
||||
if (urlparse) {
|
||||
qs = {repo:urlparse.repopath};
|
||||
}
|
||||
} else {
|
||||
qs['platform'] = platform_id;
|
||||
qs['file'] = id;
|
||||
@ -390,7 +395,7 @@ function getGithubService() {
|
||||
function getBoundGithubURL() : string {
|
||||
var toks = (repo_id||'').split('/');
|
||||
if (toks.length != 2) {
|
||||
alert("This project is not bound to a GitHub project.");
|
||||
alert("You are not in a GitHub repository. Choose Import or Publish first.");
|
||||
return null;
|
||||
}
|
||||
return 'https://github.com/' + toks[0] + '/' + toks[1];
|
||||
@ -398,7 +403,7 @@ function getBoundGithubURL() : string {
|
||||
|
||||
function importProjectFromGithub(githuburl:string) {
|
||||
var sess : GHSession;
|
||||
var urlparse = getGithubService().parseGithubURL(githuburl);
|
||||
var urlparse = parseGithubURL(githuburl);
|
||||
if (!urlparse) {
|
||||
alert('Could not parse Github URL.');
|
||||
return;
|
||||
@ -468,7 +473,7 @@ function _publishProjectToGithub(e) {
|
||||
return pushChangesToGithub('initial import from 8bitworkshop.com');
|
||||
}).then( () => {
|
||||
setWaitProgress(1.0);
|
||||
reloadProject(current_project.mainPath);
|
||||
reloadProject(current_project.stripLocalPath(current_project.mainPath));
|
||||
}).catch( (e) => {
|
||||
setWaitDialog(false);
|
||||
console.log(e);
|
||||
@ -749,6 +754,23 @@ function populateExamples(sel) {
|
||||
});
|
||||
}
|
||||
|
||||
function populateRepos(sel) {
|
||||
if (hasLocalStorage) {
|
||||
var n = 0;
|
||||
var repos = getRepos();
|
||||
if (repos) {
|
||||
for (let repopath in repos) {
|
||||
var repo = repos[repopath];
|
||||
if (getBasePlatform(repo.platform_id) == getBasePlatform(platform_id)) {
|
||||
if (n++ == 0)
|
||||
sel.append($("<option />").text("------ Repositories ------").attr('disabled','true'));
|
||||
sel.append($("<option />").val(repo.url).text(repo.url.substring(repo.url.indexOf('/'))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function populateFiles(sel:JQuery, category:string, prefix:string, callback:() => void) {
|
||||
store.keys(function(err, keys : string[]) {
|
||||
var foundSelected = false;
|
||||
@ -780,6 +802,7 @@ function updateSelector() {
|
||||
// normal: populate local and shared files
|
||||
populateFiles(sel, "Local Files", "local/", () => {
|
||||
populateFiles(sel, "Shared", "shared/", () => {
|
||||
populateRepos(sel);
|
||||
populateExamples(sel);
|
||||
sel.css('visibility','visible');
|
||||
});
|
||||
@ -787,7 +810,7 @@ function updateSelector() {
|
||||
} else {
|
||||
sel.append($("<option />").val('..').text('Leave Repository'));
|
||||
// repo: populate all files
|
||||
populateFiles(sel, "Repository Files", "", () => {
|
||||
populateFiles(sel, repo_id, "", () => {
|
||||
sel.css('visibility','visible');
|
||||
});
|
||||
}
|
||||
|
@ -108,12 +108,16 @@ describe('Store', function() {
|
||||
it('Should bind paths to Github', function(done) {
|
||||
var store = mstore.createNewPersistentStore(test_platform_id, function(store) {
|
||||
var gh = newGH(store);
|
||||
var sess = {repopath:'foo/bar', url:'_',platform_id:'vcs',mainPath:'test.c'};
|
||||
var sess = {repopath:'foo/bar', url:'_', platform_id:'vcs',mainPath:'test.c'};
|
||||
gh.bind(sess, true);
|
||||
assert.deepEqual(serv.getRepos(), {'foo/bar':{url:'_',platform_id:'vcs',mainPath:'test.c'}});
|
||||
gh.bind(sess, false);
|
||||
assert.deepEqual(serv.getRepos(), {});
|
||||
done();
|
||||
gh.getGithubSession('https://github.com/foo/bar/baz').then((sess) => {
|
||||
assert.equal(sess.url, 'https://github.com/foo/bar');
|
||||
assert.equal(sess.repopath, 'foo/bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user