Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/main/java/shef/servlets/NewRecipeServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,4 @@ private void addToSearchStrings(Collection<String> searchStrings, String stringT
}
searchStrings.add(stringToAdd.toUpperCase());
}

/** Converts a Datastore entity into a Recipe. */
private Recipe entityToRecipe(Entity recipeEntity) {
String name = (String) recipeEntity.getProperty("name");
String user = (String) recipeEntity.getProperty("user");
String description = (String) recipeEntity.getProperty("description");
LinkedHashSet<String> tags = new LinkedHashSet<>((LinkedList<String>) (LinkedList<?>) getDataAsList(recipeEntity.getProperty("tags"), TAG));
LinkedHashSet<String> ingredients = new LinkedHashSet<>((LinkedList<String>) (LinkedList<?>) getDataAsList(recipeEntity.getProperty("ingredients"), INGREDIENT));
LinkedList<Step> steps = (LinkedList<Step>) (LinkedList<?>) getDataAsList(recipeEntity.getProperty("steps"), STEP);
long timestamp = (long) recipeEntity.getProperty("timestamp");
return new Recipe(name, user, description, tags, ingredients, steps, timestamp);
}

/** Gets a list of Recipe parameters from a Datastore property. */
private Collection<Object> getDataAsList(Object propertiesObject, String field) {
Collection<EmbeddedEntity> properties = (Collection<EmbeddedEntity>) propertiesObject;
Collection<Object> dataAsList = new LinkedList<>();
for (EmbeddedEntity property : properties) {
dataAsList.add(property.getProperty(field));
}
return dataAsList;
}

private String convertToJsonUsingGson(Recipe recipe) {
Gson gson = new Gson();
return gson.toJson(recipe);
}
}
39 changes: 28 additions & 11 deletions src/main/webapp/recipe.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,40 @@
});
</script>

<!-- Calendar Test -->
<pre id="content" style="white-space: pre-wrap;"></pre>
<!--Add buttons to initiate auth sequence and sign out-->
<button id="authorize_button" style="display: block;" onclick="handleAuthClick();">Authorize</button>
<button id="signout_button" style="display: none;" onclick="handleSignoutClick();">Sign Out</button>
<button id="event_button" style="display: none;" onclick="addLiveStreamToCalendar()">Add Event</button>
<!-- Add to Calendar Modal -->
<div class="modal fade" id="addToCalModal" tabindex="-1" role="dialog" aria-labelledby="addToCalModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addToCalModalLongTitle">Add to Calendar</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<button id="authorize_button" class="btn btn-primary" style="display: block;" onclick="handleAuthClick();">Authorize</button>
<p id="event-message" style="white-space: pre-wrap;"></p>
<button id="event_button" class="btn btn-primary" style="display: none;" onclick="addLiveStreamToCalendar()">Add to calendar</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>

<div class="jumbotron text-center">
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<!-- Sharing Modal -->
<div class="modal fade" id="sharingModal" tabindex="-1" role="dialog" aria-labelledby="sharingModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Share</h5>
<h5 class="modal-title" id="sharingModalLongTitle">Share</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
Expand All @@ -85,7 +100,6 @@ <h5 class="modal-title" id="exampleModalLongTitle">Share</h5>
</a>
</li>
<li class="list-inline-item"><img src="/assets/images/mail_icon.png" id="myItem" class="share-icon"></li>
<div id="myItem" data-page_id="1510970">1510970</div>
</ul>
</div>
<div class="modal-footer">
Expand Down Expand Up @@ -124,7 +138,10 @@ <h3 id="recipe-tags"></h3>
<path fill-rule="evenodd" d="M11 5h2.02a1.5 1.5 0 0 1 1.17.563l1.481 1.85a1.5 1.5 0 0 1 .329.938V10.5a1.5 1.5 0 0 1-1.5 1.5h-1v-1h1a.5.5 0 0 0 .5-.5V8.35a.5.5 0 0 0-.11-.312l-1.48-1.85A.5.5 0 0 0 13.02 6H12v4.5h-1V5zm-8 8a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm0 1a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/>
<path fill-rule="evenodd" d="M12 13a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm0 1a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/>
</svg>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addToCalModal">
Add to Calendar
</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#sharingModal">
Share
</button>
</div>
Expand Down
33 changes: 6 additions & 27 deletions src/main/webapp/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,37 +971,19 @@ function initClient() {
*/
function handleAuthClick(event) {
var authorizeButton = document.getElementById('authorize_button');
var signoutButton = document.getElementById('signout_button');
var eventButton = document.getElementById('event_button');
gapi.auth2.getAuthInstance().signIn();
authorizeButton.style.display = 'none';
eventButton.style.display = 'block';
signoutButton.style.display = 'block';
}

/**
* Sign out the user upon button click.
* Used to display the results of the API call.
* @param {string} message Text to be placed in an element.
*/
function handleSignoutClick(event) {
var authorizeButton = document.getElementById('authorize_button');
var signoutButton = document.getElementById('signout_button');
var eventButton = document.getElementById('event_button');
gapi.auth2.getAuthInstance().signOut();
authorizeButton.style.display = 'block';
eventButton.style.display = 'none';
signoutButton.style.display = 'none';
}

/**
* Append a pre element to the body containing the given message
* as its text node. Used to display the results of the API call.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('content');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
function appendMessage(message) {
var element = document.getElementById('event-message');
element.innerHTML = message + "\n";
}

function addEvent(link, startTime, endTime){
Expand All @@ -1016,9 +998,6 @@ function addEvent(link, startTime, endTime){
'dateTime': endTime,
'timeZone': 'America/Los_Angeles'
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'reminders': {
'useDefault': false,
'overrides': [
Expand All @@ -1034,7 +1013,7 @@ function addEvent(link, startTime, endTime){
});

request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
appendMessage('Event created! Click <a href=' + event.htmlLink + ">here</a> to view it on your calendar.");
});
}

Expand Down