Skip to content

Commit

Permalink
new version: support more than 1 location per community, working on f…
Browse files Browse the repository at this point in the history
  • Loading branch information
andibraeu committed Feb 26, 2021
1 parent beab5c4 commit a19bfdf
Show file tree
Hide file tree
Showing 7 changed files with 889 additions and 35 deletions.
3 changes: 2 additions & 1 deletion generator/config.json.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apiVersion" : "0.4.14",
"defaultMapCenter" : [51, 10]
"defaultMapCenter" : [51, 10],
"mapboxKey": "example key"
}
4 changes: 2 additions & 2 deletions generator/ffapi.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
height: 20px;
}

#map {
.location-map {
height : 300px;
margin-left : 0;
}
}
14 changes: 7 additions & 7 deletions generator/ffapi.formTemplate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var ffapi = {};
ffapi.formTemplate =
ffapi.formTemplate =
[
"name",
"url", {
Expand Down Expand Up @@ -71,7 +71,8 @@ ffapi.formTemplate =
"title": "Location Details",
"expandable": true,
"items": [
"location.address"
"location.address",
"location.additionalLocations"
]
}, {
"type": "fieldset",
Expand Down Expand Up @@ -140,7 +141,7 @@ ffapi.formTemplate =
"techDetails.firmware.name",
"techDetails.firmware.url",
"techDetails.firmware.docs", {
"key" : "techDetails.firmware.vpnaccess",
"key" : "techDetails.firmware.vpnaccess",
"enum" : ["", "automatic", "fwimage", "mail", "webform", "else"],
"titleMap" : {
"automatic" : "Automatic Deployment",
Expand Down Expand Up @@ -182,7 +183,7 @@ ffapi.formTemplate =
"OLSR": "OLSR",
"OLSRv2": "OLSRv2"
}

}, {
"key": "techDetails.updatemode",
"type": "checkboxes",
Expand All @@ -191,12 +192,12 @@ ffapi.formTemplate =
"manual": "Manual updates supported (e.g. via web interface)",
"autoupdate": "We provide automatic updates"
}
}
}
]
}, {
"type": "fieldset",
"title": "Legal Issues",
"items": [
"items": [
{
"key": "techDetails.legals",
"type": "checkboxes",
Expand Down Expand Up @@ -228,4 +229,3 @@ ffapi.formTemplate =
"title": "OK - generate the full API file!"
}
];

60 changes: 37 additions & 23 deletions generator/ffapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ $.getJSON("config.json", function(config) {
$( '.autohide' ).hide();

// ---

var sanitizeOldVersions = function(schema) {
var message = "Due to updates in our specs, some fields changed and aren't backwards compatible. Please update the following details:\n";
var counter = 0;

// if schema updates aren't backwards compatible you can try to correct it right here...

if (counter > 0) {
alert(message);
}
return schema;
};

// ---

var takeJson =
Expand All @@ -37,7 +37,8 @@ $.getJSON("config.json", function(config) {
console.error( "JSON Syntax Error" );
return;
}
addMapPickerToLocation();
addMapPickerToLocation();
addMapPickerToAdditionalLocations();
};

// ---
Expand All @@ -57,7 +58,7 @@ $.getJSON("config.json", function(config) {

// ---

var dirSelect =
var dirSelect =
function() {
$( '#dirselect' ).append($('<option>').text('choose a community from list'));
var protocol = window.location.origin.split(':')[0] + ':';
Expand All @@ -75,7 +76,7 @@ $.getJSON("config.json", function(config) {
} else {
console.error("Could not load community directory: ", url);
}
});
});
};

// ---
Expand All @@ -95,8 +96,8 @@ $.getJSON("config.json", function(config) {
var errorText = 'Unfortunately there are ' + errors.length + ' errors in your file validated against our API version ' + config.apiVersion + ': <ul>';
$.each( errors, function(key, val) {
var path = val.uri.match(/.*#\/(.*$)/);
if (RegExp.$1 == "api") {
errorText += '<li>' + RegExp.$1 + ' (don\'t care about, we\'ll update it on submit)</li>';
if (RegExp.$1 == "api") {
errorText += '<li>' + RegExp.$1 + ' (don\'t care about, we\'ll update it on submit)</li>';
} else {
errorText += '<li>' + RegExp.$1 + '</li>';
}
Expand All @@ -113,7 +114,7 @@ $.getJSON("config.json", function(config) {

// ---

var validate =
var validate =
function() {
takeJson();
//var JSV = require("./JSV").JSV;
Expand All @@ -135,7 +136,7 @@ $.getJSON("config.json", function(config) {
$( '#result .message' ).show().text( 'Congrats! Your API file is valid to version ' + config.apiVersion + ' of our specs. We just updated the version and the date of change.' );
var date = new Date();
currentSchema.value.api = config.apiVersion;
currentSchema.value.state.lastchange = date.toISOString();
currentSchema.value.state.lastchange = date.toISOString();
$( '#downloadButton' ).removeAttr('disabled');
$( '#downloadButton' ).attr('title', 'Download the JSON contents');
$( '#validateButton' ).attr('title', 'There are little problems, but your API file is valid');
Expand Down Expand Up @@ -176,7 +177,7 @@ $.getJSON("config.json", function(config) {
$( '#result .message' ).show().text( 'Hello ' + values.name + '. This is your API file. Place it on a public webserver and add the URL to our directory.' );
var date = new Date();
values.api = config.apiVersion;
values.state.lastchange = date.toISOString();
values.state.lastchange = date.toISOString();
$( '#jsonText' ).val( JSON.stringify( values, null, ' ' ) );
$( 'body' ).scrollTop( 0 );
}
Expand Down Expand Up @@ -226,21 +227,34 @@ $.getJSON("config.json", function(config) {
}

function addMapPickerToLocation() {
var latInput = $('input[name="location.lat"]');
var lngInput = $('input[name="location.lon"]');
var latInput = $('input[name="location.lat"]');
var lngInput = $('input[name="location.lon"]');
addMapPickerToInput(latInput, lngInput);
}

function addMapPickerToAdditionalLocations() {
$.each($('.jsonform-error-location---additionalLocations li'), function(index, element) {
var idx = $(element).data('idx');
var latInput = $('input[name="location.additionalLocations[' + idx + '].lat"]')
var lngInput = $('input[name="location.additionalLocations[' + idx + '].lon"]');
addMapPickerToInput(latInput, lngInput, idx);
});
}

function addMapPickerToInput(latInput, lngInput, idx = 'main') {

$(("<div id=\"map\" class=\"span6\"></div>")).insertAfter(lngInput.parent(".controls"));
$(("<div id=\"map" + idx + "\" class=\"span6 location-map\"></div>")).insertAfter(lngInput.parent(".controls"));

var map = L.map('map');
var map = L.map('map' + idx);

L.tileLayer('https://{s}.tiles.mapbox.com/v3/freienetzwerke.i2lgkb76/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-i875mjb7',
noWrap : true
}).addTo(map);
var mapboxLayer = L.tileLayer('https://api.mapbox.com/styles/v1/freienetzwerke/ckatogpoebrsz1io160d3e80i/tiles/{z}/{x}/{y}?access_token=' + config.mapboxKey, {
maxZoom: 18,
attribution: '© <a href="https://apps.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
//tileSize: 512,
zoomOffset: -1,
id: 'examples.map-i875mjb7',
noWrap : true
}).addTo(map);

var updateMarker = function() {
marker
Expand Down
Loading

0 comments on commit a19bfdf

Please sign in to comment.