Un-retardeded the filters. Results are now a table
This commit is contained in:
+1
-2
@@ -52,7 +52,7 @@ def get_part_info(partID):
|
||||
r.close()
|
||||
return json.dumps(l[0])
|
||||
|
||||
@app.route('/parts/query/<filter_dummy>/<query>')
|
||||
@app.route('/parts/query/<filter_dummy>/<query>') # TODO: maybe change AND to OR or maybe not
|
||||
def query(filter_dummy, query):
|
||||
filter = request.args.to_dict()
|
||||
keywords = query.split() # Default splits with spaces
|
||||
@@ -88,7 +88,6 @@ def query(filter_dummy, query):
|
||||
s = s[:-5]
|
||||
s += ') OR '
|
||||
s = s[:-4] + ';'
|
||||
print(s)
|
||||
s = text(s)
|
||||
r = db_engine.execute(s, kw_dict)
|
||||
l = []
|
||||
|
||||
+22
-44
@@ -144,7 +144,7 @@ function save(partID) {
|
||||
|
||||
$.ajax({
|
||||
// Your server script to process the upload
|
||||
url: 'https://www.elab.kth.se/parts/alter/' + partID,
|
||||
url: 'http://127.0.0.1:5000/parts/alter/' + partID,
|
||||
type: 'POST',
|
||||
|
||||
data: data,
|
||||
@@ -183,7 +183,7 @@ function delete_entry(partID) {
|
||||
if (!confirm('Delete the selected entry?'))
|
||||
return;
|
||||
$.ajax({
|
||||
url: 'https://www.elab.kth.se/parts/delete/' + partID,
|
||||
url: 'http://127.0.0.1:5000/parts/delete/' + partID,
|
||||
type: 'GET',
|
||||
cache: false,
|
||||
contentType: false,
|
||||
@@ -199,7 +199,7 @@ function delete_entry(partID) {
|
||||
}
|
||||
|
||||
function show_part_info(partID) {
|
||||
$.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
|
||||
$.getJSON('http://127.0.0.1:5000/parts/getpartinfo/' + partID, function(data) {
|
||||
$('#block-info').text(text_filter(data.block));
|
||||
$('#type-info').text(text_filter(data.type));
|
||||
$('#partno-info').text(text_filter(data.partno) + ' ' + text_filter(data.partnoalt) + ' ' + text_filter(data.partnoalt2));
|
||||
@@ -207,7 +207,7 @@ function show_part_info(partID) {
|
||||
$('#quantity-info').text(text_filter(data.quantity));
|
||||
$('#notes-info').text(text_filter(data.notes));
|
||||
if (data.datasheet != null)
|
||||
$('#datasheet-info').html($('<a href="https://www.elab.kth.se/parts/getfile/' + data.datasheet.substring(0, data.datasheet.length - 4) + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>'));
|
||||
$('#datasheet-info').html($('<a href="http://127.0.0.1:5000/parts/getfile/' + data.datasheet.substring(0, data.datasheet.length - 4) + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>'));
|
||||
else
|
||||
$('#datasheet-info').text(' ');
|
||||
$('#edit-button').click(function() {
|
||||
@@ -223,51 +223,29 @@ function show_part_info(partID) {
|
||||
}
|
||||
|
||||
function perform_query() {
|
||||
$('#no-results').css("opacity", 0);
|
||||
var query = $('.search-bar').val();
|
||||
var filter = 0;
|
||||
if($('#type').is(':checked'))
|
||||
filter += 1;
|
||||
if($('#partno').is(':checked'))
|
||||
filter += 2 + 4 + 8;
|
||||
if($('#description').is(':checked'))
|
||||
filter += 16;
|
||||
if($('#notes').is(':checked'))
|
||||
filter += 32;
|
||||
$.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) {
|
||||
var newResults = $('<div class="results"></div>');
|
||||
for(var i = 0; i < data.length; i++) { // Create new view for results
|
||||
var newRow = $('<div class="results-row"></div>');
|
||||
var newClicker = $('<a href="#" onclick="show_part_info(' + data[i].id + ')"></a>');
|
||||
var data = {
|
||||
l:$('#type').is(':checked'),
|
||||
p:$('#partno').is(':checked'),
|
||||
d:$('#description').is(':checked'),
|
||||
n:$('#notes').is(':checked')
|
||||
};
|
||||
filter = '0';
|
||||
$.getJSON('http://127.0.0.1:5000/parts/query/' + filter + '/' + query, data, function(data) {
|
||||
$("#results").find("tr:not(:first)").remove(); // Delete all table rows
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
var newRow = $('<tr onclick="show_part_info(' + data[i].id + ')"></tr>');
|
||||
|
||||
newClicker.append($('<div class="results-block"></div>').text(text_filter(data[i].block)));
|
||||
newClicker.append($('<div class="results-type"></div>').text(text_filter(data[i].type)));
|
||||
newClicker.append($('<div class="results-partno"></div>').text(text_filter(data[i].partno)));
|
||||
newClicker.append($('<div class="results-description"></div>').text(text_filter(data[i].description)));
|
||||
var notes = $('<div class="results-notes"></div>');
|
||||
if (data[i].notes != null && data[i].notes.length > 0) {
|
||||
var icon = $('<i class="fa fa-sticky-note"></i>');
|
||||
var tooltipText = $('<div class="tooltiptext"></div>').text(data[i].notes);
|
||||
var tooltip = $('<div class="tooltip"></div>');
|
||||
tooltip.append(icon, tooltipText);
|
||||
notes.append(tooltip);
|
||||
}
|
||||
newClicker.append(notes);
|
||||
var datasheet = $('<div class="results-datasheet"></div>');
|
||||
if (data[i].datasheet != null)
|
||||
datasheet.html('<a href="https://www.elab.kth.se/parts/getfile/'
|
||||
+ data[i].datasheet.substring(0, data[i].datasheet.length - 4)
|
||||
+ '"><i class="fa fa-file-text" aria-hidden="true"></i></a>');
|
||||
newClicker.append(datasheet);
|
||||
|
||||
newRow.append(newClicker);
|
||||
newResults.append(newRow);
|
||||
newRow.append($('<td id="location"></td>').text(text_filter(data[i].location_descriptor)));
|
||||
newRow.append($('<td id="partno"></td>').text(text_filter(data[i].partno)));
|
||||
newRow.append($('<td id="description"></td>').text(text_filter(data[i].description)));
|
||||
newRow.append($('<td id="docs"></td>').text(text_filter(data[i].docs)));
|
||||
$('#results').append(newRow);
|
||||
}
|
||||
if(data.length == 0) {
|
||||
newResults = '<div class="results">';
|
||||
newResults += '<h3>No results.</h3>';
|
||||
newResults += '</div>';
|
||||
$('#no-results').animate({opacity:1},2000);
|
||||
}
|
||||
$('.results').replaceWith(newResults);
|
||||
}).fail(function() {
|
||||
var newResults = '<div class="results">';
|
||||
newResults += '<h3>No results.</h3>';
|
||||
|
||||
@@ -27,6 +27,7 @@ h3 {
|
||||
text-align: center;
|
||||
padding: 12pt;
|
||||
font-size: 20pt;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
@@ -338,3 +339,41 @@ div label input {
|
||||
.bottom-spacer {
|
||||
height: 80pt;
|
||||
}
|
||||
|
||||
table#results {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
table#results th {
|
||||
background-color: #226666;
|
||||
color: #D7E2E2;
|
||||
padding: 4pt;
|
||||
border-right: 2px solid #D7E2E2;
|
||||
border-left: 2px solid #D7E2E2;
|
||||
}
|
||||
|
||||
table#results tr:nth-child(odd) {
|
||||
background-color: #5E9292;
|
||||
}
|
||||
|
||||
table#results td {
|
||||
padding: 4pt;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#location {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
#partno {
|
||||
/*width: 20%;*/
|
||||
}
|
||||
|
||||
#description {
|
||||
width: 65%;
|
||||
}
|
||||
|
||||
#docs {
|
||||
width: 5%;
|
||||
}
|
||||
@@ -8,9 +8,9 @@
|
||||
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
|
||||
crossorigin="anonymous"></script>
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('parts/static', filename='style.css') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
||||
<script src="https://use.fontawesome.com/2fef7be393.js"></script>
|
||||
<script type="text/javascript" src="{{ url_for('parts/static', filename='script.js') }}"></script>
|
||||
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ELAB Part Search Engine</h1>
|
||||
@@ -21,20 +21,21 @@
|
||||
<div class="filter-concontainertainer">
|
||||
<div class="filter-container">
|
||||
<p>Search in:</p>
|
||||
<input type="checkbox" class="checkbox" id="type" checked></input><label class="toggle-btn" for="type">Manufacturer</label>
|
||||
<input type="checkbox" class="checkbox" id="location"></input><label class="toggle-btn" for="type">Locations</label>
|
||||
<input type="checkbox" class="checkbox" id="partno" checked></input><label class="toggle-btn" for="partno">Part Number</label>
|
||||
<input type="checkbox" class="checkbox" id="description" checked></input><label class="toggle-btn" for="description">Description</label>
|
||||
<input type="checkbox" class="checkbox" id="notes" checked></input><label class="toggle-btn" for="notes">Notes</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="res-header-small">Block</div>
|
||||
<div class="res-header">Manufacturer</div>
|
||||
<div class="res-header">Part Number</div>
|
||||
<div class="res-header-3">Description</div>
|
||||
<div class="res-header-small">Notes</div>
|
||||
<div class="res-header-small">Docs</div>
|
||||
<div class="results">
|
||||
</div>
|
||||
<table id="results">
|
||||
<tr>
|
||||
<th id="location">Location</th>
|
||||
<th id="partno">Part Number</th>
|
||||
<th id="description">Description</th>
|
||||
<th id="docs">Docs</th>
|
||||
</tr>
|
||||
</table>
|
||||
<h3 id="no-results">No results.</h3>
|
||||
<div class="bottom-spacer"></div>
|
||||
|
||||
<div class="shadow" onclick="overlay_out()"></div>
|
||||
|
||||
Reference in New Issue
Block a user