|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
var active_timer = 100;
|
|
|
|
|
var calculation = 0;
|
|
|
|
|
|
|
|
|
|
var calculation = [];
|
|
|
|
|
function capitalizeFirstLetter(string) {
|
|
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
|
}
|
|
|
|
|
function truncator(numToTruncate, intDecimalPlaces) {
|
|
|
|
|
var numPower = Math.pow(10, intDecimalPlaces); // "numPowerConverter" might be better
|
|
|
|
|
return ~~(numToTruncate * numPower)/numPower;
|
|
|
|
|
}
|
|
|
|
|
function init_edit(partID) {
|
|
|
|
|
$('table#details tr#type td p').hide();
|
|
|
|
|
$('#type-dropdown').show();
|
|
|
|
@ -57,7 +60,30 @@ function new_entry() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function calculate() {
|
|
|
|
|
let total = 0;
|
|
|
|
|
count = Object.keys(calculation).length;
|
|
|
|
|
for(let m = 0; m < count; m++) {
|
|
|
|
|
let jsonParameters = calculation[m];
|
|
|
|
|
let obj = Object.keys(jsonParameters);
|
|
|
|
|
let values = Object.values(jsonParameters);
|
|
|
|
|
|
|
|
|
|
$.getJSON(rootURL + 'getpartinfo/' + jsonParameters["partid"], function(data) {
|
|
|
|
|
|
|
|
|
|
// $('table#calculations tr#results td p').text(data.partno+" "+jsonParameters["energy"]+" J over "+jsonParameters["period"]+" seconds");
|
|
|
|
|
// $('table#calculations tr#results td p').show();
|
|
|
|
|
total+= truncator(jsonParameters["energy"],5);
|
|
|
|
|
if($('table#calculations tr#'+jsonParameters["partid"]).length == 0) {
|
|
|
|
|
$('table#calculations').append('<tr id='+jsonParameters["partid"]+'><td><p>'+data.partno+" "+truncator(jsonParameters["energy"],5)+" J over "+jsonParameters["period"]+' seconds</p></td></tr>');
|
|
|
|
|
$('table#calculations tr#'+jsonParameters["partid"]+' td p').show();
|
|
|
|
|
}
|
|
|
|
|
$('#results td p').text("Total: "+truncator(total,5)+" J");
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculateoverlay_in();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function end_edit() {
|
|
|
|
@ -95,7 +121,7 @@ function save(partID) {
|
|
|
|
|
alert('Please select a component type.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var type_id_v = $('type-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;
|
|
|
|
@ -108,7 +134,7 @@ function save(partID) {
|
|
|
|
|
total.push(elem.value);
|
|
|
|
|
mapped[elem.name] = elem.value;
|
|
|
|
|
});
|
|
|
|
|
console.log(mapped);
|
|
|
|
|
//console.log(mapped);
|
|
|
|
|
if(partno_v.length == 0){
|
|
|
|
|
alert('Please enter a part number.');
|
|
|
|
|
return;
|
|
|
|
@ -140,7 +166,7 @@ function save(partID) {
|
|
|
|
|
data.append('type_id', type_id_v);
|
|
|
|
|
data.append('description', description_v);
|
|
|
|
|
data.append('notes', notes_v);
|
|
|
|
|
data.append('parameters', mapped);
|
|
|
|
|
data.append('parameters', JSON.stringify(mapped));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
@ -199,34 +225,55 @@ function delete_entry(partID) {
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function calculate_entry(partID,parameters) {
|
|
|
|
|
function calculate_entry(partID,jsonParameters) {
|
|
|
|
|
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);
|
|
|
|
|
if(jsonParameters != null) {
|
|
|
|
|
// 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);
|
|
|
|
|
var values = Object.values(jsonParameters);
|
|
|
|
|
var voltage = 0;
|
|
|
|
|
var activepower = 0;
|
|
|
|
|
var sleeppower = 0;
|
|
|
|
|
var single_period = 0;
|
|
|
|
|
//console.log(obj);
|
|
|
|
|
for (var key in obj) {
|
|
|
|
|
var value = obj[key];
|
|
|
|
|
console.log(key+":"+value);
|
|
|
|
|
var numbers = values[key]
|
|
|
|
|
//console.log(key+":"+value+":"+numbers);
|
|
|
|
|
if(value.includes('voltage')) {
|
|
|
|
|
voltage = values[key];
|
|
|
|
|
}
|
|
|
|
|
else if(value.includes('current')) {
|
|
|
|
|
|
|
|
|
|
if(value.includes('sleep')) {
|
|
|
|
|
sleeppower = Number(values[key]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
activepower+=Number(values[key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(value.includes('mode')) {
|
|
|
|
|
single_period=Number(values[key])+Number(single_period);
|
|
|
|
|
if(value.includes('sleep')) {
|
|
|
|
|
sleeppower=sleeppower*Number(values[key]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
activepower=activepower*Number(values[key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log("Unconfigured: "+value+":"+values[key]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
jsonParameters["energy"]=voltage*(sleeppower+activepower);
|
|
|
|
|
jsonParameters["period"]=single_period;
|
|
|
|
|
jsonParameters["partid"]=partID;
|
|
|
|
|
calculation.push(jsonParameters);
|
|
|
|
|
}
|
|
|
|
|
overlay_out();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function show_part_info(partID) {
|
|
|
|
@ -248,21 +295,15 @@ 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("-"))));
|
|
|
|
@ -301,8 +342,7 @@ function show_part_info(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();
|
|
|
|
|
jsonParameters[value]=$('table#details tr#'+value.substring(0,value.indexOf("-"))+' td input').val();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
calculate_entry(partID,jsonParameters);
|
|
|
|
@ -329,7 +369,6 @@ function perform_query() {
|
|
|
|
|
var queryPromise = $.getJSON(rootURL + 'query/' + filter + '/' + query, data, function(data) {
|
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|