diff --git a/config/js/datasets.js b/config/js/datasets.js index 4bfd6654..feffdee8 100644 --- a/config/js/datasets.js +++ b/config/js/datasets.js @@ -1,6 +1,6 @@ var Datasets = { csv: null, - init: function() { + init: function () { // prettier-ignore var markup = [ "
", @@ -33,24 +33,24 @@ var Datasets = { Datasets.refreshNames(); //Upload - $(".container_datasets #datasetUploadButton > input").on("change", function( - evt - ) { - var files = evt.target.files; // FileList object + $(".container_datasets #datasetUploadButton > input").on( + "change", + function (evt) { + var files = evt.target.files; // FileList object - // use the 1st file from the list - var f = files[0]; - var ext = Datasets.getExtension(f.name).toLowerCase(); + // use the 1st file from the list + var f = files[0]; + var ext = Datasets.getExtension(f.name).toLowerCase(); - $(".container_datasets .datasetName input").val( - f.name - .split("." + ext)[0] - .replace(/[`~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "") - ); + $(".container_datasets .datasetName input").val( + f.name + .split("." + ext)[0] + .replace(/[`~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "") + ); - switch (ext) { - case "csv": - /* + switch (ext) { + case "csv": + /* var reader = new FileReader(); // Closure to capture the file information. reader.onload = (function(file) { @@ -62,16 +62,19 @@ var Datasets = { reader.readAsText(f); */ - Datasets.f = f; - $(".container_datasets .datasetUploadFilename").text(Datasets.f.name); - break; - default: - alert("Only .csv files may be uploaded."); + Datasets.f = f; + $(".container_datasets .datasetUploadFilename").text( + Datasets.f.name + ); + break; + default: + alert("Only .csv files may be uploaded."); + } } - }); + ); //Re/create - $(".container_datasets .datasetRecreate > a").on("click", function(evt) { + $(".container_datasets .datasetRecreate > a").on("click", function (evt) { let name = $(".datasetName input").val(); if (Datasets.f == null) { alert("Please upload a .csv file."); @@ -90,7 +93,7 @@ var Datasets = { let cursorSum = 0; let cursorStep = null; Papa.parse(Datasets.f, { - step: function(row, parser) { + step: function (row, parser) { if (firstStep) { header = row.data; firstStep = false; @@ -117,22 +120,22 @@ var Datasets = { name: name, csv: JSON.stringify(currentRows), header: header, - mode: first ? "full" : "append" + mode: first ? "full" : "append", }, - success: function(data) { + success: function (data) { first = false; currentRows = []; parser.resume(); }, - error: function(err) { + error: function (err) { currentRows = []; console.log(err); - } + }, }); } } }, - complete: function() { + complete: function () { if (currentRows.length > 0) { $.ajax({ type: calls.datasets_recreate.type, @@ -141,18 +144,18 @@ var Datasets = { name: name, csv: JSON.stringify(currentRows), header: header, - mode: "append" + mode: "append", }, - success: function(data) { + success: function (data) { Datasets.refreshNames(); $(".datasetRecreate a") .css("pointer-events", "inherit") .text("Re/create"); }, - error: function(err) { + error: function (err) { currentRows = []; console.log(err); - } + }, }); } else { Datasets.refreshNames(); @@ -160,40 +163,48 @@ var Datasets = { .css("pointer-events", "inherit") .text("Re/create"); } - } + }, }); }); }, - make: function() { + make: function () { $(".container_datasets").css({ opacity: 1, - pointerEvents: "inherit" + pointerEvents: "inherit", + display: "block", }); Keys.destroy(); Geodatasets.destroy(); Webhooks.destroy(); $("#missions li.active").removeClass("active"); + $(".container").css({ + display: "none", + }); }, - destroy: function() { + destroy: function () { $(".container_datasets").css({ opacity: 0, - pointerEvents: "none" + pointerEvents: "none", + display: "none", + }); + $(".container").css({ + display: "block", }); }, - getExtension: function(string) { + getExtension: function (string) { var ex = /(?:\.([^.]+))?$/.exec(string)[1]; return ex || ""; }, - sortArrayOfObjectsByKeyValue: function(arr, key, ascending, stringify) { + sortArrayOfObjectsByKeyValue: function (arr, key, ascending, stringify) { if (arr.constructor !== Array) return arr; const side = ascending ? 1 : -1; - let compareKey = function(a, b) { + let compareKey = function (a, b) { if (a[key] < b[key]) return -1 * side; if (a[key] > b[key]) return side; return 0; }; if (stringify) { - compareKey = function(a, b) { + compareKey = function (a, b) { if (JSON.stringify(a[key]) < JSON.stringify(b[key])) return -1 * side; if (JSON.stringify(a[key]) > JSON.stringify(b[key])) return side; return 0; @@ -202,12 +213,12 @@ var Datasets = { return arr.sort(compareKey); }, - refreshNames: function() { + refreshNames: function () { $.ajax({ type: calls.datasets_entries.type, url: calls.datasets_entries.url, data: {}, - success: function(data) { + success: function (data) { if (data.status == "success") { $(".container_datasets .existing ul").html(""); let entries = Datasets.sortArrayOfObjectsByKeyValue( @@ -224,11 +235,11 @@ var Datasets = { "
" ); } - } + }, }); - } + }, }; -$(document).ready(function() { +$(document).ready(function () { Datasets.init(); }); diff --git a/config/js/geodatasets.js b/config/js/geodatasets.js index 9bc07385..01a5f1d0 100644 --- a/config/js/geodatasets.js +++ b/config/js/geodatasets.js @@ -1,6 +1,6 @@ var Geodatasets = { geojson: null, - init: function() { + init: function () { // prettier-ignore var markup = [ "
", @@ -35,7 +35,7 @@ var Geodatasets = { //Upload $(".container_geodatasets #geodatasetUploadButton > input").on( "change", - function(evt) { + function (evt) { var files = evt.target.files; // FileList object // use the 1st file from the list @@ -53,8 +53,8 @@ var Geodatasets = { case "geojson": var reader = new FileReader(); // Closure to capture the file information. - reader.onload = (function(file) { - return function(e) { + reader.onload = (function (file) { + return function (e) { $(".container_geodatasets .geodatasetUploadFilename").text( file.name ); @@ -71,69 +71,78 @@ var Geodatasets = { ); //Re/create - $(".container_geodatasets .geodatasetRecreate > a").on("click", function( - evt - ) { - let name = $(".geodatasetName input").val(); - if (Geodatasets.geojson == null) { - alert("Please upload a .geojson file."); - return; - } - if (name == null) { - alert("Please enter a name."); - return; - } - - $.ajax({ - type: calls.geodatasets_recreate.type, - url: calls.geodatasets_recreate.url, - data: { - name: name, - geojson: Geodatasets.geojson - }, - success: function(data) { - Geodatasets.refreshNames(); - $.ajax({ - type: calls.geodatasets_get.type, - url: calls.geodatasets_get.url + "?layer=" + name, - success: function(data) { - console.log(data); - } - }); + $(".container_geodatasets .geodatasetRecreate > a").on( + "click", + function (evt) { + let name = $(".geodatasetName input").val(); + if (Geodatasets.geojson == null) { + alert("Please upload a .geojson file."); + return; } - }); - }); + if (name == null) { + alert("Please enter a name."); + return; + } + + $.ajax({ + type: calls.geodatasets_recreate.type, + url: calls.geodatasets_recreate.url, + data: { + name: name, + geojson: Geodatasets.geojson, + }, + success: function (data) { + Geodatasets.refreshNames(); + $.ajax({ + type: calls.geodatasets_get.type, + url: calls.geodatasets_get.url + "?layer=" + name, + success: function (data) { + console.log(data); + }, + }); + }, + }); + } + ); }, - make: function() { + make: function () { $(".container_geodatasets").css({ opacity: 1, - pointerEvents: "inherit" + pointerEvents: "inherit", + display: "block", }); Keys.destroy(); Datasets.destroy(); Webhooks.destroy(); $("#missions li.active").removeClass("active"); + $(".container").css({ + display: "none", + }); }, - destroy: function() { + destroy: function () { $(".container_geodatasets").css({ opacity: 0, - pointerEvents: "none" + pointerEvents: "none", + display: "none", + }); + $(".container").css({ + display: "block", }); }, - getExtension: function(string) { + getExtension: function (string) { var ex = /(?:\.([^.]+))?$/.exec(string)[1]; return ex || ""; }, - sortArrayOfObjectsByKeyValue: function(arr, key, ascending, stringify) { + sortArrayOfObjectsByKeyValue: function (arr, key, ascending, stringify) { if (arr.constructor !== Array) return arr; const side = ascending ? 1 : -1; - let compareKey = function(a, b) { + let compareKey = function (a, b) { if (a[key] < b[key]) return -1 * side; if (a[key] > b[key]) return side; return 0; }; if (stringify) { - compareKey = function(a, b) { + compareKey = function (a, b) { if (JSON.stringify(a[key]) < JSON.stringify(b[key])) return -1 * side; if (JSON.stringify(a[key]) > JSON.stringify(b[key])) return side; return 0; @@ -142,12 +151,12 @@ var Geodatasets = { return arr.sort(compareKey); }, - refreshNames: function() { + refreshNames: function () { $.ajax({ type: calls.geodatasets_entries.type, url: calls.geodatasets_entries.url, data: {}, - success: function(data) { + success: function (data) { if (data.status == "success") { $(".container_geodatasets .existing ul").html(""); let entries = Geodatasets.sortArrayOfObjectsByKeyValue( @@ -164,11 +173,11 @@ var Geodatasets = { "
" ); } - } + }, }); - } + }, }; -$(document).ready(function() { +$(document).ready(function () { Geodatasets.init(); }); diff --git a/config/js/keys.js b/config/js/keys.js index 58c81c3a..7641abcb 100644 --- a/config/js/keys.js +++ b/config/js/keys.js @@ -1,6 +1,6 @@ var Keys = { token: null, - init: function() { + init: function () { // prettier-ignore var markup = [ "
", @@ -47,45 +47,53 @@ var Keys = { $(".keys select").material_select(); - $(".keys_generate").on("click", function() { + $(".keys_generate").on("click", function () { $.ajax({ type: calls.longtermtoken_generate.type, url: calls.longtermtoken_generate.url, data: { - period: $("select.keys_generation_period").val() + period: $("select.keys_generation_period").val(), }, - success: function(data) { + success: function (data) { if (data.status === "success") { Keys.token = data.body.token; $("#keys_token").text(Keys.token); $("#keys_examples span").text(Keys.token); } }, - error: function(err) { + error: function (err) { Keys.token = null; console.log(err); - } + }, }); }); - $("#keys_token_copy").on("click", function() { + $("#keys_token_copy").on("click", function () { Keys.copyToClipboard(Keys.token); }); }, - make: function() { + make: function () { $(".container_keys").css({ opacity: 1, - pointerEvents: "inherit" + pointerEvents: "inherit", + display: "block", }); Geodatasets.destroy(); Datasets.destroy(); Webhooks.destroy(); $("#missions li.active").removeClass("active"); + $(".container").css({ + display: "none", + }); }, - destroy: function() { + destroy: function () { $(".container_keys").css({ opacity: 0, - pointerEvents: "none" + pointerEvents: "none", + display: "none", + }); + $(".container").css({ + display: "block", }); }, copyToClipboard(text) { @@ -107,9 +115,9 @@ var Keys = { document.getSelection().removeAllRanges(); // Unselect everything on the HTML document document.getSelection().addRange(selected); // Restore the original selection } - } + }, }; -$(document).ready(function() { +$(document).ready(function () { Keys.init(); }); diff --git a/config/js/webhooks.js b/config/js/webhooks.js index cd0e253c..df9da27d 100644 --- a/config/js/webhooks.js +++ b/config/js/webhooks.js @@ -41,16 +41,24 @@ var Webhooks = { $(".container_webhooks").css({ opacity: 1, pointerEvents: "inherit", + display: "block", }); Keys.destroy(); Datasets.destroy(); Geodatasets.destroy(); $("#missions li.active").removeClass("active"); + $(".container").css({ + display: "none", + }); }, destroy: function () { $(".container_webhooks").css({ opacity: 0, pointerEvents: "none", + display: "none", + }); + $(".container").css({ + display: "block", }); }, refreshNames: function () {