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

Play Nice With Your Companion #278

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 2 additions & 4 deletions src/crud/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public class Constant {
* prd-01
*/


public static String RERUM_REGISTRATION_URL = "http://store.rerum.io/v1/";
public static String RERUM_API_ADDR = "http://store.rerum.io/v1/api";
public static String RERUM_ACCESS_TOKEN_URL = "http://store.rerum.io/v1/api/accessToken.action";
public static String RERUM_REFRESH_TOKEN_URL = "http://store.rerum.io/v1/api/refreshToken.action";
public static String RERUM_AGENT = "http://store.rerum.io/v1/id/5da8c165d5de6ba6e2028474"; //Lived-Religion-prod

public static String RERUM_AGENT = "http://store.rerum.io/v1/id/5da8c165d5de6ba6e2028474"; //Lived-Religion-prod

/**
* dev-01
Expand All @@ -32,8 +30,8 @@ public class Constant {
public static String RERUM_ACCESS_TOKEN_URL = "http://devstore.rerum.io/v1/api/accessToken.action";
public static String RERUM_REFRESH_TOKEN_URL = "http://devstore.rerum.io/v1/api/refreshToken.action";
public static String RERUM_AGENT = "http://devstore.rerum.io/v1/id/5afeebf3e4b0b0d588705d90"; //This is sandbox-dev
public static String COMPANION_AGENT = "http://store.rerum.io/v1/id/630e79471267884358921da7"; //This is LRDA-dev (the wr-dev data, since it uses the internal API)
*/

//https://stackoverflow.com/questions/2395737/java-relative-path-of-a-file-in-a-java-web-application
public static String PROPERTIES_FILE_NAME = "lr.properties";
}
5 changes: 4 additions & 1 deletion src/crud/TinyDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
connection.disconnect();
}
if(manager.getAPISetting().equals("true")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
}
response.setStatus(codeOverwrite);
response.setHeader("Content-Type", "text/plain; charset=utf-8");
Expand Down
4 changes: 3 additions & 1 deletion src/crud/TinyOverwrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
}
connection.disconnect();
if(manager.getAPISetting().equals("true")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
}
response.setStatus(codeOverwrite);
Expand Down
6 changes: 4 additions & 2 deletions src/crud/TinyQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tokens.TinyTokenManager;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;


