Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map Part 1 (Created a html page and created a map using the Google Map API) + Map Part 2 + Map Part 3 #13

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1c12c97
added recipient as a component to the message system
yen-tt Feb 24, 2019
4d6ed3b
completed the last few steps of the Direct Messages feature
yen-tt Feb 24, 2019
edecce0
new branch
pranathil Feb 25, 2019
d00b9d2
new servlet
pranathil Feb 25, 2019
a03c6ee
datastore
pranathil Feb 25, 2019
20b9d7d
servlet logic
pranathil Feb 25, 2019
f7fe57f
Add basic Java templates for gitignore
nsallembiencodeu Feb 28, 2019
ad6de47
Merge branch 'gitignore' into PranathiDevelopment
nsallembiencodeu Feb 28, 2019
0b19389
gitignore fix
nsallembiencodeu Feb 28, 2019
736fb0f
final
pranathil Mar 3, 2019
93f633c
final
pranathil Mar 3, 2019
e28203f
fixed travis errors
pranathil Mar 3, 2019
154cf9d
changed helper name
pranathil Mar 11, 2019
cf81cc4
removed target files
pranathil Mar 11, 2019
710c3b5
fixed errors
pranathil Mar 11, 2019
c6eecba
complete guided project MAP part 1
yen-tt Mar 15, 2019
c7b59ed
Merge branch 'master' into YenDevelopment
nsallembiencodeu Mar 15, 2019
fc1ff3c
Merge pull request #3 from yen1027/YenDevelopment
nsallembiencodeu Mar 15, 2019
b7e11ea
Merge branch 'master' into PranathiDevelopment
nsallembiencodeu Mar 15, 2019
09b732f
Merge pull request #11 from yen1027/PranathiDevelopment
nsallembiencodeu Mar 15, 2019
0c98ec4
Deleting files from .gitignore
nsallembiencodeu Mar 15, 2019
3c5f592
fix build merge issue and apply linter
nsallembiencodeu Mar 15, 2019
151a420
Fixing more build errors
nsallembiencodeu Mar 15, 2019
b3c4276
Merge pull request #14 from yen1027/remove_ignored
nsallembiencodeu Mar 15, 2019
35b5fb7
added a csv file containing data that will be fetch be UfoDataServlet…
yen-tt Mar 25, 2019
7c71702
minor change to the csv file
yen-tt Mar 25, 2019
007a331
complete guided project MAP part 1
yen-tt Mar 15, 2019
0b95df9
added a csv file containing data that will be fetch be UfoDataServlet…
yen-tt Mar 25, 2019
921a12e
minor change to the csv file
yen-tt Mar 25, 2019
9ea2901
Merge branch 'Map' of https://github.com/yen1027/CodeBusters into Map
yen-tt Mar 25, 2019
6246ca4
fixed ufo csv file! Map part 2 is completed
yen-tt Mar 25, 2019
e7b0d8c
started on Map part 3, added functions to user-map html to allow user…
yen-tt Mar 25, 2019
bcb0d4b
style changes
yen-tt Mar 25, 2019
fc2d8d3
Completed Maps Part 3: User can create markers and and info, in which…
yen-tt Mar 31, 2019
ac0501e
fixed format violations on the code
yen-tt Mar 31, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to rebase this branch on top of the new master? This will make sure you have all the latest goodies in terms of .gitignore, etc.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah! will do

3 changes: 3 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
49 changes: 26 additions & 23 deletions src/main/java/com/google/codeu/data/Datastore.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public void storeMessage(Message message) {
messageEntity.setProperty("user", message.getUser());
messageEntity.setProperty("text", message.getText());
messageEntity.setProperty("timestamp", message.getTimestamp());

messageEntity.setProperty("recipient", message.getRecipient());

datastore.put(messageEntity);
}

