mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Merge pull request #2951 from SchrodingersGat/barcode-webcam-setting
Adds global setting to enable or disable webcam support for barcodes
This commit is contained in:
		@@ -842,6 +842,13 @@ class InvenTreeSetting(BaseInvenTreeSetting):
 | 
				
			|||||||
            'validator': bool,
 | 
					            'validator': bool,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        'BARCODE_WEBCAM_SUPPORT': {
 | 
				
			||||||
 | 
					            'name': _('Barcode Webcam Support'),
 | 
				
			||||||
 | 
					            'description': _('Allow barcode scanning via webcam in browser'),
 | 
				
			||||||
 | 
					            'default': True,
 | 
				
			||||||
 | 
					            'validator': bool,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        'PART_IPN_REGEX': {
 | 
					        'PART_IPN_REGEX': {
 | 
				
			||||||
            'name': _('IPN Regex'),
 | 
					            'name': _('IPN Regex'),
 | 
				
			||||||
            'description': _('Regular expression pattern for matching Part IPN')
 | 
					            'description': _('Regular expression pattern for matching Part IPN')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,11 +91,23 @@ class TemplateTagTest(TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def test_global_settings(self):
 | 
					    def test_global_settings(self):
 | 
				
			||||||
        result = inventree_extras.global_settings()
 | 
					        result = inventree_extras.global_settings()
 | 
				
			||||||
        self.assertEqual(len(result), 61)
 | 
					        self.assertEqual(len(result), len(InvenTreeSetting.SETTINGS))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_visible_global_settings(self):
 | 
					    def test_visible_global_settings(self):
 | 
				
			||||||
        result = inventree_extras.visible_global_settings()
 | 
					        result = inventree_extras.visible_global_settings()
 | 
				
			||||||
        self.assertEqual(len(result), 60)
 | 
					
 | 
				
			||||||
 | 
					        n = len(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        n_hidden = 0
 | 
				
			||||||
 | 
					        n_visible = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for val in InvenTreeSetting.SETTINGS.values():
 | 
				
			||||||
 | 
					            if val.get('hidden', False):
 | 
				
			||||||
 | 
					                n_hidden += 1
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                n_visible += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertEqual(n, n_visible)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PartTest(TestCase):
 | 
					class PartTest(TestCase):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@
 | 
				
			|||||||
<table class='table table-striped table-condensed'>
 | 
					<table class='table table-striped table-condensed'>
 | 
				
			||||||
    <tbody>
 | 
					    <tbody>
 | 
				
			||||||
        {% include "InvenTree/settings/setting.html" with key="BARCODE_ENABLE" icon="fa-qrcode" %}
 | 
					        {% include "InvenTree/settings/setting.html" with key="BARCODE_ENABLE" icon="fa-qrcode" %}
 | 
				
			||||||
 | 
					        {% include "InvenTree/settings/setting.html" with key="BARCODE_WEBCAM_SUPPORT" icon="fa-video" %}
 | 
				
			||||||
    </tbody>
 | 
					    </tbody>
 | 
				
			||||||
</table>
 | 
					</table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,7 +70,7 @@ function onBarcodeScanClicked(e) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function onCameraAvailable(hasCamera, options) {
 | 
					function onCameraAvailable(hasCamera, options) {
 | 
				
			||||||
    if ( hasCamera == true ) {
 | 
					    if (hasCamera && global_settings.BARCODE_WEBCAM_SUPPORT) {
 | 
				
			||||||
        // Camera is only acccessible if page is served over secure connection
 | 
					        // Camera is only acccessible if page is served over secure connection
 | 
				
			||||||
        if ( window.isSecureContext == true ) {
 | 
					        if ( window.isSecureContext == true ) {
 | 
				
			||||||
            qrScanner = new QrScanner(document.getElementById('barcode_scan_video'), (result) => {
 | 
					            qrScanner = new QrScanner(document.getElementById('barcode_scan_video'), (result) => {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user