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

feat: Add search bar to annotation list

parent eed4122c
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,8 @@ ol { ...@@ -17,7 +17,8 @@ ol {
.rightcolumn { .rightcolumn {
float: right; float: right;
width: 25%; width: 25%;
display: inline-block; display: flex;
flex-flow: column;
overflow: scroll; overflow: scroll;
/* background-color: blue; */ /* background-color: blue; */
} }
...@@ -29,7 +30,9 @@ ol { ...@@ -29,7 +30,9 @@ ol {
/* background-color: yellow; */ /* background-color: yellow; */
} }
.rightcontent { .rightcontent {
margin: 10px; padding: 10px;
flex: 1;
overflow: scroll;
} }
.leftcontent { .leftcontent {
max-height: 100%; max-height: 100%;
...@@ -51,7 +54,7 @@ ol { ...@@ -51,7 +54,7 @@ ol {
background-color: white; background-color: white;
} }
.annotation-card:hover { .annotation-card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2); box-shadow: 0 8px 12px 0 rgba(0,0,0,0.2);
} }
.annotation-header { .annotation-header {
padding: 5px; padding: 5px;
...@@ -164,4 +167,9 @@ ol { ...@@ -164,4 +167,9 @@ ol {
color: black; color: black;
font-weight: bold; font-weight: bold;
} }
#annotation-search {
width: 100%;
padding: 5px;
font-size: 11px;
}
...@@ -267,10 +267,30 @@ function displayAnnotation(annotation) { ...@@ -267,10 +267,30 @@ function displayAnnotation(annotation) {
dateIcon = "fas fa-clock"; dateIcon = "fas fa-clock";
} }
// declare variables
let display, input, filter, user, title, comment;
input = $('#annotation-search');
filter = input.val().toLowerCase();
user = annotation.userToken.toLowerCase();
title = annotation.body.title.toLowerCase();
comment = annotation.body.comment.toLowerCase();
// hiding based on user, title and comment
if (user.indexOf(filter) > -1 ||
title.indexOf(filter) > -1 ||
comment.indexOf(filter) > -1) {
display = ''
}
else {
display = 'none'
}
// insert annotation card // insert annotation card
list.prepend( list.prepend(
// list element // list element
$('<li>') $('<li>')
.css('display', display)
.attr('class', 'listelement') .attr('class', 'listelement')
.append( .append(
// annotation card // annotation card
...@@ -296,7 +316,7 @@ function displayAnnotation(annotation) { ...@@ -296,7 +316,7 @@ function displayAnnotation(annotation) {
$('<i>').attr('class', 'fas fa-user') $('<i>').attr('class', 'fas fa-user')
) )
.append( .append(
$('<span>').append(annotation.userToken) $('<span>').attr('class', 'annotation-header-data-user').append(annotation.userToken)
) )
) )
.append( .append(
...@@ -371,11 +391,9 @@ function displayAnnotation(annotation) { ...@@ -371,11 +391,9 @@ function displayAnnotation(annotation) {
.mouseleave(function () { .mouseleave(function () {
deleteHighlightedText(); deleteHighlightedText();
}) })
.append(function () { .append(
if ($('#annotations li').filter( ".listelement" ).length > 0) { $('<div>').attr('class', 'spacing')
return $('<div>').attr('class', 'spacing') )
}
})
); );
} }
...@@ -791,3 +809,32 @@ function isAnnotationInRange(start, end) { ...@@ -791,3 +809,32 @@ function isAnnotationInRange(start, end) {
} }
return false; return false;
} }
/**
* Display or hide annotations based on filter string
*/
function searchAnnotation() {
// declare variables
let input, filter;
input = $('#annotation-search');
filter = input.val().toLowerCase();
// iterate over annotation card and hide those who don't match the search query
$('#annotations').find('li').each(function () {
let user, title, comment;
user = $(this).find('.annotation-header-data-user').text().toLowerCase();
title = $(this).find('.annotation-header-data-title').text().toLowerCase();
comment = $(this).find('.annotation-body-text').text().toLowerCase();
// hiding based on user, title and comment
if (user.indexOf(filter) > -1 ||
title.indexOf(filter) > -1 ||
comment.indexOf(filter) > -1) {
$(this).css('display', '')
}
else {
$(this).css('display', 'none')
}
});
}
...@@ -8,7 +8,6 @@ function connect(targetId, targetCategory) { ...@@ -8,7 +8,6 @@ function connect(targetId, targetCategory) {
ws.onmessage = function (e) { ws.onmessage = function (e) {
var message = JSON.parse(e.data); var message = JSON.parse(e.data);
console.log(message.from)
if (message.type === "CREATE") { if (message.type === "CREATE") {
// get annotation from server // get annotation from server
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
</div> </div>
</div> </div>
<div class="rightcolumn"> <div class="rightcolumn">
<input type="text" id="annotation-search" onkeyup="searchAnnotation()" placeholder="Suchen...">
<div class="rightcontent"> <div class="rightcontent">
<ol id="annotations"> <ol id="annotations">
</ol> </ol>
......
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