Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept: Bulk upload #20

Open
wants to merge 7 commits into
base: gh-pages
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js"></script>
<script src="js/papaparse.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/1.7.4/i18next.min.js"></script>
</head>
<body>
Expand All @@ -35,6 +36,8 @@ <h2 data-i18n="app.title"></h2>
</div>
</div>



<div class='col12' id='address-step'>
<div class='center pad2'>
<span id='instructions' data-i18n="step1.desc"></span>
Expand All @@ -60,6 +63,18 @@ <h2 data-i18n="app.title"></h2>
</div>
</div>

<div class='col12' id='bulk-upload-count'>
</div>
<div class='col12' id='upload-step'>
<br />
<h3>Bulk Upload</h3>
<p class="prose">Need to upload multiple locations? Download and complete the <a href="template.csv">template</a>.</p>
<form onsubmit="return false">
<input type="file" id="input" />
<input type='button' onclick="read_local_file(document.getElementById('input').files[0])" value="Process" />
</form>
</div>

<div class='col12 hide' id='collect-data-step'>
<p data-i18n="[html]step2.desc"></p>
<div class='col12'>
Expand Down
6 changes: 6 additions & 0 deletions js/papaparse.min.js

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

71 changes: 67 additions & 4 deletions js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,28 @@ $(window).on('hashchange', function() {
$('#collect-data-step').removeClass('hide');
$('#address-step').addClass('hide');
$('#confirm-step').addClass('hide');
$('#upload-step').addClass('hide');
$('.steps').addClass('on-2');
$('.steps').removeClass('on-3');
} else if (location.hash == '#done') {
$('#confirm-step').removeClass('hide');
$('#collect-data-step').addClass('hide');
$('#address-step').addClass('hide');
$('#upload-step').addClass('hide');
$('.steps').addClass('on-3');
} else {
$('#address-step').removeClass('hide');
$('#collect-data-step').addClass('hide');
$('#confirm-step').addClass('hide');
$('#upload-step').addClass('hide');
$('.steps').removeClass('on-2');
$('.steps').removeClass('on-3');
}
findme_map.invalidateSize();
});

$("#collect-data-done").click(function() {
location.hash = '#done';

/** @todo Params */
function submit_note() {
var note_body = "onosm.org submitted note from a business:\n" +
"name: " + $("#name").val() + "\n" +
"phone: " + $("#phone").val() + "\n" +
Expand All @@ -129,9 +131,70 @@ $("#collect-data-done").click(function() {
text: note_body
};

$.post('https://api.openstreetmap.org/api/0.6/notes.json', qwarg);
$.post('https://api.openstreetmap.org/api/0.6/notes.json', qwarg);
}
$("#collect-data-done").click(function() {
location.hash = '#done';

submit_note();

if (locations.length > 0) {
read_next_location();
}
});

var locations = [];

function read_next_location() {
location.hash = '';
$('#bulk-upload-count').text(locations.length + " location(s) remaining to process");

var business_location = locations.pop();

console.log("Reading", business_location);

$("#address").val(business_location["Address"]);

$("#name").val(business_location["Location Name"]);
$("#phone").val(business_location["Phone Number"]);
$("#opening_hours").val(business_location["Opening Hours (“Monday to Friday 10am-5pm”)"]);
$("#website").val(business_location["Website"]);
$("#twitter").val(business_location["Twitter"]);
$("#category").val(business_location["Category"]);


$('#find').submit();
}

function read_local_file(file) {
locations = Papa.parse(file, {
delimiter: "", // auto-detect
newline: "", // auto-detect
quoteChar: '"',
header: true,
dynamicTyping: false,
preview: 0,
encoding: "",
worker: false,
comments: false,
step: undefined,
complete: function (csv) {
locations = csv.data;

console.log("Read data", locations);

read_next_location();
},
error: undefined,
download: false,
skipEmptyLines: true,
chunk: undefined,
fastMode: undefined,
beforeFirstChunk: undefined,
withCredentials: undefined
});


function clearFields() {
$("#name").val('');
$("#phone").val('');
Expand Down
3 changes: 3 additions & 0 deletions template-test-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Address,Category,Location Name,Phone Number,Website,Twitter,Opening Hours (“Monday to Friday 10am-5pm”)
"97 Pirie Street, Adelaide",Accountant,Test location,1300 600 300,http://google.com/,CloCkWeRX,24 7
"98 Pirie Street, Adelaide",American Restaurant,Test location 2,1300 600 300,http://openstreetmap.org/,OpenStreetMap,Hello world
Loading