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

Implemented searching and sorting in Information dashboard #370

Merged
merged 2 commits into from
Apr 16, 2020
Merged
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
139 changes: 89 additions & 50 deletions apps/Info.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,6 @@
<script src='../components/loading/loading.js'></script>
<script src="./loader/loader.js"></script>
<script src="./loader/chunked_upload.js"></script>
<script>
function sanitize(string) {
const map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
"/": '&#x2F;',
};
const reg = /[&<>"'/]/ig;
return string.replace(reg, (match)=>(map[match]));
}
var existingSlideNames = [];
const allowedExtensions = ['svs', 'tif', 'tiff', 'vms', 'vmu', 'ndpi', 'scn', 'mrxs', 'bif', 'svslide'];
function validateForm(callback) {
let slide = document.getElementById("slidename0");
//Check if slide name is empty
if (slide.value === "") {
changeStatus("UPLOAD", "Please enter slide name");
return false;
}
//Sanitizing input
slide.value = sanitize(slide.value);
//Checking if silde with given name already exists
if(existingSlideNames.includes(slide.value)) {
changeStatus("UPLOAD", "Slide with given name already exists");
return false;
}
//Checking for extension
let filename = document.getElementById("filename0").value
var fileExtension = filename.toLowerCase().split('.').reverse()[0];
if(!allowedExtensions.includes(fileExtension)) {
changeStatus("UPLOAD", fileExtension + " files are not compatible");
return false;
}
callback();
}
</script>
<title>CaMicroscope Data Table</title>

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
Expand Down Expand Up @@ -121,26 +82,41 @@
<h1 class="h1">caMicroscope</h1>
<p>Digital pathology image viewer with support for human/machine generated annotations and markups.</p>
</div>
<h3 class="text-center h3 mb-0" style="margin-top:8px;margin-bottom:10px;">Information Dashboard</h3>
<div class="summary">
<table class="dash">

<div class="container">
<h3 class="text-center h3 mb-2" style="margin-top:8px;margin-bottom:10px;">Information Dashboard</h3>
<div class="form-group has-search">
<span class="fa fa-search form-control-feedback"></span>
<input id="search-table" type="text" class="form-control" placeholder="Search">
</div>

<div class="table-responsive" id="summary">
<table class="table table-striped">
<thead></thead>
<tbody></tbody>
</table>
</div>
<div class="text-center text-white bg-dark p-3" style="position: absolute;bottom: 0;width: 100%;">
<p class="p">Copyright © 2020 caMicroscope</p>
</div>
</div>

<div class="text-center text-white bg-dark p-3 mt-2 footer" style="position: static;bottom: 0;width: 100%;">
<p class="p">Copyright © 2020 caMicroscope</p>
</div>

</body>
<script>

var searching=false;

function addhead(){
var table = $('table thead');
var markup = "<tr><th>_ID</th><th>Name</th><th>Annotations</th><th>Heatmap</th></tr>";
table.append(markup);
console.log(table);
let headingList=['ID','Name','Annotations','Heatmaps']
const headingMarkup = headingList.map((title,i) => `<th>${title}
<span class="sort-btn" data-order=${1} data-index=${i}>
<i class="fa fa-sort"/> </span>
</th>`);
table.append(`<tr>${headingMarkup}</tr>`);
}

function addbody(JSONdata){
var table = $('table tbody');
// console.log(JSONdata.annotations);
Expand All @@ -161,6 +137,68 @@ <h3 class="text-center h3 mb-0" style="margin-top:8px;margin-bottom:10px;">Infor
var markup = "<tr><td>"+JSONdata.id+"</td><td>"+JSONdata.name+"</td><td>"+annodisp+"</td><td>"+heatdisp+"</td></tr>"
table.append(markup);
}

function searchSummaryTable(e) {
var value = String($(this).val()).toLowerCase();
$("#summary table tbody tr").filter(function () {
var t = String($(this).text()).toLowerCase().indexOf(value);
if (t > -1) {
$(this).addClass("searched");
$(this).removeClass("d-none");
} else {
$(this).removeClass("searched");
$(this).addClass("d-none");
}
});
if (value == "") {
searching = false;
} else {
searching = true;
}
}