Expand All @@ -52,31 +53,33 @@ public void storeMessage(Message message) {
* @return a list of messages posted by the user, or empty list if user has never posted a
* message. List is sorted by time descending.
*/
public List<Message> getMessages(String user) {
List<Message> messages = new ArrayList<>();
public List<Message> getMessages(String recipient) {
List<Message> messages = new ArrayList<>();

Query query =
new Query("Message")
.setFilter(new Query.FilterPredicate("recipient", FilterOperator.EQUAL, recipient))
.addSort("timestamp", SortDirection.DESCENDING);
PreparedQuery results = datastore.prepare(query);

Query query =
new Query("Message")
.setFilter(new Query.FilterPredicate("user", FilterOperator.EQUAL, user))
.addSort("timestamp", SortDirection.DESCENDING);
PreparedQuery results = datastore.prepare(query);
for (Entity entity : results.asIterable()) {
try {
String idString = entity.getKey().getName();
UUID id = UUID.fromString(idString);
String user = (String) entity.getProperty("user");

for (Entity entity : results.asIterable()) {
try {
String idString = entity.getKey().getName();
UUID id = UUID.fromString(idString);
String text = (String) entity.getProperty("text");
long timestamp = (long) entity.getProperty("timestamp");
String text = (String) entity.getProperty("text");
long timestamp = (long) entity.getProperty("timestamp");

Message message = new Message(id, user, text, timestamp);
messages.add(message);
} catch (Exception e) {
System.err.println("Error reading message.");
System.err.println(entity.toString());
e.printStackTrace();
Message message = new Message(id, user, text, timestamp, recipient);
messages.add(message);
} catch (Exception e) {
System.err.println("Error reading message.");
System.err.println(entity.toString());
e.printStackTrace();
}
}
}

return messages;
}
return messages;
}
}
17 changes: 12 additions & 5 deletions src/main/java/com/google/codeu/data/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ public class Message {
private String user;
private String text;
private long timestamp;
private String recipient;

/**
* Constructs a new {@link Message} posted by {@code user} with {@code text} content. Generates a
* random ID and uses the current system time for the creation time.
* Constructs a new {@link Message} posted by {@code user} with {@code text} content to
* a {@code recipient}. Generates a random ID and uses the current system time for the creation time.
*/
public Message(String user, String text) {
this(UUID.randomUUID(), user, text, System.currentTimeMillis());
public Message(String user, String text, String recipient) {
this(UUID.randomUUID(), user, text, System.currentTimeMillis(), recipient);
}

public Message(UUID id, String user, String text, long timestamp) {
public Message(UUID id, String user, String text, long timestamp, String recipient) {
this.id = id;
this.user = user;
this.text = text;
this.timestamp = timestamp;
this.recipient = recipient;
}

public UUID getId() {
Expand All @@ -56,4 +58,9 @@ public String getText() {
public long getTimestamp() {
return timestamp;
}

public String getRecipient()
{
return recipient;
}
}
9 changes: 6 additions & 3 deletions src/main/java/com/google/codeu/servlets/MessageServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr

String user = userService.getCurrentUser().getEmail();
String text = Jsoup.clean(request.getParameter("text"), Whitelist.none());

Message message = new Message(user, text);
String recipient = request.getParameter("recipient");
System.out.println("print recipient:");
System.out.println(recipient);

Message message = new Message(user, text, recipient);
datastore.storeMessage(message);

response.sendRedirect("/user-page.html?user=" + user);
response.sendRedirect("/user-page.html?user=" + recipient);
}
}
3 changes: 2 additions & 1 deletion src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ <h1>CodeU Starter Project</h1>
their URL.</p>
<p>This is your code now! Feel free to make changes, and don't be afraid to get creative!
You could start by modifying this page to tell the world more about your team.</p>
<p>Hello World!</p>
</body>
</html>
</html>
32 changes: 17 additions & 15 deletions src/main/webapp/js/user-page-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ function setPageTitle() {
}

/**
* Shows the message form if the user is logged in and viewing their own page.
* Shows the message form if the user is logged in, even if they
* aren't viewing their own page.
*/
function showMessageFormIfViewingSelf() {
fetch('/login-status')
.then((response) => {
return response.json();
})
.then((loginStatus) => {
if (loginStatus.isLoggedIn &&
loginStatus.username == parameterUsername) {
const messageForm = document.getElementById('message-form');
messageForm.classList.remove('hidden');
}
});
}
function showMessageFormIfLoggedIn() {
fetch('/login-status')
.then((response) => {
return response.json();
})
.then((loginStatus) => {
if (loginStatus.isLoggedIn) {
const messageForm = document.getElementById('message-form');
messageForm.action = '/messages?recipient=' + parameterUsername;
messageForm.classList.remove('hidden');
}
});
}


/** Fetches messages and add them to the page. */
function fetchMessages() {
Expand Down Expand Up @@ -93,6 +95,6 @@ function buildMessageDiv(message) {
/** Fetches data and populates the UI of the page. */
function buildUI() {
setPageTitle();
showMessageFormIfViewingSelf();
showMessageFormIfLoggedIn();
fetchMessages();
}
45 changes: 45 additions & 0 deletions src/main/webapp/map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>Map Project</title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAWJW6lENPXp_hwUrYirFP4kdUQixTCtwo"></script>
<script>
let map;
function createMap(){

//creates a map
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 37.422, lng: -122.084},
zoom: 16
});

//add marker
const trexMarker = new google.maps.Marker({
position: {lat: 37.421903, lng: -122.084674},
map: map,
title: 'Stan the T-Rex'
});

//add popup description
var trexInfoWindow = new google.maps.InfoWindow({
content: 'This is Stan, the T-Rex statue.'
});

trexMarker.addListener('click', function() {
trexInfoWindow.open(map, trexMarker);
});
}
</script>
<style>
#map{
width: 500px;
height: 500px;
border: thin solid black;
}
</style>
</head>
<body onload="createMap();">
<h1>Map Project</h1>
<div id="map"></div>
</body>
</html>