Skip to content

Commit

Permalink
Fix Config subpage scrollbar issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Feb 9, 2022
1 parent 5941be3 commit 22df21b
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 108 deletions.
105 changes: 58 additions & 47 deletions config/js/datasets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Datasets = {
csv: null,
init: function() {
init: function () {
// prettier-ignore
var markup = [
"<div class='datasets'>",
Expand Down Expand Up @@ -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) {
Expand All @@ -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.");
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -141,59 +144,67 @@ 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();
$(".datasetRecreate a")
.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;
Expand All @@ -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(
Expand All @@ -224,11 +235,11 @@ var Datasets = {
"</div></li>"
);
}
}
},
});
}
},
};

$(document).ready(function() {
$(document).ready(function () {
Datasets.init();
});
105 changes: 57 additions & 48 deletions config/js/geodatasets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var Geodatasets = {
geojson: null,
init: function() {
init: function () {
// prettier-ignore
var markup = [
"<div class='geodatasets'>",
Expand Down Expand Up @@ -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
Expand All @@ -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
);
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -164,11 +173,11 @@ var Geodatasets = {
"</div></li>"
);
}
}
},
});
}
},
};

$(document).ready(function() {
$(document).ready(function () {
Geodatasets.init();
});
Loading

0 comments on commit 22df21b

Please sign in to comment.