fix cloud access

upd4.2
Michael Aschauer 2018-10-02 19:14:02 +02:00
rodzic 71ec1e56dc
commit 1404840d81
3 zmienionych plików z 199 dodań i 9 usunięć

Wyświetl plik

@ -34,9 +34,9 @@
<script type="text/javascript" src="stitchcode/blocks.js"></script>
<script type="text/javascript" src="stitchcode/threads.js"></script>
<script type="text/javascript" src="stitchcode/objects.js"></script>
<script type="text/javascript" src="stitchcode/gui.js"></script>
<script type="text/javascript" src="stitchcode/store.js"></script>
<script type="text/javascript" src="stitchcode/turtlecloud.js"></script>
<script type="text/javascript" src="stitchcode/gui.js"></script>
<script type="text/javascript" src="stitchcode/store.js"></script>
<script type="text/javascript">
var world;

Wyświetl plik

@ -16,7 +16,7 @@ IDE_Morph.prototype.init = function(isAutoFill) {
'Embroidery tools'
);
// this.isAnimating = false;
this.cloud = new BeetleCloud('/api');
};
// change logo
@ -2255,3 +2255,81 @@ DialogBoxMorph.prototype.informWithLink = function (
IDE_Morph.prototype.toggleStageSize = function (isSmall, forcedRatio) {
};
ProjectDialogMorph.prototype.installCloudProjectList = function (pl) {
var myself = this;
this.projectList = pl || [];
this.projectList.sort(function (x, y) {
return x.ProjectName.toLowerCase() < y.ProjectName.toLowerCase() ?
-1 : 1;
});
this.listField.destroy();
this.listField = new ListMorph(
this.projectList,
this.projectList.length > 0 ?
function (element) {
return element.ProjectName || element;
} : null,
[ // format: display shared project names bold
[
'bold',
function (proj) {return proj.Public === 'true'; }
]
],
function () {myself.ok(); }
);
this.fixListFieldItemColors();
this.listField.fixLayout = nop;
this.listField.edge = InputFieldMorph.prototype.edge;
this.listField.fontSize = InputFieldMorph.prototype.fontSize;
this.listField.typeInPadding = InputFieldMorph.prototype.typeInPadding;
this.listField.contrast = InputFieldMorph.prototype.contrast;
this.listField.drawNew = InputFieldMorph.prototype.drawNew;
this.listField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder;
this.listField.action = function (item) {
if (item === undefined) {return; }
if (myself.nameField) {
myself.nameField.setContents(item.ProjectName || '');
}
if (myself.task === 'open') {
myself.notesText.text = item.Notes || '';
myself.notesText.drawNew();
myself.notesField.contents.adjustBounds();
myself.preview.texture = item.Thumbnail || null;
myself.preview.cachedTexture = null;
myself.preview.drawNew();
(new SpeechBubbleMorph(new TextMorph(
localize('last changed') + '\n' + item.Updated,
null,
null,
null,
null,
'center'
))).popUp(
myself.world(),
myself.preview.rightCenter().add(new Point(2, 0))
);
}
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.deleteButton.show();
this.buttons.fixLayout();
this.fixLayout();
if (this.task === 'open') {
this.clearDetails();
}
};

Wyświetl plik

@ -284,9 +284,11 @@ BeetleCloud.prototype.getProjectList = function (callBack, errorCall) {
eachProject.Thumbnail = eachProject.thumbnail;
eachProject.Updated = eachProject.updated;
eachProject.Notes = eachProject.notes;
});
callBack.call(null, response);
} else {
alert("empty")
callBack.call(null, []);
}
},
@ -299,12 +301,7 @@ BeetleCloud.prototype.getProjectList = function (callBack, errorCall) {
);
};
// Backwards compatibility with old cloud
// To be removed when we finish moving to the new cloud
BeetleCloud.prototype.parseResponse = function (usr) {
return [{ username: usr, password: 'nope' }];
};
Cloud = BeetleCloud;
var SnapCloud = new BeetleCloud(
'/api'
@ -728,3 +725,118 @@ IDE_Morph.prototype.cloudMenu = function () {
menu.popup(world, pos);
};
ProjectDialogMorph.prototype.setSource = function (source) {
var myself = this,
msg;
this.source = source; //this.task === 'save' ? 'local' : source;
this.srcBar.children.forEach(function (button) {
button.refresh();
});
switch (this.source) {
case 'cloud':
msg = myself.ide.showMessage('Updating\nproject list...');
this.projectList = [];
//msg.destroy();
SnapCloud.getProjectList(
function (projectList) {
myself.installCloudProjectList(projectList);
msg.destroy();
},
function (err, lbl) {
msg.destroy();
myself.ide.cloudError().call(null, err, lbl);
}
);
return;
break;
case 'examples':
this.projectList = this.getExamplesProjectList();
break;
case 'local':
this.projectList = this.getLocalProjectList();
break;
}
this.listField.destroy();
this.listField = new ListMorph(
this.projectList,
this.projectList.length > 0 ?
function (element) {
return element.name;
} : null,
null,
function () {myself.ok(); }
);
this.fixListFieldItemColors();
this.listField.fixLayout = nop;
this.listField.edge = InputFieldMorph.prototype.edge;
this.listField.fontSize = InputFieldMorph.prototype.fontSize;
this.listField.typeInPadding = InputFieldMorph.prototype.typeInPadding;
this.listField.contrast = InputFieldMorph.prototype.contrast;
this.listField.drawNew = InputFieldMorph.prototype.drawNew;
this.listField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder;
if (this.source === 'local') {
this.listField.action = function (item) {
var src, xml;
if (item === undefined) {return; }
if (myself.nameField) {
myself.nameField.setContents(item.name || '');
}
if (myself.task === 'open') {
src = localStorage['-snap-project-' + item.name];
xml = myself.ide.serializer.parse(src);
myself.notesText.text = xml.childNamed('notes').contents
|| '';
myself.notesText.drawNew();
myself.notesField.contents.adjustBounds();
myself.preview.texture = xml.childNamed('thumbnail').contents
|| null;
myself.preview.cachedTexture = null;
myself.preview.drawNew();
}
myself.edit();
};
} else { // 'examples', 'cloud' is initialized elsewhere
this.listField.action = function (item) {
var src, xml;
if (item === undefined) {return; }
if (myself.nameField) {
myself.nameField.setContents(item.name || '');
}
src = myself.ide.getURL(item.path);
xml = myself.ide.serializer.parse(src);
myself.notesText.text = xml.childNamed('notes').contents
|| '';
myself.notesText.drawNew();
myself.notesField.contents.adjustBounds();
myself.preview.texture = xml.childNamed('thumbnail').contents
|| null;
myself.preview.cachedTexture = null;
myself.preview.drawNew();
myself.edit();
};
}
this.body.add(this.listField);
this.shareButton.hide();
this.unshareButton.hide();
if (this.source === 'local') {
this.deleteButton.show();
} else { // examples
this.deleteButton.hide();
}
this.buttons.fixLayout();
this.fixLayout();
if (this.task === 'open') {
this.clearDetails();
}
};