function sortSummaryTable(e) {
var index = e.currentTarget.dataset.index;
var order = parseInt(e.currentTarget.dataset.order);
var trs = "#summary table tbody tr";
if (searching) {
trs += ".searched";
}

$(trs).sort(function (a, b) {
let at = $(a).children('td').get(index).textContent;
let bt = $(b).children('td').get(index).textContent;
if(at&&bt)
{
at=at.toLowerCase();
bt=bt.toLowerCase();
}
else
{
at=$(a).children('td').get(index).childNodes[0].classList;
bt=$(b).children('td').get(index).childNodes[0].classList;
}
if (order === 1) {
e.currentTarget.dataset.order=2;
if (at > bt)
return 1;
else if (at < bt)
return -1;
else
return 0;
}
else {
e.currentTarget.dataset.order = 1;
if (at < bt)
return 1;
else if (at > bt)
return -1;
else
return 0;
}
}).appendTo("#summary table tbody");
}

function initialize() {
const params = getUrlVars();
const store = new Store('../data/');
Expand All @@ -173,6 +211,8 @@ <h3 class="text-center h3 mb-0" style="margin-top:8px;margin-bottom:10px;">Infor
return;
}
addhead();
$("#search-table").on("keyup",searchSummaryTable);
$(".sort-btn").on("click", sortSummaryTable);
for (var i = 0; i < data.length; i++) {
const JSONdata={};
JSONdata.id=data[i]._id.$oid;
Expand All @@ -184,8 +224,7 @@ <h3 class="text-center h3 mb-0" style="margin-top:8px;margin-bottom:10px;">Infor
addbody(JSONdata);
});
});


// console.log(JSONdata);
}
});
}
Expand Down
59 changes: 27 additions & 32 deletions apps/info.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
body{
overflow: hidden;
html,
body {
width: 100%;
height: 100%;
min-height: 100%;
display: flex;
flex-direction: column;
}
.summary{
height: auto;

width: 90vw;
margin: auto;
margin-bottom: 13vh;
overflow-y: auto;
margin-top: 1.5vh;
overflow-x: auto;
.sort-btn
{
cursor: pointer;
}
.dash{
margin: auto;
width: max-content;
border-spacing: 2px;
overflow-x: auto;
}
th{
text-align: center;
padding: .75rem;
padding-left: 1.2rem;
padding-right: 1.2rem;
vertical-align: top;
border-top: 1px solid #dee2e6;
border-bottom: 1px solid #dee2e6;

.has-search .form-control {
padding-left: 2.375rem;
}
td{
text-align: center;
padding: .75rem;
padding-left: 1.2rem;
padding-right: 1.2rem;
vertical-align: top;
border-bottom: 1px solid #dee2e6;

.has-search .form-control-feedback {
position: absolute;
z-index: 2;
display: block;
width: 2.375rem;
height: 2.375rem;
line-height: 2.375rem;
text-align: center;
pointer-events: none;
color: #aaa;
}

tr:nth-child(even){background-color: #f2f2f2}
.footer {
margin-top: auto !important;
}
5 changes: 4 additions & 1 deletion apps/landing/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<li><a href="../table.html" class="link">Slides</a></li>
<li style="float: right;"><a href="/apps/signup/signup.html" class="link">Signup</a></li>
<li style="float: right;"><a target="_blank" href="https://docs.google.com/forms/d/e/1FAIpQLScL91LxrpAZjU88GBZP9gmcdgdf8__uNUwhws2lzU6Lr4qNwA/viewform" class="link">Feedback</a></li>

</ul>

</nav>
Expand All @@ -50,6 +50,9 @@
<li class="nav-item link" style="font-family: sans-serif;">
<a class="nav-link" href="../table.html"> <i class="fas fa-list-ul"></i> Slides</a>
</li>
<li class="nav-item link">
<a class="nav-link" href="Info.html"> <i class="fas fa-info-circle"></i> Info</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item link" style="font-family: sans-serif;">
Expand Down