Add QR-Code for API-Url/Key

This commit is contained in:
fipwmaqzufheoxq92ebc 2020-09-02 11:07:39 +02:00
parent 32a4f81f62
commit 308f10f738
No known key found for this signature in database
GPG Key ID: F4DF989490C2ADB7
6 changed files with 2331 additions and 1 deletions

View File

@ -175,3 +175,19 @@ function animateCSS(selector, animationName, callback, speed = "faster")
function RandomString() {
return Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
}
function getQRCodeForContent(url)
{
var qr = qrcode(0, 'L');
qr.addData(url);
qr.make();
return qr.createImgTag(10, 5);
}
function getQRCodeForAPIKey(apikey_type, apikey_key)
{
var content = U('/api') + '|' + apikey_key;
if(apikey_type === 'special-purpose-calendar-ical')
{
content = U('/api/calendar/ical?secret=' + apikey_key);
}
return getQRCodeForContent(content);
}

2297
public/js/qrcode.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,8 @@ $("#ical-button").on("click", function(e)
{
bootbox.alert({
title: __t('Share/Integrate calendar (iCal)'),
message: __t('Use the following (public) URL to share or integrate the calendar in iCal format') + '<input type="text" class="form-control form-control-sm mt-2 easy-link-copy-textbox" value="' + result.url + '">',
message: __t('Use the following (public) URL to share or integrate the calendar in iCal format') + '<input type="text" class="form-control form-control-sm mt-2 easy-link-copy-textbox" value="' + result.url + '">'
+ getQRCodeForContent(result.url),
closeButton: false
});
},

View File

@ -61,3 +61,11 @@ $(document).on('click', '.apikey-delete-button', function(e)
}
});
});
$('.apikey-show-qr-button').on('click', function () {
var QRhtml = getQRCodeForAPIKey( $(this).data('apikey-key'), $(this).data('apikey-type'));
bootbox.alert({
title: __t('API-Key'),
message: QRhtml,
closeButton: false
});
})

View File

@ -701,6 +701,7 @@
<script src="{{ $U('/js/grocy_wakelockhandling.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/js/grocy_nightmode.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/js/grocy_clock.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/js/qrcode.js?v=', true) }}{{ $version }}"></script>
@stack('pageScripts')
@php

View File

@ -63,6 +63,13 @@
data-apikey-apikey="{{ $apiKey->api_key }}">
<i class="fas fa-trash"></i>
</a>
<a class="btn btn-info btn-sm apikey-show-qr-button"
href="#"
data-apikey-key="{{ $apiKey->api_key }}"
data-apikey-type="{{ $apiKey->key_type }}"
>
<i class="fas fa-qrcode"></i>
</a>
</td>
<td>
{{ $apiKey->api_key }}