Skip to content
Open
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
77 changes: 77 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
version = 1

[[analyzers]]
name = "docker"
enabled = true

[[analyzers]]
name = "go"
enabled = true

[analyzers.meta]
import_root = "github.com/Watemlifts/internet_monitor"

[[analyzers]]
name = "php"
enabled = true

[[analyzers]]
name = "csharp"
enabled = true

[[analyzers]]
name = "ruby"
enabled = true

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"

[[analyzers]]
name = "javascript"
enabled = true

[analyzers.meta]
plugins = [
"react",
"angularjs"
]

[[analyzers]]
name = "shell"
enabled = true

[[analyzers]]
name = "test-coverage"
enabled = true

[[transformers]]
name = "gofumpt"
enabled = true

[[transformers]]
name = "php-cs-fixer"
enabled = true

[[transformers]]
name = "dotnet-format"
enabled = true

[[transformers]]
name = "rubocop"
enabled = true

[[transformers]]
name = "standardrb"
enabled = true

[[transformers]]
name = "autopep8"
enabled = true

[[transformers]]
name = "standardjs"
enabled = true
142 changes: 68 additions & 74 deletions public/cache_thumbs.js
Original file line number Diff line number Diff line change
@@ -1,155 +1,149 @@
$( function () {
if ( $( '#cacheThumbs' ).length ) {
var map = $( '#cacheThumbs' ).geomap( {
$(function () {
if ($('#cacheThumbs').length) {
const map = $('#cacheThumbs').geomap({
tilingScheme: null,
bboxMax: [-180, -85, 180, 85],
services: [
{
id: 'map-countries-service',
type: 'shingled',
src: ""
src: ''
}
],
center: [ 0, 20 ],
center: [0, 20],
zoom: 2,
zoomMin: 0,
mode: 'static',
shapeStyle: {
height: 0,
width: 0
}
} );
})


var mapCountriesService = $( '#map-countries-service' ).geomap( 'option', 'shapeStyle', {
const mapCountriesService = $('#map-countries-service').geomap('option', 'shapeStyle', {
color: '#ccc',
fillOpacity: 1,
stroke: '#fefefe',
strokeWidth: '2px'
} );
})
/*
color: '#366936',
fillOpacity: 1,
strokeOpacity: 0
*/

// map countries from server
var mapCountries = {
const mapCountries = {
length: 0
};
}

var features = null;
var bboxen = null
let features = null
let bboxen = null

$.each( map.data( 'mapCountries' ), function( ) {
mapCountries[ this.iso3_code ] = this;
mapCountries.length++;
} );
$.each(map.data('mapCountries'), function () {
mapCountries[this.iso3_code] = this
mapCountries.length++
})

// grab the world countries file
$.getJSON('/world-countries.json', function (result) {

// append them to the map
features = result.features;
$( 'progress' ).attr( 'max', features.length );

$.each( features, function( ) {
mapCountriesService.geomap('append', this, null, false);
} );
features = result.features
$('progress').attr('max', features.length)

map.geomap('refresh');
$.each(features, function () {
mapCountriesService.geomap('append', this, null, false)
})

map.geomap('refresh')

$.getJSON( '/country_bbox.json', function( result ) {
bboxen = result;
cacheThumb();
} );
});
$.getJSON('/country_bbox.json', function (result) {
bboxen = result
cacheThumb()
})
})

var cacheIdx = 0;
var feature = null;
var country = null;
let cacheIdx = 0
let feature = null
let country = null

function cacheThumb( ) {
feature = $.extend( {}, features[ cacheIdx ] );
country = mapCountries[ feature.id ];
function cacheThumb () {
feature = $.extend({}, features[cacheIdx])
country = mapCountries[feature.id]

if ( country ) {
if (country) {
mapCountriesService.geomap('append', feature, {
color: '#5ec1a5',
fillOpacity: 1,
stroke: '#fefefe',
strokeWidth: '2px'
}, false);
map.geomap( 'option', 'bbox', bboxen[ feature.id ] );
setTimeout( storeImage, 2000 );
}, false)
map.geomap('option', 'bbox', bboxen[feature.id])
setTimeout(storeImage, 2000)
} else {
console.log( 'missing country for ' + feature.id );
cacheIdx++;
$( 'progress' ).prop( 'value', cacheIdx );
cacheIdx++
$('progress').prop('value', cacheIdx)

if ( cacheIdx < features.length ) {
setTimeout( cacheThumb, 32 );
if (cacheIdx < features.length) {
setTimeout(cacheThumb, 32)
}
}
}

function storeImage() {
var dataUrl = $( '#map-countries-service img' ).prop( 'src' );
function storeImage () {
const dataUrl = $('#map-countries-service img').prop('src')

if ( dataUrl ) {
$( '#thumb' ).prop( 'src', dataUrl );
$( '#imgSrc' ).text( dataUrl );
if (dataUrl) {
$('#thumb').prop('src', dataUrl)
$('#imgSrc').text(dataUrl)

var file = dataURLtoBlob( dataUrl );
const file = dataURLtoBlob(dataUrl)

if ( file !== null ) {
var fd = new FormData();
if (file !== null) {
const fd = new FormData()

fd.append( 'country[thumb]', file );
fd.append('country[thumb]', file)

$.ajax( {
$.ajax({
url: '/countries/' + country.id,
type: 'PUT',
data: fd,
processData: false,
contentType: false
} );
})
}
} else {
console.log( 'cannot create dataURL for ' + feature.id );

}

mapCountriesService.geomap('remove', feature);
mapCountriesService.geomap('remove', feature)

cacheIdx++;
$( 'progress' ).prop( 'value', cacheIdx );
cacheIdx++
$('progress').prop('value', cacheIdx)

if ( cacheIdx < features.length ) {
cacheThumb();
if (cacheIdx < features.length) {
cacheThumb()
}
}

// Convert dataURL to Blob object
function dataURLtoBlob(dataURL) {
function dataURLtoBlob (dataURL) {
try {
// Decode the dataURL
var binary = atob(dataURL.split(',')[1]);
const binary = atob(dataURL.split(',')[1])

// Create 8-bit unsigned array
var array = [];
for(var i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
const array = []
for (let i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i))
}

// Return our Blob object
return new Blob([new Uint8Array(array)], {type: 'image/png'});
} catch ( ex ) {
console.log( 'error creating image for ' + feature.id );
return new Blob([new Uint8Array(array)], { type: 'image/png' })
} catch (ex) {
console.log('error creating image for ' + feature.id)
}
return null;
return null
}

}

} );
})