Skip to content

Commit

Permalink
feat: support additional barcode types (fix #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
l4rm4nd committed Jan 10, 2025
1 parent 11b6e33 commit 1ed0e55
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 63 deletions.
Binary file modified locale/de/LC_MESSAGES/django.mo
Binary file not shown.
5 changes: 4 additions & 1 deletion locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3705,4 +3705,7 @@ msgid "coupon"
msgstr "Coupon"

msgid "Threshold"
msgstr "Schwellenwert"
msgstr "Schwellenwert"

msgid "Code Type"
msgstr "Code Typ"
Binary file modified locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3702,3 +3702,6 @@ msgstr "Valeur"

msgid "Threshold"
msgstr "Seuil"

msgid "Code Type"
msgstr "Code type"
Binary file modified locale/it/LC_MESSAGES/django.mo
Binary file not shown.
5 changes: 4 additions & 1 deletion locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3692,4 +3692,7 @@ msgid "coupon"
msgstr "coupon"

msgid "Threshold"
msgstr "Soglia"
msgstr "Soglia"

msgid "Code Type"
msgstr "Codice tipo"
2 changes: 1 addition & 1 deletion myapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ItemForm(forms.ModelForm):

class Meta:
model = Item
fields = ['name', 'issuer', 'redeem_code', 'pin', 'issue_date', 'expiry_date', 'description', 'logo_slug', 'type', 'value', 'value_type', 'file']
fields = ['name', 'issuer', 'redeem_code', 'pin', 'issue_date', 'expiry_date', 'description', 'logo_slug', 'type', 'value', 'value_type', 'file', 'code_type']
widgets = {
'issue_date': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
'expiry_date': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
Expand Down
18 changes: 18 additions & 0 deletions myapp/migrations/0014_item_code_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.3 on 2025-01-10 13:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('myapp', '0013_alter_appsettings_options'),
]

operations = [
migrations.AddField(
model_name='item',
name='code_type',
field=models.CharField(default='qrcode', max_length=50),
),
]
1 change: 1 addition & 0 deletions myapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Item(models.Model):
type = models.CharField(max_length=50, choices=ITEM_TYPES)
name = models.CharField(max_length=255)
redeem_code = models.CharField(max_length=50)
code_type = models.CharField(default="qrcode", max_length=50)
pin = models.CharField(max_length=10, blank=True, null=True)
issuer = models.CharField(max_length=50)
issue_date = models.DateField(default=timezone.now)
Expand Down
28 changes: 27 additions & 1 deletion myapp/static/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1327,4 +1327,30 @@ input.readonly {
.dashboard-loyalty .card-body h6
{
color: rgb(48, 47, 47);
}
}

/* Overlay create item */
.loading-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
z-index: 9999;
display: none;
justify-content: center;
align-items: center;
text-align: center;
color: white;
font-size: 20px;
}
@keyframes breathe {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.breathe-red {
animation: breathe 1s infinite;
color: red;
}
43 changes: 43 additions & 0 deletions myapp/static/assets/js/scanner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const redeemCodeField = document.getElementById('redeem_code');
const redeemTypeField = document.getElementById('code_type');
const startScannerButton = document.getElementById('startScanner');
const qrScannerSection = document.getElementById('qrScannerSection');
const video = document.getElementById('video');
Expand All @@ -11,10 +12,52 @@ const codeReader = new ZXing.BrowserMultiFormatReader();
loadingMessage.style.display = 'none'; // Initially hide the loading message
outputMessage.style.display = 'none'; // Initially hide the output message

const barcodeFormats = [
"AZTEC",
"CODABAR",
"CODE_39",
"CODE_93",
"CODE_128",
"DATA_MATRIX",
"EAN_8",
"EAN_13",
"ITF",
"MAXICODE",
"PDF_417",
"QR_CODE",
"RSS_14",
"RSS_EXPANDED",
"UPC_A",
"UPC_E",
"UPC_EAN_EXTENSION"
];

const barcodeFormatMap = {
"AZTEC": "datamatrix", // Assuming you want to use the same for Aztec, adjust if needed
"CODABAR": "code39", // Codabar is not specifically listed in your options; mapped to closest available
"CODE_39": "code39",
"CODE_93": "code39", // Code 93 is not specifically listed; mapped to closest available
"CODE_128": "code128",
"DATA_MATRIX": "datamatrix",
"EAN_8": "ean8",
"EAN_13": "ean13",
"ITF": "code39", // Interleaved Two of Five; mapped to closest available if specific mapping required
"MAXICODE": "datamatrix", // MaxiCode is not specifically listed; mapped to closest available
"PDF_417": "pdf417",
"QR_CODE": "qrcode",
"RSS_14": "ean13", // RSS-14 closely related to EAN/UPC
"RSS_EXPANDED": "ean13", // RSS Expanded closely related to EAN/UPC
"UPC_A": "upca",
"UPC_E": "upce",
"UPC_EAN_EXTENSION": "ean13" // Extension of EAN
};

function startScanning() {
codeReader.decodeFromVideoDevice(null, 'video', (result, err) => {
if (result) {
redeemCodeField.value = result.text;
const formatValue = barcodeFormatMap[barcodeFormats[result.format]]; // Use the new mapping
redeemTypeField.value = formatValue;
redeemCodeField.focus();
stopStream();
}
Expand Down
50 changes: 38 additions & 12 deletions myapp/templates/create-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

{% block content %}

<div id="loadingOverlay" class="loading-overlay">
<div>Redeem code type checking in progress...</div>
</div>

{% if form.errors %}
<div id="errors" class="alert alert-danger mt-2">
<ul>
{% for field, errors in form.errors.items %}
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endif %}

<div class="pagetitle">
<h1>{% trans "Create New Item" %}</h1>
<nav>
Expand Down Expand Up @@ -79,6 +95,25 @@ <h5 class="card-title">{% trans "Item Details" %}</h5>
</div>
</div>
</div>
<div class="row mb-3">
<label for="code_type" class="col-sm-2 col-form-label">{% trans "Code Type" %}</label>
<div class="col-sm-10">
<select class="form-control" id="code_type" name="code_type" required>
<option value="qrcode">QR Code</option>
<option value="ean13">EAN-13</option>
<option value="ean8">EAN-8</option>
<option value="code128">Code 128</option>
<option value="code39">Code 39</option>
<option value="upca">UPC-A</option>
<option value="upce">UPC-E</option>
<option value="isbn13">ISBN-13</option>
<option value="isbn10">ISBN-10</option>
<option value="issn">ISSN</option>
<option value="pdf417">PDF417</option>
<option value="datamatrix">Data Matrix</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="pin" class="col-sm-2 col-form-label">{% trans "PIN Code" %}</label>
<div class="col-sm-10">
Expand Down Expand Up @@ -139,21 +174,10 @@ <h5 class="card-title">{% trans "Item Details" %}</h5>
</div>
<div class="row mb-3">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-primary">{% trans "Create Item" %}</button>
<button type="submit" onclick="document.getElementById('loadingOverlay').style.display = 'flex';" class="btn btn-primary">{% trans "Create Item" %}</button>
</div>
</div>
</form><!-- End Item Form -->
{% if form.errors %}
<div class="alert alert-danger mt-2">
<ul>
{% for field, errors in form.errors.items %}
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down Expand Up @@ -183,7 +207,9 @@ <h5 class="card-title">{% trans "Item Details" %}</h5>
<script src="{% static 'assets/js/scanner.js' %}"></script>

<script>

document.addEventListener("DOMContentLoaded", function () {

const typeField = document.getElementById('type');
const pinField = document.getElementById('pin');
const valueField = document.getElementById('value');
Expand Down
52 changes: 37 additions & 15 deletions myapp/templates/edit-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
{% load extras %}
{% block content %}

<div id="loadingOverlay" class="loading-overlay">
<div>Redeem code type checking in progress...</div>
</div>

{% if form.errors %}
<div id="errors" class="alert alert-danger mt-2">
<ul>
{% for field, errors in form.errors.items %}
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endif %}

<div class="pagetitle">
<h1>{% trans "Edit Item" %}</h1>
<nav>
Expand Down Expand Up @@ -70,6 +86,25 @@ <h5 class="card-title">{% trans "Item Details" %}</h5>
</div>
</div>
</div>
<div class="row mb-3">
<label for="code_type" class="col-sm-2 col-form-label">{% trans "Code Type" %}</label>
<div class="col-sm-10">
<select class="form-control" id="code_type" name="code_type" required>
<option value="qrcode">QR Code</option>
<option value="ean13">EAN-13</option>
<option value="ean8">EAN-8</option>
<option value="code128">Code 128</option>
<option value="code39">Code 39</option>
<option value="upca">UPC-A</option>
<option value="upce">UPC-E</option>
<option value="isbn13">ISBN-13</option>
<option value="isbn10">ISBN-10</option>
<option value="issn">ISSN</option>
<option value="pdf417">PDF417</option>
<option value="datamatrix">Data Matrix</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="redeem_code" class="col-sm-2 col-form-label">{% trans "PIN Code" %}</label>
<div class="col-sm-10">
Expand Down Expand Up @@ -124,24 +159,10 @@ <h5 class="card-title">{% trans "Item Details" %}</h5>
</div>
<div class="row mb-3">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-primary">{% trans "Update Item" %}</button>
<button type="submit" onclick="document.getElementById('loadingOverlay').style.display = 'flex';" class="btn btn-primary">{% trans "Update Item" %}</button>
</div>
</div>
</form><!-- End Item Form -->
{% if form.errors %}
<div class="alert alert-danger mt-2">
<ul>
{% for error in form.non_field_errors %}
<li>{{ error }}</li>
{% endfor %}
{% for field, errors in form.errors.items %}
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down Expand Up @@ -172,6 +193,7 @@ <h5 class="card-title">{% trans "Item Details" %}</h5>

<script>
document.addEventListener("DOMContentLoaded", function() {

const typeField = document.getElementById('type');
const pinField = document.getElementById('pin');
const valueField = document.getElementById('value');
Expand Down
Loading

0 comments on commit 1ed0e55

Please sign in to comment.