Skip to content
Browse files

loading modules from another user is now working, going to add a list…

… to profile view
  • Loading branch information...
1 parent 8ccd4db commit 8d71b515a0f245c944b34e72dd35ac27a4c7a8ac @matthewfl matthewfl committed Dec 12, 2010
Showing with 55 additions and 55 deletions.
  1. +21 −6 Bespin/control.js
  2. +21 −1 front-end.js
  3. +12 −48 sandbox/build.js
  4. +1 −0 test.js
View
27 Bespin/control.js
@@ -573,13 +573,14 @@ exports.deleteCommand = function (args, request) {
"action": "delete",
"name": name,
}, function (d) {
- if(d)
- request.done("File deleted");
+ request.done(d ? "File deleted" : "failed to delete");
+ if(d) {
+ fileList.splice(fileList.indexOf(name),1);
+ if(publicList.indexOf(name)!=-1)
+ publicList.splice(publicList.indexOf(name),1);
+ }
});
Ajax.send();
- fileList.splice(fileList.indexOf(name),1);
- if(publicList.indexOf(name)!=-1)
- publicList.splice(publicList.indexOf(name),1);
}else
request.done("File not found");
};
@@ -590,7 +591,21 @@ exports.renameCommand = function (args, request) {
env.commandLine.setInput('mv ');
return;
}
- if(fileList.indexOf(args['file']));
+ if(fileList.indexOf(args['file']) == -1) return request.done("File not found");
+ Ajax.Call({
+ "action": "rename",
+ "from": args['file'],
+ "to": args['nfile']
+ }, function (d) {
+ request.done(d ? "File renamed" : "failed to rename");
+ if(d) {
+ fileList[fileList.indexOf(args['file'])]=args['nfile'];
+ if(publicList.indexOf(args['file'])!=-1)
+ publicList[publicList.indexOf(args['file'])]=args['nfile'];
+ }
+ });
+ Ajax.send();
+
};
exports.newUserCommand = function (args, request) {
View
22 front-end.js
@@ -173,10 +173,30 @@ var ajaxActions = {
db.remove("fs_"+user+"_"+data.name, function () {
back(true);
});
+ db.get("lsPublic_"+user, function(d) {
+ if(d.split("*").indexOf(data.name)!=-1) {
+ var a = d.split("*");
+ a.splice(a.indexOf(data.name),1);
+ db.set("lsPublic_"+user, a.join("*"));
+ }
+ });
});
},
rename: function (data, user, back) {
- back(456);
+ if(!user) return back(false);
+ db.get("lsFs_"+user, function (ls) {
+ ls = ls.split("*");
+ console.log(ls);
+ console.log(ls.indexOf(data.from));
+ if(ls.indexOf(data.from)==-1) return back(false);
+ ls[ls.indexOf(data.from)]=data.to;
+ db.set("lsFs_"+user, ls.join("*"));
+ db.get("fs_"+user+"_"+data.from, function (f) {
+ db.set("fs_"+user+"_"+data.to, f);
+ db.remove("fs_"+user+"_"+data.from);
+ back(true);
+ });
+ });
}
};
View
60 sandbox/build.js
@@ -16,7 +16,6 @@ function builder (code, user, back) {
builder.prototype.require = function (code) {
var self = this;
- console.log('require call');
code.replace(/require\s*?\((.*?)\)/g, function (r, v) {
try {
console.log(v);
@@ -34,7 +33,7 @@ builder.prototype.require = function (code) {
};
builder.prototype.searcher = function (name) {
- console.log('searcher '+name);
+ console.log(name.indexOf('/'))
if(name.indexOf("./") == 0) {
this.counter++;
(function (name,self) {
@@ -44,22 +43,23 @@ builder.prototype.searcher = function (name) {
self.count();
});
})(name, this);
- }else if(typeof modules[name] != "undefined") {}
- else if(name.indexOf('/') != -1) {
- counter++;
- var user = a.substring(0,a.indexOf('/'));
- var file = a.substring(a.indexOf('/')+1);
+ }else if(name.indexOf('/') != -1) {
+ this.counter++;
+ var user = name.substring(0,name.indexOf('/'));
+ var file = name.substring(name.indexOf('/')+1);
if(typeof this.pub[user] != "undefined") {
if(this.pub[user].indexOf(file) != -1) {
(function (name, self) {
db.get("fs_"+user+"_"+file, function (code) {
+ console.log(code)
if(code) self.require(code);
self.code[name] = code ? jsmin("",code,1) : "throw '"+name+" not found';";
self.count();
});
- })(name, self);
+ })(name, this);
}else{
this.code[name] = 'throw "external user module '+name+' was not found";';
+ this.count();
}
}else{
(function (user, self, name) {
@@ -68,13 +68,15 @@ builder.prototype.searcher = function (name) {
self.code[name] = 'throw "external user module '+name+' was not found";';
self.count();
}else{
- self.pub[user] = data;
+ self.pub[user] = data.split("*");
self.searcher(name);
+ self.count();
}
});
})(user, this, name);
}
- }else
+ }else if(typeof modules[name] != "undefined") {}
+ else
this.code[name] = 'throw "Module '+name+' not found";';
};
@@ -86,41 +88,3 @@ builder.prototype.count = function () {
exports.build = function (code, user, back) {
var b = new builder(code, user, back);
};
-
-
-/*
-
-exports.build = function (code, user, back) {
- var ret={};
- var need={};
- ret._=jsmin("", code, 1);
- code.replace(/require\s*?\((.*?)\)/g, function (r, v) {
- try {
- console.log(v);
- need[v.replace(/\"(.*)\"|\'(.*)\'/, function (r) { return r.substring(1,r.length-1); })]=true;
- }catch(e) {
- throw "Require needs to be static";
- }
- return r;
- });
- var count=1;
- for(var name in need) {
- console.log(name);
- if(name.indexOf("./") == 0) {
- count++;
- (function (name) {
- db.get("fs_"+user+"_"+name.substring(2), function (code) {
- ret[name] = code ? jsmin("",code,1) : "throw 'not found';";
- if(!--count) back(ret);
- });
- })(name);
- }else if(typeof modules[name] != "undefined") {}
- else if(name.indexOf('/')) {
- // will be used latter
- }else
- throw "Module "+name+" Not found";
- }
- if(!--count) back(ret);
-};
-
-*/
View
1 test.js
@@ -24,6 +24,7 @@ var server = http.createServer(function (req, res) {
return;
}
sandbox.build(data, urlInfo.query.user, function (d) {
+ console.log(d)
var name;
do {
name = config.testBase.replace(/\#\#/g, Math.random().toString().substring(2,12));

0 comments on commit 8d71b51

Please sign in to comment.
Something went wrong with that request. Please try again.