/**
Expand Down Expand Up @@ -112,7 +113,6 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
connection.connect();
try{
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
//Pass in the user provided JSON for the body of the rerumserver v1 request
requestJSON.element("__rerum.generatedBy", Constant.RERUM_AGENT);
byte[] toWrite = requestJSON.toString().getBytes("UTF-8");
//Pass in the user provided JSON for the body of the rerumserver v1 request
Expand Down Expand Up @@ -147,7 +147,9 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
}
connection.disconnect();
if(manager.getAPISetting().equals("true")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
}
response.setStatus(codeOverwrite);
Expand Down
5 changes: 4 additions & 1 deletion src/crud/TinySave.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
connection.disconnect();
//Hand back rerumserver response as this API's response.
if(manager.getAPISetting().equals("true")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
}
response.setStatus(codeOverwrite);
response.setHeader("Content-Type", "application/json; charset=utf-8");
Expand Down
5 changes: 4 additions & 1 deletion src/crud/TinyUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
}
connection.disconnect();
if(manager.getAPISetting().equals("true")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
}
response.setStatus(codeOverwrite);
response.setHeader("Content-Type", "application/json; charset=utf-8");
Expand Down
22 changes: 22 additions & 0 deletions src/servlets/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
jo_return.element("error", "Unauthorized");
}
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
response.addHeader("Content-Type", "application/json; charset=utf-8");
response.setContentType("UTF-8");
response.getWriter().print(jo_return);
Expand Down Expand Up @@ -97,6 +101,24 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>OPTIONS</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Headers", "*");
response.addHeader("Access-Control-Allow-Methods", "*");
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
response.setStatus(200);
}

/**
* Returns a short description of the servlet.
Expand Down
22 changes: 22 additions & 0 deletions src/servlets/Logout.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
response.setContentType("text/html;charset=UTF-8");
HttpSession sess = request.getSession();
sess.removeAttribute("lr-user");
if(!response.containsHeader("Access-Control-Allow-Origin")){
response.addHeader("Access-Control-Allow-Origin", "*"); //To use this as an API, it must contain CORS headers
}
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
response.getWriter().print("Logged Out");
}

Expand All @@ -47,6 +51,24 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>OPTIONS</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Headers", "*");
response.addHeader("Access-Control-Allow-Methods", "*");
response.setHeader("Access-Control-Expose-Headers", "*"); //Headers are restricted, unless you explicitly expose them. Darn Browsers.
response.setStatus(200);
}

/**
* Returns a short description of the servlet.
Expand Down
1 change: 1 addition & 0 deletions web/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<a href="people.html">People</a>
<a href="organizations.html">Organizations</a>
<a href="map.html">Map View</a>
<a href="fieldnotes.html">My Notes</a>
</div>
</div>
</lr-nav>
Expand Down
1 change: 1 addition & 0 deletions web/experience.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ <h4 class="text-primary">What practices are occurring? Add one at a time.</h4>
//obj.fn() would be neat if obj.fn = function(){return LR.utils.logout()} would work...see logout.html
document.location.href="dashboard.html"
})


</script>
<script src="./js/deerInitializer.js" type="module"></script>
Expand Down
109 changes: 109 additions & 0 deletions web/fieldnotes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!DOCTYPE html>
<!--
author: Bryan Haberberger <[email protected]>
-->
<html>

<head>
<title>Scratch Notes</title>
<link rel="shortcut icon" type="image/x-icon" href="./images/favicon/favicon.ico">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/lr.css">
<style>
.selectNote{
font-size: 11pt !important;
line-height: 10pt;
}
.selectNote.selected{
background-color: green;
color: white;
}
.button.primary{
margin-top: 3em;
}
</style>
</head>

<body>
<lr-nav>
<div class="nav-left">
<a class="brand" href="index.html"><img src="https://upload.wikimedia.org/wikipedia/commons/3/3d/Meuble_h%C3%A9raldique_Fleur_de_lis.svg"></a>
<div class="tabs">
<a href="places.html">Locations</a>
<a href="objects.html">Objects</a>
<a href="people.html">People</a>
<a href="organizations.html">Organizations</a>
<a href="map.html">Map View</a>
</div>
</div>
</lr-nav>
<div id="fieldnotes_wraper" class="container">
<h1 id="userDashboard" class="text-primary"> My Notes </h1>
<p>
Below you will see all your submitted notes. Click the <span class="tag is-rounded is-small selectNote" title="Assign This Note"
>&#9733</span> to select the note and begin to assign it. You will need to pick an Experience and a descriptor to assign the note text to.
Once you assign the note, it will be removed from your queue.

If you decide you do not need the note, click <span class="tag is-rounded is-small removeNote" title="Remove This Note"
>&#x274C</span> to remove it from your queue.
</p>
<ul id="notesInQueue">
<p class="text-error">You must be logged in to see your scratch notes.</p>
<p>Please wait while we gather your scratch notes.</p>
</ul>
</div>
<div id="assignNoteWrapper" class="container is-hidden" noteid="">
<label> Select which experience to assign this note to </label>
<select id="expChooser"> </select>
<br>
<label> Select which note type to assign the note as </label>
<select id="noteTypes">
<option selected value="notes">General Notes</option>
<option value="description">Description</option>
<option value="fieldNotes">Field Notes</option>
</select>
<a class="button primary is-full-width" onclick="LR.utils.assignNote(event)"> Assign This Note </a>
</div>
<div class="pageShade is-hidden"></div>
<lr-global-feedback></lr-global-feedback>
<lr-footer></lr-footer>
<!-- Need to force some authorization for this page -->
<!-- Add ins -->
<script src="./js/sysendBroadcaster.js" type="text/javascript"></script>
<script>
/**
* Catch user detection and trigger draw() for interfaces.
*/
addEventListener('lrUserKnown', event => {
LR.utils.drawInterface(event, "fieldnotes")
}, false)

/**
* Handle Login and Logout across tabs
*/
local_socket.on('loginError', function(obj) {
alert("There was a problem logging in. Check the username and password. If this problem persist, contact the administrator to reset your username and/or password.")
})

local_socket.on('loginFinished', function(obj) {
//Perhaps it could be more elegant to dispatch the lrUserKnown event. Socket events are not caught on the page they are generated...
//Reload does everything we want inside the framework we already built in <lr-login> elements
document.location.reload()
})

local_socket.on('logoutError', function(obj) {
alert("There was a problem logging out. Refresh the page and try again.")
})

local_socket.on('logoutFinished', function(obj) {
//obj.fn() would be neat if obj.fn = function(){return LR.utils.logout()} would work...see logout.html
document.location.href="dashboard.html"
})
</script>
<script src="./js/deerInitializer.js" type="module"></script>
<script src="./js/app.js" type="text/javascript"></script>
<script src="./js/components.js" type="text/javascript"></script>
</body>

</html>
Loading