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 {
connection.connect();
// build and execute request
String request = "INSERT INTO fullsubmissions (`id`, `user`, `text`) VALUES (?,?,?);";
connection.issueInsertOrDeleteStatement(request, uuid, fullSubmissionPostRequest.getUser(), fullSubmissionPostRequest.getText());
String request = "INSERT INTO fullsubmissions (`id`, `user`, `text`, `projectId`) VALUES (?,?,?,?);";
connection.issueInsertOrDeleteStatement(request, uuid, fullSubmissionPostRequest.getUser(), fullSubmissionPostRequest.getText(), fullSubmissionPostRequest.getProjectId());
// get the new submission from database
FullSubmission fullSubmission = getFullSubmission(uuid);
......@@ -283,8 +283,9 @@ public class SubmissionController implements ISubmission {
long timestamp = rs.getTimestamp("timestamp").getTime();
String user = rs.getString("user");
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 {
private long timestamp;
private String user;
private String text;
private String projectId;
// 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.timestamp = timestamp;
this.user = user;
this.text = text;
this.projectId = projectId;
}
// methods
......@@ -53,6 +55,14 @@ public class FullSubmission {
this.text = text;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override
public String toString() {
return "FullSubmission{" +
......@@ -60,6 +70,7 @@ public class FullSubmission {
", timestamp=" + timestamp +
", user='" + user + '\'' +
", text='" + text + '\'' +
", projectId='" + projectId + '\'' +
'}';
}
......
......@@ -9,11 +9,13 @@ public class FullSubmissionPostRequest {
// variables
private String user;
private String text;
private String projectId;
// constructors
public FullSubmissionPostRequest(String user, String text) {
public FullSubmissionPostRequest(String user, String text, String projectId) {
this.user = user;
this.text = text;
this.projectId = projectId;
}
public FullSubmissionPostRequest() {}
......@@ -35,11 +37,20 @@ public class FullSubmissionPostRequest {
this.text = text;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
@Override
public String toString() {
return "FullSubmissionPostRequest{" +
"user='" + user + '\'' +
", text='" + text + '\'' +
", projectId='" + projectId + '\'' +
'}';
}
......
......@@ -18,6 +18,6 @@ $(document).ready(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() {
}, function () {
// 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
......@@ -246,6 +246,8 @@ function addSelectionDataToList(startCharacter, endCharacter, category) {
function saveButtonHandler() {
// show alert message
if (window.confirm("Möchten Sie wirklich ihre Annotationen speichern?")) {
// declare array of promises
let promises = []
$('#annotations').find('.category-card').each(function () {
let array = $(this).data('array');
if (array != null) {
......@@ -273,13 +275,21 @@ function saveButtonHandler() {
submissionPartPostRequest.body.push(submissionPartBodyElement);
}
// send the post request to the back-end
createSubmissionPart(submissionPartPostRequest, function (response) {
// send the post request to the back-end and save promise
promises.push(createSubmissionPart(submissionPartPostRequest, function (response) {
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) {
*
* @param submissionPartPostRequest The post request
* @param responseHandler The response handler
* @returns A promise object
*/
function createSubmissionPart(submissionPartPostRequest, responseHandler) {
var url = "../rest/submissions/part/";
var json = JSON.stringify(submissionPartPostRequest);
$.ajax({
return $.ajax({
url: url,
type: "POST",
data: json,
......
......@@ -13,7 +13,8 @@ $(document).ready(function() {
// build request
var fullSubmissionPostRequest = {
user: user,
text: text
text: text,
projectId: getProjectIdFromUrl()
};
// save request in database
......@@ -22,7 +23,7 @@ $(document).ready(function() {
$('#upload-textarea').val("");
// 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() {
$('#upload-textarea').val("");
// 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
else {
// 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() {
});
});
......@@ -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` (
`timestamp` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`user` VARCHAR(120) NOT NULL,
`text` MEDIUMTEXT NOT NULL,
`projectId` VARCHAR(120) NOT NULL,
PRIMARY KEY (`id`)
) 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