Skip to content
Snippets Groups Projects
Commit 31e7fe37 authored by Sven Kästle's avatar Sven Kästle
Browse files

feat: Add projectId to full submission and redirect user after button click

parent 6953c2ab
No related branches found
No related tags found
No related merge requests found
Showing with 64 additions and 18 deletions
...@@ -30,8 +30,8 @@ public class SubmissionController implements ISubmission { ...@@ -30,8 +30,8 @@ public class SubmissionController implements ISubmission {
connection.connect(); connection.connect();
// build and execute request // build and execute request
String request = "INSERT INTO fullsubmissions (`id`, `user`, `text`) VALUES (?,?,?);"; String request = "INSERT INTO fullsubmissions (`id`, `user`, `text`, `projectId`) VALUES (?,?,?,?);";
connection.issueInsertOrDeleteStatement(request, uuid, fullSubmissionPostRequest.getUser(), fullSubmissionPostRequest.getText()); connection.issueInsertOrDeleteStatement(request, uuid, fullSubmissionPostRequest.getUser(), fullSubmissionPostRequest.getText(), fullSubmissionPostRequest.getProjectId());
// get the new submission from database // get the new submission from database
FullSubmission fullSubmission = getFullSubmission(uuid); FullSubmission fullSubmission = getFullSubmission(uuid);
...@@ -283,8 +283,9 @@ public class SubmissionController implements ISubmission { ...@@ -283,8 +283,9 @@ public class SubmissionController implements ISubmission {
long timestamp = rs.getTimestamp("timestamp").getTime(); long timestamp = rs.getTimestamp("timestamp").getTime();
String user = rs.getString("user"); String user = rs.getString("user");
String text = rs.getString("text"); String text = rs.getString("text");
String projectId = rs.getString("projectId");
return new FullSubmission(id, timestamp, user, text); return new FullSubmission(id, timestamp, user, text, projectId);
} }
......
...@@ -11,13 +11,15 @@ public class FullSubmission { ...@@ -11,13 +11,15 @@ public class FullSubmission {
private long timestamp; private long timestamp;
private String user; private String user;
private String text; private String text;
private String projectId;
// constructor // constructor
public FullSubmission(String id, long timestamp, String user, String text) { public FullSubmission(String id, long timestamp, String user, String text, String projectId) {
this.id = id; this.id = id;
this.timestamp = timestamp; this.timestamp = timestamp;
this.user = user; this.user = user;
this.text = text; this.text = text;
this.projectId = projectId;
} }
// methods // methods
...@@ -53,6 +55,14 @@ public class FullSubmission { ...@@ -53,6 +55,14 @@ public class FullSubmission {
this.text = text; this.text = text;
} }
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override @Override
public String toString() { public String toString() {
return "FullSubmission{" + return "FullSubmission{" +
...@@ -60,6 +70,7 @@ public class FullSubmission { ...@@ -60,6 +70,7 @@ public class FullSubmission {
", timestamp=" + timestamp + ", timestamp=" + timestamp +
", user='" + user + '\'' + ", user='" + user + '\'' +
", text='" + text + '\'' + ", text='" + text + '\'' +
", projectId='" + projectId + '\'' +
'}'; '}';
} }
......
...@@ -9,11 +9,13 @@ public class FullSubmissionPostRequest { ...@@ -9,11 +9,13 @@ public class FullSubmissionPostRequest {
// variables // variables
private String user; private String user;
private String text; private String text;
private String projectId;
// constructors // constructors
public FullSubmissionPostRequest(String user, String text) { public FullSubmissionPostRequest(String user, String text, String projectId) {
this.user = user; this.user = user;
this.text = text; this.text = text;
this.projectId = projectId;
} }
public FullSubmissionPostRequest() {} public FullSubmissionPostRequest() {}
...@@ -35,11 +37,20 @@ public class FullSubmissionPostRequest { ...@@ -35,11 +37,20 @@ public class FullSubmissionPostRequest {
this.text = text; this.text = text;
} }
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override @Override
public String toString() { public String toString() {
return "FullSubmissionPostRequest{" + return "FullSubmissionPostRequest{" +
"user='" + user + '\'' + "user='" + user + '\'' +
", text='" + text + '\'' + ", text='" + text + '\'' +
", projectId='" + projectId + '\'' +
'}'; '}';
} }
......
...@@ -18,6 +18,6 @@ $(document).ready(function(){ ...@@ -18,6 +18,6 @@ $(document).ready(function(){
}); });
$('#btnUnstructuredUpload').click(function () { $('#btnUnstructuredUpload').click(function () {
location.href="unstructured-upload.jsp?token="+getUserTokenFromUrl(); location.href="unstructured-upload.jsp?token="+getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl();
}) })
}); });
\ No newline at end of file
...@@ -26,7 +26,7 @@ $(document).ready(function() { ...@@ -26,7 +26,7 @@ $(document).ready(function() {
}, function () { }, function () {
// jump to upload page on error // jump to upload page on error
location.href="unstructured-upload.jsp?token="+getUserTokenFromUrl(); location.href="unstructured-upload.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl();
}); });
// set click listener to save button // set click listener to save button
...@@ -246,6 +246,8 @@ function addSelectionDataToList(startCharacter, endCharacter, category) { ...@@ -246,6 +246,8 @@ function addSelectionDataToList(startCharacter, endCharacter, category) {
function saveButtonHandler() { function saveButtonHandler() {
// show alert message // show alert message
if (window.confirm("Möchten Sie wirklich ihre Annotationen speichern?")) { if (window.confirm("Möchten Sie wirklich ihre Annotationen speichern?")) {
// declare array of promises
let promises = []
$('#annotations').find('.category-card').each(function () { $('#annotations').find('.category-card').each(function () {
let array = $(this).data('array'); let array = $(this).data('array');
if (array != null) { if (array != null) {
...@@ -273,13 +275,21 @@ function saveButtonHandler() { ...@@ -273,13 +275,21 @@ function saveButtonHandler() {
submissionPartPostRequest.body.push(submissionPartBodyElement); submissionPartPostRequest.body.push(submissionPartBodyElement);
} }
// send the post request to the back-end // send the post request to the back-end and save promise
createSubmissionPart(submissionPartPostRequest, function (response) { promises.push(createSubmissionPart(submissionPartPostRequest, function (response) {
console.log("send " + response.category + "'s post request to back-end") console.log("send " + response.category + "'s post request to back-end")
}) }));
} }
}); });
$.when.apply($, promises).then(function () {
// redirect user to project page after saving
location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl();
});
// redirect user to project page after saving
// location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl();
} }
} }
......
...@@ -48,11 +48,12 @@ function getFullSubmission(id, responseHandler, errorHandler) { ...@@ -48,11 +48,12 @@ function getFullSubmission(id, responseHandler, errorHandler) {
* *
* @param submissionPartPostRequest The post request * @param submissionPartPostRequest The post request
* @param responseHandler The response handler * @param responseHandler The response handler
* @returns A promise object
*/ */
function createSubmissionPart(submissionPartPostRequest, responseHandler) { function createSubmissionPart(submissionPartPostRequest, responseHandler) {
var url = "../rest/submissions/part/"; var url = "../rest/submissions/part/";
var json = JSON.stringify(submissionPartPostRequest); var json = JSON.stringify(submissionPartPostRequest);
$.ajax({ return $.ajax({
url: url, url: url,
type: "POST", type: "POST",
data: json, data: json,
......
...@@ -13,7 +13,8 @@ $(document).ready(function() { ...@@ -13,7 +13,8 @@ $(document).ready(function() {
// build request // build request
var fullSubmissionPostRequest = { var fullSubmissionPostRequest = {
user: user, user: user,
text: text text: text,
projectId: getProjectIdFromUrl()
}; };
// save request in database // save request in database
...@@ -22,7 +23,7 @@ $(document).ready(function() { ...@@ -22,7 +23,7 @@ $(document).ready(function() {
$('#upload-textarea').val(""); $('#upload-textarea').val("");
// jump to next page // jump to next page
location.href="unstructured-annotation.jsp?token=" + getUserTokenFromUrl() + "&submission=" + response.id; location.href="unstructured-annotation.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl() + "&submission=" + response.id;
}); });
} }
}); });
...@@ -36,13 +37,15 @@ $(document).ready(function() { ...@@ -36,13 +37,15 @@ $(document).ready(function() {
$('#upload-textarea').val(""); $('#upload-textarea').val("");
// jump to previous page // jump to previous page
location.href="project-student.jsp?token="+getUserTokenFromUrl(); window.history.back();
//location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl();
} }
} }
// nothing to check // nothing to check
else { else {
// jump to previous page // jump to previous page
location.href="project-student.jsp?token="+getUserTokenFromUrl(); window.history.back();
//location.href="project-student.jsp?token=" + getUserTokenFromUrl() + "&projectId=" + getProjectIdFromUrl();
} }
}); });
...@@ -63,6 +66,3 @@ $(document).ready(function() { ...@@ -63,6 +66,3 @@ $(document).ready(function() {
}); });
}); });
...@@ -13,3 +13,14 @@ function getUserTokenFromUrl() { ...@@ -13,3 +13,14 @@ function getUserTokenFromUrl() {
} }
function getProjectIdFromUrl() {
var parts = window.location.search.substr(1).split("&");
var $_GET = {};
for (var i = 0; i < parts.length; i++) {
var temp = parts[i].split("=");
$_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
return $_GET['projectId'];
}
...@@ -126,6 +126,7 @@ CREATE TABLE if not exists `fullsubmissions` ( ...@@ -126,6 +126,7 @@ CREATE TABLE if not exists `fullsubmissions` (
`timestamp` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `timestamp` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user` VARCHAR(120) NOT NULL, `user` VARCHAR(120) NOT NULL,
`text` MEDIUMTEXT NOT NULL, `text` MEDIUMTEXT NOT NULL,
`projectId` VARCHAR(120) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8; ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment