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

Simplified import #55

Merged
merged 4 commits into from
Dec 8, 2023
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
26 changes: 11 additions & 15 deletions inventree_kicad/KiCadLibraryPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"""
import datetime
import json

from django.core.validators import URLValidator

Expand Down Expand Up @@ -162,6 +161,17 @@ def import_meta_data(self, request): # noqa
if request.FILES.get('file', False):
file = request.FILES.get('file', False)

kicad_footprint_param_id = self.plugin.get_setting('KICAD_SYMBOL_PARAMETER', None)
kicad_reference_param_id = self.plugin.get_setting('KICAD_SYMBOL_PARAMETER', None)
kicad_symbol_param_id = self.plugin.get_setting('KICAD_SYMBOL_PARAMETER', None)

if kicad_footprint_param_id is None or kicad_reference_param_id is None or kicad_symbol_param_id is None:
return JsonResponse(
{
'error': 'Missing parameters. Please make sure you have selected appropriate parameters in the settings before attempting to import anything.'
},
status=422)

# Make sure we have got a xml file
if 'xml' not in file.content_type:
return JsonResponse({'error': 'XML file expected!'}, status=422)
Expand All @@ -174,20 +184,6 @@ def import_meta_data(self, request): # noqa
components = root.find('components')
inventree_parts = set()

# create dict from selection
field_name_matching = json.loads(request.POST['fieldNameMatching'])

# user needs to match all KiCad Parameter
if 'false' in field_name_matching.values():
return JsonResponse(
{'error': 'Some KiCad Parameters were not matched with an InvenTree parameter.'},
status=406
)

kicad_footprint_param_id = field_name_matching['Footprint']
kicad_reference_param_id = field_name_matching['Reference']
kicad_symbol_param_id = field_name_matching['Symbol']

# Iterate through all child components with the tag 'comp'
for idx, comp in enumerate(components.findall('comp')):

Expand Down
43 changes: 4 additions & 39 deletions inventree_kicad/templates/inventree_kicad/kicad_bom_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@
<script>
async function upload_csv() {
var formData = new FormData();
var fieldNameMatching = {};

$('#tblFieldMatching tr[id^="kicad_"]').each(function () {

let selectedIndex = this.cells[1].children[0].selectedIndex;
let selectedVal = this.cells[1].children[0].options[selectedIndex].value

fieldNameMatching[this.cells[0].getAttribute("value")] = selectedVal

});

formData.append("fieldNameMatching", JSON.stringify(fieldNameMatching)) // Matches those that begin with 'tcol'
formData.append("file", fileupload.files[0]);

const cmd_url = "{% url 'plugin:kicad-library-plugin:meta_data_upload' %}"
Expand All @@ -31,7 +20,7 @@

}

async function extract_header() {
async function submit_button_controller() {
$('#upload-form').on('change', function (evt) {

if (evt.target.files == null) {
Expand Down Expand Up @@ -86,35 +75,11 @@ <h4>KiCad Metadata Import</h4>
<div class="mb-3">
<label for="formFile" class="form-label">Please select an XML file</label>
<input class="form-control" accept=".xml" type="file" id="fileupload" name="fileupload"
onchange="extract_header()">
onchange="submit_button_controller()">
</div>

<table class="table table-condensed" id="tblFieldMatching">
<tbody>
<tr>
<th>KiCad Parameter</th>
<th>Available InvenTree Parameter</th>
</tr>

{% for ki_para in kicad_parameters %}
<tr id="kicad_{{ forloop.counter0 }}">
<td value="{{ ki_para }}"><em>{{ ki_para }}</em></td>
<td>
<select class="select form-control" name="parameters">
<option value=false>-----</option>
{% for template in part_parameter_templates %}
<option value="{{ template.id }}">{{ template.name }}</option>
{% endfor %}
</select>
</td>
</tr>
{% endfor %}

</tbody>
</table>

</form>

<button type="submit" class="btn btn-primary" onclick="upload_csv()" title='Import' id="btn_import" disabled>Import
Data
<button type="submit" class="btn btn-primary" onclick="upload_csv()" title='Import' id="btn_import" disabled>
Import Metadata
</button>
2 changes: 1 addition & 1 deletion inventree_kicad/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
KICAD_PLUGIN_VERSION = "1.3.7"
KICAD_PLUGIN_VERSION = "1.3.8"