From ec92d6c5bdfa4a0859aa8a474c7dce14a56b559d Mon Sep 17 00:00:00 2001 From: Scott Garner Date: Wed, 26 Nov 2014 12:22:08 -0800 Subject: [PATCH] Support for hidden sketches on parse and the ability to opt out of the gallery per #64 --- admin/index.html | 4 ++-- display/index.html | 5 ++++ editor/index.html | 60 +++++++++++++++++++++++++++++++++++++++------- js/display.js | 5 +++- js/editor.js | 49 +++++++++++++------------------------ js/gallery.js | 2 ++ 6 files changed, 80 insertions(+), 45 deletions(-) diff --git a/admin/index.html b/admin/index.html index 3f31987..78ce50c 100644 --- a/admin/index.html +++ b/admin/index.html @@ -41,8 +41,8 @@

Log Out

-

You are logged in as .

- +

You are logged in as . You make now make edits to sketches in the gallery.

+
diff --git a/display/index.html b/display/index.html index a4f0563..654ea1b 100644 --- a/display/index.html +++ b/display/index.html @@ -64,6 +64,11 @@ +
+ +
diff --git a/js/display.js b/js/display.js index 7336211..2dcdc4c 100644 --- a/js/display.js +++ b/js/display.js @@ -70,8 +70,10 @@ var helloDisplay = { } else { var featureScore = parseInt($("#featureScore").val()); + var hidden = $('#hidden').prop('checked'); helloDisplay.parseObject.set("featureScore", featureScore); + helloDisplay.parseObject.set("hidden", hidden); helloDisplay.parseObject.save(); } @@ -136,9 +138,10 @@ var helloDisplay = { helloDisplay.parseObject = gallery; helloDisplay.showSketch(gallery.get("source")); - $("#viewCount").val(gallery.get("viewCount")); $("#featureScore").val(gallery.get("featureScore")); + $('#hidden').prop('checked', gallery.get("hidden")); + Parse.Cloud.run('incrementViewCount', {id: gallery.id}, { success: function(result) { // Success diff --git a/js/editor.js b/js/editor.js index 6a739ff..75af7a0 100644 --- a/js/editor.js +++ b/js/editor.js @@ -204,9 +204,9 @@ var helloEditor = { }); $("#shareButton").click(function () { - helloEditor.confirmExit = false; - //helloEditor.createGist(); - helloEditor.addToGallery(); + //helloEditor.addToGallery(); + + helloEditor.showShareConfirm(); }); $("#resetExample").click(function () { @@ -242,6 +242,14 @@ var helloEditor = { /* Share UI */ + $("#modalConfirmButton").click(function () { + + var hidden = !$("#modalGalleryCheckbox").prop('checked'); + + $('#confirmModal').modal('hide'); + helloEditor.addToGallery(hidden); + }); + $("#modalGoogleButton").click(function () { var shareURL = "https://plus.google.com/share", @@ -640,7 +648,7 @@ var helloEditor = { /** * Adds to the gallery hosted on Parse */ - addToGallery: function() { + addToGallery: function(hidden) { // Post to Parse @@ -665,7 +673,9 @@ var helloEditor = { var gallery = new Parse.Object("Gallery"); gallery.set("source", processingSource); gallery.set("image", processingImage); + gallery.set("hidden", hidden) gallery.save(galleryData).then(function(object) { + helloEditor.parseObject = object; var displayURL = "http://" + $(location).attr('hostname') + (($(location).attr('port') !== "") ? ":" + $(location).attr('port') : "") + "/display/#@" + object.id; helloEditor.showShare(displayURL); }); @@ -685,35 +695,8 @@ var helloEditor = { }, - /** - * Creates a new Gist with editor contents and shows the share modal - */ - createGist: function () { - - var processingSource = this.editor.getValue(), - postURL = "https://api.github.com/gists", - postData; - - if (!(/size\(\s*\d+\s*,\s*\d+\s*\)/.test(processingSource))) { - processingSource = "size(500,400);\n\n" + processingSource; - } - - postData = { - "description": "Save for Processing Hour of Code", - "public": true, - "files": { - "demo.pde": { - "content": processingSource - } - } - }; - - $.post(postURL, JSON.stringify(postData)) - .done(function (data) { - var displayURL = "http://" + $(location).attr('hostname') + (($(location).attr('port') !== "") ? ":" + $(location).attr('port') : "") + "/display/#" + data.id; - helloEditor.showShare(displayURL); - }); - + showShareConfirm: function() { + $('#confirmModal').modal('show'); }, showShare: function(displayURL) { diff --git a/js/gallery.js b/js/gallery.js index 091c114..267a021 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -84,6 +84,8 @@ var helloGallery = { var GalleryObject = Parse.Object.extend("Gallery"); var query = new Parse.Query(GalleryObject); + + query.notEqualTo("hidden", true); query.limit(helloGallery.itemsPerPage); query.skip(helloGallery.pageNumber * helloGallery.itemsPerPage);