Forgot to commit as I developed, component search works, reading dynamic parameters from json blob works, calculation work is on-going
This commit is contained in:
+19
-2
@@ -1,4 +1,4 @@
|
||||
var rootURL = '/parts/'
|
||||
var rootURL = '/'
|
||||
|
||||
function overlay_in() {
|
||||
$('.shadow').show();
|
||||
@@ -15,4 +15,21 @@ function overlay_out() {
|
||||
$('.overlay').hide();
|
||||
});
|
||||
end_edit();
|
||||
}
|
||||
}
|
||||
|
||||
function calculateoverlay_in() {
|
||||
$('.shadow').show();
|
||||
$('.calculateoverlay').show();
|
||||
$('.shadow').animate({'opacity' : 0.7});
|
||||
$('.calculateoverlay').animate({'opacity' : 1.0, 'top' : '5%'});
|
||||
}
|
||||
|
||||
function calculateoverlay_out() {
|
||||
$('.shadow').animate({'opacity' : 0.0}, function () {
|
||||
$('.shadow').hide();
|
||||
});
|
||||
$('.calculateoverlay').animate({'opacity' : 0.0, 'top' : '0'}, function () {
|
||||
$('.calculateoverlay').hide();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ function show_location_info(locationID) {
|
||||
$('table#details tr#description td input').val(text_filter(data.description));
|
||||
container_onchange();
|
||||
if (data.datasheet != null) {
|
||||
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="parts/getfile/' + data.datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>'));
|
||||
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="/getfile/' + data.datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>'));
|
||||
$('#datasheet-input').val(data.datasheet);
|
||||
}
|
||||
else
|
||||
@@ -123,4 +123,4 @@ function placeMarker(locationID){
|
||||
|
||||
// $("#mapURL").html("elab.png?x=" + correctX + "&y=" + correctY);
|
||||
$("#clickablemap").attr("src", "map/" + $("#mapfile-input").val() + "?x=" + correctX + "&y=" + correctY);
|
||||
}
|
||||
}
|
||||
|
||||
+143
-38
@@ -1,13 +1,16 @@
|
||||
var active_timer = 100;
|
||||
var calculation = 0;
|
||||
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
function init_edit(partID) {
|
||||
$('table#details tr#location td p').hide();
|
||||
$('#location-dropdown').show();
|
||||
$('#container-dropdown').show();
|
||||
$('table#details tr#type td p').hide();
|
||||
$('#type-dropdown').show();
|
||||
|
||||
$('table#details tr#partno td p').hide();
|
||||
$('input[name=partno-input]').show();
|
||||
$('#magical_autofill').show();
|
||||
// $('#magical_autofill').show();
|
||||
|
||||
$('table#details tr#description td p').hide();
|
||||
$('input[name=description-input]').show();
|
||||
@@ -23,6 +26,16 @@ function init_edit(partID) {
|
||||
$('input[name=notes-input]').show();
|
||||
$('table#details tr#notes td p').hide();
|
||||
|
||||
$('input[name=voltage-input]').show();
|
||||
$('table#details tr#voltage td p').hide();
|
||||
$('input[name=current-input]').show();
|
||||
$('table#details tr#current td p').hide();
|
||||
$('input[name=sleepcurrent-input]').show();
|
||||
$('table#details tr#sleepcurrent td p').hide();
|
||||
$('input[name=txrx-input]').show();
|
||||
$('input[name=txrx-head]').show();
|
||||
$('table#details tr#txrx td p').hide();
|
||||
|
||||
// var newButton = '<div class="round-button-left"><a href="#" onclick="save(' + partID + ')"><i class="fa fa-check" aria-hidden="true"></i></a></div>';
|
||||
// $('.round-button-left').replaceWith(newButton);
|
||||
$('#edit-button').html('<i class="fa fa-check" aria-hidden="true"></i>');
|
||||
@@ -32,29 +45,32 @@ function init_edit(partID) {
|
||||
}
|
||||
|
||||
function new_entry() {
|
||||
$('table#details tr#location td p').text('');
|
||||
$('table#details tr#type td p').text('');
|
||||
$('table#details tr#partno td p').text('');
|
||||
$('table#details tr#description td p').text('');
|
||||
$('table#details tr#partno td input').val('');
|
||||
$('table#details tr#description td input').val('');
|
||||
$('input[name=datasheet-url-input]').val('');
|
||||
// container_onchange();
|
||||
container_onchange();
|
||||
init_edit(-1);
|
||||
overlay_in();
|
||||
}
|
||||
|
||||
function calculate() {
|
||||
calculateoverlay_in();
|
||||
}
|
||||
|
||||
function end_edit() {
|
||||
|
||||
$('table#details tr#location td p').text($('table#details tr#location td select option:checked').text());
|
||||
$('table#details tr#location td p').show();
|
||||
$('#location-dropdown').hide();
|
||||
$('#container-dropdown').hide();
|
||||
$('table#details tr#type td p').text($('table#details tr#type td select option:checked').text());
|
||||
$('table#details tr#type td p').show();
|
||||
$('#type-dropdown').hide();
|
||||
|
||||
$('table#details tr#partno td p').text($('table#details tr#partno td input').val());
|
||||
$('table#details tr#partno td p').show();
|
||||
$('table#details tr#partno td input').hide();
|
||||
|
||||
$('#magical_autofill').hide();
|
||||
// $('#magical_autofill').hide();
|
||||
|
||||
$('table#details tr#description td p').text($('table#details tr#description td input').val());
|
||||
$('table#details tr#description td p').show();
|
||||
@@ -73,17 +89,26 @@ function end_edit() {
|
||||
// $('.round-button-left').replaceWith(newButton);
|
||||
}
|
||||
|
||||
|
||||
function save(partID) {
|
||||
if (!$('#location-dropdown').val()) {
|
||||
alert('Please select a location.');
|
||||
if (!$('#type-dropdown').val()) {
|
||||
alert('Please select a component type.');
|
||||
return;
|
||||
}
|
||||
var location_id_v = $('#location-dropdown').val();
|
||||
var type_id_v = $('type-dropdown').val();
|
||||
var partno_v = $('input[name=partno-input]').val();
|
||||
var description_v = $('input[name=description-input]').val();
|
||||
var datasheet = $('table#details tr#datasheet td input')[0].files;
|
||||
var datasheet_url_v = $('input[name=datasheet-url-input]').val();
|
||||
var notes_v = $('input[name=notes-input]').val();
|
||||
var total = [];
|
||||
var mapped = {};
|
||||
$('.parameter-content').find('input').each(function(index,elem){
|
||||
//8 console.log(elem.value);
|
||||
total.push(elem.value);
|
||||
mapped[elem.name] = elem.value;
|
||||
});
|
||||
console.log(mapped);
|
||||
if(partno_v.length == 0){
|
||||
alert('Please enter a part number.');
|
||||
return;
|
||||
@@ -112,9 +137,11 @@ function save(partID) {
|
||||
data.append('datasheet-url', datasheet_url_v);
|
||||
}
|
||||
data.append('partno', partno_v);
|
||||
data.append('location_id', location_id_v);
|
||||
data.append('type_id', type_id_v);
|
||||
data.append('description', description_v);
|
||||
data.append('notes', notes_v);
|
||||
data.append('parameters', mapped);
|
||||
|
||||
|
||||
$.ajax({
|
||||
// Your server script to process the upload
|
||||
@@ -172,18 +199,48 @@ function delete_entry(partID) {
|
||||
},
|
||||
});
|
||||
}
|
||||
function calculate_entry(partID,parameters) {
|
||||
if (partID < 0)
|
||||
return;
|
||||
if (!confirm('Add selected entry to calculation?'))
|
||||
return;
|
||||
console.log(parameters);
|
||||
if(parameters != null) {
|
||||
var jsonParameters = JSON.parse(data.parameters);
|
||||
console.log(jsonParameters);
|
||||
var count = Object.keys(jsonParameters).length;
|
||||
console.log(count);
|
||||
// for(var k = 0; k < count; k++) {
|
||||
var obj = Object.keys(jsonParameters);
|
||||
var values = Object.values(jsonParameters);
|
||||
var voltage = 0;
|
||||
var currents = [];
|
||||
console.log(obj);
|
||||
for (var key in obj) {
|
||||
var value = obj[key];
|
||||
console.log(key+":"+value);
|
||||
if(value.includes('voltage')) {
|
||||
voltage = values[key];
|
||||
}
|
||||
else if(value.includes('current')) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function show_part_info(partID) {
|
||||
$.getJSON(rootURL + 'getpartinfo/' + partID, function(data) {
|
||||
$('table#details tr#location td p').text(text_filter(data.location_descriptor)); // name is the location friendly name
|
||||
$('#container-dropdown').val(data.container_id);
|
||||
$('img#map').attr('src', 'parts/map/' + data.container_id);
|
||||
$('#location-dropdown').empty();
|
||||
$.getJSON('parts/getlocationsInContainer/' + data.container_id, function(json) {
|
||||
$.each(json, function(loc_id, loc_name) {
|
||||
$('#location-dropdown').append('<option value="' + loc_id + '">' + loc_name + '</option>');
|
||||
});
|
||||
$('#location-dropdown').val(data.location_id);
|
||||
$('img#map').attr('src', 'parts/map/' + data.type_id);
|
||||
$('#type-dropdown').empty();
|
||||
$.getJSON('/getTypes', function(json) {
|
||||
$.each(json, function(type_id, type_name) {
|
||||
$('#type-dropdown').append('<option value="' + type_id + '">' + type_name + '</option>');
|
||||
if (data.type_id == type_id) {
|
||||
$('table#details tr#type td p').text(text_filter(type_name)); // name is the type friendly name
|
||||
}
|
||||
});
|
||||
$('#type-dropdown').val(data.type_id);
|
||||
});
|
||||
$('table#details tr#partno td p').text(text_filter(data.partno));
|
||||
$('table#details tr#partno td input').val(text_filter(data.partno));
|
||||
@@ -191,6 +248,38 @@ function show_part_info(partID) {
|
||||
$('table#details tr#description td input').val(text_filter(data.description));
|
||||
$('table#details tr#notes td p').text(text_filter(data.notes));
|
||||
$('input[name=notes-input]').val(text_filter(data.notes));
|
||||
console.log(data.parameters);
|
||||
if(data.parameters != null) {
|
||||
var jsonParameters = JSON.parse(data.parameters);
|
||||
console.log(jsonParameters);
|
||||
var count = Object.keys(jsonParameters).length;
|
||||
console.log(count);
|
||||
|
||||
// for(var k = 0; k < count; k++) {
|
||||
var obj = Object.keys(jsonParameters);
|
||||
var values = Object.values(jsonParameters);
|
||||
console.log(obj);
|
||||
for (var key in obj) {
|
||||
var value = obj[key];
|
||||
console.log(key+":"+value);
|
||||
console.log($('table#details tr#'+value.substring(0,value.indexOf("-"))).children().length );
|
||||
if(value.includes("input") && $('table#details tr#'+value.substring(0,value.indexOf("-"))).children().length == 0 ) {
|
||||
$('table#details').append('<tr id='+value.substring(0,value.indexOf("-"))+'><td><p></p><input type="text" name='+value+' class="pinfo-input"></td></tr>')
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td p').text(capitalizeFirstLetter(value.substring(0,value.indexOf("-"))));
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td p').show();
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td input').val(values[key]);
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td input').show();
|
||||
|
||||
}
|
||||
else {
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td p').text(capitalizeFirstLetter(value.substring(0,value.indexOf("-"))));
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td p').show();
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td input').val(values[key]);
|
||||
$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td input').show();
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// Resetting file input. Super dirty hack. Disgusting
|
||||
var $el = $('#datasheet-finput');
|
||||
$el.wrap('<form>').closest('form').get(0).reset();
|
||||
@@ -209,6 +298,15 @@ function show_part_info(partID) {
|
||||
$('#delete-button').off('click').on('click', function() {
|
||||
delete_entry(partID);
|
||||
});
|
||||
$('#calculate-add-button').off('click').on('click', function() {
|
||||
for (var key in obj) {
|
||||
var value = obj[key];
|
||||
console.log(key+":"+value);
|
||||
jsonParameters[obj[key]]=$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td input').val();
|
||||
|
||||
}
|
||||
calculate_entry(partID,jsonParameters);
|
||||
});
|
||||
overlay_in();
|
||||
}).fail(function() {
|
||||
console.log( "Fetching part info failed" );
|
||||
@@ -221,21 +319,24 @@ function perform_query() {
|
||||
$('#no-results').hide();
|
||||
var query = $('.search-bar').val();
|
||||
var data = {
|
||||
l:$('#location').is(':checked'),
|
||||
l:$('#type').is(':checked'),
|
||||
p:$('#partno').is(':checked'),
|
||||
d:$('#description').is(':checked')
|
||||
};
|
||||
|
||||
filter = '0';
|
||||
$("#results").find("tr:not(:first)").remove(); // Delete all table rows
|
||||
$.getJSON(rootURL + 'query/' + filter + '/' + query, data, function(data) {
|
||||
var queryPromise = $.getJSON(rootURL + 'query/' + filter + '/' + query, data, function(data) {
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
var newRow = $('<tr onclick="show_part_info(' + data[i].id + ')"></tr>');
|
||||
|
||||
newRow.append($('<td id="location"></td>').text(text_filter(data[i].location_descriptor)));
|
||||
console.log(data[i]);
|
||||
var newRow = $('<tr onclick="show_part_info(' + data[i].id + ')"></tr>');
|
||||
newRow.append($('<td id="type"></td>').text(text_filter(data[i].type_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)));
|
||||
$('#results').append(newRow);
|
||||
}
|
||||
|
||||
if(data.length == 0) {
|
||||
$('#no-results').show();
|
||||
$('#no-results').animate({opacity:1},2000);
|
||||
@@ -245,19 +346,23 @@ function perform_query() {
|
||||
$('#no-results').animate({opacity:1},2000);
|
||||
console.log( "Query failed" );
|
||||
});
|
||||
//});
|
||||
}
|
||||
|
||||
function container_onchange() {
|
||||
var selected_container_id = $('#container-dropdown').val();
|
||||
if (selected_container_id > 0) {
|
||||
$('img#map').attr('src', 'parts/map/' + selected_container_id);
|
||||
$('#location-dropdown').empty();
|
||||
$.getJSON('parts/getlocationsInContainer/' + selected_container_id, function(data) {
|
||||
$.each(data, function(location_id, location_name) {
|
||||
$('#location-dropdown').append('<option value="' + location_id + '">' + location_name + '</option>');
|
||||
var selected_container_id = $('#type-dropdown').val();
|
||||
// if (selected_container_id > 0) {
|
||||
//$('#type-dropdown').empty();
|
||||
$.getJSON('/getTypes', function(data) {
|
||||
$.each(data, function(type_id, type_name) {
|
||||
$('#type-dropdown').append('<option value="' + type_id + '">' + type_name + '</option>');
|
||||
if (data.type_id == type_id) {
|
||||
$('table#details tr#type td p').text(text_filter(type_name)); // name is the type friendly name
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
function octopartFetch(){
|
||||
@@ -282,7 +387,7 @@ $(document).ready(function() {
|
||||
active_timer = setTimeout(perform_query, 100);
|
||||
});
|
||||
$('.checkbox').change( function() {
|
||||
if ( !$('#location').is(':checked')
|
||||
if ( !$('#type').is(':checked')
|
||||
&& !$('#partno').is(':checked')
|
||||
&& !$('#description').is(':checked')
|
||||
&& !$('#has-docs').is(':checked'))
|
||||
@@ -296,4 +401,4 @@ $(document).ready(function() {
|
||||
// octopartFetch();
|
||||
// }
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
||||
+38
-3
@@ -81,6 +81,9 @@ input[type=text].search-bar {
|
||||
input[type=checkbox]{
|
||||
display: none;
|
||||
}
|
||||
input[type=range] {
|
||||
|
||||
}
|
||||
|
||||
input[type=checkbox] + label.toggle-btn {
|
||||
padding:10px 0 10px 0;
|
||||
@@ -126,6 +129,24 @@ input[type=checkbox]:checked + label.toggle-btn {
|
||||
opacity: 0.0;
|
||||
}
|
||||
|
||||
.calculateoverlay {
|
||||
background-color: #226666;
|
||||
color: #D7E2E2;
|
||||
display: none;
|
||||
height: 90%;
|
||||
padding: 0;
|
||||
position: fixed;
|
||||
margin:auto;
|
||||
left:0;
|
||||
right:0;
|
||||
top:0;
|
||||
min-width: 60%;
|
||||
width:900px;
|
||||
z-index: 201;
|
||||
text-align: center;
|
||||
opacity: 0.0;
|
||||
}
|
||||
|
||||
.round-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -171,7 +192,10 @@ input[type=checkbox]:checked + label.toggle-btn {
|
||||
.round-floating-button a{
|
||||
color: #D7E2E2;
|
||||
}
|
||||
|
||||
#calculate-button {
|
||||
right: 76px;
|
||||
margin-right: 8px
|
||||
}
|
||||
#datasheet-info p {
|
||||
font-size: 12pt;
|
||||
}
|
||||
@@ -203,7 +227,7 @@ input[type=checkbox]:checked + label.toggle-btn {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#results #location {
|
||||
#results #type {
|
||||
width: 18%;
|
||||
}
|
||||
|
||||
@@ -230,6 +254,9 @@ input[type=checkbox]:checked + label.toggle-btn {
|
||||
#details {
|
||||
width: 100%;
|
||||
}
|
||||
#results {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#magical_autofill{
|
||||
font-size: small;
|
||||
@@ -249,6 +276,14 @@ a.small_link{
|
||||
padding-top:6pt;
|
||||
padding-bottom:16pt;
|
||||
}
|
||||
.results-header {
|
||||
color: #013A3A;
|
||||
}
|
||||
|
||||
.results-content td{
|
||||
padding-top:6pt;
|
||||
padding-bottom:16pt;
|
||||
}
|
||||
|
||||
td p {
|
||||
margin: 0;
|
||||
@@ -275,4 +310,4 @@ td p {
|
||||
|
||||
.nothidden{
|
||||
display: initial !important;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user