Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rschrenk committed Apr 1, 2022
1 parent d181550 commit e8abf0b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 70 deletions.
2 changes: 1 addition & 1 deletion amd/build/geoassist.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions amd/src/geoassist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
define(['jquery', 'core/ajax', 'core/notification', 'core/str', 'core/url', 'core/modal_factory', 'block_gps/modal_reachedlocation', 'block_gps/leaflet'], function($, AJAX, NOTIFICATION, STR, URL, ModalFactory, ModalReachedLocation) {
return {
available_cmids: [],
available_secids: [],
courseid: 0,
debug: true,
posaccuracy: 5, // round coords to this amount of digits after comma
Expand Down Expand Up @@ -46,9 +48,21 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/str', 'core/url', 'cor
if (GEOASSIST.debug) console.log('Got honeypots', GEOASSIST.honeypots);
GEOASSIST.honeypots.forEach(function(honeypot) {
if (honeypot.uservisible) {
GEOASSIST.foundcms[honeypot.cmid] = true;
if (!initializing) {
foundnewhoneypots.push(honeypot);
if (typeof honeypot.cmid !== 'undefined') {
if (!initializing && GEOASSIST.available_cmids.indexOf(honeypot.cmid) == -1) {
foundnewhoneypots.push(honeypot);
}
if (GEOASSIST.available_cmids.indexOf(honeypot.cmid) == -1) {
GEOASSIST.available_cmids.push(honeypot.cmid);
}
}
if (typeof honeypot.sectionid !== 'undefined') {
if (!initializing && GEOASSIST.available_secids.indexOf(honeypot.sectionid) == -1) {
foundnewhoneypots.push(honeypot);
}
if (GEOASSIST.available_secids.indexOf(honeypot.sectionid) == -1) {
GEOASSIST.available_secids.push(honeypot.sectionid);
}
}
}
});
Expand Down Expand Up @@ -82,14 +96,14 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/str', 'core/url', 'cor
var GEOASSIST = this;
if (this.debug) console.log('block_gps/geoassist::interval(ms)', ms);
if (ms > 0) {
$('#block_gps_interval_toggler').find('i.fa').removeClass('fa-toggle-off').addClass('fa-toggle-on');
$('.block_gps_interval_toggler').find('i.fa').removeClass('fa-toggle-off').addClass('fa-toggle-on');
clearInterval(this.locateinterval);
this.locateinterval = setInterval(function() { GEOASSIST.locate(); }, ms);
this.locateintervalrunning = true;
// We ask for permission immediately.
navigator.geolocation.getCurrentPosition(function() {});
} else if (typeof(this.locateinterval) !== 'undefined') {
$('#block_gps_interval_toggler').find('i.fa').removeClass('fa-toggle-on').addClass('fa-toggle-off');
$('.block_gps_interval_toggler').find('i.fa').removeClass('fa-toggle-on').addClass('fa-toggle-off');
clearInterval(this.locateinterval);
this.locateinterval = null;
this.locateintervalrunning = false;
Expand Down Expand Up @@ -230,8 +244,13 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/str', 'core/url', 'cor
}
).fail(NOTIFICATION.exception);
}

GEOASSIST.lasttrackedposition = position;
},
function(error) {
NOTIFICATION.alert(
'Error ' + error.code,
error.message
);
}
);
} else {
Expand Down
1 change: 1 addition & 0 deletions classes/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public static function get_honeypots($courseid, $onlycheck = false) {
$condition->sectionid = $section->id;
$condition->sectionno = $section->section;
$condition->url = (new \moodle_url('/course/view.php', [ 'id' => $section->course], 'section-' . $section->section))->__toString();
$condition->uservisible = $section->uservisible;
$condition->visible = $section->visible;
$honeypots[] = $condition;
}
Expand Down
3 changes: 2 additions & 1 deletion templates/block.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
</a>
</div>
<div>
<a href="#" id="block_gps_interval_toggler" onclick="require(['block_gps/geoassist'], function(G) { G.intervalToggle(); }); return false;" class="btn" style="width: 100%;">
<a href="#" onclick="require(['block_gps/geoassist'], function(G) { G.intervalToggle(); }); return false;"
class="btn block_gps_interval_toggler" style="width: 100%;">
{{^setinterval}}
<i class="fa fa-toggle-off" style="font-size: 35px;"></i><br />
{{/setinterval}}
Expand Down
Loading

0 comments on commit e8abf0b

Please sign in to comment.