diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java index 27abdc4bcc7f9abed957e39b46369e80ed5f3ba9..ce29362c3f10354b41d3802bd945d638e62b52c9 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/controller/AnnotationController.java @@ -4,6 +4,7 @@ import unipotsdam.gf.core.database.mysql.MysqlConnect; import unipotsdam.gf.core.database.mysql.VereinfachtesResultSet; import unipotsdam.gf.interfaces.IAnnotation; import unipotsdam.gf.modules.annotation.model.Annotation; +import unipotsdam.gf.modules.annotation.model.AnnotationBody; import unipotsdam.gf.modules.annotation.model.AnnotationPatchRequest; import unipotsdam.gf.modules.annotation.model.AnnotationPostRequest; @@ -26,8 +27,8 @@ public class AnnotationController implements IAnnotation { connection.connect(); // build and execute request - String request = "INSERT INTO annotations (`id`, `userId`, `targetId`, `body`, `startCharacter`, `endCharacter`) VALUES (?,?,?,?,?,?);"; - connection.issueInsertOrDeleteStatement(request, uuid, annotationPostRequest.getUserId(), annotationPostRequest.getTargetId(), annotationPostRequest.getBody(), annotationPostRequest.getStartCharacter(), annotationPostRequest.getEndCharacter()); + String request = "INSERT INTO annotations (`id`, `userToken`, `targetId`, `title`, `comment`, `startCharacter`, `endCharacter`) VALUES (?,?,?,?,?,?,?);"; + connection.issueInsertOrDeleteStatement(request, uuid, annotationPostRequest.getUserToken(), annotationPostRequest.getTargetId(), annotationPostRequest.getBody().getTitle(), annotationPostRequest.getBody().getComment(),annotationPostRequest.getBody().getStartCharacter(), annotationPostRequest.getBody().getEndCharacter()); // close connection connection.close(); @@ -47,8 +48,8 @@ public class AnnotationController implements IAnnotation { connection.connect(); // build and execute request - String request = "UPDATE `annotations` SET `body` = ? WHERE `id` = ?"; - connection.issueUpdateStatement(request, annotationPatchRequest.getBody(), annotationId); + String request = "UPDATE `annotations` SET `title` = ?, `comment` = ? WHERE `id` = ?"; + connection.issueUpdateStatement(request, annotationPatchRequest.getTitle(), annotationPatchRequest.getComment(), annotationId); // close connection connection.close(); @@ -159,17 +160,27 @@ public class AnnotationController implements IAnnotation { } + /** + * Build an annotation object from a given result set + * + * @param rs The result set from a database query + * @return A new annotation object + */ private Annotation getAnnotationFromResultSet(VereinfachtesResultSet rs) { String id = rs.getString("id"); long timestamp = rs.getTimestamp(2).getTime(); - int userId = rs.getInt("userId"); + String userToken = rs.getString("userToken"); int targetId = rs.getInt("targetId"); - String body = rs.getString("body"); + + // initialize new annotation body + String title = rs.getString("title"); + String comment = rs.getString("comment"); int startCharacter = rs.getInt("startCharacter"); int endCharacter = rs.getInt("endCharacter"); + AnnotationBody body = new AnnotationBody(title, comment, startCharacter, endCharacter); - return new Annotation(id, timestamp, userId, targetId, body, startCharacter, endCharacter); + return new Annotation(id, timestamp, userToken, targetId, body); } } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java index 725967353f5685e93c53302b7a8a0e799e4ccc12..699ec3eda8ad469fda08b6688311fabb9a17bc5b 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/Annotation.java @@ -9,21 +9,17 @@ public class Annotation { // variables private String id; private long timestamp; - private int userId; + private String userToken; private int targetId; - private String body; - private int startCharacter; - private int endCharacter; + private AnnotationBody body; // constructor - public Annotation(String id, long timestamp, int userId, int targetId, String body, int startCharacter, int endCharacter) { + public Annotation(String id, long timestamp, String userToken, int targetId, AnnotationBody body) { this.id = id; this.timestamp = timestamp; - this.userId = userId; + this.userToken = userToken; this.targetId = targetId; this.body = body; - this.startCharacter = startCharacter; - this.endCharacter = endCharacter; } // methods @@ -43,12 +39,12 @@ public class Annotation { this.timestamp = timestamp; } - public int getUserId() { - return userId; + public String getUserToken() { + return userToken; } - public void setUserId(int userId) { - this.userId = userId; + public void setUserToken(String userToken) { + this.userToken = userToken; } public int getTargetId() { @@ -59,40 +55,22 @@ public class Annotation { this.targetId = targetId; } - public String getBody() { + public AnnotationBody getBody() { return body; } - public void setBody(String body) { + public void setBody(AnnotationBody body) { this.body = body; } - public int getStartCharacter() { - return startCharacter; - } - - public void setStartCharacter(int startCharacter) { - this.startCharacter = startCharacter; - } - - public int getEndCharacter() { - return endCharacter; - } - - public void setEndCharacter(int endCharacter) { - this.endCharacter = endCharacter; - } - @Override public String toString() { return "Annotation{" + - "id=" + id + + "id='" + id + '\'' + ", timestamp=" + timestamp + - ", userId=" + userId + + ", userToken='" + userToken + '\'' + ", targetId=" + targetId + - ", body='" + body + '\'' + - ", startCharacter=" + startCharacter + - ", endCharacter=" + endCharacter + + ", body=" + body + '}'; } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationBody.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationBody.java new file mode 100644 index 0000000000000000000000000000000000000000..53c65233d06da04c8792c2f15ee4c39ddebd498b --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationBody.java @@ -0,0 +1,69 @@ +package unipotsdam.gf.modules.annotation.model; + +/** + * @author Sven Kästle + * skaestle@uni-potsdam.de + */ +public class AnnotationBody { + + // variables + private String title; + private String comment; + private int startCharacter; + private int endCharacter; + + // constructors + public AnnotationBody(String title, String comment, int startCharacter, int endCharacter) { + this.title = title; + this.comment = comment; + this.startCharacter = startCharacter; + this.endCharacter = endCharacter; + } + + public AnnotationBody() { + } + + // methods + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public int getStartCharacter() { + return startCharacter; + } + + public void setStartCharacter(int startCharacter) { + this.startCharacter = startCharacter; + } + + public int getEndCharacter() { + return endCharacter; + } + + public void setEndCharacter(int endCharacter) { + this.endCharacter = endCharacter; + } + + @Override + public String toString() { + return "AnnotationBody{" + + "title='" + title + '\'' + + ", comment='" + comment + '\'' + + ", startCharacter=" + startCharacter + + ", endCharacter=" + endCharacter + + '}'; + } + +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPatchRequest.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPatchRequest.java index c41e294afda5094833771b48bef3c18656c1f283..af5be4da6ad8db3f77ff0bf644392042a3626e5b 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPatchRequest.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPatchRequest.java @@ -7,28 +7,39 @@ package unipotsdam.gf.modules.annotation.model; public class AnnotationPatchRequest { // variables - private String body; + private String title; + private String comment; // constructors - public AnnotationPatchRequest(String body) { - this.body = body; + public AnnotationPatchRequest(String title, String comment) { + this.title = title; + this.comment = comment; } public AnnotationPatchRequest() {} // methods - public String getBody() { - return body; + public String getTitle() { + return title; } - public void setBody(String body) { - this.body = body; + public void setTitle(String title) { + this.title = title; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; } @Override public String toString() { return "AnnotationPatchRequest{" + - "body='" + body + '\'' + + "title='" + title + '\'' + + ", comment='" + comment + '\'' + '}'; } diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java index 5459cb5b567c1aa2224642c2ef304007b954ba7e..5dfe6e206f1f014eb3ce88fbc22e401323b2c422 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/modules/annotation/model/AnnotationPostRequest.java @@ -7,31 +7,27 @@ package unipotsdam.gf.modules.annotation.model; public class AnnotationPostRequest { // variables - private int userId; + private String userToken; private int targetId; - private String body; - private int startCharacter; - private int endCharacter; + private AnnotationBody body; // constructors - public AnnotationPostRequest(int userId, int targetId, String body, int startCharacter, int endCharacter) { - this.userId = userId; + public AnnotationPostRequest(String userToken, int targetId, AnnotationBody body) { + this.userToken = userToken; this.targetId = targetId; this.body = body; - this.startCharacter = startCharacter; - this.endCharacter = endCharacter; } public AnnotationPostRequest() { } // methods - public int getUserId() { - return userId; + public String getUserToken() { + return userToken; } - public void setUserId(int userId) { - this.userId = userId; + public void setUserToken(String userToken) { + this.userToken = userToken; } public int getTargetId() { @@ -42,38 +38,21 @@ public class AnnotationPostRequest { this.targetId = targetId; } - public String getBody() { + public AnnotationBody getBody() { return body; } - public void setBody(String body) { + public void setBody(AnnotationBody body) { this.body = body; } - public int getStartCharacter() { - return startCharacter; - } - - public void setStartCharacter(int startCharacter) { - this.startCharacter = startCharacter; - } - - public int getEndCharacter() { - return endCharacter; - } - - public void setEndCharacter(int endCharacter) { - this.endCharacter = endCharacter; - } - @Override public String toString() { return "AnnotationPostRequest{" + - "userId=" + userId + + "userToken='" + userToken + '\'' + ", targetId=" + targetId + - ", body='" + body + '\'' + - ", startCharacter=" + startCharacter + - ", endCharacter=" + endCharacter + + ", body=" + body.toString() + '}'; } + } diff --git a/gemeinsamforschen/src/main/webapp/assets/css/annotationStyle.css b/gemeinsamforschen/src/main/webapp/assets/css/annotationStyle.css index 74ac1c7a1a6fa585af3de0ca37f55496f13f22e9..b69d4dc4cf8a2fd900e7ad1debdf79650ce9f2d2 100644 --- a/gemeinsamforschen/src/main/webapp/assets/css/annotationStyle.css +++ b/gemeinsamforschen/src/main/webapp/assets/css/annotationStyle.css @@ -127,7 +127,7 @@ ol { margin-right: 5px; cursor: pointer; } -.annotation-footer-date { +.flex-one { flex: 1 } .container-fluid-content { @@ -135,7 +135,7 @@ ol { flex-flow: column; height: 100%; } -.content-header { +.flex { display: flex; } .full-height { @@ -148,4 +148,7 @@ ol { .leftcontent-text { overflow: scroll; } +.resize-vertical { + resize: vertical; +} diff --git a/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js b/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js index beba2528b6e0ece7ca6ba9a2c4ea65d89d9693c1..7ca850714f87359c130171de86eed305354b345e 100644 --- a/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js +++ b/gemeinsamforschen/src/main/webapp/assets/js/annotationScript.js @@ -1,11 +1,11 @@ -// initialize userId, userColors and targetId -var userId = randomUserId(); +// initialize userToken, userColors and targetId +var userToken = getUserTokenFromUrl(); var userColors = new Map(); var userColorsDark = new Map(); var targetId = 200; -// declare document text -var documentText; +// declare document text, start and end character +var documentText, startCharacter, endCharacter; /** * This function will fire when the DOM is ready @@ -19,30 +19,16 @@ $(document).ready(function() { selector: '.context-menu-one', callback: function(key, options) { - // close context menu - window.close; + // action for 'annotation' click + if (key == 'annotation') { + // show modal if something is selected + if (getSelectedText().length > 0) { + startCharacter = window.getSelection().getRangeAt(0).startOffset; + endCharacter = window.getSelection().getRangeAt(0).endOffset; - // initialize selected body - var body = getSelectedText(); - - // if user selected something - if (body.length > 0) { - // annotationPostRequest - var request = { - userId: userId, - targetId: targetId, - body: body, - startCharacter: window.getSelection().getRangeAt(0).startOffset, - endCharacter: window.getSelection().getRangeAt(0).endOffset - }; - - console.log(request); - - createAnnotation(request, function(response) { - // display the new annotation - displayAnnotation(response); - - }); + // display annotation create modal + $('#annotation-create-modal').modal("show"); + } } }, @@ -58,6 +44,62 @@ $(document).ready(function() { location.href="givefeedback.jsp?token=" + getUserTokenFromUrl(); }); + + + /** + * validation of annotation create form inside the modal + */ + $('#annotation-create-form').validate({ + rules: { + title: { + required: true, + maxlength: 120 + }, + comment: { + required: true, + maxlength: 400 + } + }, + messages: { + title: { + required: "Ein Titel wird benötigt", + maxlength: "Maximal 120 Zeichen erlaubt" + }, + comment: { + required: "Ein Kommentar wird benötigt", + maxlength: "Maximal 400 Zeichen erlaubt" + } + } + }); + + /** + * Save button of the annotation create modal + * hide modal and build new annotation + */ + $('#btnSave').click(function () { + if ($('#annotation-create-form').valid()) { + // get title and comment from form + var title = $('#annotation-form-title').val(); + var comment = $('#annotation-form-comment').val(); + + // hide and clear the modal + $('#annotation-create-modal').modal('hide'); + + // save the new annotation in db and display it + saveNewAnnotation(title, comment, startCharacter, endCharacter); + } + }); + + /** + * Clear the title and comment input field of the modal + */ + $('#annotation-create-modal').on('hidden.bs.modal', function(){ + // clear title + $('#annotation-form-title').val(''); + // clear comment + $('#annotation-form-comment').val('') + }); + documentText = $('#documentText').html(); // fetch annotations from server on page start @@ -77,7 +119,7 @@ $(document).ready(function() { * @param responseHandler The response handler */ function createAnnotation(annotationPostRequest, responseHandler) { - var url = "http://localhost:8080/rest/annotations/"; + var url = "../rest/annotations/"; var json = JSON.stringify(annotationPostRequest); $.ajax({ url: url, @@ -99,7 +141,7 @@ function createAnnotation(annotationPostRequest, responseHandler) { * @param responseHandler The response handler */ function alterAnnotation(id, annotationPatchRequest, responseHandler) { - var url = "http://localhost:8080/rest/annotations/" + id; + var url = "../rest/annotations/" + id; var json = JSON.stringify(annotationPatchRequest); $.ajax({ url: url, @@ -119,7 +161,7 @@ function alterAnnotation(id, annotationPatchRequest, responseHandler) { * @param id The annotation id */ function deleteAnnotation(id) { - var url = "http://localhost:8080/rest/annotations/" + id; + var url = "../rest/annotations/" + id; $.ajax({ url: url, type: "DELETE", @@ -138,7 +180,7 @@ function deleteAnnotation(id) { * @param responseHandler The response handler */ function getAnnotations(targetId, responseHandler) { - var url = "http://localhost:8080/rest/annotations/target/" + targetId; + var url = "../rest/annotations/target/" + targetId; $.ajax({ url: url, type: "GET", @@ -186,41 +228,48 @@ function displayAnnotation(annotation) { // insert annotation card list.prepend( + // list element $('<li>') .attr('class', 'listelement') .append( + // annotation card $('<div>').attr('class', 'annotation-card') .mouseenter(function () { - $(this).children('.annotation-header').css('background-color', getDarkUserColor(annotation.userId)); + $(this).children('.annotation-header').css('background-color', getDarkUserColor(annotation.userToken)); }) .mouseleave(function () { - $(this).children('.annotation-header').css('background-color', getUserColor(annotation.userId)); + $(this).children('.annotation-header').css('background-color', getUserColor(annotation.userToken)); }) .append( + // annotation header $('<div>').attr('class', 'annotation-header') - .css('background-color', getUserColor(annotation.userId)) + .css('background-color', getUserColor(annotation.userToken)) .append( + // header data $('<div>').attr('class', 'annotation-header-title') .append( + // user $('<div>').attr('class', 'overflow-hidden') .append( $('<i>').attr('class', 'fas fa-user') ) .append( - $('<span>').append(annotation.userId) + $('<span>').append(annotation.userToken) ) ) .append( + // title $('<div>').attr('class', 'overflow-hidden') .append( $('<i>').attr('class', 'fas fa-bookmark') ) .append( - $('<span>').append('title' + annotation.userId) + $('<span>').append(annotation.body.title) ) ) ) .append( + // unfold button $('<div>').attr('class', 'annotation-header-toggle') .click(function () { toggleButtonHandler($(this)); @@ -231,16 +280,19 @@ function displayAnnotation(annotation) { ) ) .append( + // annotation body $('<div>').attr('class', 'annotation-body') .append( - $('<p>').attr('class', 'overflow-hidden').append(annotation.body) + $('<p>').attr('class', 'overflow-hidden').append(annotation.body.comment) ) ) .append( + // annotation footer $('<div>').attr('class', 'annotation-footer') .append( + // delete function () { - if (userId == annotation.userId) { + if (userToken == annotation.userToken) { return $('<div>').attr('class', 'annotation-footer-delete') .append( $('<i>').attr('class', deleteIcon) @@ -252,7 +304,8 @@ function displayAnnotation(annotation) { } ) .append( - $('<div>').attr('class', 'annotation-footer-date overflow-hidden') + // timestamp + $('<div>').attr('class', 'flex-one overflow-hidden') .append( $('<i>').attr('class', dateIcon) ) @@ -266,7 +319,7 @@ function displayAnnotation(annotation) { ) .data('annotation', annotation) .mouseenter(function () { - addHighlightedText(annotation.startCharacter, annotation.endCharacter, annotation.userId); + addHighlightedText(annotation.body.startCharacter, annotation.body.endCharacter, annotation.userToken); }) .mouseleave(function () { deleteHighlightedText(); @@ -284,11 +337,11 @@ function displayAnnotation(annotation) { * * @param startCharacter The offset of the start character * @param endCharacter The offset of the end character - * @param userId The user id + * @param userToken The user token */ -function addHighlightedText(startCharacter, endCharacter, userId) { +function addHighlightedText(startCharacter, endCharacter, userToken) { // create <span> tag with the annotated text - var replacement = $('<span></span>').css('background-color', getUserColor(userId)).html(documentText.slice(startCharacter, endCharacter)); + var replacement = $('<span></span>').css('background-color', getUserColor(userToken)).html(documentText.slice(startCharacter, endCharacter)); // wrap an <p> tag around the replacement, get its parent (the <p>) and ask for the html var replacementHtml = replacement.wrap('<p/>').parent().html(); @@ -327,39 +380,39 @@ function getSelectedText() { /** * Get color based on user id * - * @param userId The id of the user + * @param userToken The id of the user * @returns {string} The user color */ -function getUserColor(userId) { - // insert new color if there is no userId key - if (userColors.get(userId) == null) { - generateRandomColor(userId); +function getUserColor(userToken) { + // insert new color if there is no userToken key + if (userColors.get(userToken) == null) { + generateRandomColor(userToken); } // return the color - return userColors.get(userId); + return userColors.get(userToken); } /** * Get dark color based on user id * - * @param userId The id of the user + * @param userToken The token of the user * @returns {string} The dark user color */ -function getDarkUserColor(userId) { - // insert new color if there is no userId key - if (userColorsDark.get(userId) == null) { - generateRandomColor(userId); +function getDarkUserColor(userToken) { + // insert new color if there is no userToken key + if (userColorsDark.get(userToken) == null) { + generateRandomColor(userToken); } // return the color - return userColorsDark.get(userId); + return userColorsDark.get(userToken); } /** * Generate a random color of the format 'rgb(r, g, b)' * - * @param userId The given user id + * @param userToken The given user token */ -function generateRandomColor(userId) { +function generateRandomColor(userToken) { var r = Math.floor(Math.random()*56)+170; var g = Math.floor(Math.random()*56)+170; var b = Math.floor(Math.random()*56)+170; @@ -370,8 +423,8 @@ function generateRandomColor(userId) { var color = 'rgb(' + r + ',' + g + ',' + b + ')'; var colorDark = 'rgb(' + r_d + ',' + g_d + ',' + b_d + ')'; - userColors.set(userId, color); - userColorsDark.set(userId, colorDark); + userColors.set(userToken, color); + userColorsDark.set(userToken, colorDark); } /** @@ -447,10 +500,31 @@ function toggleButtonHandler(element) { element.children("i").toggleClass("fa-chevron-down fa-chevron-up") } -/* - MOCKUP FUNCTIONS +/** + * Save a new annotation in database and list + * + * @param title The title of the new annotation + * @param comment The comment of the new annotation + * @param startCharacter The startCharacter based on the annotated text + * @param endCharacter The endCharacter based on the annotated text */ -function randomUserId() { - return Math.floor((Math.random() * 12) + 1);; -} +function saveNewAnnotation(title, comment, startCharacter, endCharacter) { + // build annotationPostRequest + var annotationPostRequest = { + userToken: userToken, + targetId: targetId, + body: { + title: title, + comment: comment, + startCharacter: startCharacter, + endCharacter: endCharacter + } + }; + + // send new annotation to back-end and display it in list + createAnnotation(annotationPostRequest, function(response) { + // display the new annotation + displayAnnotation(response); + }); +} diff --git a/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp b/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp index 9f2969275d66042918a5d32cd44d1f8044d3d735..1b1515c1712672bbae51adc783f37c9800176678 100644 --- a/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp +++ b/gemeinsamforschen/src/main/webapp/pages/annotation-document.jsp @@ -24,6 +24,8 @@ <!-- js - jQuery --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> + <!-- js - jQuery validation plugin --> + <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.min.js"></script> <!-- js - bootstrap --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <!-- js - jQuery ui position --> @@ -43,7 +45,7 @@ <div class="page-content-wrapper full-height"> <div class="container-fluid full-height"> <div class="container-fluid-content"> - <div class="content-header"> + <div class="flex"> <h1>gemeinsam Forschen <a href="#"> <span class="glyphicon glyphicon-envelope" @@ -78,7 +80,39 @@ </div> </div> </div> + <!-- annotation create modal --> + <div id="annotation-create-modal" class="modal fade" role="dialog"> + <div class="modal-dialog modal-dialog-centered modal-sm"> + <div class="modal-content"> + + <!-- modal header --> + <div class="modal-header flex"> + <h4 class="modal-title flex-one">Annotation</h4> + <button type="button" class="close" data-dismiss="modal">×</button> + </div> + + <!-- modal body --> + <div class="modal-body"> + <form id="annotation-create-form"> + <div class="form-group"> + <label for="annotation-form-title" class="col-form-label">Titel:</label> + <input type="text" class="form-control" id="annotation-form-title" name="title"> + </div> + <div class="form-group"> + <label for="annotation-form-comment" class="col-form-label">Kommentar:</label> + <textarea class="form-control resize-vertical" id="annotation-form-comment" name="comment"></textarea> + </div> + </form> + <!-- modal footer --> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Abbrechen</button> + <button id="btnSave" type="button" class="btn btn-success">Speichern</button> + </div> + </div> + </div> + </div> + </div> </div> </body> -</html> \ No newline at end of file +</html> diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java index 6c64c0be2de3d76d89849450bb797ab921876b79..d0fde6c5871fd1533cc8e37308ec2e3068343327 100644 --- a/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java +++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/interfaces/AnnotationTest.java @@ -4,6 +4,7 @@ import org.junit.Before; import org.junit.Test; import unipotsdam.gf.modules.annotation.controller.AnnotationController; import unipotsdam.gf.modules.annotation.model.Annotation; +import unipotsdam.gf.modules.annotation.model.AnnotationBody; import unipotsdam.gf.modules.annotation.model.AnnotationPatchRequest; import unipotsdam.gf.modules.annotation.model.AnnotationPostRequest; @@ -31,11 +32,12 @@ public class AnnotationTest { @Test public void testAddAnnotation() { - // initialize body - String body = "body_testAddAnnotation"; + // initialize title and comment of body + String title = "title_testAddAnnotation"; + String comment = "comment_testAddAnnotation"; // prepare and execute request - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest(1, 2, body, 4, 5); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the new annotation should be found in the database @@ -49,44 +51,52 @@ public class AnnotationTest { @Test public void testAlterAnnotation() { - // initialize old and new body - String oldBody = "bodyOld_testAlterAnnotation"; - String newBody = "bodyNew_testAlterAnnotation"; + // initialize old and new title and comment of body + String titleOld = "titleOld_testAlterAnnotation"; + String commentOld = "commentOld_testAlterAnnotation"; + String titleNew = "titleNew_testAlterAnnotation"; + String commentNew = "commentNew_testAlterAnnotation"; // save new annotation in database - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest(0, 0, oldBody, 0, 0); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 0, new AnnotationBody(titleOld, commentOld, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the new annotation should be found in the database assertTrue("Can't find annotation with the id " + response.getId(), controller.existsAnnotationId(response.getId())); - // the annotation's body should be "testAlterAnnotation_oldBody" - assertEquals("The body of the annotation should be " + oldBody + " but was " + response.getBody(), oldBody, response.getBody()); + // the annotation's title should be "titleOld_testAlterAnnotation" + assertEquals("The title of the annotation should be " + titleOld + " but was " + response.getBody().getTitle(), titleOld, response.getBody().getTitle()); + + // the annotation's comment should be "commentOld_testAlterAnnotation" + assertEquals("The comment of the annotation should be " + commentOld + " but was " + response.getBody().getComment(), commentOld, response.getBody().getComment()); // alter the annotation and update the database - AnnotationPatchRequest annotationPatchRequest = new AnnotationPatchRequest(newBody); + AnnotationPatchRequest annotationPatchRequest = new AnnotationPatchRequest(titleNew, commentNew); controller.alterAnnotation(response.getId(), annotationPatchRequest); // receive the new annotation Annotation newResponse = controller.getAnnotation(response.getId()); - // the annotation's body should be "testAlterAnnotation_newBody" - assertEquals("The body of the annotation should be " + newBody + " but was " + newResponse.getBody(), newBody, newResponse.getBody()); + // the annotation's title should be "titleNew_testAlterAnnotation" + assertEquals("The title of the annotation should be " + titleNew + " but was " + newResponse.getBody().getTitle(), titleNew, newResponse.getBody().getTitle()); + + // the annotation's comment should be "commentNew_testAlterAnnotation" + assertEquals("The comment of the annotation should be " + commentNew + " but was " + newResponse.getBody().getComment(), commentNew, newResponse.getBody().getComment()); // delete the annotation controller.deleteAnnotation(response.getId()); - } @Test public void testDeleteAnnotation() { - // initialize old and new body - String body = "body_testDeleteAnnotation"; + // initialize title and comment of body + String title = "title_testDeleteAnnotation"; + String comment = "comment_testDeleteAnnotation"; - // save new annotation in database - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest(0, 0, body, 0, 0); + // prepare and execute request + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the new annotation should be found in the database @@ -103,18 +113,22 @@ public class AnnotationTest { @Test public void testGetAnnotation() { - // initialize body - String body = "body_testGetAnnotation"; + // initialize title and comment of body + String title = "title_testGetAnnotation"; + String comment = "comment_testGetAnnotation"; - // save new annotation in database - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest(0, 0, body, 0, 0); + // prepare and execute request + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 1, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // receive the new annotation Annotation getResponse = controller.getAnnotation(response.getId()); - // the annotation's body should be "testAlterAnnotation_newBody" - assertEquals("The body of the annotation should be " + body + " but was " + getResponse.getBody(), body, getResponse.getBody()); + // the annotation's title should be "title_testAlterAnnotation" + assertEquals("The title of the annotation should be " + title + " but was " + response.getBody().getTitle(), title, response.getBody().getTitle()); + + // the annotation's comment should be "comment_testAlterAnnotation" + assertEquals("The comment of the annotation should be " + comment + " but was " + response.getBody().getComment(), comment, response.getBody().getComment()); // delete the new annotation controller.deleteAnnotation(response.getId()); @@ -124,10 +138,9 @@ public class AnnotationTest { @Test public void testGetAnnotations() { - // initialize bodys - String body1 = "body1_testGetAnnotations"; - String body2 = "body2_testGetAnnotations"; - String body3 = "body3_testGetAnnotations"; + // initialize title and comment of bodys + String title = "title_testGetAnnotations"; + String comment = "comment_testGetAnnotations"; // initialize targetIds ArrayList<Integer> targetIds = new ArrayList<>(); @@ -135,23 +148,23 @@ public class AnnotationTest { targetIds.add(-2); // save new annotations in database - AnnotationPostRequest request1 = new AnnotationPostRequest(0, targetIds.get(0), body1, 0, 0); - AnnotationPostRequest request2 = new AnnotationPostRequest(0, targetIds.get(1), body2, 0, 0); - AnnotationPostRequest request3 = new AnnotationPostRequest(0, targetIds.get(1), body3, 0, 0); + AnnotationPostRequest request1 = new AnnotationPostRequest("userToken", targetIds.get(0), new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest request2 = new AnnotationPostRequest("userToken", targetIds.get(1), new AnnotationBody(title, comment, 1, 2)); + AnnotationPostRequest request3 = new AnnotationPostRequest("userToken", targetIds.get(1), new AnnotationBody(title, comment, 1, 2)); controller.addAnnotation(request1); controller.addAnnotation(request2); controller.addAnnotation(request3); - // receive the new annotations + // receive the new annotations with targetId = -2 ArrayList<Annotation> getResponse = controller.getAnnotations(targetIds.get(1)); - // the size of the getResponse should be 2 + // the size of the getResponse should be 2 assertEquals("The size of the response should be 2 but was " + getResponse.size(), 2, getResponse.size()); - // receive the new annotations + // receive the new annotations with targetId = -1 ArrayList<Annotation> getResponseNew = controller.getAnnotations(targetIds.get(0)); - // the size of the getResponse should be 2 + // the size of the getResponse should be 1 assertEquals("The size of the response should be 1 but was " + getResponseNew.size(), 1, getResponseNew.size()); // delete annotations from database @@ -164,12 +177,13 @@ public class AnnotationTest { @Test public void testExistsAnnotationId() { - // initialize body and bad id - String body = "body_testExistsAnnotationId"; + // initialize title and comment of body and bad id + String title = "title_testExistsAnnotationId"; + String comment = "comment_testExistsAnnotationId"; String badId = "badId"; // save new annotation in database - AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest(0, 0, body, 0, 0); + AnnotationPostRequest annotationPostRequest = new AnnotationPostRequest("userToken", 0, new AnnotationBody(title, comment, 1, 2)); Annotation response = controller.addAnnotation(annotationPostRequest); // the annotation shouldn't be found in the database