mirror of
https://github.com/gavanfantom/jlc-chart.git
synced 2026-07-16 21:10:53 +01:00
Add jlc-chart app
This commit is contained in:
97
jlcchart/templates/bom.html
Normal file
97
jlcchart/templates/bom.html
Normal file
@@ -0,0 +1,97 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>JLCPCB stock query: BOM</title>
|
||||
<style>
|
||||
table, th, td {
|
||||
border: 1px solid #ddd;
|
||||
border-collapse: collapse;
|
||||
padding: 8px;
|
||||
}
|
||||
th {
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
background-color: #04AA6D;
|
||||
color: white;
|
||||
}
|
||||
tr:nth-child(even) {background-color: #f2f2f2;}
|
||||
tr:hover {background-color: #ddd;}
|
||||
.error {
|
||||
background-color: #ff0000;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function add_to_db(code, id) {
|
||||
fetch('{{ url_for('bom.add') }}', {
|
||||
method:'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
'code': code
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return Promise.reject("Request failed")
|
||||
} else {
|
||||
return response.json()
|
||||
}
|
||||
})
|
||||
.then(data => {
|
||||
if (data.id) {
|
||||
document.getElementById(id).innerHTML = data.id;
|
||||
update_link();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
document.getElementById(id).innerHTML = '<div class="error">FAIL</div>';
|
||||
console.error('Error', error);
|
||||
});
|
||||
}
|
||||
function update_link() {
|
||||
var rows = {{table|length}};
|
||||
var id_col = {{headings|length}};
|
||||
var idlist = [];
|
||||
for (let i = 1; i <= rows; i++) {
|
||||
if (document.getElementById('select_' + i).checked) {
|
||||
var id = document.getElementById('td_' + i + '_' + id_col).innerHTML;
|
||||
if (!isNaN(id)) {
|
||||
idlist.push(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
var url = '{{ url_for('components.components', components='') }}' + idlist.join('+');
|
||||
document.getElementById('graphlink').href = url;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
{% for item in headings -%}
|
||||
<th>{{ item }}</th>
|
||||
{% endfor -%}
|
||||
<th>View</th>
|
||||
</tr>
|
||||
{% for row in table -%}
|
||||
{% set rowloop = loop -%}
|
||||
<tr>
|
||||
{% for item in row -%}
|
||||
{% if loop.last and item == '' -%}
|
||||
<td id="td_{{rowloop.index}}_{{loop.index}}"><button onclick="add_to_db('{{loop.previtem}}', 'td_{{rowloop.index}}_{{loop.index}}')">Fetch data</button></td>
|
||||
{% else -%}
|
||||
<td id="td_{{rowloop.index}}_{{loop.index}}">{{ item }}</td>
|
||||
{% endif -%}
|
||||
{% endfor -%}
|
||||
<td><input type="checkbox" id="select_{{rowloop.index}}" checked=checked onclick="update_link()"></td>
|
||||
</tr>
|
||||
{% endfor -%}
|
||||
</table>
|
||||
<p/>
|
||||
<center><h1><a id='graphlink' href='{{ url_for('components.components', components='') }}{{table | map('last') | select('number') | join('+') }}'>See the graphs!</a></h1></center>
|
||||
</body>
|
||||
</html>
|
||||
25
jlcchart/templates/bom_form.html
Normal file
25
jlcchart/templates/bom_form.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>JLCPCB stock query</title>
|
||||
<style>
|
||||
textarea
|
||||
{
|
||||
width: 98%;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div align="center">
|
||||
<h1>Paste your BOM here</h1>
|
||||
<textarea name="bom" rows="50" form="bomform" placeholder="Paste your CSV file here"></textarea>
|
||||
<p/>
|
||||
<form action="{{ url_for('bom.bom') }}" id="bomform" method="POST">
|
||||
<input type="submit" value="Submit BOM">
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
65
jlcchart/templates/component.html
Normal file
65
jlcchart/templates/component.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>JLCPCB stock graphs</title>
|
||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.min.js'></script>
|
||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js'></script>
|
||||
<script src='https://cdnjs.cloudflare.com/ajax/libs/chartjs-adapter-moment/1.0.0/chartjs-adapter-moment.min.js'></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!--- <center> -->
|
||||
|
||||
{% for component in components %}
|
||||
<canvas id="chart_{{component.id}}" width="600" height="400" style="display: inline;"></canvas>
|
||||
{% endfor %}
|
||||
<script>
|
||||
{% for component in components %}
|
||||
var chart_{{component.id}} = document.getElementById("chart_{{component.id}}").getContext("2d");
|
||||
var LineChart_{{component.id}} = new Chart(chart_{{component.id}}, {
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets : [{
|
||||
label: '# in stock',
|
||||
data : [
|
||||
{% for item in component.data %}
|
||||
{ x: '{{ item.timestamp }}', y: '{{item.value}}' },
|
||||
{% endfor %}]
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
time: {
|
||||
unit: 'day'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
},
|
||||
responsive: false,
|
||||
backgroundColor: "rgba(57, 204, 96, 0.7)",
|
||||
borderColor: "rgba(57, 204, 96, 1)",
|
||||
elements: {
|
||||
point: {
|
||||
pointBackgroundColor: "rgba(36, 128, 61, 0.7)",
|
||||
pointBorderColor: "rgba(36, 128, 61, 1)",
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
title: {
|
||||
display: true,
|
||||
text: ' {{ component.code }} : {{ component.name }} ',
|
||||
position: 'bottom'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
{% endfor %}
|
||||
</script>
|
||||
<!--- </center> -->
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user