Skip to content

Commit

Permalink
Integrate beetleblocks
Browse files Browse the repository at this point in the history
Added save/load to cloud.
Fixed examples.
  • Loading branch information
phlindstedt committed Nov 8, 2018
1 parent a541ae5 commit af9a64b
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 48 deletions.
59 changes: 53 additions & 6 deletions beetleblocks/beetleblocks/beetlecloud.js
Expand Up @@ -113,7 +113,7 @@ BeetleCloud.prototype.post = function (path, body, callBack, errorCall, errorMsg
};

BeetleCloud.prototype.getCurrentUser = function (callback, errorCallback) {
this.get('/user', callback, errorCallback, 'Could not retrieve current user');
callback.call(null, {username:"user"});
};

BeetleCloud.prototype.checkCredentials = function (callback, errorCallback) {
Expand Down Expand Up @@ -170,9 +170,33 @@ BeetleCloud.prototype.saveProject = function (ide, callBack, errorCall) {
}

ide.showMessage('Uploading project...');

var data = {};
data.contents = pdata;
data.id = 0;
data.ispublic = false;
data.notes = ide.projectNotes;
data.projectname = ide.projectName;
var n = pdata.indexOf("<thumbnail>")+11;
var m = pdata.indexOf("</thumbnail>");
data.thumbnail = pdata.substr(n, m-n);
console.log(data.thumbnail);
var today = new Date();
var dd = today.getDate(), mm = today.getMonth()+1, yyyy = today.getFullYear();
if(dd<10)
dd = '0'+dd
if(mm<10)
mm = '0'+mm
data.updated = yyyy+'-'+mm+'-'+dd+' '+today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
data.user = myself.username
data = JSON.stringify(data);
saveDataToCloud(data, ide.projectName, "beetleblocks");
callBack.call(
null,
"project "+ide.projectName+" updated",
'BeetleCloud'
);
//(path, body, callBack, errorCall, errorMsg)
myself.post(
/*myself.post(
'/projects/save?projectname='
+ encodeURIComponent(ide.projectName)
+ '&username='
Expand All @@ -182,7 +206,7 @@ BeetleCloud.prototype.saveProject = function (ide, callBack, errorCall) {
callBack,
errorCall,
'Project could not be saved' // error message
)
)*/

} else {
errorCall.call(this, 'You are not logged in', 'BeetleCloud');
Expand Down Expand Up @@ -270,7 +294,30 @@ BeetleCloud.prototype.getProjectList = function (callBack, errorCall) {
errorCall.call(this, 'You are not logged in', 'BeetleCloud');
return;
} else {
myself.get(
var response = getAllCloudFilesJSON();
var tmp = {}, res = Array();
var i = 0;
if (Object.keys(response.DATA).length > 0) {
response.DATA.forEach(function(eachProject) {
if(eachProject.TOOLID == 21){
var data = JSON.parse(eachProject.FILE_PATH);
// This looks absurd, but PostgreSQL doesn't respect case
tmp.Public = data.ispublic ? 'true' : 'false'; // compatibility with old cloud
tmp.ProjectName = data.projectname;
tmp.Thumbnail = data.thumbnail;
tmp.Updated = data.updated;
tmp.Notes = data.notes;
tmp.Data = data.contents;
tmp.ProjectId = eachProject.ID;
res[i] = tmp;
i++;
}
});
callBack.call(null, res);
} else {
callBack.call(null, []);
}
/*myself.get(
'/users/'
+ encodeURIComponent(myself.username)
+ '/projects',
Expand All @@ -291,7 +338,7 @@ BeetleCloud.prototype.getProjectList = function (callBack, errorCall) {
},
errorCall,
'Could not fetch project list'
);
);*/
}
},
errorCall
Expand Down
21 changes: 21 additions & 0 deletions beetleblocks/beetleblocks/examples/EXAMPLES
@@ -0,0 +1,21 @@
artichoke lamp.xml artichoke lamp
beetle.xml beetle
bracelet.xml bracelet
CDG.xml CDG
chair.xml chair
disco ball.xml disco ball
geometry tool blocks.xml geometry tool blocks
horns.xml horns
nautilus.xml nautilus
orthogonal tree.xml orthogonal tree
pine tree.xml pine tree
random walk sphere.xml random walk sphere
recursive cubes.xml recursive cubes
shell.xml shell
simple code examples.xml simple code examples
snail.xml snail
spiral basket.xml spiral basket
torus knot.xml torus knot
tower.xml tower
Tutorial 1.xml Tutorial 1
wave surface.xml wave surface
54 changes: 36 additions & 18 deletions beetleblocks/beetleblocks/gui.js
Expand Up @@ -106,13 +106,14 @@ IDE_Morph.prototype.projectMenu = function () {

if (SnapCloud.username) {
menu.addLine();
menu.addItem('My Profile', function () { window.open('/users/' + SnapCloud.username, true) });
menu.addItem('My Projects', function () { window.open('/myprojects', true) });
menu.addItem('Load from cloud', 'openProjectsBrowser');
//menu.addItem('My Profile', function () { window.open('/users/' + SnapCloud.username, true) });
//menu.addItem('Load from cloud', function () { window.open('/myprojects', true) });
}
menu.addItem(
/*menu.addItem(
'Migrate from the old cloud',
function () { window.open('/migration', true) },
'Attempt to perform an automatic\nmigration of all your projects\nin the old cloud');
'Attempt to perform an automatic\nmigration of all your projects\nin the old cloud');*/

menu.addLine();
menu.addItem('Save Ctrl+S', 'save');
Expand Down Expand Up @@ -187,7 +188,7 @@ IDE_Morph.prototype.projectMenu = function () {
);
menu.addLine();
}
if (!SnapCloud.username) {
/*if (!SnapCloud.username) {
menu.addItem(
'Login',
function () { window.open('/login'); }
Expand All @@ -205,7 +206,7 @@ IDE_Morph.prototype.projectMenu = function () {
localize('Logout') + ' / ' + SnapCloud.username,
'logout'
);
}
}*/
menu.addItem(
'Start tutorial',
function () {
Expand Down Expand Up @@ -371,7 +372,12 @@ ProjectDialogMorph.prototype.deleteProject = function () {
) + '\n"' + proj.ProjectName + '"?',
'Delete Project',
function () {
SnapCloud.deleteProject(
removeFile(proj.ProjectId);
myself.ide.hasChangedMedia = true;
idx = myself.projectList.indexOf(proj);
myself.projectList.splice(idx, 1);
myself.installCloudProjectList(myself.projectList);
/*SnapCloud.deleteProject(
proj.ProjectName,
function () {
myself.ide.hasChangedMedia = true;
Expand All @@ -382,7 +388,7 @@ ProjectDialogMorph.prototype.deleteProject = function () {
function (err, lbl) {
myself.ide.cloudError().call(null, err, lbl);
}
);
);*/
}
);
}
Expand Down Expand Up @@ -422,8 +428,8 @@ ProjectDialogMorph.prototype.shareProject = function () {
proj.ProjectName,
function () {
proj.Public = 'true';
myself.unshareButton.show();
myself.shareButton.hide();
//myself.unshareButton.show();
//myself.shareButton.hide();
entry.label.isBold = true;
entry.label.drawNew();
entry.label.changed();
Expand Down Expand Up @@ -466,8 +472,8 @@ ProjectDialogMorph.prototype.unshareProject = function () {
proj.ProjectName,
function () {
proj.Public = 'false';
myself.shareButton.show();
myself.unshareButton.hide();
//myself.shareButton.show();
//myself.unshareButton.hide();
entry.label.isBold = false;
entry.label.drawNew();
entry.label.changed();
Expand Down Expand Up @@ -994,12 +1000,21 @@ IDE_Morph.prototype.setStageExtent = function (ext) {
this.stage.reRender();
};

IDE_Morph.prototype.resourceURL = function () {
// Take in variadic inputs that represent an a nested folder structure.
// Method can be easily overridden if running in a custom location.
// Default Snap! simply returns a path (relative to snap.html)
var args = Array.prototype.slice.call(arguments, 0);
return args.join('/');
};

// Examples now pulls from local
ProjectDialogMorph.prototype.getExamplesProjectList = function () {
var dir,
return this.ide.getMediaList('beetleblocks/examples/EXAMPLES');
/*var dir,
projects = [];
dir = JSON.parse(this.ide.getURL('https://api.github.com/repos/ericrosenbaum/BeetleBlocks/contents/run/beetleblocks/examples'));
dir = JSON.parse(this.ide.getURL('./examples'));
dir.forEach(function (each){
var dta = {
name: each.name.replace('.xml',''),
Expand All @@ -1012,7 +1027,7 @@ ProjectDialogMorph.prototype.getExamplesProjectList = function () {
projects.sort(function (x, y) {
return x.name < y.name ? -1 : 1;
});
return projects;
return projects;*/
};

ProjectDialogMorph.prototype.setSource = function (source) {
Expand Down Expand Up @@ -1115,8 +1130,8 @@ ProjectDialogMorph.prototype.setSource = function (source) {
};
}
this.body.add(this.listField);
this.shareButton.hide();
this.unshareButton.hide();
//this.shareButton.hide();
//this.unshareButton.hide();
if (this.source === 'local') {
this.deleteButton.show();
} else { // examples
Expand Down Expand Up @@ -1173,6 +1188,9 @@ IDE_Morph.prototype.rawOpenCloudDataString = function (str) {

ProjectDialogMorph.prototype.rawOpenCloudProject = function (proj) {
var myself = this;
myself.ide.source = 'cloud';
myself.ide.droppedText(proj.Data);
/*
SnapCloud.reconnect(
function () {
SnapCloud.callService(
Expand Down Expand Up @@ -1200,7 +1218,7 @@ ProjectDialogMorph.prototype.rawOpenCloudProject = function (proj) {
);
},
myself.ide.cloudError()
);
);*/
this.destroy();
};

Expand Down
33 changes: 17 additions & 16 deletions beetleblocks/gui.js
Expand Up @@ -2278,7 +2278,7 @@ IDE_Morph.prototype.cloudMenu = function () {
'Reset Password...',
'resetCloudPassword'
);
} else {
}/* else {
menu.addItem(
localize('Logout') + ' ' + SnapCloud.username,
'logout'
Expand All @@ -2287,7 +2287,7 @@ IDE_Morph.prototype.cloudMenu = function () {
'Change Password...',
'changeCloudPassword'
);
}
}*/
if (shiftClicked) {
menu.addLine();
menu.addItem(
Expand Down Expand Up @@ -2970,7 +2970,7 @@ IDE_Morph.prototype.getMediaList = function (dirname, callback) {
// based on the contents file.
// If no callback is specified, synchronously return the list of files
// Note: Synchronous fetching has been deprecated and should be switched
var url = this.resourceURL(dirname, dirname.toUpperCase()),
var url = dirname,//this.resourceURL(dirname, dirname.toUpperCase()),
async = callback instanceof Function,
myself = this,
data;
Expand Down Expand Up @@ -3015,6 +3015,7 @@ IDE_Morph.prototype.parseResourceFile = function (text) {
items.push({
fileName: parts[0],
name: parts[1],
path: "beetleblocks/examples/"+parts[0],
description: parts.length > 2 ? parts[2] : ''
});
});
Expand Down Expand Up @@ -5340,8 +5341,8 @@ ProjectDialogMorph.prototype.init = function (ide, task) {
this.notesText = null;
this.notesField = null;
this.deleteButton = null;
this.shareButton = null;
this.unshareButton = null;
//this.shareButton = null;
//this.unshareButton = null;

// initialize inherited properties:
ProjectDialogMorph.uber.init.call(
Expand Down Expand Up @@ -5389,7 +5390,7 @@ ProjectDialogMorph.prototype.buildContents = function () {
}

this.addSourceButton('cloud', localize('Cloud'), 'cloud');
this.addSourceButton('local', localize('Browser'), 'storage');
//this.addSourceButton('local', localize('Browser'), 'storage');
if (this.task === 'open') {
this.buildFilterField();
this.addSourceButton('examples', localize('Examples'), 'poster');
Expand Down Expand Up @@ -5482,10 +5483,10 @@ ProjectDialogMorph.prototype.buildContents = function () {
this.addButton('saveProject', 'Save');
this.action = 'saveProject';
}
this.shareButton = this.addButton('shareProject', 'Share');
this.unshareButton = this.addButton('unshareProject', 'Unshare');
this.shareButton.hide();
this.unshareButton.hide();
//this.shareButton = this.addButton('shareProject', 'Share');
//this.unshareButton = this.addButton('unshareProject', 'Unshare');
//this.shareButton.hide();
//this.unshareButton.hide();
this.deleteButton = this.addButton('deleteProject', 'Delete');
this.addButton('cancel', 'Cancel');

Expand Down Expand Up @@ -5768,8 +5769,8 @@ ProjectDialogMorph.prototype.setSource = function (source) {
};
}
this.body.add(this.listField);
this.shareButton.hide();
this.unshareButton.hide();
//this.shareButton.hide();
//this.unshareButton.hide();
if (this.source === 'local') {
this.deleteButton.show();
} else { // examples
Expand Down Expand Up @@ -5863,20 +5864,20 @@ ProjectDialogMorph.prototype.installCloudProjectList = function (pl) {
myself.preview.rightCenter().add(new Point(2, 0))
);
}
if (item.Public === 'true') {
/*if (item.Public === 'true') {
myself.shareButton.hide();
myself.unshareButton.show();
} else {
myself.unshareButton.hide();
myself.shareButton.show();
}
}*/
myself.buttons.fixLayout();
myself.fixLayout();
myself.edit();
};
this.body.add(this.listField);
this.shareButton.show();
this.unshareButton.hide();
//this.shareButton.show();
//this.unshareButton.hide();
this.deleteButton.show();
this.buttons.fixLayout();
this.fixLayout();
Expand Down
8 changes: 8 additions & 0 deletions beetleblocks/index.html
Expand Up @@ -53,6 +53,14 @@
<script type="text/javascript" src="FileSaver.min.js"></script>

<script type="text/javascript" src="beetleblocks/beetlecloud.js"></script>

<link rel="stylesheet" href="../libraries/css/metro-all.css">
<link rel="stylesheet" href="../libraries/css/bootstrap.min.css">
<script type="text/javascript" src="../libraries/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../libraries/js/metro.js"></script>
<script type="text/javascript" src="../libraries/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../js/file_manager.js"></script>
<script type="text/javascript" src="../js/save-data.js"></script>

<script type="text/javascript">
var world,
Expand Down
4 changes: 2 additions & 2 deletions index.html
Expand Up @@ -980,11 +980,11 @@
<div data-role="tile" class="tile bg-create fg-white no-mobile" data-effect="hover-slide-up">
<span class="mif-bubble badge-medium-top pr-4 bg-transparent" onclick="openSmallWindow('./lnu/commenting/index.html','Feedback',event);"></span>
<span class="mif-question badge-medium-top m-0 bg-transparent" onclick="infoClick('./about/beetleblocks-help.html', '#BeetleBloxDialog');"></span>
<div class="slide-front" onclick="tileClick('http://beetleblocks.com/run/', undefined, event);">
<div class="slide-front" onclick="tileClick('./beetleblocks/', 'beetleblocks', event);">
<img class="icon" src="./images/beetle-blocks.png">
<span class="branding-bar">Beetle Blocks</span>
</div>
<div class="slide-back text-small d-flex flex-justify-center flex-align-center p-3" onclick="tileClick('http://beetleblocks.com/run/', undefined, event);">
<div class="slide-back text-small d-flex flex-justify-center flex-align-center p-3" onclick="tileClick('./beetleblocks/', 'beetleblocks', event);">
Design a 3D model through programming
</div>
</div>
Expand Down

0 comments on commit af9a64b

Please sign in to comment.